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