views:

51

answers:

2

I wand to implement in CMake a functionality that would enable the installation of a single binary/target through a make install-TARGET command. This is fairly straightforward to do with a custom target. However, when the target binary in question is linked dynamically against other libs of the project (BUILD_SHARED_LIBS=ON), I need to install the receptive libs as well. Is there any way to somehow query the list of libraries?

I've looked at the target properties, but haven't found anything relevant.

Tips on how to get the list of libs and/or other ways to implement the above described functionality would be very much appreciated!

[Edit]

Example:
Let's assume that there the project MyProj has a CMake target "myprog" which generates the binary myprog. I want to install only this binary with make install-myprog. However myprog links against libmy1.so and the latter links against libmy2.so, both part of MyProj. I need a mechanism to figure out that I need to install both libmy1.so and libmy2.so along myprog.

A: 

I don't do *nix development, but the functionality you're looking for is same as "Dependency Walker" for windows. A quick search brought up the following:

http://stackoverflow.com/questions/1120796/dependency-resolution-in-linux

Hope it helps.

nsr81
Not really, I think you misunderstood the question. See the edit above.
pszilard
A: 

The most elegant solution seems to be the following. One has to use the CMake COMPONENT parameter of the install command to assign each install target to a component. For example in the question this would be something like this:

install(TARGETS myprog DESTINATION ${BIN_DEST_DIR} COMPONENT myprog),

and similarly for the shared libraries

install(TARGETS my1 my2 DESTINATION ${LIB_DEST_DIR} COMPONENT my-libs).

Now, to invoke the installation of myprog as well as mylib1 and mylib2 a custom target has to be created that uses the cmake_install.cmake locate in the build tree:

add_custom_target(install-myprog
   COMMAND ${CMAKE_COMMAND} -DCOMPONENT=my-libs -P ${CMAKE_BINARY_DIR}/cmake_install.cmake
   COMMAND ${CMAKE_COMMAND} -DCOMPONENT=myprog -P ${CMAKE_BINARY_DIR}/cmake_install.cmake
   COMMENT "Installing myprog").
pszilard