我们如何在MacOS上的CMake中的目标上设置多个RPATH目录?在Linux上,我们可以使用以冒号分隔的列表:
set_target_properties(mytarget
PROPERTIES
INSTALL_RPATH "\$ORIGIN/../lib:\$ORIGIN/../thirdparty/lib"
)
在MacOS上,我们可以在技术上添加冒号分隔列表,otool -l
应该显示它,但不搜索这些目录:
set_target_properties(mytarget
PROPERTIES
INSTALL_RPATH "@loader_path/../lib:@loader_path/../thirdparty/lib"
)
通常,如果我要在MacOS上有多个RPATH目录,我会发送多个链接器标志,这些标志将与otool -l
分开显示。类似的东西:
g++-mp-4.7 mytarget.cpp -o mytarget -Wl,-rpath,@loader_path/../lib,-rpath,@loader_path/../thirdparty/lib
给出了:
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)
如何使用CMake重新创建此行为?
答案 0 :(得分:8)
根据documentation,路径不应该用冒号分隔,而是用分号分隔:
set_target_properties(mytarget
PROPERTIES
INSTALL_RPATH "@loader_path/../lib;@loader_path/../thirdparty/lib"
)
或者,使用命令set
让CMake处理分隔符:
set(MY_INSTALL_RPATH
"@loader_path/../lib"
"@loader_path/../thirdparty/lib"
)
set_target_properties(mytarget
PROPERTIES
INSTALL_RPATH "${MY_INSTALL_RPATH}"
)
编辑:(感谢Tsyvarev的评论)
或者,使用接受多值属性的命令set_property
:
set_property(
TARGET mytarget
PROPERTY INSTALL_RPATH
"@loader_path/../lib"
"@loader_path/../thirdparty/lib"
)