[question] Test and documentation of a header-only package
See original GitHub issueI am trying to package a header-only library, but I encounter a two main problems.
At least this works: Local testing and documentation
First, I succeeded to get these command work and do what I want them to do:
conan install conan/conanfile.py --build=missing --install-folder=build -pr:b=conan/profiles/clang_13 -pr:h=conan/profiles/clang_13
cd build
cmake -D CMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake ..
cmake --build .
ctest
make docs
The dependencies are successfully installed on my mac, the tests are built, run and I can generate the documentation with doxygen.
Problem 1: dependencies conflict between OS
Even if I like running things locally for testing, I also happen to use Github workflows that run on Ubuntu 22.04. In this case, the previous commands fail, and so I had to tweak the dependencies versions in my conan/conanfile.py
, where I ended up with these lines:
# zlib overriden because conflict on ubuntu 22.04 (gh-actions)
#requires = "boost/1.80.0", "gdal/3.5.2", "zlib/1.2.13"
# on my Macos Monterey clang 13
requires = "boost/[>1.75 <1.80]", "gdal/[>=3.4.0]"
How to do that properly with Conan?
Problem 2: Creating the package fails
I would like to make the package available on Artifactory. I would like the packaging method to build and run the unit tests. So I tried to run conan create ./conan demo/testing -pr:b=conan/profiles/clang_13 -pr:h=conan/profiles/clang_13
. It fails with the following error:
quetzal-CoaTL/0.1@demo/testing: Generator 'CMakeDeps' calling 'generate()'
quetzal-CoaTL/0.1@demo/testing: Calling generate()
quetzal-CoaTL/0.1@demo/testing: Aggregating env generators
quetzal-CoaTL/0.1@demo/testing: Calling build()
CMake Error: The source directory "/Users/arnaudbecheler/.conan/data/quetzal-CoaTL/0.1/demo/testing/source" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
quetzal-CoaTL/0.1@demo/testing:
quetzal-CoaTL/0.1@demo/testing: ERROR: Package '5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9' build failed
quetzal-CoaTL/0.1@demo/testing: WARN: Build folder /Users/arnaudbecheler/.conan/data/quetzal-CoaTL/0.1/demo/testing/build/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9
ERROR: quetzal-CoaTL/0.1@demo/testing: Error in build() method, line 33
cmake.configure()
ConanException: Error 1 while executing cd '/Users/arnaudbecheler/.conan/data/quetzal-CoaTL/0.1/demo/testing/build/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9' && cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE="Release" -DCMAKE_OSX_ARCHITECTURES="arm64" -DCMAKE_OSX_SYSROOT="/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk" -DCONAN_IN_LOCAL_CACHE="ON" -DCONAN_COMPILER="apple-clang" -DCONAN_COMPILER_VERSION="13" -DCONAN_LIBCXX="libc++" -DCMAKE_INSTALL_PREFIX="/Users/arnaudbecheler/.conan/data/quetzal-CoaTL/0.1/demo/testing/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9" -DCMAKE_INSTALL_BINDIR="bin" -DCMAKE_INSTALL_SBINDIR="bin" -DCMAKE_INSTALL_LIBEXECDIR="bin" -DCMAKE_INSTALL_LIBDIR="lib" -DCMAKE_INSTALL_INCLUDEDIR="include" -DCMAKE_INSTALL_OLDINCLUDEDIR="include" -DCMAKE_INSTALL_DATAROOTDIR="share" -DCMAKE_PREFIX_PATH="/Users/arnaudbecheler/.conan/data/quetzal-CoaTL/0.1/demo/testing/build/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9" -DCMAKE_MODULE_PATH="/Users/arnaudbecheler/.conan/data/quetzal-CoaTL/0.1/demo/testing/build/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9" -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY="ON" -DCONAN_EXPORTED="1" -Wno-dev '/Users/arnaudbecheler/.conan/data/quetzal-CoaTL/0.1/demo/testing/source'
I tried to modify the generate and the build functions, but without success: I do not understand what causes this behavior. Any idea?
Here is my conanfile.py:
from conans import ConanFile, CMake
from conan.tools.cmake import CMakeDeps
class QuetzalCoaTLConan(ConanFile):
name = "quetzal-CoaTL"
url = "https://github.com/Quetzal-framework/quetzal-CoaTL"
license = "GPLv3"
description = "Quetzal Coalescence Template Library"
version = "0.1"
settings = "os", "compiler", "arch", "build_type"
exports_sources = "include/*", "CMakeLists.txt", "test/*", "cmake/*", "docs/*"
no_copy_source = True
generators = "cmake", "CMakeToolchain", "CMakeDeps"
# zlib overriden because conflict on ubuntu 22.04 (gh-actions)
#requires = "boost/1.80.0", "gdal/3.5.2", "zlib/1.2.13"
# on Macos Monterey clang 13
requires = "boost/[>1.75 <1.80]", "gdal/[>=3.4.0]"
# by default, the config files (xxx-config.cmake) files are not generated: see generate()
tool_requires = "cmake/3.22.0", "doxygen/1.9.2"
# run after the installation of the dependency graph, but before build() method
def generate(self):
# generate one xxxx-config.cmake file per dependency
cmake = CMakeDeps(self)
# generate the config files for the tool require
cmake.build_context_activated = ["cmake/3.22.0", "doxygen/1.9.2"]
cmake.generate()
# this is not building a library, just tests
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
# run CTest, launch binaries, etc
cmake.test(output_on_failure=True)
def package(self):
self.copy("*.h")
def package_id(self):
self.info.clear()
Thanks!
Issue Analytics
- State:
- Created 10 months ago
- Comments:9 (4 by maintainers)
Top GitHub Comments
A few issues:
include(.../conanbuildinfo.cmake)
which has been deprecated, it is part of thecmake
legacy generator that you just removed. You need to remove that line, and rely on standardfind_package(XXX CONFIG REQUIRES)
instructions and thentarget_link_libraries(.... xxx::xxx)
It could be that the
self.copy("*.h")
is not copying correctly the headers. You can paste here the output, it should have some messages summarizing what has been copied. It is also possible to inspect the final package folders, if you read the output and go to your disk package folder, you should be able to package the navigated files.In any case, it is also recommended to modernize that
self.copy()
tocopy(self, ...
which will be more explicit, requiring to definesrc
folder (typically something fromself.build_folder
) anddst
folder (typically something withself.package_folder
).Please check that regarding the final packaged artifacts and let us know.
Regarding the
build()
method, the only thing that has changed is the .test(). You can importfrom conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake
, and use all the same, exceptcmake.test()
, becauseoutput_on_failure=True
has been removed (you can control it externally with an env-var CTEST_OUTPUT_ON_FAILURE in your profile, for example in[buildenv]
section)