| 1 |
# If we are using the Ninja generator, we can check and verify that the |
| 2 |
# USES_TERMINAL option actually works by examining the Ninja build file. |
| 3 |
# This is the only way, since CMake doesn't offer a way to examine the |
| 4 |
# options on a custom command after it has been added. Furthermore, |
| 5 |
# there isn't an easy way to test for this by actually running Ninja. |
| 6 |
# |
| 7 |
# Other generators don't currently support USES_TERMINAL at this time. |
| 8 |
# This file can be improved to support them if they do. Until then, we |
| 9 |
# simply assume success for new generator types. |
| 10 |
# |
| 11 |
# For Ninja, there is a complication. If the Ninja generator detects a |
| 12 |
# version of Ninja < 1.5, it won't actually emit the console pool command, |
| 13 |
# because those Ninja versions don't yet support the console pool. In |
| 14 |
# that case, we also have to assume success. |
| 15 |
|
| 16 |
# Check Ninja build output to verify whether or not a target step is in the |
| 17 |
# console pool. |
| 18 |
macro(CheckNinjaStep _target _step _require) |
| 19 |
if("${_build}" MATCHES |
| 20 |
" DESC = Performing ${_step} step for '${_target}' |
| 21 |
pool = console" |
| 22 |
) |
| 23 |
if(NOT ${_require}) |
| 24 |
set(RunCMake_TEST_FAILED "${_target} ${_step} step is in console pool") |
| 25 |
return() |
| 26 |
endif() |
| 27 |
else() |
| 28 |
if(${_require}) |
| 29 |
set(RunCMake_TEST_FAILED "${_target} ${_step} step not in console pool") |
| 30 |
return() |
| 31 |
endif() |
| 32 |
endif() |
| 33 |
endmacro() |
| 34 |
|
| 35 |
# Check Ninja build output to verify whether each target step is in the |
| 36 |
# console pool. |
| 37 |
macro(CheckNinjaTarget _target |
| 38 |
_download _update _patch _configure _build _test _install |
| 39 |
) |
| 40 |
CheckNinjaStep(${_target} download ${_download}) |
| 41 |
CheckNinjaStep(${_target} update ${_update}) |
| 42 |
CheckNinjaStep(${_target} patch ${_patch}) |
| 43 |
CheckNinjaStep(${_target} configure ${_configure}) |
| 44 |
CheckNinjaStep(${_target} build ${_build}) |
| 45 |
CheckNinjaStep(${_target} test ${_test}) |
| 46 |
CheckNinjaStep(${_target} install ${_install}) |
| 47 |
endmacro() |
| 48 |
|
| 49 |
# Load build/make file, depending on generator |
| 50 |
if(RunCMake_GENERATOR STREQUAL Ninja) |
| 51 |
# Check the Ninja version. If < 1.5, console pool isn't supported and |
| 52 |
# so the generator would not emit console pool usage. That would cause |
| 53 |
# this test to fail. |
| 54 |
execute_process(COMMAND ${RunCMake_MAKE_PROGRAM} --version |
| 55 |
RESULT_VARIABLE _version_result |
| 56 |
OUTPUT_VARIABLE _version |
| 57 |
ERROR_QUIET |
| 58 |
OUTPUT_STRIP_TRAILING_WHITESPACE |
| 59 |
) |
| 60 |
if(_version_result OR _version VERSION_EQUAL "0") |
| 61 |
set(RunCMake_TEST_FAILED "Failed to get Ninja version") |
| 62 |
return() |
| 63 |
endif() |
| 64 |
if(_version VERSION_LESS "1.5") |
| 65 |
return() # console pool not supported on Ninja < 1.5 |
| 66 |
endif() |
| 67 |
|
| 68 |
# Read the Ninja build file |
| 69 |
set(_build_file "${RunCMake_TEST_BINARY_DIR}/build.ninja") |
| 70 |
|
| 71 |
if(NOT EXISTS "${_build_file}") |
| 72 |
set(RunCMake_TEST_FAILED "Ninja build file not created") |
| 73 |
return() |
| 74 |
endif() |
| 75 |
|
| 76 |
file(READ "${_build_file}" _build) |
| 77 |
|
| 78 |
set(_target_check_macro CheckNinjaTarget) |
| 79 |
elseif((RunCMake_GENERATOR STREQUAL "") OR NOT DEFINED RunCMake_GENERATOR) |
| 80 |
# protection in case somebody renamed RunCMake_GENERATOR |
| 81 |
set(RunCMake_TEST_FAILED "Unknown generator") |
| 82 |
return() |
| 83 |
else() |
| 84 |
# We don't yet know how to test USES_TERMINAL on this generator. |
| 85 |
return() |
| 86 |
endif() |
| 87 |
|
| 88 |
# Actual tests: |
| 89 |
CheckNinjaTarget(TerminalTest1 |
| 90 |
true true true true true true true ) |
| 91 |
CheckNinjaTarget(TerminalTest2 |
| 92 |
true false true false true false true) |
| 93 |
CheckNinjaTarget(TerminalTest3 |
| 94 |
false true false true false true false) |
| 95 |
CheckNinjaTarget(TerminalTest4 |
| 96 |
false false false false false false false) |