Add support for using -isystem in qmake

This commit will make qmake use -isystem automatically for any
compilers that declare support for it for any paths that are listed in
QMAKE_DEFAULT_INCDIRS.

Change-Id: I36fefc6d5bba61671f65669f0ea42704b3c3cf31
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
This commit is contained in:
Thiago Macieira 2013-12-09 10:56:31 -08:00 committed by The Qt Project
parent 6f7d370ade
commit 0b144bc76a
9 changed files with 51 additions and 3 deletions

View File

@ -13,6 +13,7 @@ QMAKE_LINK_SHLIB = $$QMAKE_CXX
CONFIG += clang_pch_style
QMAKE_PCH_OUTPUT_EXT = .pch
QMAKE_CFLAGS_ISYSTEM = -isystem
QMAKE_CFLAGS_PRECOMPILE = -x c-header -c ${QMAKE_PCH_INPUT} -o ${QMAKE_PCH_OUTPUT}
QMAKE_CFLAGS_USE_PRECOMPILE = -Xclang -include-pch -Xclang ${QMAKE_PCH_OUTPUT}
QMAKE_CXXFLAGS_PRECOMPILE = -x c++-header -c ${QMAKE_PCH_INPUT} -o ${QMAKE_PCH_OUTPUT}

View File

@ -40,6 +40,7 @@ QMAKE_CFLAGS_DEBUG += -g
QMAKE_CFLAGS_SHLIB += -fPIC
QMAKE_CFLAGS_STATIC_LIB += -fPIC
QMAKE_CFLAGS_APP += -fPIE
QMAKE_CFLAGS_ISYSTEM = -isystem
QMAKE_CFLAGS_YACC += -Wno-unused -Wno-parentheses
QMAKE_CFLAGS_HIDESYMS += -fvisibility=hidden
QMAKE_CFLAGS_EXCEPTIONS_OFF += -fno-exceptions

View File

@ -45,7 +45,8 @@ defineReplace(mocCmdBase) {
}
incvar = @$$WIN_INCLUDETEMP
} else {
incvar = $(INCPATH)
incvar = -I$$QMAKESPEC -I$$_PRO_FILE_PWD_ $$join(INCLUDEPATH, " -I", -I)
incvar += $$QMAKE_FRAMEWORKPATH_FLAGS
}
RET += $$QMAKE_MOC $(DEFINES) $$join(QMAKE_COMPILER_DEFINES, " -D", -D) $$incvar $$join(QMAKE_DEFAULT_INCDIRS, " -I", -I) $$QMAKE_MOC_OPTIONS
return($$RET)

View File

@ -22,6 +22,7 @@ QMAKE_CFLAGS_DEBUG = -O0 -g
QMAKE_CFLAGS_SHLIB = -fPIC -fno-jump-tables
QMAKE_CFLAGS_STATIC_LIB = $$QMAKE_CFLAGS_SHLIB
QMAKE_CFLAGS_YACC =
QMAKE_CFLAGS_ISYSTEM = -isystem
QMAKE_CFLAGS_THREAD = -D_REENTRANT
QMAKE_CFLAGS_SSE2 += -xSSE2

View File

@ -456,6 +456,8 @@ MakefileGenerator::init()
if (v["QMAKE_LINK_O_FLAG"].isEmpty())
v["QMAKE_LINK_O_FLAG"].append("-o ");
setSystemIncludes(v["QMAKE_DEFAULT_INCDIRS"]);
ProStringList &quc = v["QMAKE_EXTRA_COMPILERS"];
//make sure the COMPILERS are in the correct input/output chain order

View File

@ -345,6 +345,30 @@ bool QMakeSourceFileInfo::containsSourceFile(const QString &f, SourceFileType ty
return false;
}
bool QMakeSourceFileInfo::isSystemInclude(const QString &name)
{
if (QDir::isRelativePath(name)) {
// if we got a relative path here, it's either an -I flag with a relative path
// or an include file we couldn't locate. Either way, conclude it's not
// a system include.
return false;
}
for (int i = 0; i < systemIncludes.size(); ++i) {
// check if name is located inside the system include dir:
QDir systemDir(systemIncludes.at(i));
QString relativePath = systemDir.relativeFilePath(name);
// the relative path might be absolute if we're crossing drives on Windows
if (QDir::isAbsolutePath(relativePath) || relativePath.startsWith("../"))
continue;
debug_msg(5, "File/dir %s is in system dir %s, skipping",
qPrintable(name), qPrintable(systemIncludes.at(i)));
return true;
}
return false;
}
char *QMakeSourceFileInfo::getBuffer(int s) {
if(!spare_buffer || spare_buffer_size < s)
spare_buffer = (char *)realloc(spare_buffer, spare_buffer_size=s);

View File

@ -78,6 +78,7 @@ private:
SourceFiles *files, *includes;
bool files_changed;
QList<QMakeLocalFileName> depdirs;
QStringList systemIncludes;
//sleezy buffer code
char *spare_buffer;
@ -98,6 +99,7 @@ protected:
virtual QFileInfo findFileInfo(const QMakeLocalFileName &);
public:
QMakeSourceFileInfo(const QString &cachefile="");
virtual ~QMakeSourceFileInfo();
@ -108,11 +110,15 @@ public:
inline void setDependencyMode(DependencyMode mode) { dep_mode = mode; }
inline DependencyMode dependencyMode() const { return dep_mode; }
void setSystemIncludes(const ProStringList &list)
{ systemIncludes = list.toQStringList(); }
enum SourceFileType { TYPE_UNKNOWN, TYPE_C, TYPE_UI, TYPE_QRC };
enum SourceFileSeek { SEEK_DEPS=0x01, SEEK_MOCS=0x02 };
void addSourceFiles(const ProStringList &, uchar seek, SourceFileType type=TYPE_C);
void addSourceFile(const QString &, uchar seek, SourceFileType type=TYPE_C);
bool containsSourceFile(const QString &, SourceFileType type=TYPE_C);
bool isSystemInclude(const QString &);
int included(const QString &file);
QStringList dependencies(const QString &file);

View File

@ -125,10 +125,16 @@ UnixMakefileGenerator::writeMakeParts(QTextStream &t)
t << " -I" << pwd;
}
{
QString isystem = var("QMAKE_CFLAGS_ISYSTEM");
const ProStringList &incs = project->values("INCLUDEPATH");
for(int i = 0; i < incs.size(); ++i) {
ProString inc = escapeFilePath(incs.at(i));
if(!inc.isEmpty())
if (inc.isEmpty())
continue;
if (!isystem.isEmpty() && isSystemInclude(inc.toQString()))
t << ' ' << isystem << ' ' << inc;
else
t << " -I" << inc;
}
}

View File

@ -321,12 +321,18 @@ void MingwMakefileGenerator::writeIncPart(QTextStream &t)
t << "-I" << pwd << " ";
}
QString isystem = var("QMAKE_CFLAGS_ISYSTEM");
const ProStringList &incs = project->values("INCLUDEPATH");
for (ProStringList::ConstIterator incit = incs.begin(); incit != incs.end(); ++incit) {
QString inc = (*incit).toQString();
inc.replace(QRegExp("\\\\$"), "");
inc.replace(QRegExp("\""), "");
t << "-I" << quote << inc << quote << " ";
if (!isystem.isEmpty() && isSystemInclude(inc))
t << isystem << ' ';
else
t << "-I";
t << quote << inc << quote << " ";
}
t << "-I" << quote << specdir() << quote
<< endl;