common_helpers.cmake 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. set(ALL_FILES_GLOB "*.${cpack_archive_extension_}")
  2. function(getPackageContent FILE RESULT_VAR)
  3. # TODO for some types this only works because libarchive handles it... (not
  4. # part of for e.g. gnu tar)
  5. execute_process(COMMAND ${CMAKE_COMMAND} -E tar -xtf ${FILE}
  6. OUTPUT_VARIABLE package_content_
  7. ERROR_QUIET
  8. OUTPUT_STRIP_TRAILING_WHITESPACE)
  9. set(${RESULT_VAR} "${package_content_}" PARENT_SCOPE)
  10. endfunction()
  11. function(getPackageNameGlobexpr NAME COMPONENT VERSION REVISION FILE_NO RESULT_VAR)
  12. if(COMPONENT)
  13. set(COMPONENT "-${COMPONENT}")
  14. endif()
  15. set(${RESULT_VAR}
  16. "${NAME}-${VERSION}-*${COMPONENT}.${cpack_archive_extension_}" PARENT_SCOPE)
  17. endfunction()
  18. function(getPackageContentList FILE RESULT_VAR)
  19. getPackageContent("${FILE}" package_content_)
  20. string(REPLACE "\n" ";" package_content_ "${package_content_}")
  21. foreach(i_ IN LISTS package_content_)
  22. string(REGEX REPLACE "/$" "" result_ "${i_}")
  23. list(APPEND items_ "${result_}")
  24. endforeach()
  25. set(${RESULT_VAR} "${items_}" PARENT_SCOPE)
  26. endfunction()
  27. function(toExpectedContentList FILE_NO CONTENT_VAR)
  28. findExpectedFile("${FILE_NO}" "file_" "glob_expr_")
  29. # component and monolithic packages differ for some reason by either having
  30. # package filename prefix in path or not
  31. if(PACKAGING_TYPE STREQUAL "MONOLITHIC")
  32. get_filename_component(prefix_ "${file_}" NAME)
  33. # NAME_WE removes everything after the dot and dot is in version so replace instead
  34. string(REPLACE ".${cpack_archive_extension_}" "/" prefix_ "${prefix_}")
  35. else()
  36. unset(prefix_)
  37. endif()
  38. # add install prefix to expected paths
  39. if(DEFINED EXPECTED_FILE_${FILE_NO}_PACKAGING_PREFIX)
  40. set(EXPECTED_FILE_PACKAGING_PREFIX
  41. "${EXPECTED_FILE_${FILE_NO}_PACKAGING_PREFIX}")
  42. elseif(NOT DEFINED EXPECTED_FILE_PACKAGING_PREFIX)
  43. # default CPack Archive packaging install prefix
  44. set(EXPECTED_FILE_PACKAGING_PREFIX "/")
  45. endif()
  46. set(prepared_ "${EXPECTED_FILE_PACKAGING_PREFIX}")
  47. foreach(part_ IN LISTS ${CONTENT_VAR})
  48. list(APPEND prepared_ "${EXPECTED_FILE_PACKAGING_PREFIX}${part_}")
  49. endforeach()
  50. unset(filtered_)
  51. foreach(part_ IN LISTS prepared_)
  52. string(REGEX REPLACE "^/" "" part_ "${part_}")
  53. if(part_)
  54. list(APPEND filtered_ "${prefix_}${part_}")
  55. endif()
  56. endforeach()
  57. set(${CONTENT_VAR} "${filtered_}" PARENT_SCOPE)
  58. endfunction()