[CMake] Rebuild target when external library changes?

Bill Hoffman bill.hoffman at kitware.com
Tue Dec 2 19:10:52 EST 2008


Lezz Giles wrote:
>  
> 
> I have a project set up that imports libraries, and I want to relink if 
> those imported libraries change;
> 
>  
> 
> For example, in a directory I have
> 
> hellow.c
> 
> libfred.a
> 
> CMakeLists.txt
> 
>  
> 
> where CMakeLists.txt contains:
> 
> -----------------------------------------
> 
> LINK_DIRECTORIES(.)
> 
> ADD_EXECUTABLE(hellow hellow.c)
> 
> TARGET_LINK_LIBRARIES(hellow fred)
> 
This should work:

target_link_libraries(hellow ${CMAKE_CURRENT_SOURCE_DIR}/libfred.a)

CMake has to know the full path to the library in order to create a 
dependency.   You could also use find_library to find libfred.

-Bill



More information about the CMake mailing list