How to install multiple RPATH directories using CMake on MacOS

How to set multiple RPATH directories on target in CMake on macOS? On Linux, we can simply use a colon-separated list:

set_target_properties(mytarget PROPERTIES INSTALL_RPATH "\$ORIGIN/../lib:\$ORIGIN/../thirdparty/lib" ) 

On MacOS, we can technically add a colon-separated list, and otool -l should show it, but these directories are not executed:

 set_target_properties(mytarget PROPERTIES INSTALL_RPATH "@loader_path/../lib:@loader_path/../thirdparty/lib" ) 

Normally, if I have several RPATH directories on MacOS, I would send several linker flags, and these flags would be displayed separately with otool -l . Sort of:

 g++-mp-4.7 mytarget.cpp -o mytarget -Wl,-rpath,@loader_path/../lib,-rpath,@loader_path/../thirdparty/lib 

What gives:

 Load command 15 cmd LC_RPATH cmdsize 32 path @loader_path/../lib (offset 12) Load command 16 cmd LC_RPATH cmdsize 48 path @loader_path/../thirdparty/lib (offset 12) 

How do I recreate this behavior with CMake?

+5
source share
1 answer

According to the documentation, the paths should not be separated by colons, but with a semicolon :

 set_target_properties(mytarget PROPERTIES INSTALL_RPATH "@loader_path/../lib;@loader_path/../thirdparty/lib" ) 

Or, using the set command to allow CMake to deal with the delimiter:

 set(MY_INSTALL_RPATH "@loader_path/../lib" "@loader_path/../thirdparty/lib" ) set_target_properties(mytarget PROPERTIES INSTALL_RPATH "${MY_INSTALL_RPATH}" ) 

EDIT: (thanks to Tsyvarev for the comment)

Or, using the set_property command, which accepts multi-valued properties:

 set_property( TARGET mytarget PROPERTY INSTALL_RPATH "@loader_path/../lib" "@loader_path/../thirdparty/lib" ) 
+7
source

Source: https://habr.com/ru/post/1258511/


All Articles