[CMake] What is a good way to exclude default library locations from install-tree rpaths?

Alan W. Irwin irwin at beluga.phys.uvic.ca
Tue Feb 2 17:26:09 EST 2010


Thanks, Alex, for responding to my questions.

On 2010-02-02 21:23+0100 Alexander Neundorf wrote:

> On Friday 29 January 2010, Alan W. Irwin wrote:
>> If target_link_libraries is given the full path to an external library,
>> then by default CMake uses rpath on Linux so that library is found at run
>> time for the build tree.  For PLplot I have adjusted the RPATH options so
>> that the install-tree rpath is similarly well determined for all our
>> external libraries.
>>
>> However, there is one difference between the build-tree rpaths handled
>> automatically by CMake and our install-tree rpaths that I would like to
>> address.  CMake is smart enough so that standard
>> locations (e.g., /usr/lib) which are automatically searched in any case by
>> the run-time loader are filtered out of the build-tree rpaths.
>
>> Currently, I don't have any functionality for removing standard locations
>> from the install-tree rpaths.  Therefore, I am getting the following
>> results from the install:
>>
>> -- Set runtime path of
>> "/home/software/plplot_svn/installcmake/lib/libplplotd.so .9.7.0" to
>> "/home/software/plplot_svn/installcmake/lib:/usr/lib:/home/software/qhull/i
>> nstall/lib"
>
> So /usr/lib doesn't appear in the build tree RPATH, but it does in the install
> RPATH ?

Yes.

> I think cmake uses the CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES variable,
> which is set in UnixPaths.cmake
>
> Which of the following two modes are you using ?
> - explicitely specify the RPATH you want to have (wouldn't that work if it
> just for the libs you installed yourself, so you know the install
> locations ?)
> - let cmake automatically compute the full RPATH by enabling the target
> property INSTALL_RPATH_USE_LINK_PATH

The PLplot CMake-based build system does not use
INSTALL_RPATH_USE_LINK_PATH. Instead, it explicitly sets the INSTALL_RPATH
target property.  The problem is that we have many different library
dependencies so contributions to that INSTALL_RPATH come from all over our
build system depending on options that the user sets controlling which
components of PLplot are built.  Also, for some of those dependent
libraries, the user has the option to use the system versions or ones that
are installed in a special location.  Also, we have a number of plugins and
libraries where rpath has to be set up.  So it is all pretty complicated and
preferably the filtering of default locations should be done automatically
for wherever the install_RPATH target property is used, but since it
currently is not done automatically, I have to implement filtering myself.

It looks like your suggestion above to use the 
CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES variable for this purpse is a good
one.  To (slightly) correct one thing you said though, UnixPaths.cmake
appends to it as do other Unix-platform-dependent files in Modules/Platform.

As a double-check, I have just printed out that variable on my (Debian
Lenny) platform using cmake-2.8.0.  The result is

-- CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES = 
/lib;/usr/lib;/usr/lib32;/usr/lib64

which agrees with what is in UnixPaths.cmake and seems to be exactly
what I need to do automatic filtering of the list that is used
for the INSTALL_RPATH target property.  However, for cmake-2.6.4
there is a bug, and the result is a duplicated list of what
appears in UnixPaths.cmake: 
-- CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES = 
/lib;/usr/lib;/usr/lib32;/usr/lib64;/lib;/usr/lib;/usr/lib32;/usr/lib64

I notice on the cmake-2.8.0 version you have some extra logic to deal with
when UnixPaths.cmake is called twice so the absence of that logic for the
cmake-2.6.4 version is probably why the list is getting duplicated.

However, it is easy to work around that duplicate list issue using

if(CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES)
   list(REMOVE_DUPLICATES CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES)
endif(CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES)

So to summarize this, I plan to filter all the many INSTALL_RPATH target
properties I set in various parts of our build system for our applications
and libraries using the CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES variable,
but a much cleaner way to do this would be if CMake itself automatically
filtered INSTALL_RPATH.  Therefore, I hope that CMake fix is implemented. (I
assume here you always want to filter out the standard locations from rpath
for the installed applications and libraries.  This is the assumption CMake
appears to make for the build-tree versions of those applications and
libraries.)

Is that a trivial fix or do you want me to make a wish-list bug so the idea
doesn't get lost?

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of
Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________

Linux-powered Science
__________________________


More information about the CMake mailing list