diff options
Diffstat (limited to 'sources/shiboken2/ApiExtractor/clangparser/compilersupport.cpp')
-rw-r--r-- | sources/shiboken2/ApiExtractor/clangparser/compilersupport.cpp | 55 |
1 files changed, 37 insertions, 18 deletions
diff --git a/sources/shiboken2/ApiExtractor/clangparser/compilersupport.cpp b/sources/shiboken2/ApiExtractor/clangparser/compilersupport.cpp index f301733fe..0b58cf5a5 100644 --- a/sources/shiboken2/ApiExtractor/clangparser/compilersupport.cpp +++ b/sources/shiboken2/ApiExtractor/clangparser/compilersupport.cpp @@ -232,7 +232,9 @@ static QByteArray noStandardIncludeOption() { return QByteArrayLiteral("-nostdin // should be picked up automatically by clang without specifying // them implicitly. -#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN) +// Besides g++/Linux, as of MSVC 19.28.29334, MSVC needs clang includes +// due to PYSIDE-1433, LLVM-47099 +#if !defined(Q_OS_DARWIN) # define NEED_CLANG_BUILTIN_INCLUDES 1 #else # define NEED_CLANG_BUILTIN_INCLUDES 0 @@ -274,7 +276,7 @@ static QString findClangBuiltInIncludesDir() for (const QFileInfo &fi : versionDirs) { const QString fileName = fi.fileName(); if (fileName.at(0).isDigit()) { - const QVersionNumber versionNumber = QVersionNumber::fromString(fileName.at(0)); + const QVersionNumber versionNumber = QVersionNumber::fromString(fileName); if (!versionNumber.isNull() && versionNumber > lastVersionNumber) { candidate = fi.absoluteFilePath(); lastVersionNumber = versionNumber; @@ -301,6 +303,24 @@ static QString compilerFromCMake(const QString &defaultCompiler) } #endif // Q_CC_CLANG, Q_CC_GNU +#if NEED_CLANG_BUILTIN_INCLUDES +static void appendClangBuiltinIncludes(HeaderPaths *p) +{ + const QString clangBuiltinIncludesDir = + QDir::toNativeSeparators(findClangBuiltInIncludesDir()); + if (clangBuiltinIncludesDir.isEmpty()) { + qCWarning(lcShiboken, "Unable to locate Clang's built-in include directory " + "(neither by checking the environment variables LLVM_INSTALL_DIR, CLANG_INSTALL_DIR " + " nor running llvm-config). This may lead to parse errors."); + } else { + qCInfo(lcShiboken, "CLANG builtins includes directory: %s", + qPrintable(clangBuiltinIncludesDir)); + p->append(HeaderPath{QFile::encodeName(clangBuiltinIncludesDir), + HeaderType::System}); + } +} +#endif // NEED_CLANG_BUILTIN_INCLUDES + // Returns clang options needed for emulating the host compiler QByteArrayList emulatedCompilerOptions() { @@ -309,26 +329,21 @@ QByteArrayList emulatedCompilerOptions() HeaderPaths headerPaths; result.append(QByteArrayLiteral("-fms-compatibility-version=19")); result.append(QByteArrayLiteral("-Wno-microsoft-enum-value")); + // Fix yvals_core.h: STL1000: Unexpected compiler version, expected Clang 7 or newer (MSVC2017 update) + result.append(QByteArrayLiteral("-D_ALLOW_COMPILER_AND_STL_VERSION_MISMATCH")); +# if NEED_CLANG_BUILTIN_INCLUDES + appendClangBuiltinIncludes(&headerPaths); +# endif // NEED_CLANG_BUILTIN_INCLUDES + #elif defined(Q_CC_CLANG) HeaderPaths headerPaths = gppInternalIncludePaths(compilerFromCMake(QStringLiteral("clang++"))); result.append(noStandardIncludeOption()); #elif defined(Q_CC_GNU) HeaderPaths headerPaths; -#if NEED_CLANG_BUILTIN_INCLUDES - const QString clangBuiltinIncludesDir = - QDir::toNativeSeparators(findClangBuiltInIncludesDir()); - if (clangBuiltinIncludesDir.isEmpty()) { - qCWarning(lcShiboken, "Unable to locate Clang's built-in include directory " - "(neither by checking the environment variables LLVM_INSTALL_DIR, CLANG_INSTALL_DIR " - " nor running llvm-config). This may lead to parse errors."); - } else { - qCInfo(lcShiboken, "CLANG builtins includes directory: %s", - qPrintable(clangBuiltinIncludesDir)); - headerPaths.append(HeaderPath{QFile::encodeName(clangBuiltinIncludesDir), - HeaderType::System}); - } -#endif // NEED_CLANG_BUILTIN_INCLUDES +# if NEED_CLANG_BUILTIN_INCLUDES + appendClangBuiltinIncludes(&headerPaths); +# endif // NEED_CLANG_BUILTIN_INCLUDES // Append the c++ include paths since Clang is unable to find <list> etc // on RHEL 7 with g++ 6.3 or CentOS 7.2. @@ -354,12 +369,16 @@ QByteArrayList emulatedCompilerOptions() LanguageLevel emulatedCompilerLanguageLevel() { -#if defined(Q_CC_MSVC) && _MSC_VER > 1900 +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + return LanguageLevel::Cpp17; +#else +# if defined(Q_CC_MSVC) && _MSC_VER > 1900 // Fixes constexpr errors in MSVC2017 library headers with Clang 4.1..5.X (0.45 == Clang 6). if (libClangVersion() < QVersionNumber(0, 45)) return LanguageLevel::Cpp1Z; -#endif // Q_CC_MSVC && _MSC_VER > 1900 +# endif // Q_CC_MSVC && _MSC_VER > 1900 return LanguageLevel::Cpp14; // otherwise, t.h is parsed as "C" +#endif // Qt 5 } struct LanguageLevelMapping |