macos-conflict.cmake 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. enable_language(C)
  2. set(test1_names rpath)
  3. set(test2_names rpath)
  4. file(WRITE "${CMAKE_BINARY_DIR}/rpath.c" "void rpath(void) {}\n")
  5. add_library(rpath SHARED "${CMAKE_BINARY_DIR}/rpath.c")
  6. set_property(TARGET rpath PROPERTY INSTALL_NAME_DIR @rpath)
  7. install(TARGETS rpath DESTINATION lib/rpath1)
  8. install(TARGETS rpath DESTINATION lib/rpath2)
  9. file(REMOVE "${CMAKE_BINARY_DIR}/test1.c")
  10. add_library(test1 SHARED "${CMAKE_BINARY_DIR}/test1.c")
  11. foreach(name ${test1_names})
  12. file(APPEND "${CMAKE_BINARY_DIR}/test1.c" "extern void ${name}(void);\n")
  13. endforeach()
  14. file(APPEND "${CMAKE_BINARY_DIR}/test1.c" "void test1(void)\n{\n")
  15. foreach(name ${test1_names})
  16. file(APPEND "${CMAKE_BINARY_DIR}/test1.c" " ${name}();\n")
  17. endforeach()
  18. file(APPEND "${CMAKE_BINARY_DIR}/test1.c" "}\n")
  19. target_link_libraries(test1 PRIVATE ${test1_names})
  20. set_property(TARGET test1 PROPERTY INSTALL_RPATH
  21. "${CMAKE_BINARY_DIR}/root-all/lib/rpath1"
  22. )
  23. file(REMOVE "${CMAKE_BINARY_DIR}/test2.c")
  24. add_library(test2 SHARED "${CMAKE_BINARY_DIR}/test2.c")
  25. foreach(name ${test2_names})
  26. file(APPEND "${CMAKE_BINARY_DIR}/test2.c" "extern void ${name}(void);\n")
  27. endforeach()
  28. file(APPEND "${CMAKE_BINARY_DIR}/test2.c" "void test2(void)\n{\n")
  29. foreach(name ${test2_names})
  30. file(APPEND "${CMAKE_BINARY_DIR}/test2.c" " ${name}();\n")
  31. endforeach()
  32. file(APPEND "${CMAKE_BINARY_DIR}/test2.c" "}\n")
  33. target_link_libraries(test2 PRIVATE ${test2_names})
  34. set_property(TARGET test2 PROPERTY INSTALL_RPATH
  35. "${CMAKE_BINARY_DIR}/root-all/lib/rpath2"
  36. )
  37. install(TARGETS test1 test2 DESTINATION lib)
  38. install(CODE [[
  39. file(GET_RUNTIME_DEPENDENCIES
  40. LIBRARIES
  41. "${CMAKE_INSTALL_PREFIX}/lib/$<TARGET_FILE_NAME:test1>"
  42. "${CMAKE_INSTALL_PREFIX}/lib/$<TARGET_FILE_NAME:test2>"
  43. PRE_INCLUDE_REGEXES "^@rpath/librpath\\.dylib$"
  44. PRE_EXCLUDE_REGEXES ".*"
  45. )
  46. message(FATAL_ERROR "This message should not be displayed")
  47. ]])