qt5base-lts/mkspecs/features/ltcg.prf
Thiago Macieira fe6f4b9ad7 Fix linking of sources without LTCG to a static lib with LTCG
Whenever a binary is created and linked against a static lib that was
compiled with LTCG, the final linking step requires the compiler flags
so that the pre-compiled data in the shared library can get properly
compiled.

This could happen for a static build of Qt with LTCG, but also happens
frequently for Qt's own build when linking regular libraries and
applications against QtBootstrap or QtPlatformSupport. The linking fails
when the target is a shared library (example: QtWaylandClient linking
against QtPlatformSupport).

The .prl file actually contains the "ltcg" flag, so the best solution
would actually be to process that flag there and add link_ltcg if any
dependent .prl has "ltcg", but I couldn't find out how to do that.

Change-Id: I4a75a14d1dcb8c2089a427285e25d5555df7d7d3
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
2014-12-01 21:33:31 +01:00

41 lines
1.5 KiB
Plaintext

CONFIG(release, debug|release) {
# We need fat object files when creating static libraries on some platforms
# so the linker will know to load a particular object from the library
# in the first place. With GCC, we have -ffat-lto-objects. MSVC
# seems to work just fine. For other compilers, we disable LTCG
# for static libraries.
msvc {
# Nothing to do
} else: gcc {
!clang:!intel_icc {
static|fat-lto {
QMAKE_CFLAGS_LTCG += -ffat-lto-objects
QMAKE_CXXFLAGS_LTCG += -ffat-lto-objects
} else {
QMAKE_CFLAGS_LTCG += -fno-fat-lto-objects
QMAKE_CXXFLAGS_LTCG += -fno-fat-lto-objects
}
linux {
# Get the number of online processors, like _SC_NPROCESSORS_ONLN
isEmpty(QMAKE_NPROCESSORS_ONLN) {
QMAKE_NPROCESSORS_ONLN = $$system("grep -c '^processor' /proc/cpuinfo 2>/dev/null || echo 1")
cache(QMAKE_NPROCESSORS_ONLN, set stash)
}
# Override LTO number of jobs
QMAKE_LFLAGS_LTCG -= -flto
QMAKE_LFLAGS_LTCG += -flto=$$QMAKE_NPROCESSORS_ONLN
}
} else: static {
QMAKE_CFLAGS_LTCG =
QMAKE_CXXFLAGS_LTCG =
QMAKE_LFLAGS_LTCG =
}
}
load(link_ltcg)
QMAKE_CFLAGS *= $$QMAKE_CFLAGS_LTCG
QMAKE_CXXFLAGS *= $$QMAKE_CXXFLAGS_LTCG
QMAKE_LFLAGS *= $$QMAKE_LFLAGS_LTCG
}