Get all required shared libs from a target

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Get all required shared libs from a target

Müller Michael
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
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Get all required shared libs from a target

Michael Wild

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
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Get all required shared libs from a target

Müller Michael
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:[hidden email]]
Gesendet: Freitag, 28. August 2009 09:30
An: Müller Michael
Cc: [hidden email]
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
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Get all required shared libs from a target

Michael Wild

You could use CMAKE_RUNTIME_OUTPUT_DIRECTORY or the  
RUNTIME_OUTPUT_DIRECTORY target property to specify where CMake should  
put all the produced runtime stuff (on Windows, AFAIK this is *.exe  
and *.dll), so you don't have to copy them around manually.
If the dll's are not built by you, you might want to have a look at  
the GetPrerequisites and InstallRequiredSystemLibraries modules.

Michael

On 28. Aug, 2009, at 10:12, Müller Michael wrote:

> 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:[hidden email]]
> Gesendet: Freitag, 28. August 2009 09:30
> An: Müller Michael
> Cc: [hidden email]
> 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
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Get all required shared libs from a target

David Cole
See also the BundleUtilities module.

Work in CVS CMake recently has extended the "fixup_bundle" function so that it works on Windows/Linux as well as on a Mac. And what you are looking for is exactly what it does. If executed in an install script, fixup_bundle will analyze a given executable and then copy/fixup any required non-system shared libraries making it easy to depend on third party dlls without adding a bunch of explicit copy steps yourself...

The prime example of its use is still Mac-only, though: grep for CompleteBundle in the ParaView source tree for the canonical example.

HTH,
David


On Fri, Aug 28, 2009 at 4:44 AM, Michael Wild <[hidden email]> wrote:

You could use CMAKE_RUNTIME_OUTPUT_DIRECTORY or the RUNTIME_OUTPUT_DIRECTORY target property to specify where CMake should put all the produced runtime stuff (on Windows, AFAIK this is *.exe and *.dll), so you don't have to copy them around manually.
If the dll's are not built by you, you might want to have a look at the GetPrerequisites and InstallRequiredSystemLibraries modules.

Michael


On 28. Aug, 2009, at 10:12, Müller Michael wrote:

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:[hidden email]]
Gesendet: Freitag, 28. August 2009 09:30
An: Müller Michael
Cc: [hidden email]
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
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Get all required shared libs from a target

Michael Jackson
In reply to this post by Müller Michael
If you pull the boost 1.39.0 sources there is an experimental CMake  
based build system. In those cmake files the developers have somehow  
figured out how to do what you want. For a given library, you can get  
all the dependencies.

  So in your case you would say that lib B depends on Lib A. Then when  
you did your C target the cmake code figures out that C, which depends  
on B, will also have a dependency on A. If you can wade through the  
CMake files it might be worth a look.

  If you want to manually do this yourself the really ugly but  
effective way would be to create all the necessary cmake variables in  
the top CMakeLists.txt. If the variables are declared in that cmake  
file then they will be available to any other included CMake file.  
This isn't the best and does not really scale well but for small  
projects it does work.

Just some thoughts.
--
Mike Jackson <www.bluequartz.net>

On Aug 28, 2009, at 4:12 AM, Müller Michael wrote:

> 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:[hidden email]]
> Gesendet: Freitag, 28. August 2009 09:30
> An: Müller Michael
> Cc: [hidden email]
> 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
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Get all required shared libs from a target

Alexander Neundorf-3
On Friday 28 August 2009, Michael Jackson wrote:
> If you pull the boost 1.39.0 sources there is an experimental CMake
> based build system. In those cmake files the developers have somehow
> figured out how to do what you want. For a given library, you can get
> all the dependencies.

Maybe you can file a feature request, so that you can do
get_target_properties(libs yourlib LINK_INTERFACE_LIBRARIES)
works if you have set LINK_INTERFACE_LIBRARIES using TARGET_LINK_LIBRARIES(...
LINK_INTERFACE_LIBRARIES)

If you haven't done that, it returns NOTFOUND. Maybe you could file a feature
request that get_target_property(<var> <target> LINK_INTERFACE_LIBRARIES)
should return the full set of linked libraries (which will be the link
interface libraries) if LINK_INTERFACE_LIBRARIES has not explicitely been
set.

For libraries you can also have a look at the <target>_LIB_DEPENDS variable,
maybe that helps.

Alex
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake