Reputation: 115
I have two C libaries, where Lib_a.a has a dependency on lib_b.a I am developing a GitLab CI/CD pipeline that will download from the package registry and link to lib_b.a when building lib_a.a
So far, the when building lib_a in the CI/CD pipeline. lib_b.a is downloaded and installed by conan. However I am unsure how or where to reference the header file for lib_b.a
cmake version: 3.26.5 conan version: 1.66.0
I have shared the related settings from the conan and GitLab pipeline configuration files as well as the pipeline terminal output below.
conanfile.py:
class helloRecipe(ConanFile):
name = "lib_a"
version = "1.0"
package_type = "library"
# Optional metadata
license = "foo"
author = "bar"
url = "https://foo.bar"
description = """text"""
topics = ("lib_a")
# Binary configuration
settings = "os", "compiler", "build_type", "arch"
requires = "lib_b/1.0beta"
generators = "CMakeDeps"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}
def generate(self):
'''
The generate() method prepares the build of the package from source. In this
case, it could be simplified to an attribute generators = "CMakeToolchain", but
it is left to show this important method. In this case, the execution of
CMakeToolchain generate() method will create a conan_toolchain.cmake file that
translates the Conan settings and options to CMake syntax. The CMakeDeps
generator is added for completitude, but it is not strictly necessary until
requires are added to the recipe.
'''
deps = CMakeDeps(self)
deps.generate()
tc = CMakeToolchain(self)
tc.generate()
def requirements(self):
self.requires("lib_b/1.0")
.gitlab-ci.yml:
- conan profile new ./profile --detect
- conan remote add lib_b_registry ${CI_API_V4_URL}/projects/11112/packages/conan False -f
- conan user ci_user -r lib_b_registry -p ${CI_JOB_TOKEN}
- conan create . -c "tools.build:verbosity='verbose'" --remote=toollib_registry
- conan remote add gitlab ${CI_API_V4_URL}/projects/11111/packages/conan False -f
- CONAN_LOGIN_USERNAME=ci_user CONAN_PASSWORD=${CI_JOB_TOKEN} conan upload "*" --confirm --force --all --remote=gitlab
pipeline terminal output:
lib_b/1.0: Retrieving from server 'lib_b_registry'
lib_b/1.0: Trying with 'lib_b_registry'...
Downloading conanmanifest.txt
Downloading conanfile.py
Downloading conan_export.tgz
lib_b/1.0: Downloaded recipe revision 0
lib_a/1.0: Forced build from source
Installing package: lib_a/1.0
Requirements
lib_a/1.0 from local cache - Cache
lib_b/1.0 from 'lib_b_registry' - Downloaded
Packages
lib_a/1.0:aid9fd64001b74d0ce5hg51de03d17e0b785558fs- Build
lib_b/1.0:gdw8aba822ahgf46849d2f1bafe4a2a62a9f83b74 - Download
Installing (downloading, building) binaries...
lib_b/1.0: Retrieving package gdw8aba822ahgf46849d2f1bafe4a2a62a9f83b74 from remote 'lib_b_registry'
Downloading conanmanifest.txt
Downloading conaninfo.txt
Downloading conan_package.tgz
lib_b/1.0: Package installed gdw8aba822ahgf46849d2f1bafe4a2a62a9f83b74
lib_b/1.0: Downloaded package revision 0
...
/root/.conan/data/lib_a/1.0/_/_/build/aid9fd64001b74d0ce5hg51de03d17e0b785558fs/src/lib_a.h:18:10: fatal error: lib_b.h: No such file or directory
18 | #include "lib_b.h"
| ^~~~~~~~
compilation terminated.
Upvotes: 1
Views: 39
Reputation: 115
I needed the import()
method in my conanfile.py, to import files from lib_b to lib_a, as shown below. Knowing the underlying conan install
led me to the answer.
def imports(self):
self.copy("*.h", dst="src", src="include")
Upvotes: 0