[CMake] Handling dependencies between projects

Raymond Wan rwan.work at gmail.com
Wed Nov 4 20:42:18 EST 2015


Dear all,

I know this is a frequent question on this mailing list, but I'm being
a bit overwhelmed with information and not too sure which direction I
should head.

Basically, I have executables X and Y who are each top-level projects.
They make use of library A.  Library A in turn makes use of library B.
Both A and B are libraries which are linked to, but they are also
executables -- I compile with a temporary main () function in order to
do some tests.  That is, their CMakeLists.txt generate both a library
and an executable.

So, the dependencies are like this:

X <-- A <-- B
Y <-- A <-- B

What I'm confused about are:

1)  Should all 4 have their own Project () lines?

2)  Should X and Y have ExternalProject () lines to A?

3)  Should A have ExternalProject () lines to B?

4)  Or maybe instead of ExternalProject (), I should use Add_Subdirectory ()?

5)  Or should X and Y have Target_Include_Directories () to A; should
A have a Target_Include_Directories () to B?

...or maybe something else?

What I think is that they should all have their own Project ().  And
perhaps A and B should have Install () lines that install libraries
into ${CMAKE_INSTALL_PREFIX}/lib/ and header files to
${CMAKE_INSTALL_PREFIX}/include/.  Then, X, Y, and A needs
Target_Include_Directories () to this path and *NOT* the where the
source code of A and B reside.

All this removes ExternalProject () from the picture...  It's true
what I'm including is mine but these libraries could be used
separately by other programs (i.e., Y).

I hope this is clear -- there are just too many options and the
documentation is thorough but the difference between each seems small.
At least too small for me to distinguish...

Thank you!

Ray


More information about the CMake mailing list