Take the 2-minute tour ×

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!


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.

share|improve this question
add comment

2 Answers

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:


Hope it helps.

share|improve this answer
Not really, I think you misunderstood the question. See the edit above. –  pszilard Sep 21 '10 at 17:05
add comment
up vote 0 down vote accepted

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:


and similarly for the shared libraries


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:

   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").
share|improve this answer
add comment

Your Answer


