[feature] Custom variables in generated `conan_paths.cmake`
See original GitHub issueThe cmake_paths generators allows us to be the least intrusive when working with Conan. It works best, when all used packages provide a <Pkg>Config.cmake file. It can still work reasonably well with the FindScripts that come with CMake, but sometimes only if you set some specific variables to define the search behavior (e.g. don’t search in the System).
Concrete example:
I’ve packaged python3 with Conan. CMake comes with a FindPython3.cmake
script which works reasonably well, but it’s default behavior is to search for the newest Python version, but not the one it locates first honoring the CMAKE_MODULE_PATH
variable generated by the conan paths generator.
As a consumer I can call the following to find the provided Conan package and not my newer system version:
set(Python3_FIND_STRATEGY LOCATION)
find_package(Python3 COMPONENT Development)
But the burden of setting the Python3_FIND_STRATEGY
variable should not be on the consumer side, but on the package creator side.
conan_paths.cmake
is everything provided to the consumer when working with that generator, so it would be great if I could, in the package_info
, specify some additional information to the cmake_paths
generator.
Possible syntax (analog to CMake.definitions
):
def package_info(self):
self.cmake_paths_info.definitions["Python3_FIND_STRATEGY"] = "LOCATION"
which translates to
# Regular conan_paths.cmake
set(CMAKE_MODULE_PATH ...)
set(CMAKE_PREFIX_PATH ...)
set(Python3_FIND_STRATEGY "LOCATION")
Is that something you would consider implementing? Or can this already be achieved?
Could also somewhat be related to #6535
- I’ve read the CONTRIBUTING guide.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:7 (4 by maintainers)
Yes, right now we have the
build_modules
attribute that is useful to include.cmake
files that declare functions, those were added thinking on packages likeprotobuf
orpybind11
that need to deploy custom functions, i.e.:protobuf_generate_cpp
orpybind11_add_module
… this is a new use-case that totally makes sense.We need to provide a way to generate/add custom CMake variables to
cmake
andcmake_find_package
generators (the consumer will need to include the generated files viainclude
orfind_package
). Right now the workaround would be: to generate a.cmake
file, add the requiredset(VAR VALUE)
to it, pack it and declare the file in thebuild_modules
. Something built-in make sense.Linking to https://github.com/conan-io/conan/issues/6125, the same considerations may apply to this feature.
Hi, thanks a lot for your feedback.
If I am using both generators, how would I access this variable? First I’d have to include that generated file, and thus modify the consumers CMakeLists.txt, correct? This is what I am trying to avoid in the first place.
This sounds reasonable, and should be easy enough. It’s been awhile since I’ve played around with custom generators, but even if i do have a cutom generator I fear that I can’t just set arbitrary fields on
self.cpp_info
? Or completely invent new fields that the generator can access?But I guess, if a new field was introduced to support setting variables for the “cmake” or “cmake_find_package” generators, I can access that variable from a custom generator, too.