Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] cmake presets generator #10101

Closed
stefaneicher opened this issue Nov 29, 2021 · 7 comments
Closed

[feature] cmake presets generator #10101

stefaneicher opened this issue Nov 29, 2021 · 7 comments
Assignees
Milestone

Comments

@stefaneicher
Copy link

Would it make sense to create a cmake presets generator?
https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html

We use the vitualenv generator and in vscode run the activate.sh to setup the environment. But in clion this does not work.
I would like to get a cmake idiomatic solution in which a cmake integration of any ide integrates seamless.
Cmake toolchaain is currently not a option since we have multiple packages in the repo and use workspaces during development that only work with the cmake generator.

@memsharded
Copy link
Member

Hi @stefaneicher

The issue is that Conan by default should support cmake 3.15: conan-io/tribe#4

While it could make sense to add later another generator for this functionality, at the moment we should focus on 1 canonical integration. This will be CMakeDeps and CMakeToolchain, beware that the other generators will be removed in 2.0.
Workspaces are not production ready, we are working on improving the editables as a foundation for future workspaces, you should be checking the layout() functionality for it too.

In any case, with the new functionalities it is now easier to create extensions. You can surely create a new block for CMakeToolchain with the new "blocks" functionality, or a new generator that creates such presets, it would be something like:

  • Create a python_requires with a new CMakePresetsGenerator with a single generate() method
  • Use that python_requires in your recipes, and add it to your generate()

@KerstinKeller
Copy link

@stefaneicher we implemented our own CMake Presets generator internally and it works great! You have a very transparent, identical workflow on all platforms, for all developers.
There is one catch tough: the last time I checked, the CMakePresets.json file needs to be located next to the main CMakeLists.txt file. Which means, either you have to generate it in your source directory (which is of course uncool, because generated files should be in a different location).
The other options (which we use), is to also generate a "new" main CMakeLists.txt file, which includes the original top level CMake file.

cmake_minimum_required(VERSION 3.20)

project(libA)
# We also generate a few other things
add_subdirectory(D:/libA libA)

@stefaneicher
Copy link
Author

stefaneicher commented Jan 13, 2022

Thanks @KerstinKeller and @memsharded for your answers! In the meantime in the new clion release I can run a script and therefore call the generated activate.sh script.

https://www.jetbrains.com/clion/whatsnew/

image

@puetzk
Copy link

puetzk commented Feb 4, 2022

The issue is that Conan by default should support cmake 3.15: conan-io/tribe#4

Moving my comment from #10515 (comment) over here, since it seems like a better place.

I'm not sure that supporing a minimum of 3.15 is necessarily a blocker; it really just means conan.tools.cmake.CMake can't use cmake --preset, not that it couldn't use the CMakePresets.json format (and parse the JSON itself for the generator argument/variables dictionary/apply_env/etc) instead of defining its own conanbuild.conf file format. To an older CMake that is unaware of CMakePresets.json, that looks just like conan doing its own thing as it currently does; to anyone using IDEs and newer CMake it would serve a nice ulterior motive.

In fact, the IDE Integration Guide explicitly endorses this sort of thing, saying

The --preset= option is intended only as a convenient frontend for command line users, and should not be used by the IDE.

and

For example, if a preset named ninja specifies Ninja as the generator and ${sourceDir}/build as the build directory, instead of running:
cmake -S /path/to/source --preset=ninja

the IDE should instead calculate the settings of the ninja preset, and then run:
cmake -S /path/to/source -B /path/to/source/build -G Ninja

And they give schemas/test cases for doing your own parsing. If conan's helper object did this (interfacing as they recommend an IDE should), that ought to be a stable integration and would make this compatible with older CMake (while also getting the benefits for newer IDEs).

@memsharded memsharded added this to the 1.47 milestone Feb 15, 2022
@memsharded memsharded reopened this Feb 15, 2022
@memsharded
Copy link
Member

memsharded commented Feb 15, 2022

We are going to explore how the presets.json interface could be directly used by Conan in cmake 3.15, following suggestions from #10515 (comment)

@memsharded
Copy link
Member

Related: #10770 (comment), needs to store another variable CMAKE_MAKE_PROGRAM for Mingw

@memsharded
Copy link
Member

memsharded commented Mar 30, 2022

We are changing the CMakeToolchain to generate (also, besides the toolchainfile) a CMakePresets.json file in 1.47 in #10903

The presets file will be generated atm in the generators_folder, so might need to be copied to root if necessary.
But I think with that PR we can close this issue, and open new more specific tickets to keep improving this initial implementation.

Feedback will be very welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants