Git+CMake: Add support for CMake presets.

CMake 3.19 added support for CMakePresets.json and
CMakeUserPresets.json, which let you prepopulate various configure,
build, and test options. Add CMakeUserPresets.json to .gitignore as
recommended by the documentation and add an example to the Developer's
Guide. CMake uses 2-space indentation; specify that for CMake*.json in
.editorconfig.
pespin/osmux-wip
Gerald Combs 2022-06-03 13:47:41 -07:00
parent c0bd7266ad
commit 2ac2b0670a
3 changed files with 28 additions and 4 deletions

View File

@ -20,6 +20,9 @@ insert_final_newline = true
# https://gitlab.kitware.com/cmake/cmake/-/blob/master/.editorconfig
[{CMake*,*.cmake,*.cmake.in}]
indent_style = tab
[CMake*.json]
indent_style = space
indent_size = 2
# Makefiles. Although we dropped Autotools we still have a few lying around.
[Makefile*]

2
.gitignore vendored
View File

@ -60,7 +60,7 @@ wireshark-tap-register.c
/*build*/
CMakeCache.txt
CMakeFiles
CMakeListsCustom.txt
CMakeUserPresets.json
cmake_install.cmake
CPackConfig.cmake
CPackSourceConfig.cmake

View File

@ -129,9 +129,30 @@ You can list all build variables (with help) by running `cmake -LH [options]
../<Name_of_WS_source_dir>`. This lists the cache of build variables
after the cmake run. To only view the current cache, add option `-N`.
You prepopulate variables using CMake's https://cmake.org/cmake/help/latest/manual/cmake.1.html#options[`-C` command line option] or by adding a file named `CMakeListsCustom.txt` to the top-level source directory.
In either case you must set each variable using CMake's “set” command.
For example `set(ENABLE_CCACHE ON)` will enable ccache.
Depending on your needs, it might be useful to save your CMake configuration options in a file outside your build directory.
CMake supports this via its https://cmake.org/cmake/help/v3.23/manual/cmake-presets.7.html[presets] option.
For example, adding the follwing to `CMakeUserPresets.json` would let you build using Ninja in the `build` directory, enable ccache, and set a custom Qt directory by running `cmake --preset mydev`:
[source,json]
----
{
"version: 4,
"configurePresets": [
{
"name": "mydev",
"displayName": "Local development",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"ENABLE_CCACHE": "ON",
},
"environment": {
"CMAKE_PREFIX_PATH": "/usr/local/Qt6"
}
}
]
}
----
After running cmake, you can always run `make help` to see a list of all possible make targets.