Browse Source

Merge topic 'cxxmodules-try_compile'

fd81024e80 cxxmodules: Honor CMAKE_CXX_SCAN_FOR_MODULES in try_compile

Acked-by: Kitware Robot <[email protected]>
Acked-by: buildbot <[email protected]>
Reviewed-by: Ben Boeckel <[email protected]>
Merge-request: !8865
Brad King 2 years ago
parent
commit
b232269c4f

+ 2 - 0
Source/cmCoreTryCompile.cxx

@@ -72,6 +72,7 @@ SETUP_LANGUAGE(swift_properties, Swift);
 
 std::string const kCMAKE_CUDA_ARCHITECTURES = "CMAKE_CUDA_ARCHITECTURES";
 std::string const kCMAKE_CUDA_RUNTIME_LIBRARY = "CMAKE_CUDA_RUNTIME_LIBRARY";
+std::string const kCMAKE_CXX_SCAN_FOR_MODULES = "CMAKE_CXX_SCAN_FOR_MODULES";
 std::string const kCMAKE_ENABLE_EXPORTS = "CMAKE_ENABLE_EXPORTS";
 std::string const kCMAKE_EXECUTABLE_ENABLE_EXPORTS =
   "CMAKE_EXECUTABLE_ENABLE_EXPORTS";
@@ -1082,6 +1083,7 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
                 &swift_properties[lang_property_start + lang_property_size]);
     vars.insert(kCMAKE_CUDA_ARCHITECTURES);
     vars.insert(kCMAKE_CUDA_RUNTIME_LIBRARY);
+    vars.insert(kCMAKE_CXX_SCAN_FOR_MODULES);
     vars.insert(kCMAKE_ENABLE_EXPORTS);
     vars.insert(kCMAKE_EXECUTABLE_ENABLE_EXPORTS);
     vars.insert(kCMAKE_SHARED_LIBRARY_ENABLE_EXPORTS);

+ 21 - 0
Tests/RunCMake/CXXModules/NoScanningVariable.cmake

@@ -0,0 +1,21 @@
+# Enable scanning by default for targets that explicitly use C++ 20.
+cmake_policy(SET CMP0155 NEW)
+
+enable_language(CXX)
+
+# Hide any real scanning rule that may be available.
+unset(CMAKE_CXX_SCANDEP_SOURCE)
+
+# Explicitly enable C++20 for all targets.
+set(CMAKE_CXX_STANDARD 20)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+
+# Explicitly suppress scanning so that support is not required.
+set(CMAKE_CXX_SCAN_FOR_MODULES OFF)
+
+add_executable(noscanning-variable main-no-use.cxx)
+
+# Verify that CMAKE_CXX_SCAN_FOR_MODULES is propagated into the check.
+# FIXME: Unset CMAKE_CXX_SCANDEP_SOURCE inside try_compile so this
+# test can verify behavior on newer compilers too.
+try_compile(result SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/main-no-use.cxx)

+ 1 - 0
Tests/RunCMake/CXXModules/RunCMakeTest.cmake

@@ -20,6 +20,7 @@ if ("cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
 
   run_cmake(NoScanningSourceFileProperty)
   run_cmake(NoScanningTargetProperty)
+  run_cmake(NoScanningVariable)
   run_cmake(CMP0155-OLD)
   run_cmake(CMP0155-NEW)
 endif ()

+ 4 - 0
Tests/RunCMake/CXXModules/main-no-use.cxx

@@ -0,0 +1,4 @@
+int main()
+{
+  return 0;
+}