docs
docs copied to clipboard
Header Only needs cpp_info.includedirs
Hello, I followed the tutorial for a header only conan package. For test purpose, I create an little example and include the header only libary with conan. The example is build with cmake. My lib is included via find_package.
I got stuck because no headers are found. After some investigations I found that inside the FindMyLib.cmake the include directory are empty:
set(MyLib_INCLUDE_DIRS)
To resolve it I need to add cpp_info.includedirs to the package_info in the header only conan package:
def package_info(self):
self.cpp_info.libs = ["MyLib"]
self.cpp_info.includedirs = ['include']
The setting of the includedirs should be part of the tutorial.
Hi @Fettpet,
The example should work fine as the self.cpp_info.includedirs
has a default value of ["include"]
(source: https://docs.conan.io/en/latest/reference/conanfile/attributes.html#cpp-info) so those extra lines are not needed. Are you sure this was the issue? Which cmake generator are you using in the consumer example? could you indicate the conan version you are using? thank you
Hello @danimtb, my conan version is 1.41.0.
I build a minimal reproducable example. Actally the problem is on another level. When I have the conanfile.py in the root directory, the documentation works as expected. In my case I had the conanfile.py in a subdirectory. I need to adapt the copy command inside the package function.
Short explanation of the example. The example consits of two parts the conanLib and the consumer.
- The conanLib has a header file with a single function inside. The conanfile.py build the library. I included two conanfile.py. The first one is on the root level. The second one is inside the subdirectory conan. The conanfile inside the subdirectory doesnt work. The outcomment line inside the package function must be add to work
- The consumer uses the conanLib to build a minimal example
I included two bash scripts to show all command to build first the conanLib and after that the consumer.
The difference between both is the builded conan package (In my case I found it in the directory C:\Users\fettpet.conan\data\MyLib\1.0\fettpet\testing\build\5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9). The subdirectory case moves the add.h is in the root directory. The root case moves the add.h inside a directory include. Base on the documentation of copy is behaivor is wrong dst (Optional, Defaulted to ""): Destination folder in the package. They will typically be include for headers, lib for libraries and so on, though you can use any convention you like. Leaving it empty means the root package folder in local cache.
Maybe this should be moved to the conan
repo?
In any case, if it is a header only library, it shouldnt have self.cpp_info.libs = ["MyLib"]
line at all, that is only for compiled libraries.
I would also strongly recommend to start checking the new build system integrations, like CMakeDeps
, etc. You can get a modernized template with conan new hello/0.1 --template=cmake_lib
.
Also, I would recommend to keep the conanfile.py
in the root of the folder, altough it is possible to put it in a subfolder, the mainstream convention is to have it in the root. I'd say it is mostly a paths issue.
@Fettpet I have check the provided example and I have made some minor modifications to get it working. It complies with the how to above, so there is no issue here. Please take a look at the attached folder conan_min_working.zip
Hello @danimtb I think @memsharded is right. The problem is different behavior of copy.
@Fettpet I think this can be closed then