Skip to content
Snippets Groups Projects
Commit 244b83b6 authored by Sebastian Eibl's avatar Sebastian Eibl
Browse files

add example for cmake presets

parent e25dffb4
No related branches found
No related tags found
1 merge request!5add example for cmake presets
......@@ -48,6 +48,13 @@ check-recipes:
- cmake --build 08_build
- ctest --test-dir 08_build || FAILED=true
- cmake --preset dev -S 10_presets -B 10_dev
- cmake --build 10_dev
- ./10_dev/app
- cmake --preset production -S 10_presets -B 10_production
- cmake --build 10_production
- ./10_production/app
check-links:
before_script:
- module purge
......
cmake_minimum_required(VERSION 3.20)
project(10_presets
LANGUAGES CXX)
add_executable(app main.cpp)
{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 20,
"patch": 0
},
"configurePresets": [
{
"name": "dev",
"displayName": "development settings",
"generator": "Unix Makefiles",
"cacheVariables": {
"CMAKE_CXX_COMPILER": "g++",
"CMAKE_CXX_FLAGS": "-Wall -Wextra"
}
},
{
"name": "production",
"displayName": "production settings",
"generator": "Unix Makefiles",
"cacheVariables": {
"CMAKE_CXX_COMPILER": "g++",
"CMAKE_CXX_FLAGS": "-march=native"
}
}
]
}
# How to add compilation configurations to your project?
Since 3.19 CMake supports [presets](https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html). Presets are able
to replace your custom shell scripts that build your application on different platforms with different settings.
Presets have a name and specify flags for the configure, build, test, install, etc stage. There are two files
that contain presets. `CMakePresets.json` holds the project-wide presets that are checked into the repository.
`CMakeUserPresets.json` contains developer specific settings and should not be part of the repository. In fact, you should
at it to your `.gitignore` file.
\ No newline at end of file
#include <iostream>
int main()
{
int a;
std::cout << a << std::endl;
}
......@@ -18,6 +18,7 @@ we run them in our CI.
* [How to get the current git hash at configure time?](06_git_configure)
* [How to get the current git hash at build time?](07_git_build)
* [How to manage all the tests in your project?](08_ctest)
* [How to add compilation configurations to your project?](10_presets)
## Why CMake?
* Automatically search for programs, libraries, and header files
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment