| 1 |
cmake_minimum_required(VERSION 3.12) |
| 2 |
include(RunCMake) |
| 3 |
|
| 4 |
# We do not contact any remote URLs, but may use a local one. |
| 5 |
# Remove any proxy configuration that may change behavior. |
| 6 |
unset(ENV{http_proxy}) |
| 7 |
unset(ENV{https_proxy}) |
| 8 |
|
| 9 |
if(RunCMake_GENERATOR STREQUAL "Borland Makefiles" OR |
| 10 |
RunCMake_GENERATOR STREQUAL "Watcom WMake") |
| 11 |
set(fs_delay 3) |
| 12 |
else() |
| 13 |
set(fs_delay 1.125) |
| 14 |
endif() |
| 15 |
|
| 16 |
run_cmake(BadIndependentStep1) |
| 17 |
run_cmake(BadIndependentStep2) |
| 18 |
run_cmake(NoOptions) |
| 19 |
run_cmake(SourceEmpty) |
| 20 |
run_cmake(SourceMissing) |
| 21 |
run_cmake(SourceDirExisting) |
| 22 |
run_cmake(CMAKE_CACHE_ARGS) |
| 23 |
run_cmake(CMAKE_CACHE_DEFAULT_ARGS) |
| 24 |
run_cmake(CMAKE_CACHE_mix) |
| 25 |
if(NOT XCODE_VERSION OR XCODE_VERSION VERSION_LESS 12) |
| 26 |
run_cmake(NO_DEPENDS-CMP0114-WARN) |
| 27 |
run_cmake(NO_DEPENDS-CMP0114-OLD) |
| 28 |
endif() |
| 29 |
run_cmake(NO_DEPENDS-CMP0114-NEW) |
| 30 |
run_cmake(NO_DEPENDS-CMP0114-NEW-Direct) |
| 31 |
run_cmake(Add_StepDependencies) |
| 32 |
run_cmake(Add_StepDependencies_iface) |
| 33 |
run_cmake(Add_StepDependencies_iface_step) |
| 34 |
run_cmake(Add_StepDependencies_no_target) |
| 35 |
run_cmake(UsesTerminal) |
| 36 |
if(XCODE_VERSION AND XCODE_VERSION VERSION_GREATER_EQUAL 12) |
| 37 |
run_cmake(Xcode-CMP0114) |
| 38 |
endif() |
| 39 |
|
| 40 |
macro(check_steps_missing proj) |
| 41 |
set(steps "${ARGN}") |
| 42 |
foreach(step ${steps}) |
| 43 |
if(EXISTS ${RunCMake_TEST_BINARY_DIR}/${proj}-${step}-mark) |
| 44 |
string(APPEND RunCMake_TEST_FAILED "${proj} '${step}' step ran but should not have\n") |
| 45 |
endif() |
| 46 |
endforeach() |
| 47 |
endmacro() |
| 48 |
|
| 49 |
macro(check_steps_present proj) |
| 50 |
set(steps "${ARGN}") |
| 51 |
foreach(step ${steps}) |
| 52 |
if(NOT EXISTS ${RunCMake_TEST_BINARY_DIR}/${proj}-${step}-mark) |
| 53 |
string(APPEND RunCMake_TEST_FAILED "${proj} '${step}' step did not run but should have\n") |
| 54 |
endif() |
| 55 |
endforeach() |
| 56 |
endmacro() |
| 57 |
|
| 58 |
function(run_steps_CMP0114 val) |
| 59 |
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Steps-CMP0114-${val}-build) |
| 60 |
run_cmake(Steps-CMP0114-${val}) |
| 61 |
set(RunCMake_TEST_NO_CLEAN 1) |
| 62 |
run_cmake_command(Steps-CMP0114-${val}-build-download ${CMAKE_COMMAND} --build . --target proj1-download) |
| 63 |
run_cmake_command(Steps-CMP0114-${val}-build-update ${CMAKE_COMMAND} --build . --target proj1-update) |
| 64 |
run_cmake_command(Steps-CMP0114-${val}-build-install ${CMAKE_COMMAND} --build . --target proj1-install) |
| 65 |
run_cmake_command(Steps-CMP0114-${val}-build-test ${CMAKE_COMMAND} --build . --target proj1-test) |
| 66 |
endfunction() |
| 67 |
if(NOT XCODE_VERSION OR XCODE_VERSION VERSION_LESS 12) |
| 68 |
run_steps_CMP0114(OLD) |
| 69 |
endif() |
| 70 |
run_steps_CMP0114(NEW) |
| 71 |
|
| 72 |
function(__ep_test_source_dir_change) |
| 73 |
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/SourceDirChange-build) |
| 74 |
set(RunCMake_TEST_NO_CLEAN 1) |
| 75 |
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") |
| 76 |
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") |
| 77 |
run_cmake(SourceDirChange) |
| 78 |
run_cmake_command(SourceDirChange-build1 ${CMAKE_COMMAND} --build .) |
| 79 |
# Because some file systems have timestamps with only one second resolution, |
| 80 |
# we have to ensure we don't re-run the configure stage too quickly after the |
| 81 |
# first build. Otherwise, the modified RepositoryInfo.txt files the next |
| 82 |
# configure writes might still have the same timestamp as the previous one. |
| 83 |
execute_process(COMMAND ${CMAKE_COMMAND} -E sleep ${fs_delay}) |
| 84 |
run_cmake_command(SourceDirChange-change ${CMAKE_COMMAND} -DSOURCE_DIR_CHANGE=YES .) |
| 85 |
run_cmake_command(SourceDirChange-build2 ${CMAKE_COMMAND} --build .) |
| 86 |
endfunction() |
| 87 |
__ep_test_source_dir_change() |
| 88 |
|
| 89 |
# Run both cmake and build steps. We always do a clean before the |
| 90 |
# build to ensure that the download step re-runs each time. |
| 91 |
function(__ep_test_with_build testName) |
| 92 |
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${testName}-build) |
| 93 |
set(RunCMake_TEST_NO_CLEAN 1) |
| 94 |
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") |
| 95 |
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") |
| 96 |
run_cmake(${testName}) |
| 97 |
run_cmake_command(${testName}-clean ${CMAKE_COMMAND} --build . --target clean) |
| 98 |
run_cmake_command(${testName}-build ${CMAKE_COMMAND} --build .) |
| 99 |
endfunction() |
| 100 |
|
| 101 |
find_package(Python3) |
| 102 |
function(__ep_test_with_build_with_server testName) |
| 103 |
if(NOT Python3_EXECUTABLE) |
| 104 |
return() |
| 105 |
endif() |
| 106 |
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${testName}-build) |
| 107 |
set(RunCMake_TEST_NO_CLEAN 1) |
| 108 |
set(RunCMake_TEST_TIMEOUT 20) |
| 109 |
set(RunCMake_TEST_OUTPUT_MERGE TRUE) |
| 110 |
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") |
| 111 |
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") |
| 112 |
set(URL_FILE ${RunCMake_BINARY_DIR}/${testName}.url) |
| 113 |
if(EXISTS "${URL_FILE}") |
| 114 |
file(REMOVE "${URL_FILE}") |
| 115 |
endif() |
| 116 |
if(NOT DOWNLOAD_SERVER_TIMEOUT) |
| 117 |
set(DOWNLOAD_SERVER_TIMEOUT 30) |
| 118 |
endif() |
| 119 |
execute_process( |
| 120 |
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/DownloadServer.py --file "${URL_FILE}" ${ARGN} |
| 121 |
OUTPUT_FILE ${RunCMake_BINARY_DIR}/${testName}-python.txt |
| 122 |
ERROR_FILE ${RunCMake_BINARY_DIR}/${testName}-python.txt |
| 123 |
RESULT_VARIABLE result |
| 124 |
TIMEOUT "${DOWNLOAD_SERVER_TIMEOUT}" |
| 125 |
) |
| 126 |
if(NOT result EQUAL 0) |
| 127 |
message(FATAL_ERROR "Failed to start download server:\n ${result}") |
| 128 |
endif() |
| 129 |
|
| 130 |
foreach(i RANGE 1 8) |
| 131 |
if(EXISTS ${URL_FILE}) |
| 132 |
break() |
| 133 |
endif() |
| 134 |
execute_process(COMMAND ${CMAKE_COMMAND} -E sleep ${i}) |
| 135 |
endforeach() |
| 136 |
|
| 137 |
if(NOT EXISTS ${URL_FILE}) |
| 138 |
message(FATAL_ERROR "Failed to load download server URL from:\n ${URL_FILE}") |
| 139 |
endif() |
| 140 |
|
| 141 |
file(READ ${URL_FILE} SERVER_URL) |
| 142 |
message(STATUS "URL : ${URL_FILE} - ${SERVER_URL}") |
| 143 |
run_cmake_with_options(${testName} -DSERVER_URL=${SERVER_URL}) |
| 144 |
run_cmake_command(${testName}-clean ${CMAKE_COMMAND} --build . --target clean) |
| 145 |
run_cmake_command(${testName}-build ${CMAKE_COMMAND} --build .) |
| 146 |
endfunction() |
| 147 |
|
| 148 |
if(RunCMake_GENERATOR MATCHES "(MSYS|MinGW|Unix) Makefiles") |
| 149 |
__ep_test_with_build(GNUMakeJobServerAware) |
| 150 |
endif() |
| 151 |
|
| 152 |
function(__ep_test_jobserver) |
| 153 |
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/DetectJobServer-build) |
| 154 |
set(RunCMake_TEST_NO_CLEAN 1) |
| 155 |
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") |
| 156 |
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") |
| 157 |
run_cmake_with_options(DetectJobServer -DDETECT_JOBSERVER=${DETECT_JOBSERVER}) |
| 158 |
run_cmake_command(DetectJobServer-clean ${CMAKE_COMMAND} --build . --target clean) |
| 159 |
run_cmake_command(DetectJobServer-build ${CMAKE_COMMAND} --build . -j4) |
| 160 |
endfunction() |
| 161 |
|
| 162 |
if(RunCMake_GENERATOR MATCHES "(MinGW|Unix) Makefiles") |
| 163 |
__ep_test_jobserver() |
| 164 |
endif() |
| 165 |
|
| 166 |
__ep_test_with_build(MultiCommand) |
| 167 |
|
| 168 |
set(RunCMake_TEST_OUTPUT_MERGE 1) |
| 169 |
__ep_test_with_build(InstallBuilds) |
| 170 |
__ep_test_with_build(PreserveEmptyArgs) |
| 171 |
set(RunCMake_TEST_OUTPUT_MERGE 0) |
| 172 |
|
| 173 |
# Output is not predictable enough to be able to verify it reliably |
| 174 |
# when using the various different Visual Studio generators |
| 175 |
if(NOT RunCMake_GENERATOR MATCHES "Visual Studio") |
| 176 |
__ep_test_with_build(LogOutputOnFailure) |
| 177 |
__ep_test_with_build(LogOutputOnFailureMerged) |
| 178 |
__ep_test_with_build(DownloadTimeout) |
| 179 |
__ep_test_with_build_with_server(DownloadInactivityTimeout --speed_limit --limit_duration 40) |
| 180 |
__ep_test_with_build_with_server(DownloadInactivityResume --speed_limit --limit_duration 1) |
| 181 |
endif() |
| 182 |
|
| 183 |
# We can't test the substitution when using the old MSYS due to |
| 184 |
# make/sh mangling the paths (substitution is performed correctly, |
| 185 |
# but the mangling means we can't reliably test the output). |
| 186 |
# There is no such issue when using the newer MSYS though. Therefore, |
| 187 |
# we need to bypass the substitution test if using old MSYS. |
| 188 |
# See merge request 1537 for discussion. |
| 189 |
set(doSubstitutionTest YES) |
| 190 |
if(RunCMake_GENERATOR STREQUAL "MSYS Makefiles") |
| 191 |
execute_process(COMMAND uname OUTPUT_VARIABLE uname) |
| 192 |
if(uname MATCHES "^MINGW32_NT") |
| 193 |
set(doSubstitutionTest NO) |
| 194 |
endif() |
| 195 |
endif() |
| 196 |
if(doSubstitutionTest) |
| 197 |
__ep_test_with_build(Substitutions) |
| 198 |
endif() |
| 199 |
|
| 200 |
function(__ep_test_BUILD_ALWAYS) |
| 201 |
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/BUILD_ALWAYS-build) |
| 202 |
run_cmake(BUILD_ALWAYS) |
| 203 |
set(RunCMake_TEST_NO_CLEAN 1) |
| 204 |
file(WRITE "${RunCMake_TEST_BINARY_DIR}/once-configure.cmake" [[message(STATUS "once: configure")]]) |
| 205 |
file(WRITE "${RunCMake_TEST_BINARY_DIR}/once-build.cmake" [[message(STATUS "once: build")]]) |
| 206 |
file(WRITE "${RunCMake_TEST_BINARY_DIR}/once-install.cmake" [[message(STATUS "once: install")]]) |
| 207 |
file(WRITE "${RunCMake_TEST_BINARY_DIR}/always-configure.cmake" [[message(STATUS "always: configure")]]) |
| 208 |
file(WRITE "${RunCMake_TEST_BINARY_DIR}/always-build.cmake" [[message(STATUS "always: build")]]) |
| 209 |
file(WRITE "${RunCMake_TEST_BINARY_DIR}/always-install.cmake" [[message(STATUS "always: install")]]) |
| 210 |
run_cmake_command(BUILD_ALWAYS-build1 ${CMAKE_COMMAND} --build . --target always) |
| 211 |
file(WRITE "${RunCMake_TEST_BINARY_DIR}/once-configure.cmake" [[message(FATAL_ERROR "once: configure should not run again")]]) |
| 212 |
file(WRITE "${RunCMake_TEST_BINARY_DIR}/once-build.cmake" [[message(FATAL_ERROR "once: build should not run again")]]) |
| 213 |
file(WRITE "${RunCMake_TEST_BINARY_DIR}/once-install.cmake" [[message(FATAL_ERROR "once: install should not run again")]]) |
| 214 |
if(NOT RunCMake_GENERATOR STREQUAL "Xcode") |
| 215 |
# The Xcode and VS 9 build systems decide to run this every time. |
| 216 |
file(WRITE "${RunCMake_TEST_BINARY_DIR}/always-configure.cmake" [[message(FATAL_ERROR "always: configure should not run again")]]) |
| 217 |
endif() |
| 218 |
run_cmake_command(BUILD_ALWAYS-build2 ${CMAKE_COMMAND} --build . --target always) |
| 219 |
endfunction() |
| 220 |
__ep_test_BUILD_ALWAYS() |
| 221 |
|
| 222 |
function(__ep_test_CONFIGURE_HANDLED_BY_BUILD) |
| 223 |
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/CONFIGURE_HANDLED_BY_BUILD-build) |
| 224 |
run_cmake(CONFIGURE_HANDLED_BY_BUILD) |
| 225 |
|
| 226 |
if(RunCMake_GENERATOR_IS_MULTI_CONFIG) |
| 227 |
set(BUILD_CONFIG --config Debug) |
| 228 |
set(STAMP_DIR "${RunCMake_TEST_BINARY_DIR}/stamp/Debug") |
| 229 |
else() |
| 230 |
set(BUILD_CONFIG "") |
| 231 |
set(STAMP_DIR "${RunCMake_TEST_BINARY_DIR}/stamp") |
| 232 |
endif() |
| 233 |
|
| 234 |
set(RunCMake_TEST_NO_CLEAN 1) |
| 235 |
run_cmake_command(CONFIGURE_HANDLED_BY_BUILD-build ${CMAKE_COMMAND} --build . ${BUILD_CONFIG}) |
| 236 |
|
| 237 |
# Calculate timestamps before rebuilding so we can compare before and after in |
| 238 |
# CONFIGURE_HANDLED_BY_BUILD-rebuild-check.cmake |
| 239 |
|
| 240 |
file(TIMESTAMP "${STAMP_DIR}/proj1-configure" PROJ1_CONFIGURE_TIMESTAMP_BEFORE "%s") |
| 241 |
# When BUILD_ALWAYS is set, the build stamp is never created. |
| 242 |
file(TIMESTAMP "${STAMP_DIR}/proj2-configure" PROJ2_CONFIGURE_TIMESTAMP_BEFORE "%s") |
| 243 |
file(TIMESTAMP "${STAMP_DIR}/proj2-build" PROJ2_BUILD_TIMESTAMP_BEFORE "%s") |
| 244 |
|
| 245 |
run_cmake_command(CONFIGURE_HANDLED_BY_BUILD-rebuild ${CMAKE_COMMAND} --build . ${BUILD_CONFIG}) |
| 246 |
endfunction() |
| 247 |
|
| 248 |
__ep_test_CONFIGURE_HANDLED_BY_BUILD() |
| 249 |
|
| 250 |
find_package(Git QUIET) |
| 251 |
if(GIT_EXECUTABLE) |
| 252 |
# Note that there appear to be differences in where git writes its output to |
| 253 |
# on some platforms. It may go to stdout or stderr, so force it to be merged. |
| 254 |
set(RunCMake_TEST_OUTPUT_MERGE TRUE) |
| 255 |
run_cmake(FetchGitRefs) |
| 256 |
unset(RunCMake_TEST_OUTPUT_MERGE) |
| 257 |
|
| 258 |
run_cmake(TLSVersionBadArg) |
| 259 |
run_cmake(TLSVersionBadVar) |
| 260 |
run_cmake(TLSVersionBadEnv) |
| 261 |
endif() |
| 262 |
|
| 263 |
set(RunCMake_TEST_OUTPUT_MERGE 1) |
| 264 |
set(ENV{ConfigVar} "con") |
| 265 |
__ep_test_with_build(EnvVars) |
| 266 |
unset(ENV{ConfigVar}) |
| 267 |
unset(RunCMake_TEST_OUTPUT_MERGE) |
| 268 |
run_cmake(InvalidEnvModification) |