RunCMakeTest.cmake 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. cmake_minimum_required(VERSION 3.12)
  2. include(RunCMake)
  3. # We do not contact any remote URLs, but may use a local one.
  4. # Remove any proxy configuration that may change behavior.
  5. unset(ENV{http_proxy})
  6. unset(ENV{https_proxy})
  7. run_cmake(BadIndependentStep1)
  8. run_cmake(BadIndependentStep2)
  9. run_cmake(IncludeScope-Add)
  10. run_cmake(IncludeScope-Add_Step)
  11. run_cmake(NoOptions)
  12. run_cmake(SourceEmpty)
  13. run_cmake(SourceMissing)
  14. run_cmake(CMAKE_CACHE_ARGS)
  15. run_cmake(CMAKE_CACHE_DEFAULT_ARGS)
  16. run_cmake(CMAKE_CACHE_mix)
  17. run_cmake(NO_DEPENDS-CMP0114-WARN)
  18. run_cmake(NO_DEPENDS-CMP0114-OLD)
  19. run_cmake(NO_DEPENDS-CMP0114-NEW)
  20. run_cmake(NO_DEPENDS-CMP0114-NEW-Direct)
  21. run_cmake(Add_StepDependencies)
  22. run_cmake(Add_StepDependencies_iface)
  23. run_cmake(Add_StepDependencies_iface_step)
  24. run_cmake(Add_StepDependencies_no_target)
  25. run_cmake(UsesTerminal)
  26. macro(check_steps_missing proj)
  27. set(steps "${ARGN}")
  28. foreach(step ${steps})
  29. if(EXISTS ${RunCMake_TEST_BINARY_DIR}/${proj}-${step}-mark)
  30. string(APPEND RunCMake_TEST_FAILED "${proj} '${step}' step ran but should not have\n")
  31. endif()
  32. endforeach()
  33. endmacro()
  34. macro(check_steps_present proj)
  35. set(steps "${ARGN}")
  36. foreach(step ${steps})
  37. if(NOT EXISTS ${RunCMake_TEST_BINARY_DIR}/${proj}-${step}-mark)
  38. string(APPEND RunCMake_TEST_FAILED "${proj} '${step}' step did not run but should have\n")
  39. endif()
  40. endforeach()
  41. endmacro()
  42. function(run_steps_CMP0114 val)
  43. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Steps-CMP0114-${val}-build)
  44. run_cmake(Steps-CMP0114-${val})
  45. set(RunCMake_TEST_NO_CLEAN 1)
  46. run_cmake_command(Steps-CMP0114-${val}-build-download ${CMAKE_COMMAND} --build . --target proj1-download)
  47. run_cmake_command(Steps-CMP0114-${val}-build-update ${CMAKE_COMMAND} --build . --target proj1-update)
  48. run_cmake_command(Steps-CMP0114-${val}-build-install ${CMAKE_COMMAND} --build . --target proj1-install)
  49. run_cmake_command(Steps-CMP0114-${val}-build-test ${CMAKE_COMMAND} --build . --target proj1-test)
  50. endfunction()
  51. run_steps_CMP0114(OLD)
  52. run_steps_CMP0114(NEW)
  53. # Run both cmake and build steps. We always do a clean before the
  54. # build to ensure that the download step re-runs each time.
  55. function(__ep_test_with_build testName)
  56. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${testName}-build)
  57. set(RunCMake_TEST_NO_CLEAN 1)
  58. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  59. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  60. run_cmake(${testName})
  61. run_cmake_command(${testName}-clean ${CMAKE_COMMAND} --build . --target clean)
  62. run_cmake_command(${testName}-build ${CMAKE_COMMAND} --build .)
  63. endfunction()
  64. find_package(Python3)
  65. function(__ep_test_with_build_with_server testName)
  66. if(NOT Python3_EXECUTABLE)
  67. return()
  68. endif()
  69. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${testName}-build)
  70. set(RunCMake_TEST_NO_CLEAN 1)
  71. set(RunCMake_TEST_TIMEOUT 20)
  72. set(RunCMake_TEST_OUTPUT_MERGE TRUE)
  73. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  74. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  75. set(URL_FILE ${RunCMake_BINARY_DIR}/${testName}.url)
  76. if(EXISTS "${URL_FILE}")
  77. file(REMOVE "${URL_FILE}")
  78. endif()
  79. execute_process(
  80. COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/DownloadServer.py --file "${URL_FILE}" ${ARGN}
  81. OUTPUT_FILE ${RunCMake_BINARY_DIR}/${testName}-python.txt
  82. ERROR_FILE ${RunCMake_BINARY_DIR}/${testName}-python.txt
  83. RESULT_VARIABLE result
  84. TIMEOUT 30
  85. )
  86. if(NOT result EQUAL 0)
  87. message(FATAL_ERROR "Failed to start download server:\n ${result}")
  88. endif()
  89. foreach(i RANGE 1 8)
  90. if(EXISTS ${URL_FILE})
  91. break()
  92. endif()
  93. execute_process(COMMAND ${CMAKE_COMMAND} -E sleep ${i})
  94. endforeach()
  95. if(NOT EXISTS ${URL_FILE})
  96. message(FATAL_ERROR "Failed to load download server URL from:\n ${URL_FILE}")
  97. endif()
  98. file(READ ${URL_FILE} SERVER_URL)
  99. message(STATUS "URL : ${URL_FILE} - ${SERVER_URL}")
  100. run_cmake_with_options(${testName} ${CMAKE_COMMAND} -DSERVER_URL=${SERVER_URL} )
  101. run_cmake_command(${testName}-clean ${CMAKE_COMMAND} --build . --target clean)
  102. run_cmake_command(${testName}-build ${CMAKE_COMMAND} --build .)
  103. endfunction()
  104. __ep_test_with_build(MultiCommand)
  105. set(RunCMake_TEST_OUTPUT_MERGE 1)
  106. __ep_test_with_build(PreserveEmptyArgs)
  107. set(RunCMake_TEST_OUTPUT_MERGE 0)
  108. # Output is not predictable enough to be able to verify it reliably
  109. # when using the various different Visual Studio generators
  110. if(NOT RunCMake_GENERATOR MATCHES "Visual Studio")
  111. __ep_test_with_build(LogOutputOnFailure)
  112. __ep_test_with_build(LogOutputOnFailureMerged)
  113. __ep_test_with_build(DownloadTimeout)
  114. __ep_test_with_build_with_server(DownloadInactivityTimeout --speed_limit --limit_duration 40)
  115. __ep_test_with_build_with_server(DownloadInactivityResume --speed_limit --limit_duration 1)
  116. endif()
  117. # We can't test the substitution when using the old MSYS due to
  118. # make/sh mangling the paths (substitution is performed correctly,
  119. # but the mangling means we can't reliably test the output).
  120. # There is no such issue when using the newer MSYS though. Therefore,
  121. # we need to bypass the substitution test if using old MSYS.
  122. # See merge request 1537 for discussion.
  123. set(doSubstitutionTest YES)
  124. if(RunCMake_GENERATOR STREQUAL "MSYS Makefiles")
  125. execute_process(COMMAND uname OUTPUT_VARIABLE uname)
  126. if(uname MATCHES "^MINGW32_NT")
  127. set(doSubstitutionTest NO)
  128. endif()
  129. endif()
  130. if(doSubstitutionTest)
  131. __ep_test_with_build(Substitutions)
  132. endif()