[CMake] question about INSTALL_PROGRAMS vs INSTALL(TARGET

Alexander Neundorf a.neundorf-work at gmx.net
Mon Jun 9 14:44:09 EDT 2008


On Monday 09 June 2008, Simon Warfield wrote:
> I am using cmake 2.6.
> I notice a difference in behaviour between
> INSTALL_PROGRAMS(/bin FILES CreateTriangleModel )
>  and
> INSTALL(TARGETS CreateTriangleModel RUNTIME DESTINATION bin )
>
> In the case of INSTALL_PROGRAMS the build tree binary and the installed
> binary  are linked with the full path of the shared libraries they use.
> In the case of INSTALL(TARGETS the build tree binary is linked with the
> full path of the shared libraries, but the installed binary is not. The
> installed binary has to find the libraries in e.g. the LD_LIBRARY_PATH
> of the user.
>
> Are these supposed to work differently ?

Yes.
INSTALL_PROGRAMS() is deprecated. The purpose was to install files which 
happen to be executables, i.e. basically the files are copied to the install 
destination and the executable bits are set.
To install programs or libraries which have been built in your project, the 
old command was install_targets() and the new one is INSTALL(TARGETS ....)

By default when you build an executable with cmake, it is built with the RPATH 
set up in such a way that it points to the shared libraries in the build tree 
and also to other shared libraries which are linked. 
Then when installing, the RPATH is modified. By default it is set empty, then 
you have to make sure the libs can be found via LD_LIBRARY_PATH or the 
standard lib directories.
Or you can use SET_TARGET_PROPERTIES() to enable an RPATH for the installed 
executables. 
You can e.g. manually set the target property INSTALL_RPATH to the RPATH you'd 
like to have in the installed executable.
Or you can set the property INSTALL_RPATH_USE_LINK_PATH to TRUE, then the 
installed executable will have the same RPATH as the executable in the build 
tree EXCEPT the directories which are inside the build tree.

Alex


More information about the CMake mailing list