Skip to content

Commit 32f45d5

Browse files
committed
Add comments to CMake stuff
1 parent 79365d8 commit 32f45d5

3 files changed

Lines changed: 36 additions & 10 deletions

File tree

build/CMake/CMakeLists.txt

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,34 @@ print_message("-------------------- COMPUTER SCIENCE --------------------")
2525
project(computer-science
2626
VERSION 1.0
2727
DESCRIPTION "Computer Science (c) 2023-2025 Dmitry Savchenkov"
28+
HOMEPAGE_URL "https://github.com/dvsav/computer-science"
2829
LANGUAGES CXX)
2930

30-
# Require at least C++17
31-
set(CMAKE_CXX_STANDARD 17) # Sets the desired C++ standard (e.g., 17 for C++17).
32-
set(CMAKE_CXX_STANDARD_REQUIRED ON) # Ensures the compiler must support the specified standard, not an older one.
33-
set(CMAKE_CXX_EXTENSIONS OFF) # Optional: disables compiler-specific extensions like GNU++17
34-
35-
# the repository's root is two folders higher than this CMakeLists file
31+
# # Sets the required C++ standard (C++17 in our case) across all of the targets in this CMakeLists file
32+
# Sets the desired C++ standard (e.g., 17 for C++17)
33+
# (https://cmake.org/cmake/help/latest/variable/CMAKE_CXX_STANDARD.html#cmake-cxx-standard).
34+
set(CMAKE_CXX_STANDARD 17)
35+
# Ensures the compiler must support the specified standard, not an older one
36+
# (https://cmake.org/cmake/help/latest/prop_tgt/CXX_STANDARD_REQUIRED.html).
37+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
38+
# Optional: disables compiler-specific extensions like GNU++17
39+
# (https://cmake.org/cmake/help/latest/variable/CMAKE_CXX_EXTENSIONS.html#cmake-cxx-extensions)
40+
set(CMAKE_CXX_EXTENSIONS OFF)
41+
42+
# Alternatively we could have set the required C++ standard for a particular build target
43+
# target_compile_features(${PROJECT_NAME} PUBLIC c_std_17)
44+
45+
# Store the paths to some interesting directories in variables
46+
# (the repository's root is two folders higher than this CMakeLists file)
3647
set(ROOT_DIR "${PROJECT_SOURCE_DIR}/../..")
3748
set(SRC_DIR "${ROOT_DIR}/src")
3849
set(TEST_DIR "${ROOT_DIR}/test")
3950

40-
# collect the source and header files
51+
# Collect the source and header files.
52+
# Without CONFIGURE_DEPENDS CMake doesn't rerun file globbing procedure during build time (cmake --build),
53+
# So without CONFIGURE_DEPENDS you need to manually regenerate (cmake -B) whenever you add any new source files
54+
# (https://cmake.org/cmake/help/latest/command/file.html).
55+
# Note that we are collecting both source and header files to be able to see them, for example, in Visual Studio project explorer.
4156
file(GLOB SOURCE_FILES CONFIGURE_DEPENDS
4257
"${SRC_DIR}/*.cpp"
4358
"${SRC_DIR}/*.h")
@@ -46,7 +61,7 @@ foreach (file ${SOURCE_FILES})
4661
print_message("source file = ${file}")
4762
endforeach()
4863

49-
# defines the executable file name (target) and its dependencies
64+
# Defines a build target - the executable file and its dependencies (the source files collected above)
5065
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
5166

5267
if (VISUAL_STUDIO)

cmake.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
#!/bin/bash
22

33
SCRIPT_DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
4+
5+
# Source directory is the directory containing the CMakeLsists.txt script
46
SOURSE_DIR=$SCRIPT_DIR/build/CMake
7+
# Build directory is going to contain project files generated by CMake.
58
BUILD_DIR=$SOURSE_DIR/gnumake
69

10+
# Create the build directory if it doesn't already exist.
711
mkdir -p $BUILD_DIR
12+
# Generate project files
813
cmake -S $SOURSE_DIR -B $BUILD_DIR
914

15+
# Build the targets defined in the project files
1016
cmake --build $BUILD_DIR --config Debug
1117

18+
# Run tests
1219
cd $BUILD_DIR && \
1320
ctest -C Debug --output-on-failure

make.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#!/bin/bash
22

33
SCRIPT_DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
4-
BLD_DIR="${SCRIPT_DIR}/build/GNUMake"
54

5+
# Build directory contains the Makefile script for GNU Make build utility
6+
BUILD_DIR="${SCRIPT_DIR}/build/GNUMake"
7+
8+
# Build the targets defined in the Makefile
9+
# passing any command line arguments to GNU Make via $@
610
echo "make $@"
7-
make -C "$BLD_DIR" $@
11+
make -C "$BUILD_DIR" $@

0 commit comments

Comments
 (0)