[CMake] intercomponent link dependencies?

Nico Schlömer nico.schloemer at gmail.com
Thu Jan 7 18:13:47 EST 2010


Wow, thanks for the elaborate answer!
I learn a lot just going through the examples.

One thing for me to understand first:

> Ah, so if those components are always necessary (that is, A always needs B,
> and B always needs C), there's no need to use the "components" option.
Ah, I found the components thing neat for its syntax, as one can
(quite semantically) say

FIND_PACKAGE( MyPackage COMPONENTS coolCompOfMyPackage anotherOne )
# very much like done in FindBoost.cmake

Of course there's not only a,b,c, but a whole set of libraries a,...,z
under the roof of MyPackage with a more or less complicated dependency
tree. Also, it would depend on the installation of MyPackage whether
all the libraries are actually there; for example, and installation
with only "b" and "c" would be possible.

Anyway, instead of hardcoding a,b,c one could possible FOREACH through
a (hardcoded) list of components, such as

SET( ALL_LIBS "a" "b" "c" "d" [...] "z" )

I guess how one would do that with the above suggestion is to further
define MYPACKAGE_{$LIB}_FOUND, and then in the CMakeLists.txt

FIND_PACKAGE( MyPackage )
IF( MYPACKAGE_a_FOUND )
  # add the necessary stuff to TARGET_LINK_LIBRARIES, for example
ELSE()
  MESSAGE( FATAL_ERROR "Too bad, we need a." )
END()

The disadvantage I see here is that FindMypackage.cmake had to be
adapted every time a new library makes it into MyPackage. Also, the
code in CMakeLists.txt would get longer than what I thought would be
nice [being:

FIND_PACKAGE( MyPackage COMPONENTS "a" "g" "t" )
# FATAL_ERRORing out if either of a, g, t hasn't been found,
# otherwise providing a slim ${MyPACKAGE_LIBRARIES} to be appended to
# TARGET_LINK_LIBRARIES or something.

].

Cheers,
Nico


More information about the CMake mailing list