Skip to content

Commit

Permalink
Merge pull request #3 from daixtrose/add-toplevel-cmake
Browse files Browse the repository at this point in the history
Add toplevel CMake file
  • Loading branch information
daixtrose authored Jul 3, 2024
2 parents 8ec9223 + cff764f commit 53def92
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@
*.app

build_*/*
.vscode/*
.vscode/*
build/*
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.29)

project(cplusplus-primer)

include(ExternalProject)

foreach(subproject example_1 example_2 example_3 example_4 library_1)
ExternalProject_Add(${subproject}
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/${subproject}
STEP_TARGETS build
INSTALL_COMMAND ""
)
endforeach()
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ A short introduction to C++. The examples build on top of each other. A special
- Use for testing small C++ code snippets
- [Craig Scott: "Professional CMake"](https://crascit.com/professional-cmake/)
- The one and only book you need about build systems
- [HSF - More Modern CMake](https://hsf-training.github.io/hsf-training-cmake-webpage/index.html)

## List of Subprojects

Expand Down
2 changes: 1 addition & 1 deletion example_2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ add_executable(example_2
# add_subdirectory(../library_1 ../build_library_1)
# but be aware of parallel builds!
# In general, keep builds separate. KISS principle!
add_subdirectory(../library_1 build_library_1)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../library_1 build_library_1)

target_link_libraries(
${PROJECT_NAME}
Expand Down
7 changes: 6 additions & 1 deletion example_3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ include(FetchContent)
# since the code for every dependency is stored on disk exactly once.
FetchContent_Declare(
library_1
SOURCE_DIR ../library_1

# Quote from Craig Scott, "Professional CMake":
# CMAKE_CURRENT_SOURCE_DIR is the directory of the CMakeLists.txt file currently being
# processed by CMake. It is updated each time a new file is processed as a result of an
# add_subdirectory() call and is restored back again when processing of that directory is complete.
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../library_1
)

FetchContent_MakeAvailable(library_1)
Expand Down
2 changes: 1 addition & 1 deletion example_4/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ include(FetchContent)
# since the code for every dependency is stored on disk exactly once.
FetchContent_Declare(
library_1
SOURCE_DIR ../library_1
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../library_1
)

FetchContent_MakeAvailable(library_1)
Expand Down
4 changes: 2 additions & 2 deletions example_4/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Here we illustrate recommended ways to use `cmake` in a **portable way**. See [t
Create a subdirectory `build_example_4` and prepare the build system for the source in `example_4` in this subdirectory:

```bash
cmake -D CMAKE_BUILD_TYPE=Release -B build_example_4 -S example_4
cmake -D CMAKE_BUILD_TYPE=Release -B build_example_4 -S example_4 --fresh
# for debug builds use
# cmake -D CMAKE_BUILD_TYPE=Debug -B build_example_4 -S example_4
```
Expand All @@ -133,7 +133,7 @@ cmake -D CMAKE_BUILD_TYPE=Release -B build_example_4 -S example_4
Call `cmake` from the top level like this:

```bash
cmake --build build_example_4 --config Release --target example_4
cmake --build build_example_4 --config Release --target example_4 --clean-first
```

### Creating release packages
Expand Down

0 comments on commit 53def92

Please sign in to comment.