Browse Source

Merge topic 'vs-scan-for-modules'

405dc7d19c Tests/CXXModules/scan_properties: use `ixx` extension
029ddc3410 cmVisualStudio10TargetGenerator: always specify scanning
6c9614cbf4 Tests/CXXModules: add a test case for VS generation without flags
34f4423851 cmVisualStudio10TargetGenerator: fix typo in flag name

Acked-by: Kitware Robot <[email protected]>
Merge-request: !9104
Brad King 1 year ago
parent
commit
899a1f64af

+ 6 - 5
Source/cmVisualStudio10TargetGenerator.cxx

@@ -2784,7 +2784,7 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
           isCppModule = true;
           if (shouldScanForModules &&
               this->GlobalGenerator->IsScanDependenciesSupported()) {
-            // ScanSourceforModuleDependencies uses 'cl /scanDependencies' and
+            // ScanSourceForModuleDependencies uses 'cl /scanDependencies' and
             // can distinguish module interface units and internal partitions.
             compileAsPerConfig = "CompileAsCpp";
           } else {
@@ -2827,7 +2827,7 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
     // use them
     if (!flags.empty() || !options.empty() || !configDefines.empty() ||
         !includes.empty() || compileAsPerConfig || noWinRT ||
-        !options.empty() || needsPCHFlags) {
+        !options.empty() || needsPCHFlags || shouldScanForModules) {
       cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
       cmIDEFlagTable const* flagtable = nullptr;
       const std::string& srclang = source->GetLanguage();
@@ -2856,9 +2856,7 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
         clOptions.AddFlag("CompileAs", compileAsPerConfig);
       }
       if (shouldScanForModules) {
-        clOptions.AddFlag("ScanSourceforModuleDependencies", "true");
-      } else {
-        clOptions.AddFlag("ScanSourceforModuleDependencies", "false");
+        clOptions.AddFlag("ScanSourceForModuleDependencies", "true");
       }
       if (noWinRT) {
         clOptions.AddFlag("CompileAsWinRT", "false");
@@ -3574,6 +3572,9 @@ void cmVisualStudio10TargetGenerator::WriteClOptions(
       e2.Element("AdditionalUsingDirectories", dirs);
     }
   }
+
+  // Disable C++ source scanning by default.
+  e2.Element("ScanSourceForModuleDependencies", "false");
 }
 
 bool cmVisualStudio10TargetGenerator::ComputeRcOptions()

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

@@ -170,6 +170,7 @@ run_cxx_module_test(scan-with-pch)
 # Tests which use named modules.
 if ("named" IN_LIST CMake_TEST_MODULE_COMPILATION)
   run_cxx_module_test(simple)
+  run_cxx_module_test(vs-without-flags)
   run_cxx_module_test(library library-static -DBUILD_SHARED_LIBS=OFF)
   run_cxx_module_test(unity-build)
   run_cxx_module_test(object-library)

+ 5 - 3
Tests/RunCMake/CXXModules/examples/scan_properties/CMakeLists.txt

@@ -18,8 +18,10 @@ string(REPLACE "<DEFINES>" "<DEFINES> -DCMAKE_SCANNED_THIS_SOURCE"
 
 set_property(SOURCE always_scan.cxx
   PROPERTY CXX_SCAN_FOR_MODULES 1)
-set_property(SOURCE never_scan.cxx
+set_property(SOURCE never_scan.ixx
   PROPERTY CXX_SCAN_FOR_MODULES 0)
+set_property(SOURCE never_scan.ixx
+  PROPERTY LANGUAGE CXX)
 
 add_executable(scans_everything)
 target_sources(scans_everything
@@ -27,7 +29,7 @@ target_sources(scans_everything
     main.cxx
     join.cxx
     always_scan.cxx
-    never_scan.cxx
+    never_scan.ixx
   PRIVATE
     FILE_SET CXX_MODULES
       BASE_DIRS
@@ -46,7 +48,7 @@ target_sources(no_scan_everything
     main.cxx
     join.cxx
     always_scan.cxx
-    never_scan.cxx
+    never_scan.ixx
   PRIVATE
     FILE_SET CXX_MODULES
       BASE_DIRS

+ 0 - 0
Tests/RunCMake/CXXModules/examples/scan_properties/never_scan.cxx → Tests/RunCMake/CXXModules/examples/scan_properties/never_scan.ixx


+ 22 - 0
Tests/RunCMake/CXXModules/examples/vs-without-flags/CMakeLists.txt

@@ -0,0 +1,22 @@
+cmake_minimum_required(VERSION 3.28)
+project(cxx_modules_vs_without_flags CXX)
+
+include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")
+
+set(CMAKE_CXX_STANDARD 23)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(CMAKE_CXX_EXTENSIONS OFF)
+set(CMAKE_CXX_SCAN_FOR_MODULES ON)
+
+add_executable(vs_without_flags)
+target_sources(vs_without_flags
+  PRIVATE
+    main.cxx
+  PRIVATE
+    FILE_SET CXX_MODULES
+      BASE_DIRS
+        "${CMAKE_CURRENT_SOURCE_DIR}"
+      FILES
+        module.cxx)
+
+add_test(NAME vs_without_flags COMMAND vs_without_flags)

+ 6 - 0
Tests/RunCMake/CXXModules/examples/vs-without-flags/main.cxx

@@ -0,0 +1,6 @@
+import mod;
+
+int main(int argc, char* argv[])
+{
+  return f();
+}

+ 6 - 0
Tests/RunCMake/CXXModules/examples/vs-without-flags/module.cxx

@@ -0,0 +1,6 @@
+export module mod;
+
+export int f()
+{
+  return 0;
+}