conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.31k stars 986 forks source link

[question] Is it a good idea to move POLICY required by conan toolchain logic in CMake presets? #11769

Open SpaceIm opened 2 years ago

SpaceIm commented 2 years ago

I've seen this PR https://github.com/conan-io/conan/pull/11098

Is it a good idea? I mean, presets are a 3.19 feature, but conan toolchain is supposed to support CMake >= 3.15.

If you have a build fully managed by conan, and CMake 3.15 is installed, how CMake helper can fallback to not using presets (because I guess the new CMake helper automatically injects generated presets, otherwise it's broken from what I understand), and therefore properly handle policies? (EDIT: ok for this case I see that CMake helper also injects the policy in command line)

In case of a build not managed by conan (for example a simple conanfile.txt just for dependency management), is it a good experience for users to have to manage these policies themselves if presets are not used?

lasote commented 2 years ago

Before introducing the CMakePresets in conan, the toolchain used a file named conanbuild.conf to write all the information, (that shouldn't or can't belong to the toolchain itself), that the CMake helper has to pass to the command line.

We replaced the conanbuild.conf invented-format with a standard one, that is the CMakePresets.json files. In both cases, if the user wanted to call cmake in command line, needed to read the file and apply the arguments properly. With the Presets if the user has a modern-enough cmake, the tool will manage automatically.

About Conan parsing the CMakePresets.json file, Kitware explicitly invented the Presets so IDEs and other tools (like Conan) can call the cmake command line with the proper arguments following a standard file format, so maybe the user is building his project without Conan but with Visual Studio Code that will manage to call CMake (even < 3.19) with the correct arguments. You only need CMake > 3.19 if you are calling cmake with the --preset argument:

From CMake docs:

IDE vendors are encouraged to read and evaluate this file the same way CMake does, and present the user with the presets listed in the file. Users should be able to see (and possibly edit) the CMake cache variables, environment variables, and command line options that are defined for a given preset. The IDE should then construct the list of appropriate [cmake(1)](https://cmake.org/cmake/help/latest/manual/cmake.1.html#manual:cmake(1)) command line arguments based on these settings, rather than using the --preset= option directly. The --preset= option is intended only as a convenient frontend for command line users, and should not be used by the IDE.