RunCMakeTest.cmake 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. if(RunCMake_GENERATOR STREQUAL "Borland Makefiles" OR
  8. RunCMake_GENERATOR STREQUAL "Watcom WMake")
  9. set(fs_delay 3)
  10. else()
  11. set(fs_delay 1.125)
  12. endif()
  13. run_cmake(BadIndependentStep1)
  14. run_cmake(BadIndependentStep2)
  15. run_cmake(NoOptions)
  16. run_cmake(SourceEmpty)
  17. run_cmake(SourceMissing)
  18. run_cmake(CMAKE_CACHE_ARGS)
  19. run_cmake(CMAKE_CACHE_DEFAULT_ARGS)
  20. run_cmake(CMAKE_CACHE_mix)
  21. if(NOT XCODE_VERSION OR XCODE_VERSION VERSION_LESS 12)
  22. run_cmake(NO_DEPENDS-CMP0114-WARN)
  23. run_cmake(NO_DEPENDS-CMP0114-OLD)
  24. endif()
  25. run_cmake(NO_DEPENDS-CMP0114-NEW)
  26. run_cmake(NO_DEPENDS-CMP0114-NEW-Direct)
  27. run_cmake(Add_StepDependencies)
  28. run_cmake(Add_StepDependencies_iface)
  29. run_cmake(Add_StepDependencies_iface_step)
  30. run_cmake(Add_StepDependencies_no_target)
  31. run_cmake(UsesTerminal)
  32. if(XCODE_VERSION AND XCODE_VERSION VERSION_GREATER_EQUAL 12)
  33. run_cmake(Xcode-CMP0114)
  34. endif()
  35. macro(check_steps_missing proj)
  36. set(steps "${ARGN}")
  37. foreach(step ${steps})
  38. if(EXISTS ${RunCMake_TEST_BINARY_DIR}/${proj}-${step}-mark)
  39. string(APPEND RunCMake_TEST_FAILED "${proj} '${step}' step ran but should not have\n")
  40. endif()
  41. endforeach()
  42. endmacro()
  43. macro(check_steps_present proj)
  44. set(steps "${ARGN}")
  45. foreach(step ${steps})
  46. if(NOT EXISTS ${RunCMake_TEST_BINARY_DIR}/${proj}-${step}-mark)
  47. string(APPEND RunCMake_TEST_FAILED "${proj} '${step}' step did not run but should have\n")
  48. endif()
  49. endforeach()
  50. endmacro()
  51. function(run_steps_CMP0114 val)
  52. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Steps-CMP0114-${val}-build)
  53. run_cmake(Steps-CMP0114-${val})
  54. set(RunCMake_TEST_NO_CLEAN 1)
  55. run_cmake_command(Steps-CMP0114-${val}-build-download ${CMAKE_COMMAND} --build . --target proj1-download)
  56. run_cmake_command(Steps-CMP0114-${val}-build-update ${CMAKE_COMMAND} --build . --target proj1-update)
  57. run_cmake_command(Steps-CMP0114-${val}-build-install ${CMAKE_COMMAND} --build . --target proj1-install)
  58. run_cmake_command(Steps-CMP0114-${val}-build-test ${CMAKE_COMMAND} --build . --target proj1-test)
  59. endfunction()
  60. if(NOT XCODE_VERSION OR XCODE_VERSION VERSION_LESS 12)
  61. run_steps_CMP0114(OLD)
  62. endif()
  63. run_steps_CMP0114(NEW)
  64. function(__ep_test_source_dir_change)
  65. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/SourceDirChange-build)
  66. set(RunCMake_TEST_NO_CLEAN 1)
  67. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  68. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  69. run_cmake(SourceDirChange)
  70. run_cmake_command(SourceDirChange-build1 ${CMAKE_COMMAND} --build .)
  71. # Because some file systems have timestamps with only one second resolution,
  72. # we have to ensure we don't re-run the configure stage too quickly after the
  73. # first build. Otherwise, the modified RepositoryInfo.txt files the next
  74. # configure writes might still have the same timestamp as the previous one.
  75. execute_process(COMMAND ${CMAKE_COMMAND} -E sleep ${fs_delay})
  76. run_cmake_command(SourceDirChange-change ${CMAKE_COMMAND} -DSOURCE_DIR_CHANGE=YES .)
  77. run_cmake_command(SourceDirChange-build2 ${CMAKE_COMMAND} --build .)
  78. endfunction()
  79. __ep_test_source_dir_change()
  80. # Run both cmake and build steps. We always do a clean before the
  81. # build to ensure that the download step re-runs each time.
  82. function(__ep_test_with_build testName)
  83. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${testName}-build)
  84. set(RunCMake_TEST_NO_CLEAN 1)
  85. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  86. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  87. run_cmake(${testName})
  88. run_cmake_command(${testName}-clean ${CMAKE_COMMAND} --build . --target clean)
  89. run_cmake_command(${testName}-build ${CMAKE_COMMAND} --build .)
  90. endfunction()
  91. find_package(Python3)
  92. function(__ep_test_with_build_with_server testName)
  93. if(NOT Python3_EXECUTABLE)
  94. return()
  95. endif()
  96. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${testName}-build)
  97. set(RunCMake_TEST_NO_CLEAN 1)
  98. set(RunCMake_TEST_TIMEOUT 20)
  99. set(RunCMake_TEST_OUTPUT_MERGE TRUE)
  100. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  101. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  102. set(URL_FILE ${RunCMake_BINARY_DIR}/${testName}.url)
  103. if(EXISTS "${URL_FILE}")
  104. file(REMOVE "${URL_FILE}")
  105. endif()
  106. if(NOT DOWNLOAD_SERVER_TIMEOUT)
  107. set(DOWNLOAD_SERVER_TIMEOUT 30)
  108. endif()
  109. execute_process(
  110. COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/DownloadServer.py --file "${URL_FILE}" ${ARGN}
  111. OUTPUT_FILE ${RunCMake_BINARY_DIR}/${testName}-python.txt
  112. ERROR_FILE ${RunCMake_BINARY_DIR}/${testName}-python.txt
  113. RESULT_VARIABLE result
  114. TIMEOUT "${DOWNLOAD_SERVER_TIMEOUT}"
  115. )
  116. if(NOT result EQUAL 0)
  117. message(FATAL_ERROR "Failed to start download server:\n ${result}")
  118. endif()
  119. foreach(i RANGE 1 8)
  120. if(EXISTS ${URL_FILE})
  121. break()
  122. endif()
  123. execute_process(COMMAND ${CMAKE_COMMAND} -E sleep ${i})
  124. endforeach()
  125. if(NOT EXISTS ${URL_FILE})
  126. message(FATAL_ERROR "Failed to load download server URL from:\n ${URL_FILE}")
  127. endif()
  128. file(READ ${URL_FILE} SERVER_URL)
  129. message(STATUS "URL : ${URL_FILE} - ${SERVER_URL}")
  130. run_cmake_with_options(${testName} -DSERVER_URL=${SERVER_URL})
  131. run_cmake_command(${testName}-clean ${CMAKE_COMMAND} --build . --target clean)
  132. run_cmake_command(${testName}-build ${CMAKE_COMMAND} --build .)
  133. endfunction()
  134. __ep_test_with_build(MultiCommand)
  135. set(RunCMake_TEST_OUTPUT_MERGE 1)
  136. __ep_test_with_build(PreserveEmptyArgs)
  137. set(RunCMake_TEST_OUTPUT_MERGE 0)
  138. # Output is not predictable enough to be able to verify it reliably
  139. # when using the various different Visual Studio generators
  140. if(NOT RunCMake_GENERATOR MATCHES "Visual Studio")
  141. __ep_test_with_build(LogOutputOnFailure)
  142. __ep_test_with_build(LogOutputOnFailureMerged)
  143. __ep_test_with_build(DownloadTimeout)
  144. __ep_test_with_build_with_server(DownloadInactivityTimeout --speed_limit --limit_duration 40)
  145. __ep_test_with_build_with_server(DownloadInactivityResume --speed_limit --limit_duration 1)
  146. endif()
  147. # We can't test the substitution when using the old MSYS due to
  148. # make/sh mangling the paths (substitution is performed correctly,
  149. # but the mangling means we can't reliably test the output).
  150. # There is no such issue when using the newer MSYS though. Therefore,
  151. # we need to bypass the substitution test if using old MSYS.
  152. # See merge request 1537 for discussion.
  153. set(doSubstitutionTest YES)
  154. if(RunCMake_GENERATOR STREQUAL "MSYS Makefiles")
  155. execute_process(COMMAND uname OUTPUT_VARIABLE uname)
  156. if(uname MATCHES "^MINGW32_NT")
  157. set(doSubstitutionTest NO)
  158. endif()
  159. endif()
  160. if(doSubstitutionTest)
  161. __ep_test_with_build(Substitutions)
  162. endif()
  163. function(__ep_test_CONFIGURE_HANDLED_BY_BUILD)
  164. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/CONFIGURE_HANDLED_BY_BUILD-build)
  165. run_cmake(CONFIGURE_HANDLED_BY_BUILD)
  166. if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
  167. set(BUILD_CONFIG --config Debug)
  168. set(STAMP_DIR "${RunCMake_TEST_BINARY_DIR}/stamp/Debug")
  169. else()
  170. set(BUILD_CONFIG "")
  171. set(STAMP_DIR "${RunCMake_TEST_BINARY_DIR}/stamp")
  172. endif()
  173. set(RunCMake_TEST_NO_CLEAN 1)
  174. run_cmake_command(CONFIGURE_HANDLED_BY_BUILD-build ${CMAKE_COMMAND} --build . ${BUILD_CONFIG})
  175. # Calculate timestamps before rebuilding so we can compare before and after in
  176. # CONFIGURE_HANDLED_BY_BUILD-rebuild-check.cmake
  177. file(TIMESTAMP "${STAMP_DIR}/proj1-configure" PROJ1_CONFIGURE_TIMESTAMP_BEFORE "%s")
  178. # When BUILD_ALWAYS is set, the build stamp is never created.
  179. file(TIMESTAMP "${STAMP_DIR}/proj2-configure" PROJ2_CONFIGURE_TIMESTAMP_BEFORE "%s")
  180. file(TIMESTAMP "${STAMP_DIR}/proj2-build" PROJ2_BUILD_TIMESTAMP_BEFORE "%s")
  181. run_cmake_command(CONFIGURE_HANDLED_BY_BUILD-rebuild ${CMAKE_COMMAND} --build . ${BUILD_CONFIG})
  182. endfunction()
  183. if(NOT RunCMake_GENERATOR MATCHES "Visual Studio 9 ")
  184. __ep_test_CONFIGURE_HANDLED_BY_BUILD()
  185. endif()
  186. find_package(Git QUIET)
  187. if(GIT_EXECUTABLE)
  188. # Note that there appear to be differences in where git writes its output to
  189. # on some platforms. It may go to stdout or stderr, so force it to be merged.
  190. set(RunCMake_TEST_OUTPUT_MERGE TRUE)
  191. run_cmake(FetchGitRefs)
  192. set(RunCMake_TEST_OUTPUT_MERGE FALSE)
  193. endif()