summaryrefslogtreecommitdiffstats
path: root/Tests/TryCompile
diff options
context:
space:
mode:
authorMatthew Woehlke <matthew.woehlke@kitware.com>2022-09-28 17:41:11 (GMT)
committerMatthew Woehlke <matthew.woehlke@kitware.com>2022-09-28 17:41:11 (GMT)
commit09b30515247b95358fa9126ce76e35f2d177c241 (patch)
tree6f629179462e2601bcd80e91ff297ced963f3ddf /Tests/TryCompile
parent164a156c7c26aaf4f30e73ae0cdb6d2e8a10e0a4 (diff)
downloadCMake-09b30515247b95358fa9126ce76e35f2d177c241.zip
CMake-09b30515247b95358fa9126ce76e35f2d177c241.tar.gz
CMake-09b30515247b95358fa9126ce76e35f2d177c241.tar.bz2
try_compile: Add NO_CACHE option (also try_run)
Add NO_CACHE option to try_compile and try_run, which places the results in regular, rather than cache, variables. Issue: #22799
Diffstat (limited to 'Tests/TryCompile')
-rw-r--r--Tests/TryCompile/old_and_new_signature_tests.cmake52
1 files changed, 52 insertions, 0 deletions
diff --git a/Tests/TryCompile/old_and_new_signature_tests.cmake b/Tests/TryCompile/old_and_new_signature_tests.cmake
index 997a5a3..ab548f7 100644
--- a/Tests/TryCompile/old_and_new_signature_tests.cmake
+++ b/Tests/TryCompile/old_and_new_signature_tests.cmake
@@ -140,6 +140,28 @@ if(APPLE)
EXPECT_FAIL(SHOULD_FAIL "${TRY_OUT}")
endif()
+# check that try_compile honors NO_CACHE
+function(try_compile_scope_test)
+ try_compile(
+ CACHED_RESULT
+ ${try_compile_bindir_or_SOURCES}
+ ${TryCompile_SOURCE_DIR}/pass.c)
+ try_compile(
+ SHOULD_NOT_ESCAPE_SCOPE_RESULT
+ ${try_compile_bindir_or_SOURCES}
+ ${TryCompile_SOURCE_DIR}/pass.c
+ NO_CACHE)
+endfunction()
+
+try_compile_scope_test()
+
+if(NOT DEFINED CACHE{CACHED_RESULT})
+ message(SEND_ERROR " Result from try_compile was not cached")
+endif()
+if(DEFINED SHOULD_NOT_ESCAPE_SCOPE_RESULT)
+ message(SEND_ERROR " Result from try_compile(NO_CACHE) leaked")
+endif()
+
######################################
# now test try_run()
@@ -222,3 +244,33 @@ endif()
if(NOT "${RUN_OUTPUT_STDERR}" MATCHES "error")
message(SEND_ERROR " RUN_OUTPUT_STDERR didn't contain \"error\": \"${RUN_OUTPUT_STDERR}\"")
endif()
+
+# check that try_run honors NO_CACHE
+function(try_run_scope_test)
+ try_run(
+ CACHED_RUN_RESULT
+ CACHED_COMPILE_RESULT
+ ${try_compile_bindir_or_SOURCES}
+ ${TryCompile_SOURCE_DIR}/exit_success.c)
+ try_run(
+ SHOULD_NOT_ESCAPE_SCOPE_RUN_RESULT
+ SHOULD_NOT_ESCAPE_SCOPE_COMPILE_RESULT
+ ${try_compile_bindir_or_SOURCES}
+ ${TryCompile_SOURCE_DIR}/exit_success.c
+ NO_CACHE)
+endfunction()
+
+try_run_scope_test()
+
+if(NOT DEFINED CACHE{CACHED_COMPILE_RESULT})
+ message(SEND_ERROR " Compile result from try_run was not cached")
+endif()
+if(NOT DEFINED CACHE{CACHED_RUN_RESULT})
+ message(SEND_ERROR " Run result from try_run was not cached")
+endif()
+if(DEFINED SHOULD_NOT_ESCAPE_SCOPE_COMPILE_RESULT)
+ message(SEND_ERROR " Compile result from try_run(NO_CACHE) leaked")
+endif()
+if(DEFINED SHOULD_NOT_ESCAPE_SCOPE_RUN_RESULT)
+ message(SEND_ERROR " Run result from try_run(NO_CACHE) leaked")
+endif()