Fix detection of QMAKE_DEFAULT_LIBDIRS with Clang under Linux

With 4183475080, Qt fails to build if
qmake is unable to detect the compiler's default include and
library search paths. Clang on non-Darwin systems was missing working
code for the detection.

Unlike GCC, Clang on its own does not print the library search paths
when called with the -v option.

On Darwin, the -Wl,-v option will reach ld64, which will print those paths.
However, neither GNU ld nor gold will print anything useful with just
-v. GNU ld has a --verbose option that does print some search paths, but
those are not the ones used when ld is invoked (via collect2) by GCC or
Clang, so it can't be used.

To make Clang print its library search paths one can use
-print-search-dirs, which however doesn't print include search paths. So
amend the existing code in order to make a second call to clang on
non-Darwin systems. This second call is used for library path detection,
and fixes the build on non-Darwin (tested on Linux).

Change-Id: Ic858f908ee1a2e0eb307abb074daee0ded38abd5
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
This commit is contained in:
Giuseppe D'Angelo 2017-07-04 00:56:38 +02:00
parent f2db946fa4
commit 353fb118c3

View File

@ -111,6 +111,26 @@ isEmpty($${target_prefix}.INCDIRS) {
}
}
}
!darwin:clang {
# Clang on a non-Apple system (that is, a system without ld64 -- say, with GNU ld
# or gold under Linux) will not print any library search path. Need to use another
# invocation with different options (which in turn doesn't print include search
# paths, so it can't just be used in place of the above code).
# What's more, -print-search-dirs can't be used on clang on Apple because it
# won't print all the library paths (only the clang-internal ones).
output = $$system("$$cmd_prefix $$QMAKE_CXX -print-search-dirs", lines, ec)
!equals(ec, 0): \
error("Cannot run compiler '$$QMAKE_CXX'. Maybe you forgot to setup the environment?")
for (line, output) {
contains(line, "^libraries: .*") {
line ~= s,^libraries: ,,
paths = $$split(line, $$QMAKE_DIRLIST_SEP)
for (path, paths): \
QMAKE_DEFAULT_LIBDIRS += $$clean_path($$replace(path, ^=, $$[SYSROOT]))
}
}
}
isEmpty(QMAKE_DEFAULT_LIBDIRS)|isEmpty(QMAKE_DEFAULT_INCDIRS): \
!integrity: \
error("failed to parse default search paths from compiler output")