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.

[problem] cmake_multi INTERFACE_LINK_LIBRARIES uses generator expressions, does not support custom build configurations

See original GitHub issue

I hope I have understood this problem correctly, and that I’ll be able to explain it properly.

The cmake_multi generator defines imported targets and sets properties on them that specify where the include and library files are located.

Here’s an example for GLEW, formatted for a bit of clarity:

CONAN_PKG::glew INTERFACE_LINK_LIBRARIES = 

CONAN_PKG::opengl;
CONAN_PKG::glu;

$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,SHARED_LIBRARY>:>;
$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,MODULE_LIBRARY>:>;
$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:>;

$<$<CONFIG:Release>:
  CONAN_LIB::glew_glew32release;
  CONAN_PKG::opengl;
  CONAN_PKG::glu;
  $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,SHARED_LIBRARY>:>;
  $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,MODULE_LIBRARY>:>;
  $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:>
>;
$<$<CONFIG:RelWithDebInfo>:
  ;
  CONAN_PKG::opengl;
  CONAN_PKG::glu;
  $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,SHARED_LIBRARY>:>;
  $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,MODULE_LIBRARY>:>;
  $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:>
>;
$<$<CONFIG:MinSizeRel>:
  ;
  CONAN_PKG::opengl;
  CONAN_PKG::glu;
  $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,SHARED_LIBRARY>:>;
  $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,MODULE_LIBRARY>:>;
  $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:>
>;
$<$<CONFIG:Debug>:
  CONAN_LIB::glew_glew32ddebug;
  CONAN_PKG::opengl;
  CONAN_PKG::glu;
  $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,SHARED_LIBRARY>:>;
  $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,MODULE_LIBRARY>:>;
  $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:>
>

cmake_multi seems to forgo the use of per-configuration properties such as INTERFACE_LINK_LIBRARIES_DEBUG or INTERFACE_LINK_LIBRARIES_RELEASE, preferring to set the config-independent properties and using generator expressions to ensure the correct files are used for each configuration.

The problem is that this only seems to work for the predefined configurations Release, RelWithDebInfo, MinSizeRel, and Debug. When the CMake script or user adds extra configurations, e.g. DebugSpecial, then tries to map that configuration to Debug for imported dependencies via set(CMAKE_MAP_IMPORTED_CONFIG_DEBUGSPECIAL Debug), the library won’t be found: CMake will probably first try looking for the property INTERFACE_LINK_LIBRARIES_DEBUGSPECIAL, find that it doesn’t exist, and based on the defined mapping try to fall back to INTERFACE_LINK_LIBRARIES_DEBUG, which won’t exist either. Lastly, it would fall back to INTERFACE_LINK_LIBRARIES, which unfortunately only contains generator expressions for the predefined configurations.

Is this a known problem ?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:17 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
memshardedcommented, Jun 30, 2021

@memsharded I’m still trying to work my way through CMakeDeps - is it correct that CMakeDeps no longer uses the CONAN_PKG:: namespace on dependency targets ?

Yes, CMakeDeps use native find_package(). No need to change CMakeLists.txt at all to account for Conan specific targets.

1reaction
memshardedcommented, Jun 29, 2021

Even if I don’t like it very much, there is the relatively popular cmake-conan integration (https://github.com/conan-io/cmake-conan) that helps calling conan install directly from CMake, as a consumer. It supports the GENERATORS argument to specify which generator you want to use (even your own one, if you wanted), it is not restricted by the cmake-conan tool, it will just pass the value to Conan.

Otherwise, my preference is having a conanfile.txt defined, for consumption and let the flow be:

$ git clone .... repo && cd repo
$ conan install .
$ cmake ... -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake

This is more or less the intended user experience. Having the conan install explicit helps understanding many more things, and give power and flexibility with low cost (using yet another abstraction as cmake-conan also has a cost)

The new integrations as CMakeDeps use native find_package() so in theory it is not necessary to modify the CMakeLists.txt at all either.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Generator expressions should be supported by ...
I have a project where I use Ninja Multi-Config to generate "Release" and "Debug" build types in a single tree. I also have...
Read more >
cmake-generator-expressions(7)
Generator expressions are evaluated during build system generation to produce information specific to each build configuration. They have the form $<...> .
Read more >
CMake multi config generator on multi platform
I am working on a project that uses CMake ...
Read more >
[feature] conan imports build_type · Issue #8437
Importing dlls using a cmake multi config generator may cause issues when the library names are identical for different configurations.
Read more >
CMake Part 2 - Release and Debug builds - Sticky Bits
To support multiple build configurations for our training projects we just need ... To do this, we make use of CMake generator expressions, ......
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