'How to set CMAKE_INSTALL_RPATH with multiple directories?
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"
)
Solution 1:[1]
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:
- https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_RPATH.html
- https://cmake.org/cmake/help/latest/prop_tgt/BUILD_WITH_INSTALL_RPATH.html
Related CMP:
Solution 2:[2]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 |