-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* extend user CMakePresets * minor changes * minor changes * minor changes --------- Co-authored-by: czoido <mrgalleta@gmail.com>
- Loading branch information
1 parent
cf7e0f1
commit d05a61f
Showing
7 changed files
with
172 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
examples/tools/cmake/cmake_toolchain/extend_own_cmake_presets.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
.. _examples-tools-cmake-toolchain-build-project-extend-presets: | ||
|
||
CMakeToolchain: Extending your CMakePresets with Conan generated ones | ||
===================================================================== | ||
|
||
In this example we are going to see how to extend your own CMakePresets to include Conan | ||
generated ones. | ||
|
||
.. include:: ../../../../tutorial/cmake_presets_note.rst | ||
|
||
Please, first of all, clone the sources to recreate this project. You can find them in the | ||
`examples2.0 repository <https://github.com/conan-io/examples2>`_ in GitHub: | ||
|
||
.. code-block:: bash | ||
$ git clone https://github.com/conan-io/examples2.git | ||
$ cd examples2/examples/tools/cmake/cmake_toolchain/local_flow_cmake_presets | ||
Please open the `conanfile.py` and check how it sets ``tc.user_presets_path = | ||
'ConanPresets.json'``. By modifying this attribute of `CMakeToolchain`, you can change the | ||
default filename of the generated preset. | ||
|
||
.. code:: python | ||
def generate(self): | ||
tc = CMakeToolchain(self) | ||
tc.user_presets_path = 'ConanPresets.json' | ||
tc.generate() | ||
... | ||
Now you can provide your own ``CMakePresets.json``, besides the ``CMakeLists.txt``: | ||
|
||
.. code-block:: json | ||
:caption: CMakePresets.json | ||
{ | ||
"version": 4, | ||
"include": ["./ConanPresets.json"], | ||
"configurePresets": [ | ||
{ | ||
"name": "default", | ||
"displayName": "multi config", | ||
"inherits": "conan-default" | ||
}, | ||
{ | ||
"name": "release", | ||
"displayName": "release single config", | ||
"inherits": "conan-release" | ||
}, | ||
{ | ||
"name": "debug", | ||
"displayName": "debug single config", | ||
"inherits": "conan-debug" | ||
} | ||
], | ||
"buildPresets": [ | ||
{ | ||
"name": "multi-release", | ||
"configurePreset": "default", | ||
"configuration": "Release", | ||
"inherits": "conan-release" | ||
}, | ||
{ | ||
"name": "multi-debug", | ||
"configurePreset": "default", | ||
"configuration": "Debug", | ||
"inherits": "conan-debug" | ||
}, | ||
{ | ||
"name": "release", | ||
"configurePreset": "release", | ||
"configuration": "Release", | ||
"inherits": "conan-release" | ||
}, | ||
{ | ||
"name": "debug", | ||
"configurePreset": "debug", | ||
"configuration": "Debug", | ||
"inherits": "conan-debug" | ||
} | ||
] | ||
} | ||
Note how the ``"include": ["./ConanPresets.json"],`` and that every preset ``inherits`` a | ||
Conan generated one. | ||
|
||
We can now install for both Release and Debug (and other configurations also, with the | ||
help of ``build_folder_vars`` if we want): | ||
|
||
.. code-block:: bash | ||
$ conan install . | ||
$ conan install . -s build_type=Debug | ||
And build and run our application, by using **our own presets** that extend the Conan generated ones: | ||
|
||
.. code-block:: bash | ||
# Linux (single-config, 2 configure, 2 builds) | ||
$ cmake --preset debug | ||
$ cmake --build --preset debug | ||
$ ./build/Debug/foo | ||
> Hello World Debug! | ||
$ cmake --preset release | ||
$ cmake --build --preset release | ||
$ ./build/Release/foo | ||
> Hello World Release! | ||
# Windows VS (Multi-config, 1 configure 2 builds) | ||
$ cmake --preset default | ||
$ cmake --build --preset multi-debug | ||
$ build\\Debug\\foo | ||
> Hello World Debug! | ||
$ cmake --build --preset multi-release | ||
$ build\\Release\\foo | ||
> Hello World Release! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters