From 0b144bc76a368ecc6c5c1121a1b51e888a0621ac Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 9 Dec 2013 10:56:31 -0800 Subject: 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 --- mkspecs/common/clang.conf | 1 + mkspecs/common/gcc-base.conf | 1 + mkspecs/features/moc.prf | 3 ++- mkspecs/linux-icc/qmake.conf | 1 + qmake/generators/makefile.cpp | 2 ++ qmake/generators/makefiledeps.cpp | 24 ++++++++++++++++++++++++ qmake/generators/makefiledeps.h | 6 ++++++ qmake/generators/unix/unixmake2.cpp | 8 +++++++- qmake/generators/win32/mingw_make.cpp | 8 +++++++- 9 files changed, 51 insertions(+), 3 deletions(-) diff --git a/mkspecs/common/clang.conf b/mkspecs/common/clang.conf index ace2496f10..d58b44b295 100644 --- a/mkspecs/common/clang.conf +++ b/mkspecs/common/clang.conf @@ -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} diff --git a/mkspecs/common/gcc-base.conf b/mkspecs/common/gcc-base.conf index b1f2ad4979..e3e72741ab 100644 --- a/mkspecs/common/gcc-base.conf +++ b/mkspecs/common/gcc-base.conf @@ -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 diff --git a/mkspecs/features/moc.prf b/mkspecs/features/moc.prf index b688f81367..f60e7b54e3 100644 --- a/mkspecs/features/moc.prf +++ b/mkspecs/features/moc.prf @@ -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) diff --git a/mkspecs/linux-icc/qmake.conf b/mkspecs/linux-icc/qmake.conf index ee5f1f0ea4..d0ca604f07 100644 --- a/mkspecs/linux-icc/qmake.conf +++ b/mkspecs/linux-icc/qmake.conf @@ -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 diff --git a/qmake/generators/makefile.cpp b/qmake/generators/makefile.cpp index ac8bd8f9a7..83d38d1b14 100644 --- a/qmake/generators/makefile.cpp +++ b/qmake/generators/makefile.cpp @@ -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 diff --git a/qmake/generators/makefiledeps.cpp b/qmake/generators/makefiledeps.cpp index df37957f9b..e1fb42e0a4 100644 --- a/qmake/generators/makefiledeps.cpp +++ b/qmake/generators/makefiledeps.cpp @@ -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); diff --git a/qmake/generators/makefiledeps.h b/qmake/generators/makefiledeps.h index ba55c36998..516abd4afd 100644 --- a/qmake/generators/makefiledeps.h +++ b/qmake/generators/makefiledeps.h @@ -78,6 +78,7 @@ private: SourceFiles *files, *includes; bool files_changed; QList 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); diff --git a/qmake/generators/unix/unixmake2.cpp b/qmake/generators/unix/unixmake2.cpp index 1444161ca9..8e18f69c03 100644 --- a/qmake/generators/unix/unixmake2.cpp +++ b/qmake/generators/unix/unixmake2.cpp @@ -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; } } diff --git a/qmake/generators/win32/mingw_make.cpp b/qmake/generators/win32/mingw_make.cpp index 1aeaef1d23..6d5764f59c 100644 --- a/qmake/generators/win32/mingw_make.cpp +++ b/qmake/generators/win32/mingw_make.cpp @@ -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; -- cgit v1.2.3