Skip to content

Commit a58841c

Browse files
committed
Use dedicated binary dirs for presets
Using dedicated directories allows the developer to have multiple builds existing at the same time in the `build` directory, so normal builds, coverage and sanitizer builds can all coexist by default.
1 parent c5578fd commit a58841c

File tree

5 files changed

+28
-23
lines changed

5 files changed

+28
-23
lines changed

cmake-init/__main__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ def print_tips(d):
211211
in that order:
212212
213213
cmake --preset=dev
214-
cmake --build build{config} -j {cpus}
215-
cmake --install build{config} --prefix prefix
216-
ctest --test-dir build{test_cfg} -j {cpus} --output-on-failure
214+
cmake --build build/dev{config} -j {cpus}
215+
cmake --install build/dev{config} --prefix prefix
216+
ctest --test-dir build/dev{test_cfg} -j {cpus} --output-on-failure
217217
""")
218218
extra = [" docs - build the documentation using Doxygen and m.css"]
219219
if d["examples"]:
@@ -231,7 +231,7 @@ def print_tips(d):
231231
These targets are only available in developer mode, because they are generally
232232
not useful for consumers. You can run these targets with the following command:
233233
234-
cmake --build build{config} -t <target>
234+
cmake --build build/dev{config} -t <target>
235235
""")
236236

237237

cmake-init/templates/common/.github/workflows/ci.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,18 @@ jobs:
3131
run: cmake --preset=ci-coverage
3232

3333
- name: Build
34-
run: cmake --build build -j 2
34+
run: cmake --build build/coverage -j 2
3535

3636
- name: Test
37-
working-directory: build
37+
working-directory: build/coverage
3838
env:
3939
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
4040
PS4: "\e[36m+++\e[0m "
4141
run: |
4242
set -x
4343
ctest --output-on-failure -j 2
44-
lcov -c -d .. -o coverage.info --include '${{ github.workspace }}/*'
44+
lcov -c -d '${{ github.workspace }}' -o coverage.info \
45+
--include '${{ github.workspace }}/*'
4546
lcov --list coverage.info
4647
bash <(curl -s https://codecov.io/bash) -f coverage.info
4748
@@ -56,7 +57,7 @@ jobs:
5657
run: cmake --preset=ci-sanitize
5758

5859
- name: Build
59-
run: cmake --build build -j 2
60+
run: cmake --build build/sanitize -j 2
6061

6162
- name: Test
6263
env:
@@ -66,7 +67,7 @@ jobs:
6667
strict_init_order=1:\
6768
detect_leaks=1"
6869
UBSAN_OPTIONS: print_stacktrace=1
69-
run: ctest --test-dir build --output-on-failure -j 2
70+
run: ctest --test-dir build/sanitize --output-on-failure -j 2
7071

7172
test:
7273
strategy:

cmake-init/templates/common/CMakePresets.json

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,25 @@
4242
"CMAKE_CXX_FLAGS": "/W4 /permissive- /EHsc /volatile:iso /Zc:__cplusplus /Zc:throwingNew"
4343
}
4444
},
45-
{
46-
"name": "ci-build",
47-
"binaryDir": "${sourceDir}/build",
48-
"hidden": true
49-
},
5045
{
5146
"name": "ci-unix",
5247
"generator": "Unix Makefiles",
5348
"hidden": true,
54-
"inherits": ["flags-unix", "ci-build"],
49+
"inherits": "flags-unix",
5550
"cacheVariables": {
5651
"CMAKE_BUILD_TYPE": "Release"
5752
}
5853
},
5954
{
6055
"name": "ci-win64",
61-
"inherits": ["flags-windows", "ci-build"],
56+
"inherits": "flags-windows",
6257
"generator": "Visual Studio 16 2019",
6358
"architecture": "x64",
6459
"hidden": true
6560
},
6661
{
6762
"name": "ci-coverage",
63+
"binaryDir": "${sourceDir}/build/coverage",
6864
"inherits": ["ci-unix", "dev-mode"],
6965
"cacheVariables": {
7066
"CMAKE_BUILD_TYPE": "Coverage",
@@ -75,23 +71,29 @@
7571
},
7672
{
7773
"name": "ci-sanitize",
74+
"binaryDir": "${sourceDir}/build/sanitize",
7875
"inherits": ["ci-unix", "dev-mode"],
7976
"cacheVariables": {
8077
"CMAKE_BUILD_TYPE": "Sanitize",
8178
"CMAKE_CXX_FLAGS_SANITIZE": "-O2 -g -fsanitize=address,undefined -fno-omit-frame-pointer -fno-common"
8279
}
8380
},
81+
{
82+
"name": "ci-build",
83+
"binaryDir": "${sourceDir}/build",
84+
"hidden": true
85+
},
8486
{
8587
"name": "ci-macos",
86-
"inherits": ["ci-unix", "dev-mode"]
88+
"inherits": ["ci-build", "ci-unix", "dev-mode"]
8789
},
8890
{
8991
"name": "ci-ubuntu",
90-
"inherits": ["ci-unix", "clang-tidy", "cppcheck", "dev-mode"]
92+
"inherits": ["ci-build", "ci-unix", "clang-tidy", "cppcheck", "dev-mode"]
9193
},
9294
{
9395
"name": "ci-windows",
94-
"inherits": ["ci-win64", "dev-mode"]
96+
"inherits": ["ci-build", "ci-win64", "dev-mode"]
9597
}
9698
]
9799
}

cmake-init/templates/common/CMakeUserPresets.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"configurePresets": [
99
{
1010
"name": "dev",
11+
"binaryDir": "${sourceDir}/build/dev",
1112
"inherits": ["dev-mode", "ci-%(os)s"{if use_clang_tidy}, "clang-tidy"{end}{if use_cppcheck}, "cppcheck"{end}],
1213
"cacheVariables": {
1314
"BUILD_DOCUMENTATION": "ON"

cmake-init/templates/common/HACKING.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ the project:
4040
"configurePresets": [
4141
{
4242
"name": "dev",
43+
"binaryDir": "${sourceDir}/build/dev",
4344
"inherits": ["dev-mode", "ci-<os>"]
4445
}
4546
]
@@ -62,16 +63,16 @@ Windows:
6263

6364
```sh
6465
cmake --preset=dev
65-
cmake --build build --config Release
66-
ctest --test-dir build -C Release
66+
cmake --build build/dev --config Release
67+
ctest --test-dir build/dev -C Release
6768
```
6869

6970
And here is the same on a Unix based system (Linux, macOS):
7071

7172
```sh
7273
cmake --preset=dev
73-
cmake --build build
74-
ctest --test-dir build
74+
cmake --build build/dev
75+
ctest --test-dir build/dev
7576
```
7677

7778
[1]: https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html

0 commit comments

Comments
 (0)