RunCPackVerifyResult.cmake 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. message(STATUS "=============================================================================")
  2. message(STATUS "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)")
  3. message(STATUS "")
  4. if(NOT CPackComponentsForAll_BINARY_DIR)
  5. message(FATAL_ERROR "CPackComponentsForAll_BINARY_DIR not set")
  6. endif()
  7. if(NOT CPackGen)
  8. message(FATAL_ERROR "CPackGen not set")
  9. endif()
  10. get_filename_component(CPACK_LOCATION ${CMAKE_COMMAND} PATH)
  11. set(CPackCommand "${CPACK_LOCATION}/cpack")
  12. message("cpack = ${CPackCommand}")
  13. if(NOT CPackCommand)
  14. message(FATAL_ERROR "CPackCommand not set")
  15. endif()
  16. if(NOT CPackComponentWay)
  17. message(FATAL_ERROR "CPackComponentWay not set")
  18. endif()
  19. set(expected_file_mask "")
  20. # The usual default behavior is to expect a single file
  21. # Then some specific generators (Archive, RPM, ...)
  22. # May produce several numbers of files depending on
  23. # CPACK_COMPONENT_xxx values
  24. set(expected_count 1)
  25. set(config_type $ENV{CMAKE_CONFIG_TYPE})
  26. set(config_args )
  27. if(config_type)
  28. set(config_args -C ${config_type})
  29. endif()
  30. set(config_verbose )
  31. if(CPackGen MATCHES "ZIP")
  32. set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/MyLib-*.zip")
  33. if (${CPackComponentWay} STREQUAL "default")
  34. set(expected_count 1)
  35. elseif (${CPackComponentWay} STREQUAL "OnePackPerGroup")
  36. set(expected_count 3)
  37. elseif (${CPackComponentWay} STREQUAL "IgnoreGroup")
  38. set(expected_count 4)
  39. elseif (${CPackComponentWay} STREQUAL "AllInOne")
  40. set(expected_count 1)
  41. endif ()
  42. elseif (CPackGen MATCHES "RPM")
  43. set(config_verbose -D "CPACK_RPM_PACKAGE_DEBUG=1")
  44. set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/MyLib-*.rpm")
  45. if (${CPackComponentWay} STREQUAL "default")
  46. set(expected_count 1)
  47. elseif (${CPackComponentWay} STREQUAL "OnePackPerGroup")
  48. set(expected_count 3)
  49. elseif (${CPackComponentWay} STREQUAL "IgnoreGroup")
  50. set(expected_count 4)
  51. elseif (${CPackComponentWay} STREQUAL "AllInOne")
  52. set(expected_count 1)
  53. endif ()
  54. elseif (CPackGen MATCHES "DEB")
  55. set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/MyLib-*.deb")
  56. if (${CPackComponentWay} STREQUAL "default")
  57. set(expected_count 1)
  58. elseif (${CPackComponentWay} STREQUAL "OnePackPerGroup")
  59. set(expected_count 3)
  60. elseif (${CPackComponentWay} STREQUAL "IgnoreGroup")
  61. set(expected_count 4)
  62. elseif (${CPackComponentWay} STREQUAL "AllInOne")
  63. set(expected_count 1)
  64. endif ()
  65. endif()
  66. if(CPackGen MATCHES "DragNDrop")
  67. set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/MyLib-*.dmg")
  68. if (${CPackComponentWay} STREQUAL "default")
  69. set(expected_count 1)
  70. elseif (${CPackComponentWay} STREQUAL "OnePackPerGroup")
  71. set(expected_count 3)
  72. elseif (${CPackComponentWay} STREQUAL "IgnoreGroup")
  73. set(expected_count 4)
  74. elseif (${CPackComponentWay} STREQUAL "AllInOne")
  75. set(expected_count 1)
  76. endif ()
  77. endif()
  78. # clean-up previously CPack generated files
  79. if(expected_file_mask)
  80. file(GLOB expected_file "${expected_file_mask}")
  81. if (expected_file)
  82. file(REMOVE ${expected_file})
  83. endif()
  84. endif()
  85. message("config_args = ${config_args}")
  86. message("config_verbose = ${config_verbose}")
  87. execute_process(COMMAND ${CPackCommand} ${config_verbose} -G ${CPackGen} ${config_args}
  88. RESULT_VARIABLE CPack_result
  89. OUTPUT_VARIABLE CPack_output
  90. ERROR_VARIABLE CPack_error
  91. WORKING_DIRECTORY ${CPackComponentsForAll_BINARY_DIR})
  92. if (CPack_result)
  93. message(FATAL_ERROR "error: CPack execution went wrong!, CPack_output=${CPack_output}, CPack_error=${CPack_error}")
  94. else ()
  95. message(STATUS "CPack_output=${CPack_output}")
  96. endif()
  97. # Now verify if the number of expected file is OK
  98. # - using expected_file_mask and
  99. # - expected_count
  100. if(expected_file_mask)
  101. file(GLOB expected_file "${expected_file_mask}")
  102. message(STATUS "expected_count='${expected_count}'")
  103. message(STATUS "expected_file='${expected_file}'")
  104. message(STATUS "expected_file_mask='${expected_file_mask}'")
  105. if(NOT expected_file)
  106. message(FATAL_ERROR "error: expected_file=${expected_file} does not exist: CPackComponentsForAll test fails. (CPack_output=${CPack_output}, CPack_error=${CPack_error}")
  107. endif()
  108. list(LENGTH expected_file actual_count)
  109. message(STATUS "actual_count='${actual_count}'")
  110. if(NOT actual_count EQUAL expected_count)
  111. 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})")
  112. endif()
  113. endif()