diff options
author | Denis Shienkov <denis.shienkov@gmail.com> | 2020-06-09 20:31:09 +0300 |
---|---|---|
committer | Denis Shienkov <denis.shienkov@gmail.com> | 2020-06-11 16:18:34 +0000 |
commit | 3ee7145b4b3c23a66a006ecc7aec072c88efda7e (patch) | |
tree | 740d882ea0b1ebaa38e21a533eeae30783f6caea /share | |
parent | ed95565cfb63ac1ad169b27c8a329f0d4202828c (diff) |
MSVC: Use "/external:I" flag to set the system include paths
Previously we were using the "/I" compiler option to specify
the system include paths, because the MSVC compiler had not
the special option for that.
But since v15.6, the MSVC 2017 compiler has the special
"/external:I" option to specify the system include paths:
* https://devblogs.microsoft.com/cppblog/broken-warnings-theory/
So, it makes sense to use this new option for the MSVC versions
which are supports it (since _MSC_VER 1913, aka MSVC 2017
update 6, v15. 6.0):
* https://dev.to/yumetodo/list-of-mscver-and-mscfullver-8nd
But, due to MSVC 2017 update 6 has some bugs:
* https://developercommunity.visualstudio.com/content/problem/181006/externali-include-paths-not-working.html
which are fixed since MSVC 2017 update 9 (aka _MSC_VER 1916),
then we just keep _MSC_VER 1916 as a base version.
In other cases we fall back to the "/I" option.
Fixes: QBS-1573
Change-Id: Ie180ba61a1988aaec7955f545b989edf406c7730
Reviewed-by: Ivan Komissarov <ABBAPOH@gmail.com>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'share')
-rw-r--r-- | share/qbs/modules/cpp/msvc.js | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/share/qbs/modules/cpp/msvc.js b/share/qbs/modules/cpp/msvc.js index 8611ebe50..53f386996 100644 --- a/share/qbs/modules/cpp/msvc.js +++ b/share/qbs/modules/cpp/msvc.js @@ -82,6 +82,16 @@ function hasCxx17Option(input) || (input.qbs.toolchain.contains("clang-cl") && input.cpp.compilerVersionMajor >= 7); } +function supportsExternalIncludesOption(input) { + if (input.qbs.toolchain.contains("clang-cl")) + return false; // Exclude clang-cl. + // This option was introcuded since MSVC 2017 v15.6 (aka _MSC_VER 19.13). + // But due to some MSVC bugs: + // * https://developercommunity.visualstudio.com/content/problem/181006/externali-include-paths-not-working.html + // this option has been fixed since MSVC 2017 update 9, v15.9 (aka _MSC_VER 19.16). + return Utilities.versionCompare(input.cpp.compilerVersion, "19.16") >= 0; +} + function addLanguageVersionFlag(input, args) { var cxxVersion = Cpp.languageVersion(input.cpp.cxxLanguageVersion, ["c++17", "c++14", "c++11", "c++98"], "C++"); @@ -189,15 +199,25 @@ function prepareCompiler(project, product, inputs, outputs, input, output, expli args.push('/Wall') if (input.cpp.treatWarningsAsErrors) args.push('/WX') - var allIncludePaths = []; var includePaths = input.cpp.includePaths; - if (includePaths) - allIncludePaths = allIncludePaths.uniqueConcat(includePaths); + if (includePaths) { + args = args.concat([].uniqueConcat(includePaths).map(function(path) { + return '/I' + FileInfo.toWindowsSeparators(path); + })); + } + + var allSystemIncludePaths = []; var systemIncludePaths = input.cpp.systemIncludePaths; if (systemIncludePaths) - allIncludePaths = allIncludePaths.uniqueConcat(systemIncludePaths); - for (i in allIncludePaths) - args.push('/I' + FileInfo.toWindowsSeparators(allIncludePaths[i])) + allSystemIncludePaths = allSystemIncludePaths.uniqueConcat(systemIncludePaths); + var includeFlag = "/I"; + if (supportsExternalIncludesOption(input)) { + args.push("/experimental:external"); + includeFlag = "/external:I" + } + allSystemIncludePaths.forEach(function(path) { + args.push(includeFlag, FileInfo.toWindowsSeparators(path)); }); + var allDefines = []; var platformDefines = input.cpp.platformDefines; if (platformDefines) |