I'm trying to package up the PCG-CPP library to conan, however I am having major problems. Here are the steps to reproduce:
conanfile.py:
from conans import ConanFile
class PcgcppConan(ConanFile):
name = "pcg-cpp"
version = "1.0.0"
build_policy = 'missing'
no_copy_source = True
def source(self):
self.run("git clone https://github.com/imneme/pcg-cpp")
def package(self):
self.copy("*.hpp", dst='.')
def package_id(self):
self.info.header_only()
Run:
conan create . dodiknikola/pcg-cpp
conan export . pcg-cpp/1.0.0@dodiknikola/
In a different project's conanfile.txt, include pcg-cpp/1.0.0@dodiknikola/stable, and run conan install .., cmake ...
In one of the project files have #include <pcg_random.hpp>, and get the following error from GCC when trying to compile:
fatal error: pcg_random.hpp: No such file or directory
#include <pcg_random.hpp>
The documentation wasn't able to explain to me how to fix this problem, and I would be grateful if somebody could clear this up for me?
Hi @dodiknikola !
You need to change your package method:
def package(self):
self.copy("*.hpp", dst="include", keep_path=False)
When conan downloads pcg-cpp and copies it to build folder, it searches for all *.hpp files and preserve their paths, so your package folder looks like:
${HOME}/.conan/data/pcg-cpp/1.0.0/dodiknikola/stable/package/
However, Conan uses package_folder/include as include directory by default. Thus, you need to declare keep_path=False to remove all directories from path and set dst="include" to indicate the headers place.
Also, you could change the includedir path:
def package_info(self):
self.cpp_info.includedirs = ["pcg-cpp/include"]
But it sounds tricky, so I do recommend the first option.
If you read Conan documentation about header-only, it shows self.copy("*.h"), but all files must be in include dir and your current path must be build_folder/project_name.
Regards!
Yay it worked, thank you!
Hi @dodiknikola
A couple of notes and hints:
conan create . dodiknikola/testing
conan export . dodiknikola/testing
export. The export is already done in the create as the first step, actually.build_policy = 'missing', it is usually better to actually create the package.no_copy_source, unless the package is very big and performance of the copy is an issue, no need to use it, it is only a small optimization.test_package (as the one generated with conan new -t), check the docs. Such test_package is exactly a consumer project, but automated.As this question seems to be solver, I am closing it now, but do not hesitate to ask for further help if needed! :)
Most helpful comment
Hi @dodiknikola !
You need to change your
packagemethod:When conan downloads pcg-cpp and copies it to build folder, it searches for all
*.hppfiles and preserve their paths, so your package folder looks like:${HOME}/.conan/data/pcg-cpp/1.0.0/dodiknikola/stable/package//pcg-cpp/include/
However, Conan uses package_folder/include as include directory by default. Thus, you need to declare
keep_path=Falseto remove all directories from path and setdst="include"to indicate the headers place.Also, you could change the includedir path:
But it sounds tricky, so I do recommend the first option.
If you read Conan documentation about header-only, it shows
self.copy("*.h"), but all files must be inincludedir and your current path must be build_folder/project_name.Regards!