[CMake] Get all required shared libs from a target

Müller Michael michael.mueller at dkfz-heidelberg.de
Fri Aug 28 04:12:22 EDT 2009


Hi Michael,

Thanks for your repsonse but I need the required DLLs to copy them in a post-build step. So I need the information which libaries are required for executing something. E.g., in your example

add_library(a ${A_SRCS})
add_library(b ${B_SRCS})
target_link_libraries(b a)
add_executable(c ${C_SRCS})
target_link_libraries(c b)

I`d like to have something like 
GET_TARGET_PROPERTY(LIBS c IMPORTED_LINK_DEPENDENT_LIBRARIES) and then LIBS would contain "C:\project\a.dll;C:\project\b.dll". I also tried it with IMPORTED_LINK_DEPENDENT_LIBRARIES but that gives me an empty variable.

Hopefully, this made my problem clearer.

Michael

-----Ursprüngliche Nachricht-----
Von: Michael Wild [mailto:themiwi at gmail.com] 
Gesendet: Freitag, 28. August 2009 09:30
An: Müller Michael
Cc: cmake at cmake.org
Betreff: Re: [CMake] Get all required shared libs from a target


On 28. Aug, 2009, at 8:29, Müller Michael wrote:

> Hi guys,
>
> is it possible to "investigate" a target for all required shared  
> libs (transitively). That means i dont which libraries where set  
> with TARGET_LINK_LIBRARIES and somewhere in my CMakeLists.txt i want  
> to find it out again.
>
> Thank you
> Michael


Hi

You don't need this (for the case you described). CMake remembers for  
you:


add_library(a ${A_SRCS})
add_library(b ${B_SRCS})
target_link_libraries(b a)
add_executable(c ${C_SRCS})
target_link_libraries(c b)


As you see in the last line, c is mentioned to link against b. CMake,  
however, remembers that b also links against a, and consequently also  
adds a to the list of libraries to link against.


HTH

Michael


More information about the CMake mailing list