From 027b962a810d7b808c2107b574c57019d4c33be9 Mon Sep 17 00:00:00 2001 From: Tyler Yankee Date: Mon, 20 Jul 2026 09:52:06 -0400 Subject: [PATCH] VS: Avoid unsupported ScanSourceForModuleDependencies under ClangCl As of commit ed48feeae8 (clang-cl: Add support for C++ modules, 2026-03-27, v4.4.0-rc1~428^2) CMake tries to support modules for clang-cl, which can mostly be accomplished, except for the ClangCl VS toolset, where the /scanDependencies flag is not yet supported. Amend commit 3022f0363f (VS: set ScanSourceForModuleDependencies at vcxproj level, 2024-04-27, v3.28.5~3^2) to only emit this setting when scanning is supported by the toolchain. Fixes: #27957 Issue: #27977 --- Help/manual/cmake-cxxmodules.7.rst | 4 +++- Help/release/4.4.rst | 4 +++- Source/cmGlobalVisualStudio10Generator.cxx | 10 ++++++++++ Source/cmGlobalVisualStudio10Generator.h | 3 +++ Source/cmGlobalVisualStudioVersionedGenerator.cxx | 6 ++++++ Source/cmVisualStudio10TargetGenerator.cxx | 13 ++++++++----- 6 files changed, 33 insertions(+), 7 deletions(-) diff --git a/Help/manual/cmake-cxxmodules.7.rst b/Help/manual/cmake-cxxmodules.7.rst index 013880bb66..fe150400ce 100644 --- a/Help/manual/cmake-cxxmodules.7.rst +++ b/Help/manual/cmake-cxxmodules.7.rst @@ -77,7 +77,9 @@ modules includes: .. versionadded:: 4.4 - ``clang-cl`` version 19.1 and newer + ``clang-cl`` version 19.1 and newer, except with the + :ref:`Visual Studio Generators` (i.e., the ``ClangCl`` + :variable:`toolset `). * GCC 14 and newer diff --git a/Help/release/4.4.rst b/Help/release/4.4.rst index 38ac7798c7..e49729a0d7 100644 --- a/Help/release/4.4.rst +++ b/Help/release/4.4.rst @@ -111,7 +111,9 @@ Languages Compilers --------- -* C++ 20 named modules are now supported with ``clang-cl``. +* C++ 20 named modules are now supported with ``clang-cl``, except with the + :ref:`Visual Studio Generators` (i.e., the ``ClangCl`` + :variable:`toolset `). See :manual:`cmake-cxxmodules(7)`. * The ``ibm-flang`` compiler is now supported with diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx index cbc6ddea52..5580bd8f24 100644 --- a/Source/cmGlobalVisualStudio10Generator.cxx +++ b/Source/cmGlobalVisualStudio10Generator.cxx @@ -742,6 +742,16 @@ std::string const& cmGlobalVisualStudio10Generator::GetPlatformToolsetString() return empty; } +bool cmGlobalVisualStudio10Generator::IsClangClToolset() const +{ + std::string const& toolset = this->GetPlatformToolsetString(); + static cmsys::RegularExpression llvmToolset( + "^[Ll][Ll][Vv][Mm](_v[0-9]+(_xp)?)?$"); + static cmsys::RegularExpression clangClToolset( + "^[Cc][Ll][Aa][Nn][Gg]([Cc][Ll]$|_[0-9])"); + return llvmToolset.find(toolset) || clangClToolset.find(toolset); +} + std::string const& cmGlobalVisualStudio10Generator::GetPlatformToolsetVersionProps() const { diff --git a/Source/cmGlobalVisualStudio10Generator.h b/Source/cmGlobalVisualStudio10Generator.h index 00124d3670..8f312cd0cd 100644 --- a/Source/cmGlobalVisualStudio10Generator.h +++ b/Source/cmGlobalVisualStudio10Generator.h @@ -71,6 +71,9 @@ public: char const* GetPlatformToolset() const; std::string const& GetPlatformToolsetString() const; + /** Return true when using a Visual Studio clang-cl toolset. */ + bool IsClangClToolset() const; + /** The toolset version props file, if any. */ std::string const& GetPlatformToolsetVersionProps() const; diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.cxx b/Source/cmGlobalVisualStudioVersionedGenerator.cxx index ab76a429cb..8e5235a862 100644 --- a/Source/cmGlobalVisualStudioVersionedGenerator.cxx +++ b/Source/cmGlobalVisualStudioVersionedGenerator.cxx @@ -777,6 +777,12 @@ bool cmGlobalVisualStudioVersionedGenerator::IsUtf8EncodingSupported() const bool cmGlobalVisualStudioVersionedGenerator::IsScanDependenciesSupported() const { + if (this->IsClangClToolset()) { + // FIXME(#27977): The ClangCL toolset does not support + // ScanSourceForModuleDependencies yet. + return false; + } + // Supported from Visual Studio 17.6 Preview 7. if (this->Version > cmGlobalVisualStudioGenerator::VSVersion::VS17) { return true; diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 8837fc0411..4344bc3262 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -293,13 +293,15 @@ cmVisualStudio10TargetGenerator::cmVisualStudio10TargetGenerator( this->Android = gg->TargetsAndroid(); this->WindowsKernelMode = gg->TargetsWindowsKernelModeDriver(); auto scanProp = target->GetProperty("CXX_SCAN_FOR_MODULES"); + bool const scanDepsSupported = gg->IsScanDependenciesSupported(); for (auto const& config : this->Configurations) { if (scanProp.IsSet()) { - this->ScanSourceForModuleDependencies[config] = scanProp.IsOn(); - } else { this->ScanSourceForModuleDependencies[config] = + scanDepsSupported && scanProp.IsOn(); + } else { + this->ScanSourceForModuleDependencies[config] = scanDepsSupported && target->NeedCxxDyndep(config) == - cmGeneratorTarget::CxxModuleSupport::Enabled; + cmGeneratorTarget::CxxModuleSupport::Enabled; } } for (unsigned int& version : this->NsightTegraVersion) { @@ -3012,8 +3014,9 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( if (compileAsPerConfig) { clOptions.AddFlag("CompileAs", compileAsPerConfig); } - if (shouldScanForModules != - this->ScanSourceForModuleDependencies[config]) { + if (gg->IsScanDependenciesSupported() && + shouldScanForModules != + this->ScanSourceForModuleDependencies[config]) { clOptions.AddFlag("ScanSourceForModuleDependencies", shouldScanForModules ? "true" : "false"); }