[CMake] Dependencies between independent projects
André Caron
andre.l.caron at gmail.com
Wed May 2 13:48:43 EDT 2012
I've run into this issue before and posted a question about this on
Programmers.StackExchange[1]. While the exact workflow I present is for
Git & CMake, the question is really similar. The idea is to have a certain
library B that depends on library A, as well as a program C that depends on
B and A. I want to be able to build each library by itself for library
development and testing, as well building them as part of a program.
I've come up with a simple workflow where each library project exports a
"library-config.cmake" file and any project that includes it defines the
"library_DIR" variable to the folder containing this "library-config.cmake"
file so that it can be resolved from anywhere in the CMake scripts using
only "find_package()". This way, when the library can either set the
"library_DIR" variable or inherit it from the parent project. This solves
the problem of using either its own Git submodule or a parent project's Git
submodule, ensuring you build the library only once for the entire project
and that all sub-projects use the same version.
Note that you don't necessarily need to list all of each project's
dependencies in the root CMake lists. I do so out of convention (to
explicitly document what library versions I'm using) and convenience (to
avoid recursive Git submodule checkouts). You only typically need to do so
for libraries referenced by multiple shared libraries, unless, of course,
you really want to build the same library multiple times, possibly in
multiple versions.
I'm slowly converting all my projects to CMake using this pattern. You can
find some of those on my GitHub profile[2]. One example is cfcgi[3]. Note
that I'm learning a lot along the way and I don't guarantee that all of
this conforms to CMake best practices. I'm only referring to this for the
project structure and CMake concept to clarify my explanation with an
example. That being said, if anyone has comments about the CMake scripts
in there, your input is welcome :-)
André
[1]: http://programmers.stackexchange.com/questions/114719
[2] : https://github.com/AndreLouisCaron
[3]: https://github.com/AndreLouisCaron/cfcgi
Le 29/04/2012 21:43, Alexander Broekhuis a écrit :
>>
>> Hi all,
>>
>> I am looking for a way to have dependencies between independent
>> projects. For examplehave been
>>
>> ProjectA
>> ProjectB depends on A
>> ProjectC depends on B and A
>>
>> What I like to do is that when project B or C is build, the
>> dependencies are also build. But I also want the project to be independent,
>> to be more specific, if the project files for A are being generated I don't
>> want the files for B and C generated.
>>
>> Basically my problem is, that I don't want all Makefile to be generated
>> all at once. But only those needed for a certain project (and its
>> dependencies). This helps with not having installed every library needed by
>> all (sub)projects.
>>
>> Has anyone any experience with this, or perhaps some hints how I can
>> solve this problem?
>>
>> TiA!
>>
>>
>> --
>> Met vriendelijke groet,
>>
>> Alexander Broekhuis
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120502/01366b4d/attachment.htm>
More information about the CMake
mailing list