Modules/CMakeTest*Compiler: use try_compile(NO_CACHE)

Instead of manually doing the cache dance manually, just skip the cache
in the first place.
This commit is contained in:
Ben Boeckel
2026-04-08 16:19:25 -04:00
parent 3e3db36520
commit 2c75267803
9 changed files with 9 additions and 27 deletions
+1 -3
View File
@@ -55,11 +55,9 @@ if(NOT CMAKE_C_COMPILER_WORKS)
# Puts test result in cache variable.
try_compile(CMAKE_C_COMPILER_WORKS
SOURCE_FROM_VAR testCCompiler.c __TestCompiler_testCCompilerSource
NO_CACHE
OUTPUT_VARIABLE __CMAKE_C_COMPILER_OUTPUT)
unset(__TestCompiler_testCCompilerSource)
# Move result from cache to normal variable.
set(CMAKE_C_COMPILER_WORKS ${CMAKE_C_COMPILER_WORKS})
unset(CMAKE_C_COMPILER_WORKS CACHE)
__TestCompiler_restoreTryCompileTargetType()
if(NOT CMAKE_C_COMPILER_WORKS)
PrintTestCompilerResult(CHECK_FAIL "broken")
+1 -3
View File
@@ -33,12 +33,10 @@ if(NOT CMAKE_CSharp_COMPILER_WORKS)
# Puts test result in cache variable.
try_compile(CMAKE_CSharp_COMPILER_WORKS
SOURCE_FROM_VAR testCSharpCompiler.cs __TestCompiler_testCSharpCompilerSource
NO_CACHE
OUTPUT_VARIABLE __CMAKE_CSharp_COMPILER_OUTPUT
)
unset(__TestCompiler_testCSharpCompilerSource)
# Move result from cache to normal variable.
set(CMAKE_CSharp_COMPILER_WORKS ${CMAKE_CSharp_COMPILER_WORKS})
unset(CMAKE_CSharp_COMPILER_WORKS CACHE)
set(CSharp_TEST_WAS_RUN 1)
endif()
+1 -3
View File
@@ -47,12 +47,10 @@ if(NOT CMAKE_CUDA_COMPILER_WORKS)
# Puts test result in cache variable.
try_compile(CMAKE_CUDA_COMPILER_WORKS
SOURCE_FROM_VAR main.cu __TestCompiler_testCudaCompilerSource
NO_CACHE
OUTPUT_VARIABLE __CMAKE_CUDA_COMPILER_OUTPUT)
unset(__TestCompiler_testCudaCompilerSource)
# Move result from cache to normal variable.
set(CMAKE_CUDA_COMPILER_WORKS ${CMAKE_CUDA_COMPILER_WORKS})
unset(CMAKE_CUDA_COMPILER_WORKS CACHE)
if(NOT CMAKE_CUDA_COMPILER_WORKS)
PrintTestCompilerResult(CHECK_FAIL "broken")
string(REPLACE "\n" "\n " _output "${__CMAKE_CUDA_COMPILER_OUTPUT}")
+1 -3
View File
@@ -55,6 +55,7 @@ if(NOT CMAKE_CXX_COMPILER_WORKS)
# Puts test result in cache variable.
try_compile(CMAKE_CXX_COMPILER_WORKS
SOURCE_FROM_VAR testCXXCompiler.cxx __TestCompiler_testCXXCompilerSource
NO_CACHE
OUTPUT_VARIABLE __CMAKE_CXX_COMPILER_OUTPUT)
if(DEFINED __CMAKE_SAVED_CXX_SCAN_FOR_MODULES)
set(CMAKE_CXX_SCAN_FOR_MODULES "${__CMAKE_SAVED_CXX_SCAN_FOR_MODULES}")
@@ -63,9 +64,6 @@ if(NOT CMAKE_CXX_COMPILER_WORKS)
unset(CMAKE_CXX_SCAN_FOR_MODULES)
endif()
unset(__TestCompiler_testCXXCompilerSource)
# Move result from cache to normal variable.
set(CMAKE_CXX_COMPILER_WORKS ${CMAKE_CXX_COMPILER_WORKS})
unset(CMAKE_CXX_COMPILER_WORKS CACHE)
__TestCompiler_restoreTryCompileTargetType()
if(NOT CMAKE_CXX_COMPILER_WORKS)
PrintTestCompilerResult(CHECK_FAIL "broken")
+1 -3
View File
@@ -48,11 +48,9 @@ if(NOT CMAKE_Fortran_COMPILER_WORKS)
# Puts test result in cache variable.
try_compile(CMAKE_Fortran_COMPILER_WORKS
SOURCE_FROM_VAR testFortranCompiler.f __TestCompiler_testFortranCompilerSource
NO_CACHE
OUTPUT_VARIABLE OUTPUT)
unset(__TestCompiler_testFortranCompilerSource)
# Move result from cache to normal variable.
set(CMAKE_Fortran_COMPILER_WORKS ${CMAKE_Fortran_COMPILER_WORKS})
unset(CMAKE_Fortran_COMPILER_WORKS CACHE)
if(NOT CMAKE_Fortran_COMPILER_WORKS)
PrintTestCompilerResult(CHECK_FAIL "broken")
string(REPLACE "\n" "\n " _output "${OUTPUT}")
+1 -3
View File
@@ -61,11 +61,9 @@ if(NOT CMAKE_HIP_COMPILER_WORKS)
# Puts test result in cache variable.
try_compile(CMAKE_HIP_COMPILER_WORKS
SOURCE_FROM_VAR testHIPCompiler.hip __TestCompiler_testHIPCompilerSource
NO_CACHE
OUTPUT_VARIABLE __CMAKE_HIP_COMPILER_OUTPUT)
unset(__TestCompiler_testHIPCompilerSource)
# Move result from cache to normal variable.
set(CMAKE_HIP_COMPILER_WORKS ${CMAKE_HIP_COMPILER_WORKS})
unset(CMAKE_HIP_COMPILER_WORKS CACHE)
__TestCompiler_restoreTryCompileTargetType()
if(NOT CMAKE_HIP_COMPILER_WORKS)
PrintTestCompilerResult(CHECK_FAIL "broken")
+1 -3
View File
@@ -52,11 +52,9 @@ if(NOT CMAKE_OBJC_COMPILER_WORKS)
# Puts test result in cache variable.
try_compile(CMAKE_OBJC_COMPILER_WORKS
SOURCE_FROM_VAR testObjCCompiler.m __TestCompiler_testObjCCompilerSource
NO_CACHE
OUTPUT_VARIABLE __CMAKE_OBJC_COMPILER_OUTPUT)
unset(__TestCompiler_testObjCCompilerSource)
# Move result from cache to normal variable.
set(CMAKE_OBJC_COMPILER_WORKS ${CMAKE_OBJC_COMPILER_WORKS})
unset(CMAKE_OBJC_COMPILER_WORKS CACHE)
__TestCompiler_restoreTryCompileTargetType()
if(NOT CMAKE_OBJC_COMPILER_WORKS)
PrintTestCompilerResult(CHECK_FAIL "broken")
+1 -3
View File
@@ -51,11 +51,9 @@ if(NOT CMAKE_OBJCXX_COMPILER_WORKS)
# Puts test result in cache variable.
try_compile(CMAKE_OBJCXX_COMPILER_WORKS
SOURCE_FROM_VAR testObjCXXCompiler.mm __TestCompiler_testObjCXXCompilerSource
NO_CACHE
OUTPUT_VARIABLE __CMAKE_OBJCXX_COMPILER_OUTPUT)
unset(__TestCompiler_testObjCXXCompilerSource)
# Move result from cache to normal variable.
set(CMAKE_OBJCXX_COMPILER_WORKS ${CMAKE_OBJCXX_COMPILER_WORKS})
unset(CMAKE_OBJCXX_COMPILER_WORKS CACHE)
__TestCompiler_restoreTryCompileTargetType()
if(NOT CMAKE_OBJCXX_COMPILER_WORKS)
PrintTestCompilerResult(CHECK_FAIL "broken")
+1 -3
View File
@@ -30,10 +30,8 @@ if(NOT CMAKE_Swift_COMPILER_WORKS)
"}")
try_compile(CMAKE_Swift_COMPILER_WORKS
SOURCE_FROM_VAR main.swift __CMAKE_Swift_TEST_SOURCE
NO_CACHE
OUTPUT_VARIABLE __CMAKE_Swift_COMPILER_OUTPUT)
# Move result from cache to normal variable.
set(CMAKE_Swift_COMPILER_WORKS ${CMAKE_Swift_COMPILER_WORKS})
unset(CMAKE_Swift_COMPILER_WORKS CACHE)
set(Swift_TEST_WAS_RUN 1)
endif()