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