From 2c75267803b3c72f2275707bcb269c03c0f1d2f8 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 8 Apr 2026 16:19:25 -0400 Subject: [PATCH] Modules/CMakeTest*Compiler: use `try_compile(NO_CACHE)` Instead of manually doing the cache dance manually, just skip the cache in the first place. --- Modules/CMakeTestCCompiler.cmake | 4 +--- Modules/CMakeTestCSharpCompiler.cmake | 4 +--- Modules/CMakeTestCUDACompiler.cmake | 4 +--- Modules/CMakeTestCXXCompiler.cmake | 4 +--- Modules/CMakeTestFortranCompiler.cmake | 4 +--- Modules/CMakeTestHIPCompiler.cmake | 4 +--- Modules/CMakeTestOBJCCompiler.cmake | 4 +--- Modules/CMakeTestOBJCXXCompiler.cmake | 4 +--- Modules/CMakeTestSwiftCompiler.cmake | 4 +--- 9 files changed, 9 insertions(+), 27 deletions(-) diff --git a/Modules/CMakeTestCCompiler.cmake b/Modules/CMakeTestCCompiler.cmake index d32fb6c29e..62225c6cdc 100644 --- a/Modules/CMakeTestCCompiler.cmake +++ b/Modules/CMakeTestCCompiler.cmake @@ -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") diff --git a/Modules/CMakeTestCSharpCompiler.cmake b/Modules/CMakeTestCSharpCompiler.cmake index d34ae92aff..30b0faf0fe 100644 --- a/Modules/CMakeTestCSharpCompiler.cmake +++ b/Modules/CMakeTestCSharpCompiler.cmake @@ -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() diff --git a/Modules/CMakeTestCUDACompiler.cmake b/Modules/CMakeTestCUDACompiler.cmake index fbeadf7f9b..32c9144b8a 100644 --- a/Modules/CMakeTestCUDACompiler.cmake +++ b/Modules/CMakeTestCUDACompiler.cmake @@ -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}") diff --git a/Modules/CMakeTestCXXCompiler.cmake b/Modules/CMakeTestCXXCompiler.cmake index 5c3542666f..c005011a5b 100644 --- a/Modules/CMakeTestCXXCompiler.cmake +++ b/Modules/CMakeTestCXXCompiler.cmake @@ -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") diff --git a/Modules/CMakeTestFortranCompiler.cmake b/Modules/CMakeTestFortranCompiler.cmake index bf4100ed38..04c790b3a8 100644 --- a/Modules/CMakeTestFortranCompiler.cmake +++ b/Modules/CMakeTestFortranCompiler.cmake @@ -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}") diff --git a/Modules/CMakeTestHIPCompiler.cmake b/Modules/CMakeTestHIPCompiler.cmake index ed1df10656..57994b9729 100644 --- a/Modules/CMakeTestHIPCompiler.cmake +++ b/Modules/CMakeTestHIPCompiler.cmake @@ -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") diff --git a/Modules/CMakeTestOBJCCompiler.cmake b/Modules/CMakeTestOBJCCompiler.cmake index 800341586b..056c4ee0e5 100644 --- a/Modules/CMakeTestOBJCCompiler.cmake +++ b/Modules/CMakeTestOBJCCompiler.cmake @@ -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") diff --git a/Modules/CMakeTestOBJCXXCompiler.cmake b/Modules/CMakeTestOBJCXXCompiler.cmake index 1b4bf60cb4..dbdd2ba416 100644 --- a/Modules/CMakeTestOBJCXXCompiler.cmake +++ b/Modules/CMakeTestOBJCXXCompiler.cmake @@ -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") diff --git a/Modules/CMakeTestSwiftCompiler.cmake b/Modules/CMakeTestSwiftCompiler.cmake index 0abaabe169..64751eb854 100644 --- a/Modules/CMakeTestSwiftCompiler.cmake +++ b/Modules/CMakeTestSwiftCompiler.cmake @@ -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()