Suppress a specific path in the RPATH of an executable explicitly

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Suppress a specific path in the RPATH of an executable explicitly

Cornelis Bockemühl
In a project setup I am copying a number of shared library files into the executable directory (basically with a mechanism involving configure_file - because the "install" logic was simply too complicated for the project and for my limited brain capacity!).

On a Windows system this works nicely, but on a Linux system there is always some logic that puts the original shared library location into the executable's RUNPATH, with the effect that they are not found in the place where they are supposed to be found.

I tried to avoid this by using

set_target_properties(
    <imported targets>
    PROPERTIES
        CMAKE_SKIP_RPATH TRUE)

However, any effect was not visible: the "old" path is still included in RUNPATH. Maybe I overlooked one more imported target, overriding the effect of above, or it does not work on imported targets at all. Anyway, it would be much easier if I could simply drop one specific path explicitly with some setting! Dropping all is again too much - because I need other entries for other libraries.

Is there such an option available?

Maybe a workaround would be to explicitly prepend "$ORIGIN" to the RUNPATH in the executable: In this way the shared libs would be found in the executable directory first and any other "wrong" paths would not hurt.

Many thanks and regards,
Cornelis Bockemühl
--

Powered by kitware.com/cmake

Kitware offers various services to support the CMake community. For more information on each offering, please visit https://cmake.org/services

Visit other Kitware open-source projects at https://www.kitware.com/platforms

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

This mailing list is deprecated in favor of https://discourse.cmake.org
Reply | Threaded
Open this post in threaded view
|

Re: Suppress a specific path in the RPATH of an executable explicitly

Eric Doenges
On 19.12.19 10:52, Cornelis Bockemühl wrote:

> In a project setup I am copying a number of shared library files into
> the executable directory (basically with a mechanism involving
> configure_file - because the "install" logic was simply too complicated
> for the project and for my limited brain capacity!).
>
> On a Windows system this works nicely, but on a Linux system there is
> always some logic that puts the original shared library location into
> the executable's RUNPATH, with the effect that they are not found in the
> place where they are supposed to be found.
>
> I tried to avoid this by using
>
> set_target_properties(
>     <imported targets>
>     PROPERTIES
>         CMAKE_SKIP_RPATH TRUE)

This cannot work because CMAKE_SKIP_RPATH is a variable, not a property.
Variables are set with the set() command (or from the command line with
the -D option), and often serve as the default values for a specific
property if that property isn't explicitly set. Properties are set with
set_property() or set_target_properties() and apply only to the specific
target they are set for. In general, anything with a 'CMAKE_' prefix is
a variable, not a property.

Note that CMake distinguishes between "build time" and "install time"
rpath, allowing you to have different rpaths for the binaries in your
build and install directories. So if you do not want any rpath
information added to your binaries, you would

set(CMAKE_SKIP_RPATH TRUE)
set(CMAKE_SKIP_INSTALL_RPATH TRUE)

before defining any targets.

If you want to control the rpath for individual binaries, you would set
the appropriate properties for the binary target(s) whose rpath you want
to set. Check the CMake documentation for properties containing 'RPATH'
to see which properties are available - there is quite a number of them.
As far as I know, these properties are not transitive, so you cannot set
the rpath for a shared library and expect targets linked against that
library to receive this rpath.

It sounds to me that what you probably want to do is set the RPATH of
your executables to look in $ORIGIN and nowhere else. One way to do this
would be to

set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH "$ORIGIN")

before defining your targets. If you want control over individual
targets, you would set the BUILD_WITH_INSTALL_RPATH and INSTALL_RPATH
properties on the individual targets.

For more details, see
https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/RPATH-handling.

--

Powered by kitware.com/cmake

Kitware offers various services to support the CMake community. For more information on each offering, please visit https://cmake.org/services

Visit other Kitware open-source projects at https://www.kitware.com/platforms

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

This mailing list is deprecated in favor of https://discourse.cmake.org