Michel
Michel

Reputation: 617

How does one package inter-dependent libraries with Conan?

I have a project for which I am trying to use conan as the package manager. The project uses a large number of libraries, most of which are self-sufficient. However, some of them depend on another library. To give a concrete example, let's say we have a project P that requires libraries A and B. A is self contained, but B depends on A for its compilation and linking.

I can easily create the conanfile.py for library A. I can create a conanfile.txt for project P. Assuming A and B have not been build yet, I want to be able to type in P's build directory:

conan install ../ --build=missing

and have conan download, compile and install library A, THEN download compile and install library B, with B having the correct references to A.

What is the proper approach in writing the conanfile.py of B?

Upvotes: 5

Views: 4182

Answers (1)

drodri
drodri

Reputation: 5972

When you write the package recipe for package B, you specify that it depends on A:

class PackageB(ConanFile):
    requires = "A/1.0@user/stable"

When you specify the dependencies in your project (either with a conanfile.txt or a conanfile.py), you specify as usual your dependencies. Conan handle transitive dependencies, so it knows that it has to build (or retrieve package binary if desired) package A first, and then package B.

It is typical that the build script for package B has to take into account the dependency to A. If using CMake, the solution would be using the cmake generator, and consuming the conanbuildinfo.cmake that has the include directories, library names, etc. for package A.

The docs specify a bit more about the syntax: http://docs.conan.io/en/latest/reference/conanfile.html#requirements

You can check some of the existing packages which are already managing transitive dependencies:

Upvotes: 4

Related Questions