diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2021-04-23 15:19:11 (GMT) |
---|---|---|
committer | Kyle Edwards <kyle.edwards@kitware.com> | 2021-06-04 12:52:01 (GMT) |
commit | 2ef3ea394f424bf2397878b00725b93ebe04c589 (patch) | |
tree | 8af040cd82162771cda213033da055d7fa2829e0 /Tests/RunCMake/file-GET_RUNTIME_DEPENDENCIES/macos-rpath.cmake | |
parent | b613e09778260c26c6323026dc2ccb980c102f3e (diff) | |
download | CMake-2ef3ea394f424bf2397878b00725b93ebe04c589.zip CMake-2ef3ea394f424bf2397878b00725b93ebe04c589.tar.gz CMake-2ef3ea394f424bf2397878b00725b93ebe04c589.tar.bz2 |
file(GET_RUNTIME_DEPENDENCIES): Add undocumented RPATH_PREFIX option
Diffstat (limited to 'Tests/RunCMake/file-GET_RUNTIME_DEPENDENCIES/macos-rpath.cmake')
-rw-r--r-- | Tests/RunCMake/file-GET_RUNTIME_DEPENDENCIES/macos-rpath.cmake | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/Tests/RunCMake/file-GET_RUNTIME_DEPENDENCIES/macos-rpath.cmake b/Tests/RunCMake/file-GET_RUNTIME_DEPENDENCIES/macos-rpath.cmake new file mode 100644 index 0000000..798045f --- /dev/null +++ b/Tests/RunCMake/file-GET_RUNTIME_DEPENDENCIES/macos-rpath.cmake @@ -0,0 +1,35 @@ +enable_language(C) + +file(WRITE "${CMAKE_BINARY_DIR}/toplib.c" "extern void sublib1(void);\nextern void sublib2(void);\nvoid toplib(void)\n{\n sublib1();\n sublib2();\n}\n") +add_library(toplib SHARED "${CMAKE_BINARY_DIR}/toplib.c") +file(WRITE "${CMAKE_BINARY_DIR}/sublib1.c" "extern void sublib2(void);\nvoid sublib1(void)\n{\n sublib2();\n}\n") +add_library(sublib1 SHARED "${CMAKE_BINARY_DIR}/sublib1.c") +file(WRITE "${CMAKE_BINARY_DIR}/sublib2.c" "void sublib2(void)\n{\n}\n") +add_library(sublib2 SHARED "${CMAKE_BINARY_DIR}/sublib2.c") +target_link_libraries(toplib PRIVATE sublib1 sublib2) +target_link_libraries(sublib1 PRIVATE sublib2) +set_property(TARGET toplib PROPERTY INSTALL_RPATH "@loader_path/d1;@loader_path/d2") +set_property(TARGET sublib1 PROPERTY INSTALL_RPATH "@loader_path/;@loader_path/../d2") +install(TARGETS toplib DESTINATION lib) +install(TARGETS sublib1 DESTINATION lib/d1) +install(TARGETS sublib2 DESTINATION lib/d2) + +install(CODE [[ + file(GET_RUNTIME_DEPENDENCIES + LIBRARIES + "${CMAKE_INSTALL_PREFIX}/lib/$<TARGET_FILE_NAME:toplib>" + RPATH_PREFIX _rpaths + ) + + set(_expected_rpath "(^|;)@loader_path/;@loader_path/\\.\\./d2$") + set(_actual_rpath "${_rpaths_${CMAKE_INSTALL_PREFIX}/lib/d1/$<TARGET_FILE_NAME:sublib1>}") + if(NOT _actual_rpath MATCHES "${_expected_rpath}") + message(FATAL_ERROR "Expected rpath:\n ${_expected_rpath}\nActual rpath:\n ${_actual_rpath}") + endif() + + # Since RPATH_PREFIX is an undocumented option for install(), we don't really need the rpath + # for the top files anyway. + if(DEFINED "_rpaths_${CMAKE_INSTALL_PREFIX}/lib/$<TARGET_FILE_NAME:toplib>") + message(FATAL_ERROR "rpath for top library should not be defined") + endif() + ]]) |