diff options
author | Brad King <brad.king@kitware.com> | 2024-12-09 17:27:44 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2024-12-09 19:57:35 (GMT) |
commit | 30139913e99db6cc23ae3dd002cdc9f07d2b891b (patch) | |
tree | 89de25bcc09c9d701326297ea8778b6887fef001 /Source | |
parent | 57da8712c1527fa697e65dc823b09fb9de570d89 (diff) | |
download | CMake-30139913e99db6cc23ae3dd002cdc9f07d2b891b.zip CMake-30139913e99db6cc23ae3dd002cdc9f07d2b891b.tar.gz CMake-30139913e99db6cc23ae3dd002cdc9f07d2b891b.tar.bz2 |
VS: Restore support for mixing C++23 and C in one target with clang-cl
Since commit 474eafe28c (clang-cl: Add support for C++23, 2024-09-13,
v3.31.0-rc1~97^2) we use a Clang-specific flag to enable C++23 since
`clang-cl` has no `-std:c++23` flag, and `-std:c++latest` may enable an
even newer version of C++. However, in `.vcxproj` files there is no way
to express a target-wide `-clang:-std=c++23` flag for only C++ sources
when the target also has C sources. Add a special case to map back to
`-std:c++latest` for targets with C++23 and C together.
Fixes: #26508
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmVisualStudio10TargetGenerator.cxx | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 95ff7e6..f7515f1 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -3480,6 +3480,20 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( } } + if (isCXXwithC) { + // Modules/Compiler/Clang.cmake has a special case for clang-cl versions + // that do not have a -std:c++23 flag to pass the standard through to the + // underlying clang directly. Unfortunately that flag applies to all + // sources in a single .vcxproj file, so if we have C sources too then we + // cannot use it. Map it back to -std::c++latest, even though that might + // end up enabling C++26 or later, so it does not apply to C sources. + static const std::string kClangStdCxx23 = "-clang:-std=c++23"; + std::string::size_type p = flags.find(kClangStdCxx23); + if (p != std::string::npos) { + flags.replace(p, kClangStdCxx23.size(), "-std:c++latest"); + } + } + clOptions.Parse(flags); clOptions.Parse(defineFlags); std::vector<std::string> targetDefines; |