From 0a27bc2e78c3e747926e02fcdeb1fe758e3fa93d Mon Sep 17 00:00:00 2001 From: Cristian Adam Date: Mon, 18 Mar 2024 16:45:59 +0100 Subject: [PATCH] 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 --- .../cppeditor/compileroptionsbuilder.cpp | 3 +-- .../cppeditor/compileroptionsbuilder_test.cpp | 18 +++++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/plugins/cppeditor/compileroptionsbuilder.cpp b/src/plugins/cppeditor/compileroptionsbuilder.cpp index be40b9c914f..a860edbee34 100644 --- a/src/plugins/cppeditor/compileroptionsbuilder.cpp +++ b/src/plugins/cppeditor/compileroptionsbuilder.cpp @@ -692,8 +692,7 @@ void CompilerOptionsBuilder::addIncludeDirOptionForPath(const HeaderPath &path) if (path.type == HeaderPathType::BuiltIn) { systemPath = true; } else if (path.type == HeaderPathType::System) { - if (m_useSystemHeader == UseSystemHeader::Yes) - systemPath = true; + systemPath = true; } else { // ProjectExplorer::HeaderPathType::User if (m_useSystemHeader == UseSystemHeader::Yes && m_projectPart.hasProject() diff --git a/src/plugins/cppeditor/compileroptionsbuilder_test.cpp b/src/plugins/cppeditor/compileroptionsbuilder_test.cpp index ed53ef99229..81cade277c3 100644 --- a/src/plugins/cppeditor/compileroptionsbuilder_test.cpp +++ b/src/plugins/cppeditor/compileroptionsbuilder_test.cpp @@ -196,7 +196,7 @@ void CompilerOptionsBuilderTest::testHeaderPathOptionsOrder() QCOMPARE(compilerOptionsBuilder.options(), (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")})); } @@ -212,9 +212,9 @@ void CompilerOptionsBuilderTest::testHeaderPathOptionsOrderMsvc() QCOMPARE(compilerOptionsBuilder.options(), (QStringList{"-nostdinc", "-nostdinc++", "-I" + t.toNative("/tmp/path"), - "-I" + t.toNative("/tmp/system_path"), "/clang:-isystem", - "/clang:" + t.toNative("/dummy"), "/clang:-isystem", - "/clang:" + t.toNative("/tmp/builtin_path")})); + "/clang:-isystem", "/clang:" + t.toNative("/tmp/system_path"), + "/clang:-isystem", "/clang:" + t.toNative("/dummy"), + "/clang:-isystem", "/clang:" + t.toNative("/tmp/builtin_path")})); } void CompilerOptionsBuilderTest::testUseSystemHeader() @@ -239,7 +239,7 @@ void CompilerOptionsBuilderTest::testNoClangHeadersPath() t.compilerOptionsBuilder->addHeaderPathOptions(); 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() @@ -260,7 +260,7 @@ void CompilerOptionsBuilderTest::testClangHeadersAndCppIncludePathsOrderMacOs() QCOMPARE(compilerOptionsBuilder.options(), (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/backward"), "-isystem", t.toNative("/usr/local/include"), @@ -599,7 +599,7 @@ void CompilerOptionsBuilderTest::testBuildAllOptions() wrappedQtHeadersPath, // contains -I already wrappedQtCoreHeadersPath, // contains -I already "-I" + t.toNative("/tmp/path"), - "-I" + t.toNative("/tmp/system_path"), + "-isystem", t.toNative("/tmp/system_path"), "-isystem", t.toNative("/dummy"), "-isystem", t.toNative("/tmp/builtin_path")})); } @@ -628,7 +628,7 @@ void CompilerOptionsBuilderTest::testBuildAllOptionsMsvc() wrappedQtHeadersPath, // contains -I already wrappedQtCoreHeadersPath, // contains -I already "-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("/tmp/builtin_path")})); } @@ -659,7 +659,7 @@ void CompilerOptionsBuilderTest::testBuildAllOptionsMsvcWithExceptions() wrappedQtHeadersPath, // contains -I already wrappedQtCoreHeadersPath, // contains -I already "-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("/tmp/builtin_path")})); }