UsesTerminal-check.cmake 3.3 KB

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