[CMake] intercomponent link dependencies?

Nico Schlömer nico.schloemer at gmail.com
Tue Jan 12 19:55:56 EST 2010


Pheeew..
So I've now been trying to include one *single* library from an
external project (liba.a) into my own project, writing FindA.cmake.
Somehow I still fail to apply the dependencies correctly. What I do is

[...]
ADD_LIBRARY(A STATIC IMPORTED)
SET_TARGET_PROPERTIES( A PROPERTIES
                                             IMPORTED_LOCATION
"${A_LIBRARY}"     %set above
                                             LINK_INTERFACE_LIBRARIES
"${A_LINK_INTERFACE_LIBRARIES}"   % set above to something like
"/usr/lib/liblapack.a;/usr/lib/blas.a;"
                       )
[...]

[Setting TARGET_LINK_LIBRARIES(A LINK_INTERFACE_LIBRARIES
"${A_LINK_INTERFACE_LIBRARIES}" ) did *not* work for me.]

Now,  in the main CMakeLists.txt I say Find( A REQUIRED ), and I was
naivly expecting that upon

TARGET_LINK_LIBRARIES ( main.out A )

*all* the dependent libraries would be pulled in too. This is not the case. :/

What am I missing?

Cheers,
Nico





On Fri, Jan 8, 2010 at 11:00 AM, Nico Schlömer <nico.schloemer at gmail.com> wrote:
> Hi,
>
>> I am guessing that
>> you're putting the detection for every library that your app can/must use
>> into one "find" module, when you actually probably should have a directory
>> in your source tree added to your CMAKE_MODULE_PATH that contains a large
>> number of find modules, some of which are interdependent (just like how the
>> example I sent uses find_package(BLAS) - which is a module that comes
>> bundled with cmake).
>
> -- Exactly!
>
> I'm thinking now that this is indeed a good solution: Writing
> *separate* FindLibraryX.cmake files for all the libraries included in
> MyPackage and putting all the dependency information in there; then,
> make a meta .cmake file which will allow for specifying the keyword
> COMPONENTS, and where all the meta information goes (e.g., version
> number of MyPackage).
>
> Minor drawbacks of this approach I find would be that the fact that
> all those libraries live under one roof is entirely discarded, that
> is, that they all share a common LIB directory, INCLUDE directory, all
> have the same version string (namely the one of MyPackage). Plus also,
> new libraries included require their own new FindNewLib.cmake to be
> created, while all FindLibrary*.cmake would actually be the same file,
> except for the dependency info (nasty (?) code duplication).
>
> How I came to think about COMPONENTS in the first place was looking at
> FindBoost.cmake which I *thought does what I'm doing -- except for the
> intercomponent linking info.
>
> Cheers!
> Nico
>


More information about the CMake mailing list