From daec98ba6155c55e267409cba464fb53a3adaaa6 Mon Sep 17 00:00:00 2001 From: Matthew Woehlke Date: Thu, 12 Mar 2026 16:19:18 -0400 Subject: [PATCH] Diagnostics: Fix passing diagnostic state to try_compile Do not propagate deprecated diagnostic variables to try_compile. Instead, if any diagnostic is ignored in the calling instance, also ignore it in the try_compile instance. --- Source/cmCoreTryCompile.cxx | 2 -- Source/cmMakefile.cxx | 12 ++++++------ ...cated-stderr.txt => CudaArchitectures-stderr.txt} | 4 ++-- ...{WarnDeprecated.cmake => CudaArchitectures.cmake} | 4 ++-- Tests/RunCMake/try_compile/RunCMakeTest.cmake | 2 +- 5 files changed, 11 insertions(+), 13 deletions(-) rename Tests/RunCMake/try_compile/{WarnDeprecated-stderr.txt => CudaArchitectures-stderr.txt} (67%) rename Tests/RunCMake/try_compile/{WarnDeprecated.cmake => CudaArchitectures.cmake} (79%) diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index 80e5cc3deb..23098979c4 100644 --- a/Source/cmCoreTryCompile.cxx +++ b/Source/cmCoreTryCompile.cxx @@ -84,7 +84,6 @@ std::string const kCMAKE_TRY_COMPILE_OSX_ARCHITECTURES = "CMAKE_TRY_COMPILE_OSX_ARCHITECTURES"; std::string const kCMAKE_TRY_COMPILE_PLATFORM_VARIABLES = "CMAKE_TRY_COMPILE_PLATFORM_VARIABLES"; -std::string const kCMAKE_WARN_DEPRECATED = "CMAKE_WARN_DEPRECATED"; std::string const kCMAKE_WATCOM_RUNTIME_LIBRARY_DEFAULT = "CMAKE_WATCOM_RUNTIME_LIBRARY_DEFAULT"; std::string const kCMAKE_MSVC_DEBUG_INFORMATION_FORMAT_DEFAULT = @@ -1136,7 +1135,6 @@ cm::optional cmCoreTryCompile::TryCompileCode( vars.insert(kCMAKE_SYSROOT); vars.insert(kCMAKE_SYSROOT_COMPILE); vars.insert(kCMAKE_SYSROOT_LINK); - vars.insert(kCMAKE_WARN_DEPRECATED); vars.emplace("CMAKE_MSVC_RUNTIME_LIBRARY"_s); vars.emplace("CMAKE_WATCOM_RUNTIME_LIBRARY"_s); vars.emplace("CMAKE_MSVC_DEBUG_INFORMATION_FORMAT"_s); diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index d074b99afd..ae1cba4312 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -3348,12 +3348,12 @@ int cmMakefile::TryCompile(std::string const& srcdir, // to save time we pass the EnableLanguage info directly cm.GetGlobalGenerator()->EnableLanguagesFromGenerator( this->GetGlobalGenerator(), this); - if (this->IsOn("CMAKE_SUPPRESS_DEVELOPER_WARNINGS")) { - cm.AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", "TRUE", "", - cmStateEnums::INTERNAL); - } else { - cm.AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", "FALSE", "", - cmStateEnums::INTERNAL); + for (unsigned dc = 1; dc < cmDiagnostics::CategoryCount; ++dc) { + auto const category = static_cast(dc); + if (this->GetDiagnosticAction(category) == cmDiagnostics::Ignore) { + cm.GetCurrentSnapshot().SetDiagnostic(category, cmDiagnostics::Ignore, + false); + } } if (cm.Configure() != 0) { this->IssueMessage(MessageType::FATAL_ERROR, diff --git a/Tests/RunCMake/try_compile/WarnDeprecated-stderr.txt b/Tests/RunCMake/try_compile/CudaArchitectures-stderr.txt similarity index 67% rename from Tests/RunCMake/try_compile/WarnDeprecated-stderr.txt rename to Tests/RunCMake/try_compile/CudaArchitectures-stderr.txt index 2c6b62fe2e..76948bd2e4 100644 --- a/Tests/RunCMake/try_compile/WarnDeprecated-stderr.txt +++ b/Tests/RunCMake/try_compile/CudaArchitectures-stderr.txt @@ -3,9 +3,9 @@ Executing try_compile \(CMAKE_C_ABI_COMPILED\) in: [^ -]*/Tests/RunCMake/try_compile/WarnDeprecated-build/CMakeFiles/CMakeScratch/TryCompile-[^/]+ +]*/Tests/RunCMake/try_compile/CudaArchitectures-build/CMakeFiles/CMakeScratch/TryCompile-[^/]+ Call Stack \(most recent call first\): [^ ]*/Modules/CMakeTestCCompiler\.cmake:[0-9]+ \(CMAKE_DETERMINE_COMPILER_ABI\) - WarnDeprecated\.cmake:[0-9]+ \(enable_language\) + CudaArchitectures\.cmake:[0-9]+ \(enable_language\) CMakeLists\.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/try_compile/WarnDeprecated.cmake b/Tests/RunCMake/try_compile/CudaArchitectures.cmake similarity index 79% rename from Tests/RunCMake/try_compile/WarnDeprecated.cmake rename to Tests/RunCMake/try_compile/CudaArchitectures.cmake index dfcb5f903b..527c8f80e4 100644 --- a/Tests/RunCMake/try_compile/WarnDeprecated.cmake +++ b/Tests/RunCMake/try_compile/CudaArchitectures.cmake @@ -1,6 +1,6 @@ enable_language(C) -set(CMAKE_WARN_DEPRECATED SOME_VALUE) +set(CMAKE_CUDA_ARCHITECTURES SOME_VALUE) try_compile(result ${CMAKE_CURRENT_BINARY_DIR} SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src.c @@ -12,7 +12,7 @@ endif() # Check that the cache was populated with our custom variable. file(STRINGS ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/CMakeCache.txt entries - REGEX CMAKE_WARN_DEPRECATED:UNINITIALIZED=${CMAKE_WARN_DEPRECATED} + REGEX CMAKE_CUDA_ARCHITECTURES:UNINITIALIZED=${CMAKE_CUDA_ARCHITECTURES} ) if(NOT entries) message(FATAL_ERROR "try_compile did not populate cache as expected") diff --git a/Tests/RunCMake/try_compile/RunCMakeTest.cmake b/Tests/RunCMake/try_compile/RunCMakeTest.cmake index 3c684d2768..07bf0990f2 100644 --- a/Tests/RunCMake/try_compile/RunCMakeTest.cmake +++ b/Tests/RunCMake/try_compile/RunCMakeTest.cmake @@ -52,7 +52,7 @@ run_cmake(ProjectVars) set(RunCMake_TEST_OPTIONS --debug-trycompile) run_cmake(PlatformVariables) -run_cmake(WarnDeprecated) +run_cmake(CudaArchitectures) unset(RunCMake_TEST_OPTIONS) if (CMAKE_SYSTEM_NAME MATCHES "^(Linux|Darwin|Windows)$" AND