conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.25k stars 980 forks source link

[question] PUBLIC compile definition not propagated #16569

Closed Drllap closed 4 months ago

Drllap commented 4 months ago

What is your question?

I'm creating a conan package for a 3rd party library. This library has a preprocessor macro in the public headers. Then in the CMakeList it has

target_compile_definitions(${PROJECT_NAME} PUBLIC SOME_COMPILE_DEFINITION)

My understanding is that because this compile definition is PUBLIC it should be propagated to the consumer of the conan package but it doesn't seem to be working for me. Is there something specific that I need to add to the conanfile.py?

Have you read the CONTRIBUTING guide?

memsharded commented 4 months ago

Hi @Drllap

Thanks for your question.

Whatever a package build scripts have is completely internal to the package. It doesn't even matter if a package is built with CMake, Meson, Autotools or other build system.

What defines what information needs to be propagated to the consumers of a package is the package_info() method. Please check:

Drllap commented 4 months ago

I just pushed an example repo here: https://github.com/Drllap/conan-compile-definition-propagation-test

Drllap commented 4 months ago

@memsharded Thanks Adding

    def package_info(self):
        self.cpp_info.libs = ["cpt"]
        self.cpp_info.defines = ["SOME_COMPILE_DEFINITION"]

Works