[question] CMake generators - how to use libraries form a different build config
See original GitHub issueHello,
I would want to fetch googletest via Conan, I am using v1.50 on debian Linux with Make/Ninja generators. The problem is generally that you don’t necessarily want the same config on your project as on your dependencies. For my example I would want to build my project with debug/sanitize/coverage configuration, while gtest and other dependencies are the release variants.
I cant do this currently, using the CMakeDeps
generator atleast. Doing a debug-build the find_package(GTest)
call will work,
but those targets are empty and using gtest headers will fail.
Why isnt this done more like “normal” CMake installations where the property IMPORTED_CONFIGURATIONS
is set, and CMake picks the correct flavor, while also allowing handpicked overrides via MAP_IMPORTED_CONFIG_<CONFIG>
.
So in short, your generated imports should:
- Drop all
$<$<CONFIG:.*>:.*>
stuff. otherwise its not possible to use them elsewhere. - use
IMPORTED_CONFIGURATIONS
instead. - check_build_type_defined shouldnt be necessary?
That way, conan packages could be used just like regular installed CMake packages when created with the official helpers. Output of these helpers looks like this.
- I’ve read the CONTRIBUTING guide.
Issue Analytics
- State:
- Created a year ago
- Comments:8 (3 by maintainers)
Hi. It looks like I’m hit by the same problem.
I need to be able to independently change the build_type of dependencies and their consumer. The use case is the following: I have an application and want to use the release version of the dependencies regardless of the config my application is being built or change the build_type for a certain dependency only. Using debug versions for all dependencies may lead to significant performance degradation.
The only workaround I’ve found is to override the generate method in the following way:
and then
conan install -s build_type="Release" ...
This way I have release version of dependencies, and I can change the consumerCMAKE_BUILD_TYPE
between Release and Debug. This approach, however, is very inconvenient, especially if I want to have some consumer specificCMAKE_BULD_TYPE
, which for example, turns on a lot of additional logging.It would be great to have the ability to tell the
CMakeDeps
generator to ignore thebuild_type
setting. In case I’ve missed something, please advise how I can build the described workflow using conan.I also hit this recently, and I guess a lot of people must have by now.
I also agree with @nolange that the Conan generated .cmake files (e.g.
<PKG>Config.cmake
) should be completely free of configuration specifications like $CONFIG:Release - it is not Conan’s job to interfere with how the project is configured, it should just hand you the include directories and libraries no matter what. If one wants a debug version of a dependency that is specified in theconanfile.txt
.@memsharded can you comment on this?