RunCPackVerifyResult.cmake 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. # prevent older policies from interfearing with this script
  2. cmake_policy(PUSH)
  3. cmake_policy(VERSION ${CMAKE_VERSION})
  4. message(STATUS "=============================================================================")
  5. message(STATUS "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)")
  6. message(STATUS "")
  7. if(NOT CPackComponentsForAll_BINARY_DIR)
  8. message(FATAL_ERROR "CPackComponentsForAll_BINARY_DIR not set")
  9. endif()
  10. if(NOT CPackGen)
  11. message(FATAL_ERROR "CPackGen not set")
  12. endif()
  13. message("CMAKE_CPACK_COMMAND = ${CMAKE_CPACK_COMMAND}")
  14. if(NOT CMAKE_CPACK_COMMAND)
  15. message(FATAL_ERROR "CMAKE_CPACK_COMMAND not set")
  16. endif()
  17. if(NOT CPackComponentWay)
  18. message(FATAL_ERROR "CPackComponentWay not set")
  19. endif()
  20. set(expected_file_mask "")
  21. # The usual default behavior is to expect a single file
  22. # Then some specific generators (Archive, RPM, ...)
  23. # May produce several numbers of files depending on
  24. # CPACK_COMPONENT_xxx values
  25. set(expected_count 1)
  26. set(config_type $ENV{CMAKE_CONFIG_TYPE})
  27. set(config_args )
  28. if(config_type)
  29. set(config_args -C ${config_type})
  30. endif()
  31. set(config_verbose )
  32. if(CPackGen MATCHES "ZIP")
  33. set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/MyLib-*.zip")
  34. if(${CPackComponentWay} STREQUAL "default")
  35. set(expected_count 1)
  36. elseif(${CPackComponentWay} STREQUAL "OnePackPerGroup")
  37. set(expected_count 3)
  38. elseif(${CPackComponentWay} STREQUAL "IgnoreGroup")
  39. set(expected_count 4)
  40. elseif(${CPackComponentWay} STREQUAL "AllInOne")
  41. set(expected_count 1)
  42. endif()
  43. elseif(CPackGen MATCHES "RPM")
  44. set(config_verbose -D "CPACK_RPM_PACKAGE_DEBUG=1")
  45. set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/MyLib-*.rpm")
  46. if(${CPackComponentWay} STREQUAL "default")
  47. set(expected_count 1)
  48. elseif(${CPackComponentWay} STREQUAL "OnePackPerGroup")
  49. set(expected_count 3)
  50. elseif(${CPackComponentWay} STREQUAL "IgnoreGroup")
  51. set(expected_count 4)
  52. elseif(${CPackComponentWay} STREQUAL "AllInOne")
  53. set(expected_count 1)
  54. endif()
  55. elseif(CPackGen MATCHES "DEB")
  56. set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/mylib*_1.0.2_*.deb")
  57. if(${CPackComponentWay} STREQUAL "default")
  58. set(expected_count 1)
  59. elseif(${CPackComponentWay} STREQUAL "OnePackPerGroup")
  60. set(expected_count 3)
  61. elseif(${CPackComponentWay} STREQUAL "IgnoreGroup")
  62. set(expected_count 4)
  63. elseif(${CPackComponentWay} STREQUAL "AllInOne")
  64. set(expected_count 1)
  65. endif()
  66. elseif(CPackGen MATCHES "NuGet")
  67. set(config_verbose -D "CPACK_NUGET_PACKAGE_DEBUG=1")
  68. set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/MyLib*1.0.2.nupkg")
  69. if(${CPackComponentWay} STREQUAL "default")
  70. set(expected_count 1)
  71. elseif(${CPackComponentWay} STREQUAL "OnePackPerGroup")
  72. set(expected_count 3)
  73. elseif(${CPackComponentWay} STREQUAL "IgnoreGroup")
  74. set(expected_count 4)
  75. elseif(${CPackComponentWay} STREQUAL "AllInOne")
  76. set(expected_count 1)
  77. endif()
  78. endif()
  79. if(CPackGen MATCHES "DragNDrop")
  80. set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/MyLib-*.dmg")
  81. if(${CPackComponentWay} STREQUAL "default")
  82. set(expected_count 1)
  83. set(expect_dmg_sla 1)
  84. elseif(${CPackComponentWay} STREQUAL "OnePackPerGroup")
  85. set(expected_count 3)
  86. elseif(${CPackComponentWay} STREQUAL "IgnoreGroup")
  87. set(expected_count 4)
  88. elseif(${CPackComponentWay} STREQUAL "AllInOne")
  89. set(expected_count 1)
  90. set(expect_dmg_sla 1)
  91. endif()
  92. endif()
  93. # clean-up previously CPack generated files
  94. if(expected_file_mask)
  95. file(GLOB expected_file "${expected_file_mask}")
  96. if(expected_file)
  97. file(REMOVE ${expected_file})
  98. endif()
  99. endif()
  100. message("config_args = ${config_args}")
  101. message("config_verbose = ${config_verbose}")
  102. execute_process(COMMAND ${CMAKE_CPACK_COMMAND} ${config_verbose} -G ${CPackGen} ${config_args}
  103. RESULT_VARIABLE CPack_result
  104. OUTPUT_VARIABLE CPack_output
  105. ERROR_VARIABLE CPack_error
  106. WORKING_DIRECTORY ${CPackComponentsForAll_BINARY_DIR})
  107. if(CPack_result)
  108. message(FATAL_ERROR "error: CPack execution went wrong!, CPack_output=${CPack_output}, CPack_error=${CPack_error}")
  109. else ()
  110. message(STATUS "CPack_output=${CPack_output}")
  111. endif()
  112. # Now verify if the number of expected file is OK
  113. # - using expected_file_mask and
  114. # - expected_count
  115. if(expected_file_mask)
  116. file(GLOB expected_file "${expected_file_mask}")
  117. message(STATUS "expected_count='${expected_count}'")
  118. message(STATUS "expected_file='${expected_file}'")
  119. message(STATUS "expected_file_mask='${expected_file_mask}'")
  120. if(NOT expected_file)
  121. message(FATAL_ERROR "error: expected_file does not exist: CPackComponentsForAll test fails. (CPack_output=${CPack_output}, CPack_error=${CPack_error}")
  122. endif()
  123. list(LENGTH expected_file actual_count)
  124. message(STATUS "actual_count='${actual_count}'")
  125. if(NOT actual_count EQUAL expected_count)
  126. message(FATAL_ERROR "error: expected_count=${expected_count} does not match actual_count=${actual_count}: CPackComponents test fails. (CPack_output=${CPack_output}, CPack_error=${CPack_error})")
  127. endif()
  128. if(expect_dmg_sla)
  129. execute_process(COMMAND hdiutil udifderez -xml "${expected_file}" OUTPUT_VARIABLE out ERROR_VARIABLE err RESULT_VARIABLE res)
  130. if(NOT res EQUAL 0)
  131. string(REPLACE "\n" "\n " err " ${err}")
  132. message(FATAL_ERROR "error: running 'hdiutil udifderez -xml' on\n ${expected_file}\nfailed with:\n${err}")
  133. endif()
  134. foreach(key "LPic" "STR#" "TEXT")
  135. if(NOT out MATCHES "<key>${key}</key>")
  136. string(REPLACE "\n" "\n " out " ${out}")
  137. message(FATAL_ERROR "error: running 'hdiutil udifderez -xml' on\n ${expected_file}\ndid not show '${key}' key:\n${out}")
  138. endif()
  139. endforeach()
  140. foreach(line
  141. # LPic first and last base64 lines
  142. "\tAAIAEQADAAEAAAAAAAIAAAAIAAMAAAABAAQAAAAEAAUAAAAOAAYA\n"
  143. "\tAA0AAABbAAQAAAAzAA8AAQAMABAAAAALAA4AAA==\n"
  144. # STR# first and last base64 lines
  145. "\tAAkHRW5nbGlzaAVBZ3JlZQhEaXNhZ3JlZQVQcmludAdTYXZlLi4u\n"
  146. "\tdGVkIGEgcHJpbnRlci4=\n"
  147. # TEXT first and last base64 lines
  148. "\tTElDRU5TRQ0tLS0tLS0tDVRoaXMgaXMgYW4gaW5zdGFsbGVyIGNy\n"
  149. "\tTm8gbGljZW5zZSBwcm92aWRlZC4NDQ==\n"
  150. )
  151. if(NOT out MATCHES "${line}")
  152. string(REPLACE "\n" "\n " out " ${out}")
  153. message(FATAL_ERROR "error: running 'hdiutil udifderez -xml' on\n ${expected_file}\ndid not show '${line}':\n${out}")
  154. endif()
  155. endforeach()
  156. endif()
  157. endif()
  158. # Validate content
  159. if(CPackGen MATCHES "RPM")
  160. find_program(RPM_EXECUTABLE rpm)
  161. if(NOT RPM_EXECUTABLE)
  162. message(FATAL_ERROR "error: missing rpm executable required by the test")
  163. endif()
  164. set(CPACK_RPM_PACKAGE_SUMMARY "default summary")
  165. set(CPACK_RPM_HEADERS_PACKAGE_SUMMARY "headers summary")
  166. set(CPACK_RPM_HEADERS_PACKAGE_DESCRIPTION "headers description")
  167. set(CPACK_COMPONENT_APPLICATIONS_DESCRIPTION
  168. "An extremely useful application that makes use of MyLib")
  169. set(CPACK_COMPONENT_LIBRARIES_DESCRIPTION
  170. "Static libraries used to build programs with MyLib")
  171. set(LIB_SUFFIX "6?4?")
  172. # test package info
  173. if(${CPackComponentWay} STREQUAL "IgnoreGroup")
  174. # set gnu install prefixes to what they are set during rpm creation
  175. # CMAKE_SIZEOF_VOID_P is not set here but lib is prefix of lib64 so
  176. # relocation path test won't fail on OSes with lib64 library location
  177. include(GNUInstallDirs)
  178. set(CPACK_PACKAGING_INSTALL_PREFIX "/usr/foo/bar")
  179. foreach(check_file ${expected_file})
  180. string(REGEX MATCH ".*libraries.*" check_file_libraries_match ${check_file})
  181. string(REGEX MATCH ".*headers.*" check_file_headers_match ${check_file})
  182. string(REGEX MATCH ".*applications.*" check_file_applications_match ${check_file})
  183. string(REGEX MATCH ".*Unspecified.*" check_file_Unspecified_match ${check_file})
  184. execute_process(COMMAND ${RPM_EXECUTABLE} -pqi ${check_file}
  185. OUTPUT_VARIABLE check_file_content
  186. ERROR_QUIET
  187. OUTPUT_STRIP_TRAILING_WHITESPACE)
  188. execute_process(COMMAND ${RPM_EXECUTABLE} -pqa ${check_file}
  189. RESULT_VARIABLE check_package_architecture_result
  190. OUTPUT_VARIABLE check_package_architecture
  191. ERROR_QUIET
  192. OUTPUT_STRIP_TRAILING_WHITESPACE)
  193. execute_process(COMMAND ${RPM_EXECUTABLE} -pql ${check_file}
  194. OUTPUT_VARIABLE check_package_content
  195. ERROR_QUIET
  196. OUTPUT_STRIP_TRAILING_WHITESPACE)
  197. set(whitespaces "[\\t\\n\\r ]*")
  198. if(check_file_libraries_match)
  199. set(check_file_match_expected_summary ".*${CPACK_RPM_PACKAGE_SUMMARY}.*")
  200. set(check_file_match_expected_description ".*${CPACK_COMPONENT_LIBRARIES_DESCRIPTION}.*")
  201. set(check_file_match_expected_relocation_path "Relocations${whitespaces}:${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}${LIB_SUFFIX}${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}/other_relocatable${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}${LIB_SUFFIX}/inside_relocatable_two/depth_two/different_relocatable")
  202. set(check_file_match_expected_architecture "") # we don't explicitly set this value so it is different on each platform - ignore it
  203. set(spec_regex "*libraries*")
  204. set(check_content_list "^/usr/foo/bar/lib${LIB_SUFFIX}
  205. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_one
  206. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_one/depth_two
  207. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_one/depth_two/depth_three
  208. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_one/depth_two/depth_three/symlink_parentdir_path
  209. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_one/depth_two/symlink_outside_package
  210. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_one/depth_two/symlink_outside_wdr
  211. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_one/depth_two/symlink_relocatable_subpath
  212. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_one/depth_two/symlink_samedir_path
  213. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_one/depth_two/symlink_samedir_path_current_dir
  214. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_one/depth_two/symlink_samedir_path_longer
  215. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_one/symlink_subdir_path
  216. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_two
  217. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_two/depth_two
  218. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_two/depth_two/different_relocatable
  219. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_two/depth_two/different_relocatable/bar
  220. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_two/depth_two/symlink_other_relocatable_path
  221. /usr/foo/bar/lib${LIB_SUFFIX}/inside_relocatable_two/depth_two/symlink_to_non_relocatable_path
  222. /usr/foo/bar/lib${LIB_SUFFIX}/libmylib.a
  223. /usr/foo/bar/non_relocatable
  224. /usr/foo/bar/non_relocatable/depth_two
  225. /usr/foo/bar/non_relocatable/depth_two/symlink_from_non_relocatable_path
  226. /usr/foo/bar/other_relocatable
  227. /usr/foo/bar/other_relocatable/depth_two(\n.*\.build-id.*)*$")
  228. elseif(check_file_headers_match)
  229. set(check_file_match_expected_summary ".*${CPACK_RPM_HEADERS_PACKAGE_SUMMARY}.*")
  230. set(check_file_match_expected_description ".*${CPACK_RPM_HEADERS_PACKAGE_DESCRIPTION}.*")
  231. set(check_file_match_expected_relocation_path "Relocations${whitespaces}:${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}")
  232. set(check_file_match_expected_architecture "noarch")
  233. set(spec_regex "*headers*")
  234. set(check_content_list "^/usr/foo/bar\n/usr/foo/bar/include\n/usr/foo/bar/include/mylib.h(\n.*\.build-id.*)*$")
  235. elseif(check_file_applications_match)
  236. set(check_file_match_expected_summary ".*${CPACK_RPM_PACKAGE_SUMMARY}.*")
  237. set(check_file_match_expected_description ".*${CPACK_COMPONENT_APPLICATIONS_DESCRIPTION}.*")
  238. set(check_file_match_expected_relocation_path "Relocations${whitespaces}:${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}")
  239. set(check_file_match_expected_architecture "armv7hf")
  240. set(spec_regex "*applications*")
  241. set(check_content_list "^/usr/foo/bar
  242. /usr/foo/bar/bin
  243. /usr/foo/bar/bin/mylibapp(\n.*\.build-id.*)*$")
  244. elseif(check_file_Unspecified_match)
  245. set(check_file_match_expected_summary ".*${CPACK_RPM_PACKAGE_SUMMARY}.*")
  246. set(check_file_match_expected_description ".*DESCRIPTION.*")
  247. set(check_file_match_expected_relocation_path "Relocations${whitespaces}:${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}")
  248. set(check_file_match_expected_architecture "") # we don't explicitly set this value so it is different on each platform - ignore it
  249. set(spec_regex "*Unspecified*")
  250. set(check_content_list "^/usr/foo/bar
  251. /usr/foo/bar/bin
  252. /usr/foo/bar/bin/@in@_@path@@with
  253. /usr/foo/bar/bin/@in@_@path@@with/@and
  254. /usr/foo/bar/bin/@in@_@path@@with/@and/@
  255. /usr/foo/bar/bin/@in@_@path@@with/@and/@/@in_path@
  256. /usr/foo/bar/bin/@in@_@path@@with/@and/@/@in_path@/mylibapp2
  257. /usr/foo/bar/share
  258. /usr/foo/bar/share/man
  259. /usr/foo/bar/share/man/mylib
  260. /usr/foo/bar/share/man/mylib/man3
  261. /usr/foo/bar/share/man/mylib/man3/mylib.1
  262. /usr/foo/bar/share/man/mylib/man3/mylib.1/mylib
  263. /usr/foo/bar/share/man/mylib/man3/mylib.1/mylib2(\n.*\.build-id.*)*$")
  264. else()
  265. message(FATAL_ERROR "error: unexpected rpm package '${check_file}'")
  266. endif()
  267. #######################
  268. # test package info
  269. #######################
  270. string(REGEX MATCH ${check_file_match_expected_summary} check_file_match_summary ${check_file_content})
  271. if(NOT check_file_match_summary)
  272. message(FATAL_ERROR "error: '${check_file}' rpm package summary does not match expected value - regex '${check_file_match_expected_summary}'; RPM output: '${check_file_content}'")
  273. endif()
  274. string(REGEX MATCH ${check_file_match_expected_description} check_file_match_description ${check_file_content})
  275. if(NOT check_file_match_description)
  276. message(FATAL_ERROR "error: '${check_file}' rpm package description does not match expected value - regex '${check_file_match_expected_description}'; RPM output: '${check_file_content}'")
  277. endif()
  278. string(REGEX MATCH ${check_file_match_expected_relocation_path} check_file_match_relocation_path ${check_file_content})
  279. if(NOT check_file_match_relocation_path)
  280. file(GLOB_RECURSE spec_file "${CPackComponentsForAll_BINARY_DIR}/${spec_regex}.spec")
  281. if(spec_file)
  282. file(READ ${spec_file} spec_file_content)
  283. endif()
  284. message(FATAL_ERROR "error: '${check_file}' rpm package relocation path does not match expected value - regex '${check_file_match_expected_relocation_path}'; RPM output: '${check_file_content}'; generated spec file: '${spec_file_content}'")
  285. endif()
  286. #######################
  287. # test package architecture
  288. #######################
  289. string(REGEX MATCH "Architecture${whitespaces}:" check_info_contains_arch ${check_file_content})
  290. if(check_info_contains_arch) # test for rpm versions that contain architecture in package info (e.g. 4.11.x)
  291. string(REGEX MATCH "Architecture${whitespaces}:${whitespaces}${check_file_match_expected_architecture}" check_file_match_architecture ${check_file_content})
  292. if(NOT check_file_match_architecture)
  293. message(FATAL_ERROR "error: '${check_file}' Architecture does not match expected value - '${check_file_match_expected_architecture}'; RPM output: '${check_file_content}'; generated spec file: '${spec_file_content}'")
  294. endif()
  295. elseif(NOT check_package_architecture_result) # test result only on platforms that support -pqa rpm query
  296. # test for rpm versions that do not contain architecture in package info (e.g. 4.8.x)
  297. string(REGEX MATCH ".*${check_file_match_expected_architecture}" check_file_match_architecture "${check_package_architecture}")
  298. if(NOT check_file_match_architecture)
  299. message(FATAL_ERROR "error: '${check_file}' Architecture does not match expected value - '${check_file_match_expected_architecture}'; RPM output: '${check_package_architecture}'; generated spec file: '${spec_file_content}'")
  300. endif()
  301. # else rpm version too old (e.g. 4.4.x) - skip test
  302. endif()
  303. #######################
  304. # test package content
  305. #######################
  306. string(REGEX MATCH "${check_content_list}" expected_content_list "${check_package_content}")
  307. if(NOT expected_content_list)
  308. file(GLOB_RECURSE spec_file "${CPackComponentsForAll_BINARY_DIR}/${spec_regex}.spec")
  309. if(spec_file)
  310. file(READ ${spec_file} spec_file_content)
  311. endif()
  312. message(FATAL_ERROR "error: '${check_file}' rpm package content does not match expected value - regex '${check_content_list}'; RPM output: '${check_package_content}'; generated spec file: '${spec_file_content}'")
  313. endif()
  314. # validate permissions user and group
  315. execute_process(COMMAND ${RPM_EXECUTABLE} -pqlv ${check_file}
  316. OUTPUT_VARIABLE check_file_content
  317. ERROR_QUIET
  318. OUTPUT_STRIP_TRAILING_WHITESPACE)
  319. if(check_file_libraries_match)
  320. set(check_file_match_expected_permissions ".*-rwx------.*user.*defgrp.*")
  321. elseif(check_file_headers_match)
  322. set(check_file_match_expected_permissions ".*-rwxr--r--.*defusr.*defgrp.*")
  323. elseif(check_file_applications_match)
  324. set(check_file_match_expected_permissions ".*-rwxr--r--.*defusr.*group.*")
  325. elseif(check_file_Unspecified_match)
  326. set(check_file_match_expected_permissions ".*-rwxr--r--.*defusr.*defgrp.*")
  327. else()
  328. message(FATAL_ERROR "error: unexpected rpm package '${check_file}'")
  329. endif()
  330. string(REGEX MATCH "${check_file_match_expected_permissions}" check_file_match_permissions "${check_file_content}")
  331. if(NOT check_file_match_permissions)
  332. message(FATAL_ERROR "error: '${check_file}' rpm package permissions do not match expected value - regex '${check_file_match_expected_permissions}'")
  333. endif()
  334. endforeach()
  335. #######################
  336. # verify generated symbolic links
  337. #######################
  338. file(GLOB_RECURSE symlink_files RELATIVE "${CPackComponentsForAll_BINARY_DIR}" "${CPackComponentsForAll_BINARY_DIR}/*/symlink_*")
  339. foreach(check_symlink IN LISTS symlink_files)
  340. get_filename_component(symlink_name "${check_symlink}" NAME)
  341. execute_process(COMMAND ls -la "${check_symlink}"
  342. WORKING_DIRECTORY "${CPackComponentsForAll_BINARY_DIR}"
  343. OUTPUT_VARIABLE SYMLINK_POINT_
  344. OUTPUT_STRIP_TRAILING_WHITESPACE)
  345. if("${symlink_name}" STREQUAL "symlink_samedir_path"
  346. OR "${symlink_name}" STREQUAL "symlink_samedir_path_current_dir"
  347. OR "${symlink_name}" STREQUAL "symlink_samedir_path_longer")
  348. string(REGEX MATCH "^.*${whitespaces}->${whitespaces}depth_three$" check_symlink "${SYMLINK_POINT_}")
  349. elseif("${symlink_name}" STREQUAL "symlink_subdir_path")
  350. string(REGEX MATCH "^.*${whitespaces}->${whitespaces}depth_two/depth_three$" check_symlink "${SYMLINK_POINT_}")
  351. elseif("${symlink_name}" STREQUAL "symlink_parentdir_path")
  352. string(REGEX MATCH "^.*${whitespaces}->${whitespaces}../$" check_symlink "${SYMLINK_POINT_}")
  353. elseif("${symlink_name}" STREQUAL "symlink_to_non_relocatable_path")
  354. string(REGEX MATCH "^.*${whitespaces}->${whitespaces}${CPACK_PACKAGING_INSTALL_PREFIX}/non_relocatable/depth_two$" check_symlink "${SYMLINK_POINT_}")
  355. elseif("${symlink_name}" STREQUAL "symlink_outside_package")
  356. string(REGEX MATCH "^.*${whitespaces}->${whitespaces}outside_package$" check_symlink "${SYMLINK_POINT_}")
  357. elseif("${symlink_name}" STREQUAL "symlink_outside_wdr")
  358. string(REGEX MATCH "^.*${whitespaces}->${whitespaces}/outside_package_wdr$" check_symlink "${SYMLINK_POINT_}")
  359. elseif("${symlink_name}" STREQUAL "symlink_other_relocatable_path"
  360. OR "${symlink_name}" STREQUAL "symlink_from_non_relocatable_path"
  361. OR "${symlink_name}" STREQUAL "symlink_relocatable_subpath")
  362. # these links were not changed - post install script only - ignore them
  363. else()
  364. message(FATAL_ERROR "error: unexpected rpm symbolic link '${check_symlink}'")
  365. endif()
  366. if(NOT check_symlink)
  367. message(FATAL_ERROR "symlink points to unexpected location '${SYMLINK_POINT_}'")
  368. endif()
  369. endforeach()
  370. # verify post install symlink relocation script
  371. file(GLOB_RECURSE spec_file "${CPackComponentsForAll_BINARY_DIR}/*libraries*.spec")
  372. file(READ ${spec_file} spec_file_content)
  373. file(READ "${CMAKE_CURRENT_LIST_DIR}/symlink_postinstall_expected.txt" symlink_postinstall_expected)
  374. # prepare regex
  375. string(STRIP "${symlink_postinstall_expected}" symlink_postinstall_expected)
  376. string(REPLACE "[" "\\[" symlink_postinstall_expected "${symlink_postinstall_expected}")
  377. string(REPLACE "$" "\\$" symlink_postinstall_expected "${symlink_postinstall_expected}")
  378. string(REPLACE "lib" "lib${LIB_SUFFIX}" symlink_postinstall_expected "${symlink_postinstall_expected}")
  379. # compare
  380. string(REGEX MATCH ".*${symlink_postinstall_expected}.*" symlink_postinstall_expected_matches "${spec_file_content}")
  381. if(NOT symlink_postinstall_expected_matches)
  382. message(FATAL_ERROR "error: unexpected rpm symbolic link postinstall script! generated spec file: '${spec_file_content}'")
  383. endif()
  384. endif()
  385. endif()
  386. cmake_policy(POP)