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
This commit is contained in:
Tyler Yankee
2026-07-21 17:02:29 -04:00
committed by Brad King
parent 6a5e95f6c5
commit 027b962a81
6 changed files with 33 additions and 7 deletions
+3 -1
View File
@@ -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 <CMAKE_GENERATOR_TOOLSET>`).
* GCC 14 and newer
+3 -1
View File
@@ -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 <CMAKE_GENERATOR_TOOLSET>`).
See :manual:`cmake-cxxmodules(7)`.
* The ``ibm-flang`` compiler is now supported with
@@ -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
{
+3
View File
@@ -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;
@@ -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;
+8 -5
View File
@@ -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");
}