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] `CMakeDeps` failed on header only libs

See original GitHub issue

conanfile.py

requires = ["rapidjson/cci.20200410"]
generators = ["CMakeDeps", "CMakeToolchain"]
$ conan create .
...
ERROR: Error in generator 'CMakeDeps': 'settings.build_type' doesn't exist

Does it mean that CMakeDeps can not be used if any lib in requires has no build_type settings?

conafile.py for rapidjson

from conans import ConanFile, tools
import os

required_conan_version = ">=1.33.0"


class RapidjsonConan(ConanFile):
    name = "rapidjson"
    description = "A fast JSON parser/generator for C++ with both SAX/DOM style API"
    topics = ("conan", "rapidjson", "json", "parser", "generator")
    url = "https://github.com/conan-io/conan-center-index"
    homepage = "http://rapidjson.org"
    license = "MIT"
    no_copy_source = True

    @property
    def _source_subfolder(self):
        return "source_subfolder"

    def source(self):
       tools.get(**self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder)

    def package(self):
        self.copy(pattern="license.txt", dst="licenses", src=self._source_subfolder)
        self.copy(pattern="*", dst="include", src=os.path.join(self._source_subfolder, "include"))

    def package_id(self):
        self.info.header_only()

    def package_info(self):
        self.cpp_info.names["cmake_find_package"] = "RapidJSON"
        self.cpp_info.names["cmake_find_package_multi"] = "RapidJSON"

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
czoidocommented, Sep 15, 2021

But why a header only lib needs settings = "build_type", this will lead to duplication of the lib in local conan cache unnecessarily, right?

The lib will not be duplicated because it does not have the build_type setting, it’s deleted because it’s a header only and will have only one package_id, please read more about this here: https://docs.conan.io/en/latest/howtos/header_only.html

BTW, after fixing #9611, I have tried to delete settings = "build_type" and do conan create ., it succeeds. It is not necessary, isn’t it?

That’s because you are using cmake_find_package generator there and will not need it.

1reaction
czoidocommented, Sep 15, 2021

Hi @playgithub, As I said, you have to add at least the build_type setting to the conanfile. The CMakeDeps generator needs that setting information. So please add: settings = "build_type" to the consumer’s conanfile like this:

class CppjiebaConan(ConanFile):
    settings = "build_type"
    ...

Some other conan generators may not need this setting.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[question] How to work in Debug mode with CMakeDeps and ...
Hi, I have a header-only library with cmake generator and it works fine. I've migrated it to CMakeDeps and CMakeToolchain.
Read more >
CMake include header-only-library into another library, make fail
library B (libB) is a header only library in my view (correct me if I'm using the incorrect terms). So libA actually 'uses'...
Read more >
Changelog — conan 1.56.0 documentation
#11759; Bugfix: The CMakeDeps generator failed for consumers with CMake projects ... It will impact header-only libraries that are consumed using targets ...
Read more >
How do you use a header-only library package in ROS2?
The Problem (in short) I'm trying to create and use a header-only library package in ROS2 Foxy. However the compilation fails with a...
Read more >
Why is it that package managers are unnecessarily hard? : r/cpp
This is the answer! The problem is that conan declared that libraries are in CONFIG:Release.
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