From 406a103318ee58774ae7afd25d6746a5629f956a Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 10 May 2023 15:48:27 -0400 Subject: [PATCH] VS: Add support for C++ module internal partitions in VS 17.6 and newer VS 17.6 now implements `ScanSourceforModuleDependencies` using the same `cl /scanDependencies` scanner that our Ninja generator uses. It can distinguish module internal partitions from module interface units based on their content. Switch from `CompileAsCppModule` to `CompileAsCpp` for `CXX_MODULES` sources so that MSBuild can scan and classify them. --- .gitlab/ci/configure_windows_vs2022_x64.cmake | 2 +- Source/cmGlobalVisualStudio10Generator.h | 2 ++ .../cmGlobalVisualStudioVersionedGenerator.cxx | 16 ++++++++++++++++ Source/cmGlobalVisualStudioVersionedGenerator.h | 2 ++ Source/cmVisualStudio10TargetGenerator.cxx | 9 ++++++++- 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/.gitlab/ci/configure_windows_vs2022_x64.cmake b/.gitlab/ci/configure_windows_vs2022_x64.cmake index 1e0f584eef..290d3806ff 100644 --- a/.gitlab/ci/configure_windows_vs2022_x64.cmake +++ b/.gitlab/ci/configure_windows_vs2022_x64.cmake @@ -1,4 +1,4 @@ -set(CMake_TEST_MODULE_COMPILATION "named,partitions" CACHE STRING "") +set(CMake_TEST_MODULE_COMPILATION "named,partitions,internal_partitions" CACHE STRING "") include("${CMAKE_CURRENT_LIST_DIR}/configure_windows_msvc_cxx_modules_common.cmake") include("${CMAKE_CURRENT_LIST_DIR}/configure_windows_vs_common.cmake") diff --git a/Source/cmGlobalVisualStudio10Generator.h b/Source/cmGlobalVisualStudio10Generator.h index 6917ffcc06..38942cb6c2 100644 --- a/Source/cmGlobalVisualStudio10Generator.h +++ b/Source/cmGlobalVisualStudio10Generator.h @@ -149,6 +149,8 @@ public: virtual bool IsUtf8EncodingSupported() const { return false; } + virtual bool IsScanDependenciesSupported() const { return false; } + static std::string GetInstalledNsightTegraVersion(); /** Return the first two components of CMAKE_SYSTEM_VERSION. */ diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.cxx b/Source/cmGlobalVisualStudioVersionedGenerator.cxx index f28419a80c..602b42fbc8 100644 --- a/Source/cmGlobalVisualStudioVersionedGenerator.cxx +++ b/Source/cmGlobalVisualStudioVersionedGenerator.cxx @@ -739,6 +739,22 @@ bool cmGlobalVisualStudioVersionedGenerator::IsUtf8EncodingSupported() const cmSystemTools::VersionCompareGreaterEq(*vsVer, vsVer16_10_P2)); } +bool cmGlobalVisualStudioVersionedGenerator::IsScanDependenciesSupported() + const +{ + // Supported from Visual Studio 17.6 Preview 7. + if (this->Version > cmGlobalVisualStudioGenerator::VSVersion::VS17) { + return true; + } + if (this->Version < cmGlobalVisualStudioGenerator::VSVersion::VS17) { + return false; + } + static std::string const vsVer17_6_P7 = "17.6.33706.43"; + cm::optional vsVer = this->GetVSInstanceVersion(); + return (vsVer && + cmSystemTools::VersionCompareGreaterEq(*vsVer, vsVer17_6_P7)); +} + const char* cmGlobalVisualStudioVersionedGenerator::GetAndroidApplicationTypeRevision() const diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.h b/Source/cmGlobalVisualStudioVersionedGenerator.h index fb4b1d7934..558ea7ca1c 100644 --- a/Source/cmGlobalVisualStudioVersionedGenerator.h +++ b/Source/cmGlobalVisualStudioVersionedGenerator.h @@ -44,6 +44,8 @@ public: bool IsUtf8EncodingSupported() const override; + bool IsScanDependenciesSupported() const override; + const char* GetAndroidApplicationTypeRevision() const override; bool CheckCxxModuleSupport() override diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 7360bf5d75..6d62aff5c1 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -2802,7 +2802,14 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( fs->GetType() == "CXX_MODULE_HEADER_UNITS"_s)) { if (lang == "CXX"_s) { if (fs->GetType() == "CXX_MODULES"_s) { - compileAsPerConfig = "CompileAsCppModule"; + if (shouldScanForModules && + this->GlobalGenerator->IsScanDependenciesSupported()) { + // ScanSourceforModuleDependencies uses 'cl /scanDependencies' and + // can distinguish module interface units and internal partitions. + compileAsPerConfig = "CompileAsCpp"; + } else { + compileAsPerConfig = "CompileAsCppModule"; + } } else { compileAsPerConfig = "CompileAsHeaderUnit"; }