RunCPackVerifyResult.cmake 4.4 KB

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