[bug] Using build/host profiles, Conan does not generate (some?) CMake variables
See original GitHub issueEnvironment Details (include every applicable attribute)
- Operating System+version: CentOS 8
- Compiler+version: LLVM 10.1
- Conan version: 1.33.0
- Python version: 3.8.6
Steps to reproduce (Include if Applicable)
I have created this example repo: https://github.com/daravi/test-conan-profile
When using build/host profiles (at least some) CMake variables seem to not be generated. Specifically in the above example I try to display conan_<package_name>_root variable of a build_requirement. In the successful test, I just run conan install and then cmake and see the variable correctly printed out. In the fail case I run conan install with build and/or host profiles specified and run cmake again and see that the cmake variable has not been defined.
Logs (Executed commands with output) (Include/Attach if Applicable)
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (11 by maintainers)
Top Results From Across the Web
Conan Documentation
Conan is a dependency and package manager for C and C++ languages. It is free and open-source, works in all platforms ( Windows,...
Read more >Master Index CMake 2.8.12
List cache variables will run CMake and list all the variables from the CMake cache that are not marked as INTERNAL or ADVANCED....
Read more >Using CMake and Managing Dependencies - Hacker News
At least with Conan, your project's CMake list does not have to ... can consume dependencies from Conan and use `cmake_paths` generator and ......
Read more >Avoid repeating config between Conan profile and CMake
Normally you would use Conan to setup all your external libraries and then use them from CMake. You can however do the other...
Read more >Using Conan and cross-compile to EV3
I have struggled enough with trying to find and build libraries, and a package manager will make life much eassier. I am by...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

All the generators operate on all the information that they have available (propagation logic is controlled by the graph). Some generators will use only information from the host context and some others use information from the build context too.
Generators like
cmake,cmake_find_package,… that are used to generate files with information from the dependencies you are going to use to link with your project/library, will generate only those files for packages in the host context. For example, say you are usingprotobuflibrary and you want to useprotoc(provided by packageprotobuf) compile inReleasewhile you want to build your project in Debug. Here you need:Given two profiles with Release in the build profile and Debug in the host profile, Conan needs to retrieve the same package twice, one for each configuration, and you will use in you
CMakeLists.txtto find includes/libraries you want to link your project with:You expect CMake to find the Debug package, which is the one that offers the configuration you are building. This is just an example, but you can realize that we cannot propagate the information from build AND host, we can only generate only
FindProtobuf.cmakefile and it will match the configuration from the host profile, which is the one you are linking with.That was an example, I hope it explains a bit the problematic we are trying to fix here. Now let’s think about you scenario, you have a build-requires that provides some
xxx.cmakefiles you want to use in your project. These CMake files can be a toolchain (and the package might beandroid_ndk) or just plain CMake files with utilities, functions and/or macros you need.Disclaimer - We don’t have a canonical answer for it, we are designing a new
confparadigm to pass information to the new toolchain classes and generators. It will take into account this issue and should provide the solution that will be aligned with Conan 2.0.Depending on the nature of your package you can use different approaches (I will use
cmake-utilsas the name of your package with CMake scripts):abuse generators built-in functionality. You can declare
self.build_requires('cmake-utils', force_host_context=True)and Conan will force this build-requires to stay in the host context, Conan will generate the information you expect as with any other requirement. Of course, this will only work if the package doesn’t provide binaries you need to run in the build machine.propagate information using
user_infoentry:and then, in the consumers, get the information via
user_info_buildIn the future, we should be able to provide a more integrated way.
@jgsogo Thank you! For anyone reading the thread it is also possible to use
CMakeToolchainif you don’t want to usevirtualrunenv.