RunCMakeTest.cmake 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. if(NOT XCODE_VERSION OR XCODE_VERSION VERSION_LESS 12)
  18. run_cmake(NO_DEPENDS-CMP0114-WARN)
  19. run_cmake(NO_DEPENDS-CMP0114-OLD)
  20. endif()
  21. run_cmake(NO_DEPENDS-CMP0114-NEW)
  22. run_cmake(NO_DEPENDS-CMP0114-NEW-Direct)
  23. run_cmake(Add_StepDependencies)
  24. run_cmake(Add_StepDependencies_iface)
  25. run_cmake(Add_StepDependencies_iface_step)
  26. run_cmake(Add_StepDependencies_no_target)
  27. run_cmake(UsesTerminal)
  28. if(XCODE_VERSION AND XCODE_VERSION VERSION_GREATER_EQUAL 12)
  29. run_cmake(Xcode-CMP0114)
  30. endif()
  31. macro(check_steps_missing proj)
  32. set(steps "${ARGN}")
  33. foreach(step ${steps})
  34. if(EXISTS ${RunCMake_TEST_BINARY_DIR}/${proj}-${step}-mark)
  35. string(APPEND RunCMake_TEST_FAILED "${proj} '${step}' step ran but should not have\n")
  36. endif()
  37. endforeach()
  38. endmacro()
  39. macro(check_steps_present proj)
  40. set(steps "${ARGN}")
  41. foreach(step ${steps})
  42. if(NOT EXISTS ${RunCMake_TEST_BINARY_DIR}/${proj}-${step}-mark)
  43. string(APPEND RunCMake_TEST_FAILED "${proj} '${step}' step did not run but should have\n")
  44. endif()
  45. endforeach()
  46. endmacro()
  47. function(run_steps_CMP0114 val)
  48. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Steps-CMP0114-${val}-build)
  49. run_cmake(Steps-CMP0114-${val})
  50. set(RunCMake_TEST_NO_CLEAN 1)
  51. run_cmake_command(Steps-CMP0114-${val}-build-download ${CMAKE_COMMAND} --build . --target proj1-download)
  52. run_cmake_command(Steps-CMP0114-${val}-build-update ${CMAKE_COMMAND} --build . --target proj1-update)
  53. run_cmake_command(Steps-CMP0114-${val}-build-install ${CMAKE_COMMAND} --build . --target proj1-install)
  54. run_cmake_command(Steps-CMP0114-${val}-build-test ${CMAKE_COMMAND} --build . --target proj1-test)
  55. endfunction()
  56. if(NOT XCODE_VERSION OR XCODE_VERSION VERSION_LESS 12)
  57. run_steps_CMP0114(OLD)
  58. endif()
  59. run_steps_CMP0114(NEW)
  60. # Run both cmake and build steps. We always do a clean before the
  61. # build to ensure that the download step re-runs each time.
  62. function(__ep_test_with_build testName)
  63. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${testName}-build)
  64. set(RunCMake_TEST_NO_CLEAN 1)
  65. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  66. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  67. run_cmake(${testName})
  68. run_cmake_command(${testName}-clean ${CMAKE_COMMAND} --build . --target clean)
  69. run_cmake_command(${testName}-build ${CMAKE_COMMAND} --build .)
  70. endfunction()
  71. find_package(Python3)
  72. function(__ep_test_with_build_with_server testName)
  73. if(NOT Python3_EXECUTABLE)
  74. return()
  75. endif()
  76. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${testName}-build)
  77. set(RunCMake_TEST_NO_CLEAN 1)
  78. set(RunCMake_TEST_TIMEOUT 20)
  79. set(RunCMake_TEST_OUTPUT_MERGE TRUE)
  80. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  81. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  82. set(URL_FILE ${RunCMake_BINARY_DIR}/${testName}.url)
  83. if(EXISTS "${URL_FILE}")
  84. file(REMOVE "${URL_FILE}")
  85. endif()
  86. execute_process(
  87. COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/DownloadServer.py --file "${URL_FILE}" ${ARGN}
  88. OUTPUT_FILE ${RunCMake_BINARY_DIR}/${testName}-python.txt
  89. ERROR_FILE ${RunCMake_BINARY_DIR}/${testName}-python.txt
  90. RESULT_VARIABLE result
  91. TIMEOUT 30
  92. )
  93. if(NOT result EQUAL 0)
  94. message(FATAL_ERROR "Failed to start download server:\n ${result}")
  95. endif()
  96. foreach(i RANGE 1 8)
  97. if(EXISTS ${URL_FILE})
  98. break()
  99. endif()
  100. execute_process(COMMAND ${CMAKE_COMMAND} -E sleep ${i})
  101. endforeach()
  102. if(NOT EXISTS ${URL_FILE})
  103. message(FATAL_ERROR "Failed to load download server URL from:\n ${URL_FILE}")
  104. endif()
  105. file(READ ${URL_FILE} SERVER_URL)
  106. message(STATUS "URL : ${URL_FILE} - ${SERVER_URL}")
  107. run_cmake_with_options(${testName} ${CMAKE_COMMAND} -DSERVER_URL=${SERVER_URL} )
  108. run_cmake_command(${testName}-clean ${CMAKE_COMMAND} --build . --target clean)
  109. run_cmake_command(${testName}-build ${CMAKE_COMMAND} --build .)
  110. endfunction()
  111. __ep_test_with_build(MultiCommand)
  112. set(RunCMake_TEST_OUTPUT_MERGE 1)
  113. __ep_test_with_build(PreserveEmptyArgs)
  114. set(RunCMake_TEST_OUTPUT_MERGE 0)
  115. # Output is not predictable enough to be able to verify it reliably
  116. # when using the various different Visual Studio generators
  117. if(NOT RunCMake_GENERATOR MATCHES "Visual Studio")
  118. __ep_test_with_build(LogOutputOnFailure)
  119. __ep_test_with_build(LogOutputOnFailureMerged)
  120. __ep_test_with_build(DownloadTimeout)
  121. __ep_test_with_build_with_server(DownloadInactivityTimeout --speed_limit --limit_duration 40)
  122. __ep_test_with_build_with_server(DownloadInactivityResume --speed_limit --limit_duration 1)
  123. endif()
  124. # We can't test the substitution when using the old MSYS due to
  125. # make/sh mangling the paths (substitution is performed correctly,
  126. # but the mangling means we can't reliably test the output).
  127. # There is no such issue when using the newer MSYS though. Therefore,
  128. # we need to bypass the substitution test if using old MSYS.
  129. # See merge request 1537 for discussion.
  130. set(doSubstitutionTest YES)
  131. if(RunCMake_GENERATOR STREQUAL "MSYS Makefiles")
  132. execute_process(COMMAND uname OUTPUT_VARIABLE uname)
  133. if(uname MATCHES "^MINGW32_NT")
  134. set(doSubstitutionTest NO)
  135. endif()
  136. endif()
  137. if(doSubstitutionTest)
  138. __ep_test_with_build(Substitutions)
  139. endif()
  140. function(__ep_test_CONFIGURE_HANDLED_BY_BUILD)
  141. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/CONFIGURE_HANDLED_BY_BUILD-build)
  142. run_cmake(CONFIGURE_HANDLED_BY_BUILD)
  143. if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
  144. set(BUILD_CONFIG --config Debug)
  145. set(STAMP_DIR "${RunCMake_TEST_BINARY_DIR}/stamp/Debug")
  146. else()
  147. set(BUILD_CONFIG "")
  148. set(STAMP_DIR "${RunCMake_TEST_BINARY_DIR}/stamp")
  149. endif()
  150. set(RunCMake_TEST_NO_CLEAN 1)
  151. run_cmake_command(CONFIGURE_HANDLED_BY_BUILD-build ${CMAKE_COMMAND} --build . ${BUILD_CONFIG})
  152. # Calculate timestamps before rebuilding so we can compare before and after in
  153. # CONFIGURE_HANDLED_BY_BUILD-rebuild-check.cmake
  154. file(TIMESTAMP "${STAMP_DIR}/proj1-configure" PROJ1_CONFIGURE_TIMESTAMP_BEFORE "%s")
  155. # When BUILD_ALWAYS is set, the build stamp is never created.
  156. file(TIMESTAMP "${STAMP_DIR}/proj2-configure" PROJ2_CONFIGURE_TIMESTAMP_BEFORE "%s")
  157. file(TIMESTAMP "${STAMP_DIR}/proj2-build" PROJ2_BUILD_TIMESTAMP_BEFORE "%s")
  158. run_cmake_command(CONFIGURE_HANDLED_BY_BUILD-rebuild ${CMAKE_COMMAND} --build . ${BUILD_CONFIG})
  159. endfunction()
  160. if(NOT RunCMake_GENERATOR MATCHES "Visual Studio 9 ")
  161. __ep_test_CONFIGURE_HANDLED_BY_BUILD()
  162. endif()