summaryrefslogtreecommitdiffstats
path: root/Tests/CMakeGUI/CMakeGUITest.cmake
blob: 3d8c27ed14f793b68e7bd58b9c7ca60b05fc7075 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
function(run_cmake_gui_test name)
  if(DEFINED ENV{CMakeGUITest_TEST_FILTER} AND NOT name MATCHES "$ENV{CMakeGUITest_TEST_FILTER}")
    return()
  endif()

  set(_fail)

  cmake_parse_arguments(_rcgt
    "DO_CONFIGURE"
    "GENERATOR"
    "ARGS;CONFIGURE_ARGS"
    ${ARGN}
    )

  string(REPLACE ":" "-" _file_name "${name}")
  set(_srcdir "${CMakeGUITest_SOURCE_DIR}/${_file_name}")
  set(_workdir "${CMakeGUITest_BINARY_DIR}/${_file_name}")

  file(REMOVE_RECURSE "${_workdir}")
  file(MAKE_DIRECTORY "${_workdir}")

  set(_ini_in "${_srcdir}/CMakeSetup.ini.in")
  if(EXISTS "${_ini_in}")
    configure_file("${_ini_in}" "${_workdir}/config/Kitware/CMakeSetup.ini" @ONLY)
  endif()
  set(_cmakelists_in "${_srcdir}/CMakeLists.txt.in")
  if(EXISTS "${_cmakelists_in}")
    configure_file("${_cmakelists_in}" "${_workdir}/src/CMakeLists.txt" @ONLY)
  endif()
  if(_rcgt_DO_CONFIGURE)
    if(NOT _rcgt_GENERATOR)
      set(_rcgt_GENERATOR "${CMakeGUITest_GENERATOR}")
    endif()
    execute_process(
      COMMAND "${CMAKE_COMMAND}"
        -S "${_workdir}/src"
        -B "${_workdir}/build"
        -G "${_rcgt_GENERATOR}"
        ${_rcgt_CONFIGURE_ARGS}
      RESULT_VARIABLE _result
      OUTPUT_VARIABLE _output
      ERROR_VARIABLE _error
      )
    if(_result)
      set(_fail 1)
      string(REPLACE "\n" "\n  " _formatted_output "${_output}")
      string(REPLACE "\n" "\n  " _formatted_error "${_error}")
      message(SEND_ERROR
        "Configuring ${_workdir}/src failed with exit code ${_result}, should be 0\n"
        "stdout:\n  ${_formatted_output}\n"
        "stderr:\n  ${_formatted_error}"
        )
    endif()
  endif()

  set(ENV{CMake_GUI_TEST_NAME} "${name}")
  set(ENV{CMake_GUI_CONFIG_DIR} "${_workdir}/config")
  execute_process(
    COMMAND "${CMakeGUITest_COMMAND}" ${_rcgt_ARGS}
    WORKING_DIRECTORY "${_workdir}"
    RESULT_VARIABLE _result
    OUTPUT_VARIABLE _output
    ERROR_VARIABLE _error
    )
  if(_result)
    set(_fail 1)
    string(REPLACE "\n" "\n  " _formatted_output "${_output}")
    string(REPLACE "\n" "\n  " _formatted_error "${_error}")
    message(SEND_ERROR "CMake GUI test ${name} failed with exit code ${_result}, should be 0\n"
    "stdout:\n  ${_formatted_output}\n"
    "stderr:\n  ${_formatted_error}"
    )
  endif()

  if(NOT _fail)
    message(STATUS "${name} -- passed")
  endif()
endfunction()

run_cmake_gui_test(sourceBinaryArgs:sourceAndBinaryDir
  ARGS
    -S "${CMakeGUITest_BINARY_DIR}/sourceBinaryArgs-sourceAndBinaryDir/src"
    -B "${CMakeGUITest_BINARY_DIR}/sourceBinaryArgs-sourceAndBinaryDir/build"
  )
run_cmake_gui_test(sourceBinaryArgs:sourceAndBinaryDirRelative
  ARGS
    "-Ssrc"
    "-Bbuild"
  )
run_cmake_gui_test(sourceBinaryArgs:sourceDir
  ARGS
    "${CMakeGUITest_BINARY_DIR}/sourceBinaryArgs-sourceDir/src"
  )
run_cmake_gui_test(sourceBinaryArgs:binaryDir
  DO_CONFIGURE
  ARGS
    "${CMakeGUITest_BINARY_DIR}/sourceBinaryArgs-binaryDir/build"
  )
run_cmake_gui_test(sourceBinaryArgs:noExist
  ARGS
    "${CMakeGUITest_BINARY_DIR}/sourceBinaryArgs-noExist/noexist"
  )
run_cmake_gui_test(sourceBinaryArgs:noExistConfig
  ARGS
    "${CMakeGUITest_BINARY_DIR}/sourceBinaryArgs-noExistConfig/noexist"
  )
run_cmake_gui_test(sourceBinaryArgs:noExistConfigExists
  DO_CONFIGURE
  ARGS
    "${CMakeGUITest_BINARY_DIR}/sourceBinaryArgs-noExistConfigExists/noexist"
  )