forked from qt-creator/qt-creator
Clang: Fix C++ paths search in compiler options builder
Take into account paths from MinGW and NDK Clang. Fixes: QTCREATORBUG-21540 Change-Id: I00906c75dc4ddeb92fe5942a0222285d8ce2eb9d Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
@@ -235,14 +235,15 @@ static int lastIncludeIndex(const QStringList &options, const QRegularExpression
|
|||||||
|
|
||||||
static int includeIndexForResourceDirectory(const QStringList &options, bool isMacOs = false)
|
static int includeIndexForResourceDirectory(const QStringList &options, bool isMacOs = false)
|
||||||
{
|
{
|
||||||
// include/c++/{version}, include/c++/v1 and include/g++
|
// include/c++, include/g++, libc++\include and libc++abi\include
|
||||||
static const QRegularExpression includeRegExp(
|
static const QString cppIncludes = R"((.*[\/\\]include[\/\\].*(g\+\+|c\+\+).*))"
|
||||||
R"(\A.*[\/\\]include[\/\\].*(g\+\+.*\z|c\+\+[\/\\](v1\z|\d+.*\z)))");
|
R"(|(.*libc\+\+[\/\\]include))"
|
||||||
|
R"(|(.*libc\+\+abi[\/\\]include))";
|
||||||
|
static const QRegularExpression includeRegExp("\\A(" + cppIncludes + ")\\z");
|
||||||
|
|
||||||
// The same as includeRegExp but also matches /usr/local/include
|
// The same as includeRegExp but also matches /usr/local/include
|
||||||
static const QRegularExpression includeRegExpMac(
|
static const QRegularExpression includeRegExpMac(
|
||||||
R"(\A(.*[\/\\]include[\/\\].*(g\+\+.*\z|c\+\+[\/\\](v1\z|\d+.*\z))))"
|
"\\A(" + cppIncludes + R"(|([\/\\]usr[\/\\]local[\/\\]include))" + ")\\z");
|
||||||
R"(|([\/\\]usr[\/\\]local[\/\\]include\z))");
|
|
||||||
|
|
||||||
const int cppIncludeIndex = lastIncludeIndex(options, isMacOs
|
const int cppIncludeIndex = lastIncludeIndex(options, isMacOs
|
||||||
? includeRegExpMac
|
? includeRegExpMac
|
||||||
|
|||||||
@@ -230,6 +230,84 @@ TEST_F(CompilerOptionsBuilder, ClangHeadersAndCppIncludesPathsOrderLinux)
|
|||||||
"-isystem", QDir::toNativeSeparators("/usr/include")));
|
"-isystem", QDir::toNativeSeparators("/usr/include")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(CompilerOptionsBuilder, ClangHeadersAndCppIncludesPathsOrderNoVersion)
|
||||||
|
{
|
||||||
|
projectPart.headerPaths = {HeaderPath{"C:\\Qt\\Tools\\mingw530_32\\i686-w64-mingw32\\include", HeaderPathType::BuiltIn},
|
||||||
|
HeaderPath{"C:\\Qt\\Tools\\mingw530_32\\i686-w64-mingw32\\include\\c++", HeaderPathType::BuiltIn},
|
||||||
|
HeaderPath{"C:\\Qt\\Tools\\mingw530_32\\i686-w64-mingw32\\include\\c++\\i686-w64-mingw32", HeaderPathType::BuiltIn},
|
||||||
|
HeaderPath{"C:\\Qt\\Tools\\mingw530_32\\i686-w64-mingw32\\include\\c++\\backward", HeaderPathType::BuiltIn}
|
||||||
|
};
|
||||||
|
projectPart.toolChainTargetTriple = "x86_64-w64-windows-gnu";
|
||||||
|
CppTools::CompilerOptionsBuilder compilerOptionsBuilder(projectPart,
|
||||||
|
CppTools::UseSystemHeader::No,
|
||||||
|
CppTools::SkipBuiltIn::No,
|
||||||
|
CppTools::SkipLanguageDefines::Yes,
|
||||||
|
"7.0.0",
|
||||||
|
"");
|
||||||
|
|
||||||
|
compilerOptionsBuilder.addHeaderPathOptions();
|
||||||
|
|
||||||
|
ASSERT_THAT(compilerOptionsBuilder.options(),
|
||||||
|
ElementsAre("-nostdinc",
|
||||||
|
"-nostdlibinc",
|
||||||
|
"-isystem", QDir::toNativeSeparators("C:\\Qt\\Tools\\mingw530_32\\i686-w64-mingw32\\include"),
|
||||||
|
"-isystem", QDir::toNativeSeparators("C:\\Qt\\Tools\\mingw530_32\\i686-w64-mingw32\\include\\c++"),
|
||||||
|
"-isystem", QDir::toNativeSeparators("C:\\Qt\\Tools\\mingw530_32\\i686-w64-mingw32\\include\\c++\\i686-w64-mingw32"),
|
||||||
|
"-isystem", QDir::toNativeSeparators("C:\\Qt\\Tools\\mingw530_32\\i686-w64-mingw32\\include\\c++\\backward"),
|
||||||
|
"-isystem", QDir::toNativeSeparators(CLANG_RESOURCE_DIR "")));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(CompilerOptionsBuilder, ClangHeadersAndCppIncludesPathsOrderAndroidClang)
|
||||||
|
{
|
||||||
|
projectPart.headerPaths = {
|
||||||
|
HeaderPath{
|
||||||
|
"C:\\Users\\test\\AppData\\Local\\Android\\sdk\\ndk-bundle\\sysroot\\usr\\include\\i686-linux-android",
|
||||||
|
HeaderPathType::BuiltIn},
|
||||||
|
HeaderPath{
|
||||||
|
"C:\\Users\\test\\AppData\\Local\\Android\\sdk\\ndk-bundle\\sources\\cxx-stl\\llvm-libc++\\include",
|
||||||
|
HeaderPathType::BuiltIn},
|
||||||
|
HeaderPath{
|
||||||
|
"C:\\Users\\test\\AppData\\Local\\Android\\sdk\\ndk-bundle\\sources\\android\\support\\include",
|
||||||
|
HeaderPathType::BuiltIn},
|
||||||
|
HeaderPath{
|
||||||
|
"C:\\Users\\test\\AppData\\Local\\Android\\sdk\\ndk-bundle\\sources\\cxx-stl\\llvm-libc++abi\\include",
|
||||||
|
HeaderPathType::BuiltIn},
|
||||||
|
HeaderPath{"C:\\Users\\test\\AppData\\Local\\Android\\sdk\\ndk-bundle\\sysroot\\usr\\include",
|
||||||
|
HeaderPathType::BuiltIn}};
|
||||||
|
projectPart.toolChainTargetTriple = "i686-linux-android";
|
||||||
|
CppTools::CompilerOptionsBuilder compilerOptionsBuilder(projectPart,
|
||||||
|
CppTools::UseSystemHeader::No,
|
||||||
|
CppTools::SkipBuiltIn::No,
|
||||||
|
CppTools::SkipLanguageDefines::Yes,
|
||||||
|
"7.0.0",
|
||||||
|
"");
|
||||||
|
|
||||||
|
compilerOptionsBuilder.addHeaderPathOptions();
|
||||||
|
|
||||||
|
ASSERT_THAT(
|
||||||
|
compilerOptionsBuilder.options(),
|
||||||
|
ElementsAre(
|
||||||
|
"-nostdinc",
|
||||||
|
"-nostdlibinc",
|
||||||
|
"-isystem",
|
||||||
|
QDir::toNativeSeparators(
|
||||||
|
"C:\\Users\\test\\AppData\\Local\\Android\\sdk\\ndk-bundle\\sysroot\\usr\\include\\i686-linux-android"),
|
||||||
|
"-isystem",
|
||||||
|
QDir::toNativeSeparators(
|
||||||
|
"C:\\Users\\test\\AppData\\Local\\Android\\sdk\\ndk-bundle\\sources\\cxx-stl\\llvm-libc++\\include"),
|
||||||
|
"-isystem",
|
||||||
|
QDir::toNativeSeparators(
|
||||||
|
"C:\\Users\\test\\AppData\\Local\\Android\\sdk\\ndk-bundle\\sources\\android\\support\\include"),
|
||||||
|
"-isystem",
|
||||||
|
QDir::toNativeSeparators(
|
||||||
|
"C:\\Users\\test\\AppData\\Local\\Android\\sdk\\ndk-bundle\\sources\\cxx-stl\\llvm-libc++abi\\include"),
|
||||||
|
"-isystem",
|
||||||
|
QDir::toNativeSeparators(CLANG_RESOURCE_DIR ""),
|
||||||
|
"-isystem",
|
||||||
|
QDir::toNativeSeparators(
|
||||||
|
"C:\\Users\\test\\AppData\\Local\\Android\\sdk\\ndk-bundle\\sysroot\\usr\\include")));
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(CompilerOptionsBuilder, NoPrecompiledHeader)
|
TEST_F(CompilerOptionsBuilder, NoPrecompiledHeader)
|
||||||
{
|
{
|
||||||
compilerOptionsBuilder.addPrecompiledHeaderOptions(CppTools::CompilerOptionsBuilder::PchUsage::None);
|
compilerOptionsBuilder.addPrecompiledHeaderOptions(CppTools::CompilerOptionsBuilder::PchUsage::None);
|
||||||
|
|||||||
Reference in New Issue
Block a user