[CMake] packaging configuration files

James C. Sutherland James.Sutherland at utah.edu
Wed Nov 11 12:16:23 EST 2009


On Nov 11, 2009, at 9:05 AM, Brad King wrote:

> James C. Sutherland wrote:
>> Thanks.  To be clear, it only works if I use
>> 
>> 	set( ExprLib_LIBRARIES @TPL_LIBRARIES@ )
>> 
>> because otherwise I have no way of propagating the dependents of
>> ExprLib downstream.  It is true that CMake will add the ExprLib
>> library as a "target" that can be used internally in downstream
>> projects, but the other third-party libraries that ExprLib
>> requires can only be propagated "manually" - right?
> 
> In this example:
> 
>  # Library
>  add_library(foo foo.c)
>  target_link_libraries(foo m)
>  install(TARGETS foo DESTINATION lib EXPORT FooLib)
>  install(EXPORT FooLib DESTINATION lib/FooLib)
> 
> the FooLib.cmake file will provide the dependency on 'm'.
> In an application:
> 
>  # App
>  include(.../lib/FooLib/FooLib.cmake)
>  add_executable(bar bar.c)
>  target_link_libraries(bar foo)
> 
> The link line for 'bar' will contain
> 
>  -o bar ... /path/to/lib/libfoo.a -lm ...
> 
> -Brad

Thank you, Brad!  

I did not have the "target_link_libraries" for my library since I figured it didn't do anything.  I guess that it doesn't affect the library creation, but it does allow CMake to do the export properly.  In hindsight that makes complete sense.  Adding the "target_link_libraries" results in the proper library dependencies being pulled for my library.

This exchange was instructive!


More information about the CMake mailing list