Common.cmake 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. # Prepare binaries on which to operate.
  2. set(in "${CMAKE_CURRENT_LIST_DIR}/${format}")
  3. set(out "${CMAKE_CURRENT_BINARY_DIR}")
  4. foreach(f ${dynamic})
  5. file(COPY ${in}/${f} DESTINATION ${out} NO_SOURCE_PERMISSIONS)
  6. list(APPEND dynamic_files "${out}/${f}")
  7. endforeach()
  8. foreach(f ${static})
  9. file(COPY ${in}/${f} DESTINATION ${out} NO_SOURCE_PERMISSIONS)
  10. list(APPEND static_files "${out}/${f}")
  11. endforeach()
  12. foreach(f ${dynamic_files})
  13. # Check for the initial RPATH.
  14. file(RPATH_CHECK FILE "${f}" RPATH "/sample/rpath")
  15. if(NOT EXISTS "${f}")
  16. message(FATAL_ERROR "RPATH_CHECK removed ${f}")
  17. endif()
  18. # Change the RPATH.
  19. file(RPATH_CHANGE FILE "${f}"
  20. OLD_RPATH "/sample/rpath"
  21. NEW_RPATH "/path1:/path2")
  22. set(rpath)
  23. file(STRINGS "${f}" rpath REGEX "/path1:/path2" LIMIT_COUNT 1)
  24. if(NOT rpath)
  25. message(FATAL_ERROR "RPATH not changed in ${f}")
  26. endif()
  27. # Change the RPATH without compiler defined rpath removed
  28. file(RPATH_CHANGE FILE "${f}"
  29. OLD_RPATH "/path2"
  30. NEW_RPATH "/path3")
  31. set(rpath)
  32. file(STRINGS "${f}" rpath REGEX "/path1:/path3" LIMIT_COUNT 1)
  33. if(NOT rpath)
  34. message(FATAL_ERROR "RPATH not updated in ${f}")
  35. endif()
  36. # Change the RPATH with compiler defined rpath removed
  37. file(RPATH_CHANGE FILE "${f}"
  38. OLD_RPATH "/path3"
  39. NEW_RPATH "/rpath/sample"
  40. INSTALL_REMOVE_ENVIRONMENT_RPATH)
  41. set(rpath)
  42. file(STRINGS "${f}" rpath REGEX "/rpath/sample" LIMIT_COUNT 1)
  43. if(NOT rpath)
  44. message(FATAL_ERROR "RPATH not updated in ${f}")
  45. endif()
  46. file(STRINGS "${f}" rpath REGEX "/path1" LIMIT_COUNT 1)
  47. if(rpath)
  48. message(FATAL_ERROR "RPATH not removed in ${f}")
  49. endif()
  50. # Remove the RPATH.
  51. file(RPATH_REMOVE FILE "${f}")
  52. set(rpath)
  53. file(STRINGS "${f}" rpath REGEX "/rpath/sample" LIMIT_COUNT 1)
  54. if(rpath)
  55. message(FATAL_ERROR "RPATH not removed from ${f}")
  56. endif()
  57. # Check again...this should remove the file.
  58. file(RPATH_CHECK FILE "${f}" RPATH "/sample/rpath")
  59. if(EXISTS "${f}")
  60. message(FATAL_ERROR "RPATH_CHECK did not remove ${f}")
  61. endif()
  62. endforeach()
  63. # TODO Implement RPATH_SET in XCOFF.
  64. if(format STREQUAL "ELF")
  65. foreach(f ${dynamic})
  66. file(COPY ${in}/${f} DESTINATION ${out} NO_SOURCE_PERMISSIONS)
  67. endforeach()
  68. foreach(f ${dynamic_files})
  69. # Set the RPATH.
  70. file(RPATH_SET FILE "${f}"
  71. NEW_RPATH "/new/rpath")
  72. set(rpath)
  73. file(STRINGS "${f}" rpath REGEX "/new/rpath" LIMIT_COUNT 1)
  74. if(NOT rpath)
  75. message(FATAL_ERROR "RPATH not set in ${f}")
  76. endif()
  77. file(STRINGS "${f}" rpath REGEX "/rpath/sample" LIMIT_COUNT 1)
  78. if(rpath)
  79. message(FATAL_EROR "RPATH not removed in ${f}")
  80. endif()
  81. # Remove the RPATH.
  82. file(RPATH_SET FILE "${f}"
  83. NEW_RPATH "")
  84. set(rpath)
  85. file(STRINGS "${f}" rpath REGEX "/new/rpath" LIMIT_COUNT 1)
  86. if(rpath)
  87. message(FATAL_ERROR "RPATH not removed from ${f}")
  88. endif()
  89. # Check again...this should remove the file.
  90. file(RPATH_CHECK FILE "${f}" RPATH "/new/rpath")
  91. if(EXISTS "${f}")
  92. message(FATAL_ERROR "RPATH_CHECK did not remove ${f}")
  93. endif()
  94. endforeach()
  95. endif()
  96. # Verify that modifying rpaths on a static library is a no-op
  97. foreach(f ${static_files})
  98. file(RPATH_CHANGE FILE "${f}" OLD_RPATH "/rpath/foo" NEW_RPATH "/rpath/bar")
  99. endforeach()