diff options
-rw-r--r-- | doc/reference/modules/cpp-module.qdoc | 14 | ||||
-rw-r--r-- | share/qbs/modules/cpp/msvc.js | 16 | ||||
-rw-r--r-- | share/qbs/modules/cpp/windows-msvc-base.qbs | 1 | ||||
-rw-r--r-- | share/qbs/modules/cpp/windows-msvc.qbs | 2 |
4 files changed, 33 insertions, 0 deletions
diff --git a/doc/reference/modules/cpp-module.qdoc b/doc/reference/modules/cpp-module.qdoc index 1628bc80e..dba1d9d79 100644 --- a/doc/reference/modules/cpp-module.qdoc +++ b/doc/reference/modules/cpp-module.qdoc @@ -1925,3 +1925,17 @@ \windowsproperty \nodefaultvalue */ + +/*! + \qmlproperty string cpp::enableCxxLanguageMacro + \since Qbs 1.20 + + Whether to set the \c{/Zc:__cplusplus} macro + (\l{https://docs.microsoft.com/en-us/cpp/build/reference/zc-cplusplus}) + + This property only applies to MSVC toolchain. clang-cl also supports + this option, but it has no effect. + + \windowsproperty + \defaultvalue \c{true} for MSVC, \c{false} for clang-cl +*/ diff --git a/share/qbs/modules/cpp/msvc.js b/share/qbs/modules/cpp/msvc.js index 1ebe5173b..3e528ddee 100644 --- a/share/qbs/modules/cpp/msvc.js +++ b/share/qbs/modules/cpp/msvc.js @@ -83,6 +83,19 @@ function hasCxx17Option(input) || (input.qbs.toolchain.contains("clang-cl") && input.cpp.compilerVersionMajor >= 7); } +function hasZCplusPlusOption(input) +{ + // /Zc:__cplusplus is supported starting from Visual Studio 15.7 + // Looks like closest MSVC version is 14.14.26428 (cl ver 19.14.26433) + // At least, this version is tested + // https://docs.microsoft.com/en-us/cpp/build/reference/zc-cplusplus + // clang-cl supports this option starting around-ish versions 8/9, but it + // ignores this option, so this doesn't really matter + // https://reviews.llvm.org/D45877 + return Utilities.versionCompare(input.cpp.compilerVersion, "19.14.26433") >= 0 + || (input.qbs.toolchain.contains("clang-cl") && input.cpp.compilerVersionMajor >= 9); +} + function supportsExternalIncludesOption(input) { if (input.qbs.toolchain.contains("clang-cl")) return false; // Exclude clang-cl. @@ -240,6 +253,9 @@ function prepareCompiler(project, product, inputs, outputs, input, output, expli if (input.cpp.generateCompilerListingFiles) args.push("/Fa" + FileInfo.toWindowsSeparators(outputs.lst[0].filePath)); + if (input.cpp.enableCxxLanguageMacro && hasZCplusPlusOption(input)) + args.push("/Zc:__cplusplus"); + var objectMap = outputs.obj || outputs.intermediate_obj var objOutput = objectMap ? objectMap[0] : undefined args.push('/Fo' + FileInfo.toWindowsSeparators(objOutput.filePath)) diff --git a/share/qbs/modules/cpp/windows-msvc-base.qbs b/share/qbs/modules/cpp/windows-msvc-base.qbs index 4efd20668..3d4975dda 100644 --- a/share/qbs/modules/cpp/windows-msvc-base.qbs +++ b/share/qbs/modules/cpp/windows-msvc-base.qbs @@ -104,6 +104,7 @@ CppModule { property var buildEnv readonly property bool shouldSignArtifacts: codesign.enableCodeSigning + property bool enableCxxLanguageMacro: false setupBuildEnvironment: { for (var key in product.cpp.buildEnv) { diff --git a/share/qbs/modules/cpp/windows-msvc.qbs b/share/qbs/modules/cpp/windows-msvc.qbs index 33c5e74c8..5e41c76fa 100644 --- a/share/qbs/modules/cpp/windows-msvc.qbs +++ b/share/qbs/modules/cpp/windows-msvc.qbs @@ -65,4 +65,6 @@ MsvcBaseModule { toolchainInstallPath: compilerPathProbe.found ? compilerPathProbe.path : undefined buildEnv: msvcProbe.buildEnv + + enableCxxLanguageMacro: true } |