RunCPackVerifyResult.cmake 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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()
  30. message(" ${config_args}")
  31. execute_process(COMMAND ${CPackCommand} -G ${CPackGen} ${config_args}
  32. RESULT_VARIABLE CPack_result
  33. OUTPUT_VARIABLE CPack_output
  34. ERROR_VARIABLE CPack_error
  35. WORKING_DIRECTORY ${CPackComponentsForAll_BINARY_DIR})
  36. if (CPack_result)
  37. message(FATAL_ERROR "error: CPack execution went wrong!, CPack_output=${CPack_output}, CPack_error=${CPack_error}")
  38. else (CPack_result)
  39. message(STATUS "CPack_output=${CPack_output}")
  40. endif(CPack_result)
  41. if(CPackGen MATCHES "ZIP")
  42. set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/MyLib-*.zip")
  43. if (${CPackComponentWay} STREQUAL "default")
  44. set(expected_count 1)
  45. endif(${CPackComponentWay} STREQUAL "default")
  46. endif(CPackGen MATCHES "ZIP")
  47. # Now verify if the number of expected file is OK
  48. # - using expected_file_mask and
  49. # - expected_count
  50. if(expected_file_mask)
  51. file(GLOB expected_file "${expected_file_mask}")
  52. message(STATUS "expected_count='${expected_count}'")
  53. message(STATUS "expected_file='${expected_file}'")
  54. message(STATUS "expected_file_mask='${expected_file_mask}'")
  55. if(NOT expected_file)
  56. message(FATAL_ERROR "error: expected_file=${expected_file} does not exist: CPackComponentsForAll test fails. (CPack_output=${CPack_output}, CPack_error=${CPack_error}")
  57. endif(NOT expected_file)
  58. list(LENGTH expected_file actual_count)
  59. message(STATUS "actual_count='${actual_count}'")
  60. if(NOT actual_count EQUAL expected_count)
  61. 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})")
  62. endif(NOT actual_count EQUAL expected_count)
  63. endif(expected_file_mask)