From 34f4423851a09aeccab8ca6e135c31de4bf149e0 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Tue, 26 Dec 2023 11:42:42 -0500 Subject: cmVisualStudio10TargetGenerator: fix typo in flag name It is case insensitive, so this only matches the official flag name and still works. --- Source/cmVisualStudio10TargetGenerator.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 4860d9a..e0be04d 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/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 { @@ -2856,9 +2856,9 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( clOptions.AddFlag("CompileAs", compileAsPerConfig); } if (shouldScanForModules) { - clOptions.AddFlag("ScanSourceforModuleDependencies", "true"); + clOptions.AddFlag("ScanSourceForModuleDependencies", "true"); } else { - clOptions.AddFlag("ScanSourceforModuleDependencies", "false"); + clOptions.AddFlag("ScanSourceForModuleDependencies", "false"); } if (noWinRT) { clOptions.AddFlag("CompileAsWinRT", "false"); -- cgit v0.12 From 6c9614cbf4538924367ffd422f69e7ad086543d2 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Tue, 26 Dec 2023 11:50:33 -0500 Subject: Tests/CXXModules: add a test case for VS generation without flags Previously, the `ScanSourceForModuleDependencies` flag was not added to the VS project if "nothing" prompted custom flags. See: #25519 --- Tests/RunCMake/CXXModules/RunCMakeTest.cmake | 1 + .../examples/vs-without-flags/CMakeLists.txt | 22 ++++++++++++++++++++++ .../CXXModules/examples/vs-without-flags/main.cxx | 6 ++++++ .../examples/vs-without-flags/module.cxx | 6 ++++++ 4 files changed, 35 insertions(+) create mode 100644 Tests/RunCMake/CXXModules/examples/vs-without-flags/CMakeLists.txt create mode 100644 Tests/RunCMake/CXXModules/examples/vs-without-flags/main.cxx create mode 100644 Tests/RunCMake/CXXModules/examples/vs-without-flags/module.cxx diff --git a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake index fcfa60a..514e0f3 100644 --- a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake +++ b/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(object-library) run_cxx_module_test(generated) diff --git a/Tests/RunCMake/CXXModules/examples/vs-without-flags/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/vs-without-flags/CMakeLists.txt new file mode 100644 index 0000000..0d18a66 --- /dev/null +++ b/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) diff --git a/Tests/RunCMake/CXXModules/examples/vs-without-flags/main.cxx b/Tests/RunCMake/CXXModules/examples/vs-without-flags/main.cxx new file mode 100644 index 0000000..239ab00 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/vs-without-flags/main.cxx @@ -0,0 +1,6 @@ +import mod; + +int main(int argc, char* argv[]) +{ + return f(); +} diff --git a/Tests/RunCMake/CXXModules/examples/vs-without-flags/module.cxx b/Tests/RunCMake/CXXModules/examples/vs-without-flags/module.cxx new file mode 100644 index 0000000..27a61a6 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/vs-without-flags/module.cxx @@ -0,0 +1,6 @@ +export module mod; + +export int f() +{ + return 0; +} -- cgit v0.12 From 029ddc341055b6eeee0c90ed843cf4b56e10a0e9 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Tue, 26 Dec 2023 11:43:03 -0500 Subject: cmVisualStudio10TargetGenerator: always specify scanning Set that sources should not be scanned on a target-wide basis and then enable on a per-TU basis as needed. Fixes: #25519 --- Source/cmVisualStudio10TargetGenerator.cxx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index e0be04d..708cbaf 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -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(); @@ -2857,8 +2857,6 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( } if (shouldScanForModules) { clOptions.AddFlag("ScanSourceForModuleDependencies", "true"); - } else { - clOptions.AddFlag("ScanSourceForModuleDependencies", "false"); } if (noWinRT) { clOptions.AddFlag("CompileAsWinRT", "false"); @@ -3564,6 +3562,9 @@ void cmVisualStudio10TargetGenerator::WriteClOptions( e2.Element("AdditionalUsingDirectories", dirs); } } + + // Disable C++ source scanning by default. + e2.Element("ScanSourceForModuleDependencies", "false"); } bool cmVisualStudio10TargetGenerator::ComputeRcOptions() -- cgit v0.12 From 405dc7d19c4e71cf3ac7e4daa93016d2b4665d3c Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 6 Jan 2024 15:46:25 -0500 Subject: Tests/CXXModules/scan_properties: use `ixx` extension This ensures that Visual Studio is told not to scan this explicitly. --- .../CXXModules/examples/scan_properties/CMakeLists.txt | 8 +++++--- .../CXXModules/examples/scan_properties/never_scan.cxx | 10 ---------- .../CXXModules/examples/scan_properties/never_scan.ixx | 10 ++++++++++ 3 files changed, 15 insertions(+), 13 deletions(-) delete mode 100644 Tests/RunCMake/CXXModules/examples/scan_properties/never_scan.cxx create mode 100644 Tests/RunCMake/CXXModules/examples/scan_properties/never_scan.ixx diff --git a/Tests/RunCMake/CXXModules/examples/scan_properties/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/scan_properties/CMakeLists.txt index 47be1d9..110e411 100644 --- a/Tests/RunCMake/CXXModules/examples/scan_properties/CMakeLists.txt +++ b/Tests/RunCMake/CXXModules/examples/scan_properties/CMakeLists.txt @@ -18,8 +18,10 @@ string(REPLACE "" " -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 diff --git a/Tests/RunCMake/CXXModules/examples/scan_properties/never_scan.cxx b/Tests/RunCMake/CXXModules/examples/scan_properties/never_scan.cxx deleted file mode 100644 index b47510b..0000000 --- a/Tests/RunCMake/CXXModules/examples/scan_properties/never_scan.cxx +++ /dev/null @@ -1,10 +0,0 @@ -#if SCANNING_CONTROL -# ifdef CMAKE_SCANNED_THIS_SOURCE -# error "This file should not have been scanned" -# endif -#endif - -int never_scan() -{ - return 0; -} diff --git a/Tests/RunCMake/CXXModules/examples/scan_properties/never_scan.ixx b/Tests/RunCMake/CXXModules/examples/scan_properties/never_scan.ixx new file mode 100644 index 0000000..b47510b --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/scan_properties/never_scan.ixx @@ -0,0 +1,10 @@ +#if SCANNING_CONTROL +# ifdef CMAKE_SCANNED_THIS_SOURCE +# error "This file should not have been scanned" +# endif +#endif + +int never_scan() +{ + return 0; +} -- cgit v0.12