question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[feature] Custom variables in generated `conan_paths.cmake`

See original GitHub issue

The 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

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
jgsogocommented, Feb 21, 2020

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 like protobuf or pybind11 that need to deploy custom functions, i.e.: protobuf_generate_cpp or pybind11_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 and cmake_find_package generators (the consumer will need to include the generated files via include or find_package). Right now the workaround would be: to generate a .cmake file, add the required set(VAR VALUE) to it, pack it and declare the file in the build_modules. Something built-in make sense.


Linking to https://github.com/conan-io/conan/issues/6125, the same considerations may apply to this feature.

0reactions
KerstinKellercommented, Feb 21, 2020

Hi, thanks a lot for your feedback.

or using two generators like cmake_paths and cmake, you can include the later one too (it won’t execute anything, it justs set variables and declare functions) and there you can have that variable available.

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.

writing a custom generator would be one way to go.

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

cmake_paths generator — conan 1.4.5 documentation
This generator is especially useful if you are using CMake based only on the find_package feature to locate the dependencies. The cmake_paths generator...
Read more >
cmake-variables(7) — CMake 3.25.1 Documentation
This page documents variables that are provided by CMake or have meaning to CMake when set by project code. For general information on...
Read more >
User Interaction Guide — CMake 3.25.1 Documentation
Generating a Buildsystem. Command line environment. Command line -G option. Choosing a generator in cmake-gui. Setting Build Variables.
Read more >
cmake-generator-expressions(7)
Using variables to build up a more complex generator expression is also a good ... One possible way to generate debug messages is...
Read more >
CPack DEB Generator — CMake 3.25.1 Documentation
The CPack DEB generator has specific features which are controlled by the specifics CPACK_DEBIAN_XXX variables. CPACK_DEBIAN_<COMPONENT>_XXXX variables may be ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found