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] How to generate no configuration suffix when using CMakeDeps?

See original GitHub issue

When consuming targets and CMake variables generated by CMakeDeps, it generates all variables with a suffix based on its configuration:

https://github.com/conan-io/conan/blob/47353ab2e38b7cf5638dfce26d1fd2640eb2775e/conan/tools/cmake/cmakedeps/templates/__init__.py#L78

@property
def suffix(self):
    if not self.conanfile.is_build_context:
        return ""
    return self.cmakedeps.build_context_suffix.get(self.conanfile.ref.name, "")

As result, it regenerates variables like FOO_LIBS_RELEASE and foo_COMPILE_DEFINITIONS_RELEASE.

The question is, how to generate only FOO_LIBS (without build type suffix)?

We could try a workaround, forcing the CMakeDeps configuration, but fails:

def generate(self):
    deps = CMakeDeps(self)
    deps.configuration = ""
    deps.generate()
conan create . foo/0.1@
ERROR: Traceback (most recent call last):
  File "/Users/uilian/.pyenv/versions/3.10.4/lib/python3.10/site-packages/conans/errors.py", line 34, in conanfile_exception_formatter
    yield
  File "/Users/uilian/.pyenv/versions/3.10.4/lib/python3.10/site-packages/conans/client/generators/__init__.py", line 253, in write_toolchain
    conanfile.generate()
  File "/Users/uilian/.conan/data/foo/0.1/_/_/export/conanfile.py", line 16, in generate
    tc.generate()
  File "/Users/uilian/.pyenv/versions/3.10.4/lib/python3.10/site-packages/conan/tools/cmake/cmakedeps/cmakedeps.py", line 46, in generate
    generator_files = self.content
  File "/Users/uilian/.pyenv/versions/3.10.4/lib/python3.10/site-packages/conan/tools/cmake/cmakedeps/cmakedeps.py", line 88, in content
    self._generate_files(require, dep, ret, find_module_mode=False)
  File "/Users/uilian/.pyenv/versions/3.10.4/lib/python3.10/site-packages/conan/tools/cmake/cmakedeps/cmakedeps.py", line 101, in _generate_files
    ret[data_target.filename] = data_target.render()
  File "/Users/uilian/.pyenv/versions/3.10.4/lib/python3.10/site-packages/conan/tools/cmake/cmakedeps/templates/target_data.py", line 20, in filename
    data_fname += "{}-{}".format(self.file_name, self.configuration.lower())
AttributeError: 'NoneType' object has no attribute 'lower'

Some projects use LIBS instead of LIBRARIES and have been working so far, and forcing to patch only because Conan uses target multi feature sounds a bit aggressive.

/cc @ericLemanissier

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
ericLemanissiercommented, Sep 30, 2022

Thanks for the report. cf https://github.com/conan-io/conan-center-index/pull/13228 for an example of actual failure caused by this issue

0reactions
ericLemanissiercommented, Dec 5, 2022

re-ping @jcar87 do you need more information ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

[question] CMakeDeps and layout() creates but wrong test ...
I would need to see the imports. This is not necessary anymore with the new from conan.tools.cmake import CMake : def _configure_cmake(self): ...
Read more >
CMakeDeps — conan 1.56.0 documentation
The CMakeDeps helper will generate one xxxx-config.cmake file per dependency, ... You can use the build_context_suffix attribute to specify a suffix for a ......
Read more >
Cmake find_package does not work with Doxygen
I am trying to have CMake find Doxygen on a bunch of different systems and configurations: Online documentation is generated on Ubuntu; Local ......
Read more >
conan Changelog - pyup.io
Bugfix: The `CMakeDeps` generator was not working properly when the consumer maps configurations of the dependencies using `CMAKE_MAP_IMPORTED_CONFIG_XXX`.
Read more >
CMake 3.25.1 Documentation
When using one of the IDE Build Tool Generators, no particular environment is needed. Generate a Project Buildsystem¶. Run CMake with one of...
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