conan-io / examples2

Conan 2.x examples
MIT License
94 stars 48 forks source link

header-only package with components #150

Closed Dimitrius-dev closed 5 months ago

Dimitrius-dev commented 5 months ago

Description: Is there any example of header-only package with components? I tried to compose it myself but it did not work. Tested it with __test_package__. This is head of the lib which only contains other lib parts so it has not any code insertion.

Example i use


...
class Lib(ConanFile):
    name = "some_lib"
    version = "0.0.1"

    settings = "os", "arch", "compiler", "build_type"
    generators = "CMakeToolchain", "CMakeDeps"

    no_copy_source = True

    def requirements(self):
        for mdp_lib_name in self.mdp_components:
            self.requires("spdlog/1.14.1") # some dependency 
        pass

    def export_sources(self):
        copy(self, "CMakeLists.txt", self.recipe_folder, self.export_sources_folder, keep_path = True)
        pass

    def package_info(self):
        self.cpp_info.components["some_part_of_lib1"].libs = ["some_part_of_lib1"]
        self.cpp_info.components["some_part_of_lib1"].set_property("cmake_target_name",  "some_part_of_lib1")
        . . .
        pass

    def package_id(self):
        self.info.clear()
        pass
memsharded commented 5 months ago

Hi @memsharded

Thanks for your question.

Header-only packages do not have compiled libraries so something like .libs = ["some_part_of_lib1"] is incorrect and shouldn't be done.

The thing is that components main benefit is avoid overlinking, and header-only do not suffer that, so there is very little benefit specifying components for header-only libraries. I wouldn't recommend it for most cases, and keep it simple.

If you still want to do it, the fields that need to be defined will be self.cpp_info.components["some_part_of_lib1"].includedirs = ["part1_include_dir"] and probably setting libdirs = [] and bindirs = [] for every component (for being complete and clean)

Dimitrius-dev commented 5 months ago

Thank you so much for help!

memsharded commented 5 months ago

That clarifies the issue? Maybe we can close the ticket? You can always open a new one for further questions (you can also use the main Conan client repo in https://github.com/conan-io/conan for general Conan client questions)

Dimitrius-dev commented 5 months ago

Yes, closing