[CMake] Inter-project dependencies

Emmanuel Blot eblotml at free.fr
Wed May 21 18:09:17 EDT 2008


> In the second project make sure you specify the libraries to link from
> the first project by full path.  Then the dependencies will be hooked
> up.  Without a full path CMake does not know how to add a build-time
> dependency on a library.  You can get a full path in the second  
> project
> by using find_library.  Even better, use export/import capabilities:
>
> http://www.cmake.org/Wiki/CMake_2.6_Notes#Exporting_and_Importing_Targets

Hi,

I tried the importing target feature, but unfortunately, it does not  
seem to work as (I ?) expected.
The executable of the second CMake project does not get relinked when  
a library of the first project is updated (i.e. more recent than the  
executable).

I've tried to change the rule
set_property(TARGET foo PROPERTY IMPORTED_LOCATION /path/to/libfoo.a)
with a non-existing file, i.e.
set_property(TARGET foo PROPERTY IMPORTED_LOCATION /path/to/libfoo2.a)

GCC fails to link the executable against the libfoo2.a library, as  
expected.
Note that the missing file as reported from GCC is a full path, which  
demonstrates that full path to the library are actually generated by  
CMake
(I also run make VERBOSE=1 to cross check: full path name to the  
libraries are definitely used)

Then, I reverted the invalid change to the proper library file path:
set_property(TARGET foo PROPERTY IMPORTED_LOCATION /path/to/libfoo.a)
and re-run make. At this point the executable DID get relinked (not  
rebuild, as expected).
So it seems that it gets closer to what I'd like to achieve, but  
there's still some issue with the dependency processing.

"touching" the libfoo.a never leads to relink the executable file.

I'm using CMake 2.6:

$> cmake --version
cmake version 2.6-patch 0

As a side note,
> http://www.cmake.org/Wiki/CMake_2.6_Notes#Exporting_and_Importing_Targets
uses the following example:
add_library(foo IMPORTED)
but it seems that this statement is not valid: the type of the library  
is required (STATIC, SHARED, etc) such as in
add_library(foo STATIC IMPORTED)



More information about the CMake mailing list