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.
diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx
index 80e5cc3..2309897 100644
--- a/Source/cmCoreTryCompile.cxx
+++ b/Source/cmCoreTryCompile.cxx
@@ -84,7 +84,6 @@
   "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 @@
     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 d074b99..ae1cba4 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -3348,12 +3348,12 @@
   // 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<cmDiagnosticCategory>(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 2c6b62f..76948bd 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 dfcb5f9..527c8f8 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 @@
 
 # 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 3c684d2..07bf099 100644
--- a/Tests/RunCMake/try_compile/RunCMakeTest.cmake
+++ b/Tests/RunCMake/try_compile/RunCMakeTest.cmake
@@ -52,7 +52,7 @@
 
 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