[CMake] new RPATH support questions

Brad King brad.king at kitware.com
Tue Mar 7 12:54:31 EST 2006


Alexander Neundorf wrote:
> Hi, 
>  
> 
>>Von: Brad King <brad.king at kitware.com> 
>> 
>>Alexander Neundorf wrote: 
>>
>>>Ok, I tested now the following:  
>>>  
>>>set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)  
>>>set(CMAKE_SKIP_BUILD_RPATH TRUE)  
>>>  
>>>set(CMAKE_INSTALL_RPATH ${LIBRARY_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/   
>>>                        ${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR})  
>>>  
>>>Which gives 
>>> 
>>>
>>
> 
> CMAKE_INSTALL_RPATH=/home/alex/src/kde4-svn/kdelibs-build/lib/.:/opt/kde4/lib
> 
> 
>>> 
>>>as expected.   
>>>When linking, this is then used for RPATH.  
>>>This should have the effect that it can be installed without 
>>> relinking  
>>>and that it has RPATH both to the build dir and to the install dir 
>>>set.  
>>>  
>>>Before these changes, there was also the directory to the Qt libs  
>>>(/usr/lib/qt4/lib) used for the RPATH. This is gone now, I didn't 
>>>expect this. I expected that only the paths to the libraries compiled 
>>>within this project would be removed by setting 
>>>CMAKE_SKIP_BUILD_RPATH to true. 
>>>  
>>>Is this a bug or a feature ? If it's a feature, why has it been  
>>>implemented this way ?  
>>
>> 
>>The default policy is really simple: 
>> 
>>1.) Binaries in the build tree should be able to run without  
>>LD_LIBRARY_PATH so the rpath is configured to be the same as the link  
>>library search path (-L options). 
>> 
>>2.) Binaries in the install tree should have whatever rpath is 
>>specified  
>>by the developer (via INSTALL_RPATH) without any magic, and by default  
>>no rpath at all.  CMake cannot know the final organization for outside  
>>libraries intended by the developer so no guesses are made.  For  
>>example, what if a Qt build tree was used to provide Qt to your  
>>project's build tree but they would both be installed and distributed  
>>together? 
> 
>  
> But this will be quite hard to get right e.g. for kdelibs. 
> We link to really a lot of libraries there. If I want to have RPATH for 
> the installed executables, I don't really know how to find out which 
> directories I need in RPATH. 
> I think currently it is like this: 
>  
> BUILD_RPATH = RPATH for external libs + RPATH for internal libs 
> INSTALL_RPATH = user specified install RPATH 
>  
> This means when installing it will be quite hard to get a right RPATH, 
> since I don't know how to figure out the RPATH for the external libs. 
> I could add the directory for the Qt libs, but I don't know which other 
> of the libs also need RPATH. 
>  
> Would it possible to split this into three parts ? 
>  
> BUILD_RPATH: RPATH for the libs built in this project, all inside 
>                    CMAKE_BINARY_DIR 
> INSTALL_RPATH: RPATH set when installing specified by the user 
> EXTERNAL_RPATH: RPATH pointing outside CMAKE_BINARY_DIR 
>  
> BUILD_RPATH is then removed on installing (if it was built without 
> SKIP_BUILD_RPATH). INSTALL_RPATH is added when installing (except it was 
> compiled with COMPILE_WITH_INSTALL_RPATH). EXTERNAL_RPATH is removed when 
> installing depending on an additional flag. 
>  
> What do you think ? 
> This should be much easier to do in cmake directly than in 
> CMakeLists.txt. 

CMake has no way to know what the proper RPATH is for external libraries 
in the installed binaries.  Again, take my example of using a separate 
Qt build tree.  KDE would build and install with an rpath pointing at 
the Qt build tree instead of the installed Qt.

CMake is providing an interface to get whatever RPATHs you want into the 
installed binary.  It is is up to a project's code to produce the proper 
path for its distribution.  Only the project authors know how the 
binaries will finally be distributed and where other libraries will be 
located.

-Brad


More information about the CMake mailing list