[CMake] more on an executable dependency on external library

Bill Hoffman bill.hoffman at kitware.com
Tue Dec 5 20:15:53 EST 2006


Crni Gorac wrote:
> OK, I've tried in the meantime various arrangements with
> ADD_CUSTOM_TARGET(), but seems hard to employ it to have CMake to put
> following simple dependency of an executable "foo" on system library
> "libbar.a" into generated Makefile:
> foo: /usr/local/lib/libbar.a
>
> There exists of course ADD_EXECUTABLE() statement for executable foo,
> and there exists also TARGET_LINK_LIBRARIES() statement specifying
> that "foo" should be linked with "libbar.a".  The library "libbar.a"
> is a system-wide installed library, however let's say it changes
> often, and it is necessary to have above dependency somehow captured
> by CMake.  Any suggestion on how to accomplish this?
If you link to the full path it should do what you want.

target_link_libraries(foo /usr/local/lib/libbar.a)
Of course you would not want to hard code the path to libbar.a,
but rather use a FIND_LIBRARY(BAR bar)
target_link_libraries(foo ${BAR})

But either way if you have a full path the makefile will have 
foo:/usr/local/lib/libbar.a in it.
(At least it will with 2.4.5)

-Bill



More information about the CMake mailing list