Clang: Use -isystem for system headers

The project manager was passing correctly the system headers, but the
compileroptionsbuilder was ignoring them by having UseSystemHeader::No.

This change makes the project's view to be reflected in clangd's
compile_commands.json.

Fixes: QTCREATORBUG-30474
Change-Id: Ie3b80642e27ada4c8c8725f21e3cfbb2a4051aa0
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Cristian Adam
2024-03-18 16:45:59 +01:00
parent f5ba46ccbd
commit 0a27bc2e78
2 changed files with 10 additions and 11 deletions

View File

@@ -692,7 +692,6 @@ void CompilerOptionsBuilder::addIncludeDirOptionForPath(const HeaderPath &path)
if (path.type == HeaderPathType::BuiltIn) { if (path.type == HeaderPathType::BuiltIn) {
systemPath = true; systemPath = true;
} else if (path.type == HeaderPathType::System) { } else if (path.type == HeaderPathType::System) {
if (m_useSystemHeader == UseSystemHeader::Yes)
systemPath = true; systemPath = true;
} else { } else {
// ProjectExplorer::HeaderPathType::User // ProjectExplorer::HeaderPathType::User

View File

@@ -196,7 +196,7 @@ void CompilerOptionsBuilderTest::testHeaderPathOptionsOrder()
QCOMPARE(compilerOptionsBuilder.options(), QCOMPARE(compilerOptionsBuilder.options(),
(QStringList{"-nostdinc", "-nostdinc++", "-I" + t.toNative("/tmp/path"), (QStringList{"-nostdinc", "-nostdinc++", "-I" + t.toNative("/tmp/path"),
"-I" + t.toNative("/tmp/system_path"), "-isystem", t.toNative("/dummy"), "-isystem", t.toNative("/tmp/system_path"), "-isystem", t.toNative("/dummy"),
"-isystem", t.toNative("/tmp/builtin_path")})); "-isystem", t.toNative("/tmp/builtin_path")}));
} }
@@ -212,9 +212,9 @@ void CompilerOptionsBuilderTest::testHeaderPathOptionsOrderMsvc()
QCOMPARE(compilerOptionsBuilder.options(), QCOMPARE(compilerOptionsBuilder.options(),
(QStringList{"-nostdinc", "-nostdinc++", "-I" + t.toNative("/tmp/path"), (QStringList{"-nostdinc", "-nostdinc++", "-I" + t.toNative("/tmp/path"),
"-I" + t.toNative("/tmp/system_path"), "/clang:-isystem", "/clang:-isystem", "/clang:" + t.toNative("/tmp/system_path"),
"/clang:" + t.toNative("/dummy"), "/clang:-isystem", "/clang:-isystem", "/clang:" + t.toNative("/dummy"),
"/clang:" + t.toNative("/tmp/builtin_path")})); "/clang:-isystem", "/clang:" + t.toNative("/tmp/builtin_path")}));
} }
void CompilerOptionsBuilderTest::testUseSystemHeader() void CompilerOptionsBuilderTest::testUseSystemHeader()
@@ -239,7 +239,7 @@ void CompilerOptionsBuilderTest::testNoClangHeadersPath()
t.compilerOptionsBuilder->addHeaderPathOptions(); t.compilerOptionsBuilder->addHeaderPathOptions();
QCOMPARE(t.compilerOptionsBuilder->options(), QCOMPARE(t.compilerOptionsBuilder->options(),
(QStringList{"-I" + t.toNative("/tmp/path"), "-I" + t.toNative("/tmp/system_path")})); (QStringList{"-I" + t.toNative("/tmp/path"), "-isystem", t.toNative("/tmp/system_path")}));
} }
void CompilerOptionsBuilderTest::testClangHeadersAndCppIncludePathsOrderMacOs() void CompilerOptionsBuilderTest::testClangHeadersAndCppIncludePathsOrderMacOs()
@@ -260,7 +260,7 @@ void CompilerOptionsBuilderTest::testClangHeadersAndCppIncludePathsOrderMacOs()
QCOMPARE(compilerOptionsBuilder.options(), QCOMPARE(compilerOptionsBuilder.options(),
(QStringList{"-nostdinc", "-nostdinc++", "-I" + t.toNative("/tmp/path"), (QStringList{"-nostdinc", "-nostdinc++", "-I" + t.toNative("/tmp/path"),
"-I" + t.toNative("/tmp/system_path"), "-isystem", t.toNative("/tmp/system_path"),
"-isystem", t.toNative("/usr/include/c++/4.2.1"), "-isystem", t.toNative("/usr/include/c++/4.2.1"),
"-isystem", t.toNative("/usr/include/c++/4.2.1/backward"), "-isystem", t.toNative("/usr/include/c++/4.2.1/backward"),
"-isystem", t.toNative("/usr/local/include"), "-isystem", t.toNative("/usr/local/include"),
@@ -599,7 +599,7 @@ void CompilerOptionsBuilderTest::testBuildAllOptions()
wrappedQtHeadersPath, // contains -I already wrappedQtHeadersPath, // contains -I already
wrappedQtCoreHeadersPath, // contains -I already wrappedQtCoreHeadersPath, // contains -I already
"-I" + t.toNative("/tmp/path"), "-I" + t.toNative("/tmp/path"),
"-I" + t.toNative("/tmp/system_path"), "-isystem", t.toNative("/tmp/system_path"),
"-isystem", t.toNative("/dummy"), "-isystem", t.toNative("/dummy"),
"-isystem", t.toNative("/tmp/builtin_path")})); "-isystem", t.toNative("/tmp/builtin_path")}));
} }
@@ -628,7 +628,7 @@ void CompilerOptionsBuilderTest::testBuildAllOptionsMsvc()
wrappedQtHeadersPath, // contains -I already wrappedQtHeadersPath, // contains -I already
wrappedQtCoreHeadersPath, // contains -I already wrappedQtCoreHeadersPath, // contains -I already
"-I" + t.toNative("/tmp/path"), "-I" + t.toNative("/tmp/path"),
"-I" + t.toNative("/tmp/system_path"), "/clang:-isystem", "/clang:" + t.toNative("/tmp/system_path"),
"/clang:-isystem", "/clang:" + t.toNative("/dummy"), "/clang:-isystem", "/clang:" + t.toNative("/dummy"),
"/clang:-isystem", "/clang:" + t.toNative("/tmp/builtin_path")})); "/clang:-isystem", "/clang:" + t.toNative("/tmp/builtin_path")}));
} }
@@ -659,7 +659,7 @@ void CompilerOptionsBuilderTest::testBuildAllOptionsMsvcWithExceptions()
wrappedQtHeadersPath, // contains -I already wrappedQtHeadersPath, // contains -I already
wrappedQtCoreHeadersPath, // contains -I already wrappedQtCoreHeadersPath, // contains -I already
"-I" + t.toNative("/tmp/path"), "-I" + t.toNative("/tmp/path"),
"-I" + t.toNative("/tmp/system_path"), "/clang:-isystem", "/clang:" + t.toNative("/tmp/system_path"),
"/clang:-isystem", "/clang:" + t.toNative("/dummy"), "/clang:-isystem", "/clang:" + t.toNative("/dummy"),
"/clang:-isystem", "/clang:" + t.toNative("/tmp/builtin_path")})); "/clang:-isystem", "/clang:" + t.toNative("/tmp/builtin_path")}));
} }