2

On the question CMAKE RPATH not working - could not find shared object file I see how to set CMAKE_INSTALL_RPATH for a single path, but I need it for multiple paths. I tried these using but I did not worked:

SET( CMAKE_INSTALL_RPATH "/opt/my/lib;/other/lib" )
SET( CMAKE_INSTALL_RPATH "/opt/my/lib:/other/lib" )

On the question How to set multiple RPATH directories using CMake on MacOS I see I can set multiple paths with semicolon ; for a target, but I would like to set it for all targets instead of setting it for each one. Is there a equivalent of set_target_properties for all targets (including subprojects) ? For example:

set_target_properties(alltargets
    PROPERTIES
    INSTALL_RPATH "/opt/my/lib;/other/lib"
)
Evandro Coan
  • 8,560
  • 11
  • 83
  • 144

2 Answers2

3

Snippet:

# note: macOS is APPLE and also UNIX !
if(APPLE)
  set_target_properties(foo PROPERTIES
    INSTALL_RPATH "@loader_path;@loader_path/...")
elseif(UNIX)
  set_target_properties(foo PROPERTIES
    INSTALL_RPATH "$ORIGIN:$ORIGIN/...")
endif()

Related CMake variable:

Related CMP:

Mizux
  • 8,222
  • 7
  • 32
  • 48
0

After testing, it seems the first option using semicolons as separator is working SET( CMAKE_INSTALL_RPATH "/opt/my/lib;/other/lib" ). For reference, there is the cmake documentation, but I did not found this answer there: https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling

The thing I do not know about is how I can use something like set_target_properties for all my alltargets automatically.

Evandro Coan
  • 8,560
  • 11
  • 83
  • 144
  • 1
    You reference not a documentation but a **wiki**. The **documentation** for the variable `CMAKE_INSTALL_RPATH` is here: https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_RPATH.html. It explicitly tells that variable is interpreted as a **list** of paths, and it explicitly tells that the variable's setting affects on `INSTALL_RPATH` property for **all targets**. Documentation for [INSTALL_RPATH](https://cmake.org/cmake/help/latest/prop_tgt/INSTALL_RPATH.html) tells "This property is initialized by the value of the variable CMAKE_INSTALL_RPATH if it is set when a target is created." – Tsyvarev Sep 24 '21 at 07:23