forked from qt-creator/qt-creator
GCC/Clang: Use sysroot from build system if kit doesn't set sysroot
If the kit has a sysroot set, we use that when determining the system header paths of the tool chain for the code model. But if the kit doesn't have a sysroot set, we should use the sysroot setting that we find in the CXX flags that we get from the build system. In the specific issue, we detect the Clang compiler from the Xcode installation on macOS, which actually needs to be passed a sysroot to return sensible system header paths. Task-number: QTCREATORBUG-18633 Change-Id: Ida401bee8c4b82bb4fa2e6f952b8cc174ea081c6 Reviewed-by: Vikas Pachdha <vikas.pachdha@qt.io>
This commit is contained in:
@@ -638,14 +638,26 @@ ToolChain::SystemHeaderPathsRunner GccToolChain::createSystemHeaderPathsRunner()
|
|||||||
(const QStringList &cxxflags, const QString &sysRoot) {
|
(const QStringList &cxxflags, const QString &sysRoot) {
|
||||||
// Prepare arguments
|
// Prepare arguments
|
||||||
QStringList arguments;
|
QStringList arguments;
|
||||||
if (!sysRoot.isEmpty())
|
const bool hasKitSysroot = !sysRoot.isEmpty();
|
||||||
|
if (hasKitSysroot)
|
||||||
arguments.append(QString::fromLatin1("--sysroot=%1").arg(sysRoot));
|
arguments.append(QString::fromLatin1("--sysroot=%1").arg(sysRoot));
|
||||||
|
|
||||||
QStringList flags;
|
QStringList flags;
|
||||||
flags << platformCodeGenFlags << cxxflags;
|
flags << platformCodeGenFlags << cxxflags;
|
||||||
foreach (const QString &a, flags) {
|
for (int i = 0; i < flags.size(); ++i) {
|
||||||
if (a.startsWith("-stdlib=") || a.startsWith("--gcctoolchain="))
|
const QString &flag = flags.at(i);
|
||||||
arguments << a;
|
if (flag.startsWith("-stdlib=") || flag.startsWith("--gcctoolchain=")) {
|
||||||
|
arguments << flag;
|
||||||
|
} else if (!hasKitSysroot) {
|
||||||
|
// pass build system's sysroot to compiler, if we didn't pass one from kit
|
||||||
|
if (flag.startsWith("--sysroot=")) {
|
||||||
|
arguments << flag;
|
||||||
|
} else if ((flag.startsWith("-isysroot") || flag.startsWith("--sysroot"))
|
||||||
|
&& i < flags.size() - 1) {
|
||||||
|
arguments << flag << flags.at(i + 1);
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
arguments << "-xc++" << "-E" << "-v" << "-";
|
arguments << "-xc++" << "-E" << "-v" << "-";
|
||||||
|
Reference in New Issue
Block a user