RunCPackVerifyResult.cmake 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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(NOT CPackComponentsForAll_BINARY_DIR)
  7. if(NOT CPackGen)
  8. message(FATAL_ERROR "CPackGen not set")
  9. endif(NOT CPackGen)
  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(NOT CPackCommand)
  16. if(NOT CPackComponentWay)
  17. message(FATAL_ERROR "CPackComponentWay not set")
  18. endif(NOT CPackComponentWay)
  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(config_type)
  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. endif(${CPackComponentWay} STREQUAL "default")
  36. if (${CPackComponentWay} STREQUAL "OnePackPerGroup")
  37. set(expected_count 3)
  38. endif (${CPackComponentWay} STREQUAL "OnePackPerGroup")
  39. if (${CPackComponentWay} STREQUAL "IgnoreGroup")
  40. set(expected_count 4)
  41. endif (${CPackComponentWay} STREQUAL "IgnoreGroup")
  42. if (${CPackComponentWay} STREQUAL "AllInOne")
  43. set(expected_count 1)
  44. endif (${CPackComponentWay} STREQUAL "AllInOne")
  45. if (${CPackComponentWay} STREQUAL "AllGroupsInOne")
  46. set(expected_count 1)
  47. endif (${CPackComponentWay} STREQUAL "AllGroupsInOne")
  48. elseif (CPackGen MATCHES "RPM")
  49. set(config_verbose -D "CPACK_RPM_PACKAGE_DEBUG=1")
  50. set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/MyLib-*.rpm")
  51. if (${CPackComponentWay} STREQUAL "default")
  52. set(expected_count 1)
  53. endif (${CPackComponentWay} STREQUAL "default")
  54. if (${CPackComponentWay} STREQUAL "OnePackPerGroup")
  55. set(expected_count 2)
  56. endif (${CPackComponentWay} STREQUAL "OnePackPerGroup")
  57. if (${CPackComponentWay} STREQUAL "IgnoreGroup")
  58. set(expected_count 4)
  59. endif (${CPackComponentWay} STREQUAL "IgnoreGroup")
  60. if (${CPackComponentWay} STREQUAL "AllInOne")
  61. set(expected_count 1)
  62. endif (${CPackComponentWay} STREQUAL "AllInOne")
  63. if (${CPackComponentWay} STREQUAL "AllGroupsInOne")
  64. set(expected_count 1)
  65. endif (${CPackComponentWay} STREQUAL "AllGroupsInOne")
  66. endif(CPackGen MATCHES "ZIP")
  67. # clean-up previously CPack generated files
  68. if(expected_file_mask)
  69. file(GLOB expected_file "${expected_file_mask}")
  70. if (expected_file)
  71. file(REMOVE ${expected_file})
  72. endif(expected_file)
  73. endif(expected_file_mask)
  74. message("config_args = ${config_args}")
  75. message("config_verbose = ${config_verbose}")
  76. execute_process(COMMAND ${CPackCommand} ${config_verbose} -G ${CPackGen} ${config_args}
  77. RESULT_VARIABLE CPack_result
  78. OUTPUT_VARIABLE CPack_output
  79. ERROR_VARIABLE CPack_error
  80. WORKING_DIRECTORY ${CPackComponentsForAll_BINARY_DIR})
  81. if (CPack_result)
  82. message(FATAL_ERROR "error: CPack execution went wrong!, CPack_output=${CPack_output}, CPack_error=${CPack_error}")
  83. else (CPack_result)
  84. message(STATUS "CPack_output=${CPack_output}")
  85. endif(CPack_result)
  86. # Now verify if the number of expected file is OK
  87. # - using expected_file_mask and
  88. # - expected_count
  89. if(expected_file_mask)
  90. file(GLOB expected_file "${expected_file_mask}")
  91. message(STATUS "expected_count='${expected_count}'")
  92. message(STATUS "expected_file='${expected_file}'")
  93. message(STATUS "expected_file_mask='${expected_file_mask}'")
  94. if(NOT expected_file)
  95. message(FATAL_ERROR "error: expected_file=${expected_file} does not exist: CPackComponentsForAll test fails. (CPack_output=${CPack_output}, CPack_error=${CPack_error}")
  96. endif(NOT expected_file)
  97. list(LENGTH expected_file actual_count)
  98. message(STATUS "actual_count='${actual_count}'")
  99. if(NOT actual_count EQUAL expected_count)
  100. 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})")
  101. endif(NOT actual_count EQUAL expected_count)
  102. endif(expected_file_mask)