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.
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
myprogas well asmylib1andmylib2a custom target has to be created that uses thecmake_install.cmakelocate in the build tree: