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.

[question] CMake generators - how to use libraries form a different build config

See original GitHub issue

Hello,

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.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
666melkor666commented, Jul 19, 2022

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:

def generate(self):
    deps = CMakeDeps(self)
    deps.configuration = "Release"
    deps.generate()
    deps.configuration = "Debug"
    deps.generate()

and then conan install -s build_type="Release" ... This way I have release version of dependencies, and I can change the consumer CMAKE_BUILD_TYPE between Release and Debug. This approach, however, is very inconvenient, especially if I want to have some consumer specific CMAKE_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 the build_type setting. In case I’ve missed something, please advise how I can build the described workflow using conan.

0reactions
fanselmcommented, Sep 3, 2022

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 the conanfile.txt.

@memsharded can you comment on this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

CMake configuration specific library name when using multi ...
I am looking for a means to create a different library name for each configuration, e.g. a MyLib for the release build and...
Read more >
Better CMake Part 8 -- Package Configs for Normal Libraries
Time stamps: 0:00​ - Intro 1:42​ - Overview of example project 4:45 - Build vs. install interfaces ( generator expressions) 8:39 - Using...
Read more >
cmake-generators(7) — CMake 3.25.1 Documentation
The cmake(1) command-line tool --help output lists available generators on the current platform. Use its -G option to specify the generator for a...
Read more >
cmake-buildsystem(7) — CMake 3.25.1 Documentation
Target Properties · Transitive Usage Requirements · Compatible Interface Properties · Property Origin Debugging · Link Libraries and Generator Expressions.
Read more >
Cross Platform Make - CMake
A makefile generator is responsible for generating a particular build system. ... Use ADD_DEPENDENCIES to add dependencies to or from other targets.
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