Determine the compiler's default include and lib directories at qmake time

This fixes a long-standing issue for Qt packages, where the
paths detected at configure time do not necessarily match the
paths on the user's machine. Hence they have been stripped
manually from qconfig.pri so far, preventing moc from resolving
some includes.

The same logic in configure is left alone for the time being,
since the paths there are also used to filter paths returned
by pg_config and mysql_config. I expect that this will
eventually be removed too in a bigger refactoring going on
right now in dev.

Asking the compiler for implicit paths only works for non-msvc
builds - that is, gcc, clang and icc fortunately have a
compatible way to retrieve the paths. MSVC works
solely on environment variables, which will be taken into
account by a separate patch.

[ChangeLog][qmake] The implicit compiler directories that
moc needs for resolving include files are now determined
when qmake runs. So far QMAKE_DEFAULT_INCDIR was determined
at configure time, which might be wrong for relocated
installations.

Task-number: QTBUG-52687
Change-Id: If0706e8c56a5aca2b6e777e79e90342c498726f3
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
This commit is contained in:
Kai Koehne 2016-05-02 17:09:11 +02:00 committed by Jani Heikkinen
parent 65ae3de2e1
commit efd2ea8ea7
3 changed files with 41 additions and 14 deletions

9
configure vendored
View File

@ -115,13 +115,6 @@ shellEscape()
echo "$@" | sed 's/ /\ /g' echo "$@" | sed 's/ /\ /g'
} }
shellQuoteLines()
{
# The call of the outer echo makes the shell word-split the output of
# the nested pipe, thus effectively converting newlines to spaces.
echo `echo "$1" | sed 's,^[^ ]* .*$,"&",'`
}
makeabs() makeabs()
{ {
local FILE="$1" local FILE="$1"
@ -7163,8 +7156,6 @@ host_build {
QT_TARGET_ARCH = $CFG_ARCH QT_TARGET_ARCH = $CFG_ARCH
} else { } else {
QT_ARCH = $CFG_ARCH QT_ARCH = $CFG_ARCH
QMAKE_DEFAULT_LIBDIRS = `shellQuoteLines "$DEFAULT_LIBDIRS"`
QMAKE_DEFAULT_INCDIRS = `shellQuoteLines "$DEFAULT_INCDIRS"`
} }
QT_CONFIG += $QT_CONFIG QT_CONFIG += $QT_CONFIG

View File

@ -24,3 +24,44 @@ contains(QT_CONFIG, c++11):lessThan(QT_COMPILER_STDCXX, 201103): CONFIG += c++11
} }
unset(today) unset(today)
} }
isEmpty(QMAKE_DEFAULT_INCDIRS):!host_build {
#
# Get default include and library paths from compiler
#
gcc {
equals(QMAKE_DIR_SEP, /) {
cmd_prefix = "LC_ALL=C"
cmd_suffix = "</dev/null >/dev/null"
} else {
cmd_prefix = "set LC_ALL=C&"
cmd_suffix = "<NUL >NUL"
}
output = $$system("$$cmd_prefix $$QMAKE_CXX $$QMAKE_CXXFLAGS -xc++ -E -v - 2>&1 $$cmd_suffix", lines)
add_includes = false
for (line, output) {
line ~= s/^ *// # remove leading spaces
contains(line, "LIBRARY_PATH=.*") {
line ~= s/^LIBRARY_PATH=// # remove leading LIBRARY_PATH=
paths = $$split(line, $$QMAKE_DIRLIST_SEP)
for (path, paths): \
QMAKE_DEFAULT_LIBDIRS += $$clean_path($$path)
} else: contains(line, "$${LITERAL_HASH}include <.*") { # #include <...> search starts here:
add_includes = true
} else: contains(line, "End of search list.*") {
add_includes = false
} else {
$$add_includes: QMAKE_DEFAULT_INCDIRS += $$clean_path($$line)
}
}
QMAKE_DEFAULT_LIBDIRS = $$unique(QMAKE_DEFAULT_LIBDIRS)
}
unix {
isEmpty(QMAKE_DEFAULT_INCDIRS): QMAKE_DEFAULT_INCDIRS = /usr/include /usr/local/include
isEmpty(QMAKE_DEFAULT_LIBDIRS): QMAKE_DEFAULT_LIBDIRS = /lib /usr/lib
}
!isEmpty(QMAKE_DEFAULT_INCDIRS): cache(QMAKE_DEFAULT_INCDIRS, set stash)
!isEmpty(QMAKE_DEFAULT_LIBDIRS): cache(QMAKE_DEFAULT_LIBDIRS, set stash)
}

View File

@ -3496,11 +3496,6 @@ void Configure::generateQConfigPri()
configStream << " QT_TARGET_ARCH = " << dictionary["QT_ARCH"] << endl; configStream << " QT_TARGET_ARCH = " << dictionary["QT_ARCH"] << endl;
configStream << "} else {" << endl; configStream << "} else {" << endl;
configStream << " QT_ARCH = " << dictionary["QT_ARCH"] << endl; configStream << " QT_ARCH = " << dictionary["QT_ARCH"] << endl;
if (dictionary.contains("XQMAKESPEC")) {
// FIXME: add detection
configStream << " QMAKE_DEFAULT_LIBDIRS = /lib /usr/lib" << endl;
configStream << " QMAKE_DEFAULT_INCDIRS = /usr/include /usr/local/include" << endl;
}
configStream << "}" << endl; configStream << "}" << endl;
configStream << "QT_CONFIG += " << qtConfig.join(' ') << endl; configStream << "QT_CONFIG += " << qtConfig.join(' ') << endl;