conan-io / conan

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

[question] Header only package - cannot access headers #16485

Closed mzbro closed 2 weeks ago

mzbro commented 2 weeks ago

Hi! I would like to create a package, which uses a local header only library package. To simplify the problem, I've used an example from official conan repository (package "sum"):

Official header only example

Next, I have created a package from cmake_lib template, which requires sum:

conan new cmake_lib -d name=example -d version=1.0.0 -d requires="sum/0.1@mz/stable"

I have uploaded my project to illustrate this issue: https://github.com/mzbro/conan-header-only/tree/main

Problem description

My example project can access header sum.h, but the header is not available for my example/test_package test. I have compared generated *.cmake files, and there is one diff for sum's cmake files:

diff example/build/Release/generators/sum-release-x86_64-data.cmake example/test_package/build/gcc-11-x86_64-gnu17-release/generators/sum-release-x86_64-data.cmake
18c18
< set(sum_INCLUDE_DIRS_RELEASE "${sum_PACKAGE_FOLDER_RELEASE}/include")
---
> set(sum_INCLUDE_DIRS_RELEASE )

The one for test_package misses "${sum_PACKAGE_FOLDER_RELEASE}/include" for includes.

Is this a bug, or am I missing something in my recipes?

Platform description

conan version: 2.4.1 OS: Ubuntu 22.04.4 LTS (amd64) - edited Compiler: gcc 11.4.0 Host: native (bare metal)

Have you read the CONTRIBUTING guide?

memsharded commented 2 weeks ago

Hi @mzbro

Thanks for your question.

Headers are not transitive by default, the expectation is that dependencies are implementation details. There are 2 possibilities:

Please let us know if that helps.

mzbro commented 2 weeks ago

Adding transitive_headers=True to my example project solved this issue. Thank you very much! I must have missed that in the tutorial.

memsharded commented 2 weeks ago

Happy to help.

The truth is that the basic tutorial doesn't cover this transitivity, it is a bit more advanced case, we might try to add some hints or links there.

Thanks for the feedback!