Skip to content

Commit a01406f

Browse files
committed
Use presets version 2
Presets version 2 requires CMake 3.20. This commit allows users with VSCode to comfortably use the generated projects with the "CMake Tools" extension out of the box. Hints printed after project generation and generated documentation have been adjusted to use the new capabilities of the presets, which results in simpler workflow for developers regardless of what build system or operating system they use. The CI workflows or the checked in presets file have not been further adjusted, because the additional build and test presets aren't as useful there. The workflows are already deduplicated and serve as a sort of preset on their own. Users may add their own if that better suits their tastes. Fixes #34
1 parent ba0076b commit a01406f

File tree

5 files changed

+54
-20
lines changed

5 files changed

+54
-20
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ libraries! (Part 2)](https://www.youtube.com/watch?v=_5weX5mx8hc)
6767
Make sure you have these programs installed:
6868

6969
* Python 3.8 or newer
70-
* CMake 3.19 or newer
70+
* CMake 3.20 or newer
7171
* git
7272
* [clang-tidy](#clang-tidy) (optional)
7373
* [cppcheck](#cppcheck) (optional)

cmake-init/cmake_init.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ def ask(*args, **kwargs):
166166
"c_header": False,
167167
"include_source": False,
168168
"has_source": True,
169+
"cpus": os.cpu_count(),
169170
}
170171
d["uc_name"] = d["name"].upper().replace("-", "_")
171172
if d["type_id"] != "e":
@@ -268,17 +269,15 @@ def git_init(cwd):
268269

269270
def print_tips(d):
270271
config = " --config Debug" if is_windows else ""
271-
test_cfg = " -C Debug" if is_windows else ""
272-
cpus = os.cpu_count()
273272
print(f"""\
274273
To get you started with the project in developer mode, you may configure,
275274
build, install and test with the following commands from the project directory,
276275
in that order:
277276
278277
cmake --preset=dev
279-
cmake --build build/dev{config} -j {cpus}
278+
cmake --build --preset=dev
280279
cmake --install build/dev{config} --prefix prefix
281-
cd build/dev && ctest{test_cfg} -j {cpus} --output-on-failure
280+
ctest --preset=dev
282281
""")
283282
extra = [" docs - build the documentation using Doxygen and m.css"]
284283
if d["c_examples"] or d["cpp_examples"]:
@@ -296,7 +295,7 @@ def print_tips(d):
296295
These targets are only available in developer mode, because they are generally
297296
not useful for consumers. You can run these targets with the following command:
298297
299-
cmake --build build/dev{config} -t <target>
298+
cmake --build --preset=dev -t <target>
300299
""")
301300

302301

@@ -330,7 +329,7 @@ def create(args, zip):
330329
git_init(path)
331330
print_tips(d)
332331
print("""\
333-
Now make sure you have at least CMake 3.19 installed for local development, to
332+
Now make sure you have at least CMake 3.20 installed for local development, to
334333
make use of all the nice Quality-of-Life improvements in newer releases:
335334
https://cmake.org/download/
336335

cmake-init/templates/common/CMakePresets.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": 1,
2+
"version": 2,
33
"cmakeMinimumRequired": {
44
"major": 3,
55
"minor": 14,

cmake-init/templates/common/CMakeUserPresets.json

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": 1,
2+
"version": 2,
33
"cmakeMinimumRequired": {
44
"major": 3,
55
"minor": 14,
@@ -37,5 +37,26 @@
3737
"binaryDir": "${sourceDir}/build/coverage",
3838
"inherits": ["dev-mode", "coverage-unix"]
3939
}
40+
],
41+
"buildPresets": [
42+
{
43+
"name": "dev",
44+
"configurePreset": "dev",
45+
"configuration": "Debug",
46+
"jobs": %(cpus)s
47+
}
48+
],
49+
"testPresets": [
50+
{
51+
"name": "dev",
52+
"configurePreset": "dev",
53+
"configuration": "Debug",
54+
"output": {
55+
"outputOnFailure": true
56+
},
57+
"execution": {
58+
"jobs": %(cpus)s
59+
}
60+
}
4061
]
4162
}

cmake-init/templates/common/HACKING.md

+25-11
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ the project:
3131

3232
```json
3333
{
34-
"version": 1,
34+
"version": 2,
3535
"cmakeMinimumRequired": {
3636
"major": 3,
3737
"minor": 14,
@@ -46,6 +46,23 @@ the project:
4646
"CMAKE_BUILD_TYPE": "Debug"
4747
}
4848
}
49+
],
50+
"buildPresets": [
51+
{
52+
"name": "dev",
53+
"configurePreset": "dev",
54+
"configuration": "Debug"
55+
}
56+
],
57+
"testPresets": [
58+
{
59+
"name": "dev",
60+
"configurePreset": "dev",
61+
"configuration": "Debug",
62+
"output": {
63+
"outputOnFailure": true
64+
}
65+
}
4966
]
5067
}
5168
```
@@ -62,21 +79,18 @@ in the terminal.
6279

6380
If you followed the above instructions, then you can configure, build and test
6481
the project respectively with the following commands from the project root on
65-
Windows:
82+
any operating system with any build system:
6683

6784
```sh
6885
cmake --preset=dev
69-
cmake --build build/dev --config Debug
70-
cd build/dev && ctest -C Debug
86+
cmake --build --preset=dev
87+
ctest --preset=dev
7188
```
7289

73-
And here is the same on a Unix based system (Linux, macOS):
74-
75-
```sh
76-
cmake --preset=dev
77-
cmake --build build/dev
78-
cd build/dev && ctest
79-
```
90+
Please note that both the build and test command accepts a `-j` flag to specify
91+
the number of jobs to use, which should ideally be specified to the number of
92+
threads your CPU has. You may also want to add that to your preset using the
93+
`jobs` property, see the [presets documentation][1] for more details.
8094

8195
[1]: https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html
8296
[2]: https://cmake.org/download/

0 commit comments

Comments
 (0)