From 310bf3f57c49ad0d05e479e088a62b06e7616ba8 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 28 Sep 2016 18:54:29 +0200 Subject: [PATCH] Make sure flags from library detections go to the right places Split them and add -I flags to INCLUDEPATH and -D flags to DEFINES. Anything else gets reported as a problem and dropped. This has the benefit that qmake will automatically use -isystem for those paths if they lie in a system directory. As a consequence of that, we won't get any warnings in headers located there. There are multiple cases of glib, gtk, etc. headers producing warnings (such as enums ending in comma). This does not fix warnings produced by use of macros declared in system headers, though... Done-with: Oswald Buddenhagen Change-Id: I4b844cb518dbae5ea499811221f9015af985110a Reviewed-by: Thiago Macieira Reviewed-by: Oswald Buddenhagen --- mkspecs/common/linux.conf | 1 - mkspecs/features/qmake_use.prf | 9 ++++---- mkspecs/features/qt_configure.prf | 35 ++++++++++++++++++++----------- src/sql/configure.pri | 6 ------ 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/mkspecs/common/linux.conf b/mkspecs/common/linux.conf index 1a39c88425..13916a5646 100644 --- a/mkspecs/common/linux.conf +++ b/mkspecs/common/linux.conf @@ -36,7 +36,6 @@ QMAKE_LIBS_OPENGL_ES2 = -lGLESv2 QMAKE_LIBS_OPENVG = -lOpenVG QMAKE_LIBS_THREAD = -lpthread -QMAKE_CFLAGS_WAYLAND = QMAKE_INCDIR_WAYLAND = QMAKE_LIBS_WAYLAND_CLIENT = -lwayland-client QMAKE_LIBS_WAYLAND_SERVER = -lwayland-server diff --git a/mkspecs/features/qmake_use.prf b/mkspecs/features/qmake_use.prf index a8e2e6c417..81b841d457 100644 --- a/mkspecs/features/qmake_use.prf +++ b/mkspecs/features/qmake_use.prf @@ -10,16 +10,17 @@ for(ever) { else: \ libs = $$eval(QMAKE_LIBS_$${nu}_RELEASE) libs += $$eval(QMAKE_LIBS_$$nu) - cflags = $$eval(QMAKE_CFLAGS_$${nu}) + defines = $$eval(QMAKE_DEFINES_$${nu}) + includes = $$eval(QMAKE_INCDIR_$${nu}) - isEmpty(libs):isEmpty(cflags): \ + isEmpty(libs):isEmpty(defines):isEmpty(includes): \ error("Library '$$name' is not defined.") !contains(use, nolink): \ LIBS$${suffix} += $$libs !contains(use, linkonly) { - QMAKE_CFLAGS += $$cflags - QMAKE_CXXFLAGS += $$cflags + DEFINES += $$defines + INCLUDEPATH += $$includes } } !isEmpty(suffix): break() diff --git a/mkspecs/features/qt_configure.prf b/mkspecs/features/qt_configure.prf index 58e0b1c88e..7f575b8a1b 100644 --- a/mkspecs/features/qt_configure.prf +++ b/mkspecs/features/qt_configure.prf @@ -475,8 +475,6 @@ defineTest(qtConfLibrary_inline) { !isEmpty(prefix) { $${1}.includedir = $$prefix/include export($${1}.includedir) - $${1}.cflags = -I$$prefix/include - export($${1}.cflags) $${1}.libs = "-L$$prefix/lib $$eval($${1}.libs)" export($${1}.libs) } @@ -493,8 +491,6 @@ defineTest(qtConfLibrary_makeSpec) { $${1}.includedir = "$$val_escape(QMAKE_INCDIR_$$spec)" export($${1}.includedir) - $${1}.cflags = "$$val_escape(QMAKE_CFLAGS_$$spec)" - export($${1}.cflags) libs = for (l, QMAKE_LIBDIR_$$spec): \ libs += -L$$l @@ -522,15 +518,8 @@ defineTest(qtConfLibrary_pkgConfig) { qtRunLoggedCommand("$$pkg_config --modversion $$args", version)|return(false) qtRunLoggedCommand("$$pkg_config --libs-only-L --libs-only-l $$args", $${1}.libs)|return(false) qtRunLoggedCommand("$$pkg_config --cflags $$args", $${1}.cflags)|return(false) - qtRunLoggedCommand("$$pkg_config --cflags-only-I $$args", includes)|return(false) - eval(includes = $$includes) - includes ~= s/^-I//g - $${1}.includedir = "$$val_escape(includes)" version ~= s/[^0-9.].*$// $${1}.version = $$first(version) - export($${1}.libs) - export($${1}.cflags) - export($${1}.includedir) export($${1}.version) return(true) } @@ -562,6 +551,9 @@ defineReplace(qtConfLibraryArgs) { includedir = $$eval($${1}.includedir) !isEmpty(includedir): \ qmake_args += $$system_quote(INCLUDEPATH *= $$includedir) + cflags = $$eval($${1}.cflags) + !isEmpty(cflags): \ + qmake_args += $$system_quote(QMAKE_CFLAGS += $$cflags) $$system_quote(QMAKE_CXXFLAGS += $$cflags) return($$qmake_args) } @@ -588,12 +580,31 @@ defineTest(qtConfExportLibrary) { eval(includes = $$eval($${1}.includedir)) version = $$eval($${1}.version) + # Split $$cflags into stuff that goes into DEFINES, INCLUDEPATH, and other stuff. + defines = + ignored = + for (i, cflags) { + contains(i, "-I.*") { + i ~= s/^-I// + includes += $$i + } else: contains(i, "-D.*") { + i ~= s/^-D// + defines += $$i + } else { + # Sometimes, pkg-config files or *-config scripts include other flags + # we really don't need and shouldn't add (pg_config is really bad). + ignored += $$i + } + } + !isEmpty(ignored): \ + qtConfAddNote("Dropped compiler flags '$$ignored' when detecting library '$$2'.") + NAME = $$upper($$2) !isEmpty(libs): qtConfOutputVar(assign, $$output, QMAKE_LIBS_$$NAME, $$libs) for (b, $${1}.builds._KEYS_): \ qtConfOutputVar(assign, $$output, QMAKE_LIBS_$${NAME}_$$upper($$b), \ $$eval($${1}.builds.$${b})) - !isEmpty(cflags): qtConfOutputVar(assign, $$output, QMAKE_CFLAGS_$$NAME, $$cflags) + !isEmpty(defines): qtConfOutputVar(assign, $$output, QMAKE_DEFINES_$$NAME, $$defines) !isEmpty(includes): qtConfOutputVar(assign, $$output, QMAKE_INCDIR_$$NAME, $$includes) !isEmpty(version) { qtConfOutputVar(assign, $$output, QMAKE_$${NAME}_VERSION, $$version) diff --git a/src/sql/configure.pri b/src/sql/configure.pri index 948808f4f7..1d8847b4bc 100644 --- a/src/sql/configure.pri +++ b/src/sql/configure.pri @@ -22,11 +22,8 @@ defineTest(qtConfLibrary_psqlConfig) { $${1}.libs = "$$val_escape(libs)" includedir -= $$QMAKE_DEFAULT_INCDIRS $${1}.includedir = "$$val_escape(includedir)" - !isEmpty(includedir): \ - $${1}.cflags = "-I$$val_escape(includedir)" export($${1}.libs) export($${1}.includedir) - export($${1}.cflags) return(true) } return(false) @@ -65,11 +62,8 @@ defineTest(qtConfLibrary_mysqlConfig) { includedir ~= s/^-I//g includedir -= $$QMAKE_DEFAULT_INCDIRS $${1}.includedir = "$$val_escape(includedir)" - !isEmpty(includedir): \ - $${1}.cflags = "-I$$val_escape(includedir)" export($${1}.libs) export($${1}.includedir) - export($${1}.cflags) return(true) } return(false)