summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/CPack/CPackTestHelpers.cmake
blob: 7ea2a24b307fa8dd3137fa9e8ce7b90df8ea3e5b (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
cmake_policy(SET CMP0057 NEW)

function(run_cpack_test TEST_NAME types build)
  if(TEST_TYPE IN_LIST types)
    set(RunCMake_TEST_NO_CLEAN TRUE)
    set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/${TEST_NAME}-build")

     # TODO this should be executed only once per ctest run (not per generator)
    file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
    file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")

    # execute cmake
    execute_process(
      COMMAND "${CMAKE_COMMAND}" -DRunCMake_TEST=${TEST_NAME}
          -DGENERATOR_TYPE=${TEST_TYPE} "${RunCMake_SOURCE_DIR}"
      WORKING_DIRECTORY "${RunCMake_TEST_BINARY_DIR}"
      RESULT_VARIABLE res
      OUTPUT_FILE "${RunCMake_TEST_BINARY_DIR}/test_output.txt"
      ERROR_FILE "${RunCMake_TEST_BINARY_DIR}/test_error.txt"
      )

    if(res)
      run_cmake_command(
        ${TEST_TYPE}/${TEST_NAME}
        "${CMAKE_COMMAND}"
          -DRunCMake_TEST_STEP=configure
          -Dreturn_code=${res}
          "-Dbin_dir=${RunCMake_TEST_BINARY_DIR}"
          -P "${RunCMake_SOURCE_DIR}/PreTestError.cmake"
        )
      return()
    endif()

    # execute optional build step
    if(build)
      execute_process(
        COMMAND "${CMAKE_COMMAND}" --build "${RunCMake_TEST_BINARY_DIR}"
        RESULT_VARIABLE res
        OUTPUT_FILE "${RunCMake_TEST_BINARY_DIR}/test_output.txt"
        ERROR_FILE "${RunCMake_TEST_BINARY_DIR}/test_error.txt"
        )
    endif()

    if(res)
      run_cmake_command(
        ${TEST_TYPE}/${TEST_NAME}
        "${CMAKE_COMMAND}"
          -DRunCMake_TEST_STEP=build
          -Dreturn_code=${res}
          "-Dbin_dir=${RunCMake_TEST_BINARY_DIR}"
          -P "${RunCMake_SOURCE_DIR}/PreTestError.cmake"
        )
      return()
    endif()

    # execute cpack
    execute_process(
      COMMAND "${CMAKE_CPACK_COMMAND}"
      WORKING_DIRECTORY "${RunCMake_TEST_BINARY_DIR}"
      OUTPUT_FILE "${RunCMake_TEST_BINARY_DIR}/test_output.txt"
      ERROR_FILE "${RunCMake_TEST_BINARY_DIR}/test_error.txt"
      )

    # verify result
    run_cmake_command(
      ${TEST_TYPE}/${TEST_NAME}
      "${CMAKE_COMMAND}"
        -DRunCMake_TEST=${TEST_NAME}
        -DGENERATOR_TYPE=${TEST_TYPE}
        "-Dsrc_dir=${RunCMake_SOURCE_DIR}"
        "-Dbin_dir=${RunCMake_TEST_BINARY_DIR}"
        "-Dconfig_file=${config_file}"
        -P "${RunCMake_SOURCE_DIR}/VerifyResult.cmake"
      )
  endif()
endfunction()