Imported Upstream version 2.8.11.2
[platform/upstream/cmake.git] / Tests / CPackTestAllGenerators / RunCPack.cmake
1 if(NOT DEFINED dir)
2   message(FATAL_ERROR "dir not defined")
3 endif()
4
5 # Analyze 'cpack --help' output for list of available generators:
6 #
7 execute_process(COMMAND ${CMAKE_CPACK_COMMAND} --help
8   RESULT_VARIABLE result
9   OUTPUT_VARIABLE stdout
10   ERROR_VARIABLE stderr
11   WORKING_DIRECTORY ${dir})
12
13 string(REPLACE ";" "\\;" stdout "${stdout}")
14 string(REPLACE "\n" "E;" stdout "${stdout}")
15
16 set(collecting 0)
17 set(generators)
18 foreach(eline ${stdout})
19   string(REGEX REPLACE "^(.*)E$" "\\1" line "${eline}")
20   if(collecting AND NOT line STREQUAL "")
21     string(REGEX REPLACE "^  ([^ ]+) += (.*)$" "\\1" gen "${line}")
22     string(REGEX REPLACE "^  ([^ ]+) += (.*)$" "\\2" doc "${line}")
23     set(generators ${generators} ${gen})
24   endif()
25   if(line STREQUAL "Generators")
26     set(collecting 1)
27   endif()
28 endforeach()
29
30 # Call cpack with -G on each available generator. We do not care if this
31 # succeeds or not. We expect it *not* to succeed if the underlying packaging
32 # tools are not installed on the system... This test is here simply to add
33 # coverage for the various cpack generators, even/especially to test ones
34 # where the tools are not installed.
35 #
36 message(STATUS "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)")
37
38 message(STATUS "CPack generators='${generators}'")
39
40 foreach(g ${generators})
41   message(STATUS "Calling cpack -G ${g}...")
42   execute_process(COMMAND ${CMAKE_CPACK_COMMAND} -G ${g}
43     RESULT_VARIABLE result
44     OUTPUT_VARIABLE stdout
45     ERROR_VARIABLE stderr
46     WORKING_DIRECTORY ${dir})
47   message(STATUS "result='${result}'")
48   message(STATUS "stdout='${stdout}'")
49   message(STATUS "stderr='${stderr}'")
50   message(STATUS "")
51 endforeach()