From 0c0c04b4053d0298dff881a15ae64e6ff6d29f93 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Thu, 6 Sep 2012 13:51:37 +0200 Subject: [PATCH] Fix semantics of the src dir in the include search paths with MinGW This issue originates from https://bugs.webkit.org/show_bug.cgi?id=95736 Suppose we have main.cpp somedirectory/someheader.h -- which has #include "anotherheader.h" anotherheader.h With unix generator, the directory where main.cpp is located is included, unless no_include_pwd is set. Hence the look-up of anotherheader.h from within someheader.h will work. With MSVC this works because MSVC looks "in the directories of any previously opened include files in the reverse order in which they were opened." (from http://msdn.microsoft.com/en-us/library/36k2cdd4.aspx) Unfortunately the build breaks with MinGW, because it lacks support for including the source directory in the include search path just like the unix generator does. This patch adds the same functionality to the MinGW generator as well as an auto-test. Change-Id: Iea8bb06e34862c51b8fd4eca2ee26668e24a319a Reviewed-by: Qt Doc Bot Reviewed-by: Sergio Ahumada Reviewed-by: Jonathan Liu Reviewed-by: Oswald Buddenhagen --- qmake/generators/win32/mingw_make.cpp | 7 +++++++ .../tools/qmake/testdata/include_pwd/anotherheader.h | 2 ++ .../tools/qmake/testdata/include_pwd/include_pwd.pro | 4 ++++ tests/auto/tools/qmake/testdata/include_pwd/main.cpp | 6 ++++++ .../testdata/include_pwd/somedirectory/someheader.h | 1 + tests/auto/tools/qmake/tst_qmake.cpp | 9 +++++++++ 6 files changed, 29 insertions(+) create mode 100644 tests/auto/tools/qmake/testdata/include_pwd/anotherheader.h create mode 100644 tests/auto/tools/qmake/testdata/include_pwd/include_pwd.pro create mode 100644 tests/auto/tools/qmake/testdata/include_pwd/main.cpp create mode 100644 tests/auto/tools/qmake/testdata/include_pwd/somedirectory/someheader.h diff --git a/qmake/generators/win32/mingw_make.cpp b/qmake/generators/win32/mingw_make.cpp index a630d19f07..36772e60ac 100644 --- a/qmake/generators/win32/mingw_make.cpp +++ b/qmake/generators/win32/mingw_make.cpp @@ -320,6 +320,13 @@ void MingwMakefileGenerator::writeIncPart(QTextStream &t) { t << "INCPATH = "; + if (!project->isActiveConfig("no_include_pwd")) { + QString pwd = escapeFilePath(fileFixify(qmake_getpwd())); + if (pwd.isEmpty()) + pwd = "."; + t << "-I" << pwd << " "; + } + const ProStringList &incs = project->values("INCLUDEPATH"); for (ProStringList::ConstIterator incit = incs.begin(); incit != incs.end(); ++incit) { QString inc = (*incit).toQString(); diff --git a/tests/auto/tools/qmake/testdata/include_pwd/anotherheader.h b/tests/auto/tools/qmake/testdata/include_pwd/anotherheader.h new file mode 100644 index 0000000000..a3a63e26bf --- /dev/null +++ b/tests/auto/tools/qmake/testdata/include_pwd/anotherheader.h @@ -0,0 +1,2 @@ + +/* This file should be included indirectly through main.cpp */ diff --git a/tests/auto/tools/qmake/testdata/include_pwd/include_pwd.pro b/tests/auto/tools/qmake/testdata/include_pwd/include_pwd.pro new file mode 100644 index 0000000000..c00815f5b4 --- /dev/null +++ b/tests/auto/tools/qmake/testdata/include_pwd/include_pwd.pro @@ -0,0 +1,4 @@ +TEMPLATE = app +SOURCES = main.cpp +CONFIG -= debug_and_release_target +INCLUDEPATH += somedirectory diff --git a/tests/auto/tools/qmake/testdata/include_pwd/main.cpp b/tests/auto/tools/qmake/testdata/include_pwd/main.cpp new file mode 100644 index 0000000000..c98935f87d --- /dev/null +++ b/tests/auto/tools/qmake/testdata/include_pwd/main.cpp @@ -0,0 +1,6 @@ +#include "someheader.h" + +int main() +{ + return 0; +} diff --git a/tests/auto/tools/qmake/testdata/include_pwd/somedirectory/someheader.h b/tests/auto/tools/qmake/testdata/include_pwd/somedirectory/someheader.h new file mode 100644 index 0000000000..f977346945 --- /dev/null +++ b/tests/auto/tools/qmake/testdata/include_pwd/somedirectory/someheader.h @@ -0,0 +1 @@ +#include "anotherheader.h" diff --git a/tests/auto/tools/qmake/tst_qmake.cpp b/tests/auto/tools/qmake/tst_qmake.cpp index 54032ad750..b940e57543 100644 --- a/tests/auto/tools/qmake/tst_qmake.cpp +++ b/tests/auto/tools/qmake/tst_qmake.cpp @@ -76,6 +76,7 @@ private slots: void duplicateLibraryEntries(); void export_across_file_boundaries(); void include_dir(); + void include_pwd(); void install_files(); void install_depends(); void quotedfilenames(); @@ -320,6 +321,14 @@ void tst_qmake::include_dir() QVERIFY( test_compiler.makeDistClean( buildDir )); } +void tst_qmake::include_pwd() +{ + QString workDir = base_path + "/testdata/include_pwd"; + QVERIFY( test_compiler.qmake( workDir, "include_pwd" )); + QVERIFY( test_compiler.make( workDir )); + QVERIFY( test_compiler.makeDistClean( workDir )); +} + void tst_qmake::install_files() { QString workDir = base_path + "/testdata/shadow_files";