summaryrefslogtreecommitdiffstats
path: root/mkspecs/features/ltcg.prf
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2014-06-26 14:56:06 -0700
committerhjk <hjk121@nokiamail.com>2014-07-23 11:12:02 +0200
commit1bd27f24fb7f7d82f4b67cffe43e0af644709106 (patch)
tree4f35d7ed8bb0a9e5f7a4381e0b09f69414d8f9d5 /mkspecs/features/ltcg.prf
parent849d1fece1da7136911464bc47439b4126145440 (diff)
Add link-time optimization support for Clang, GCC and ICC
GCC currently requires fat object files for static libraries, since the linker would otherwise not load the .o file from the archive at all and the linking would fail with a lot of undefined references. Clang on Linux also needs this, but it has no equivalent flag, so enabling LTCG for Clang on static libraries will result in linker error. This commit does not add support for enabling it in configure. It can be enabled on a per-project basis by doing CONFIG += ltcg or by passing -config ltcg to qmake's command-line. Change-Id: I52cf99f1ed9f1701e23a3b457ba3502fd28126ce Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
Diffstat (limited to 'mkspecs/features/ltcg.prf')
-rw-r--r--mkspecs/features/ltcg.prf54
1 files changed, 54 insertions, 0 deletions
diff --git a/mkspecs/features/ltcg.prf b/mkspecs/features/ltcg.prf
new file mode 100644
index 0000000000..b418135014
--- /dev/null
+++ b/mkspecs/features/ltcg.prf
@@ -0,0 +1,54 @@
+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 =
+ }
+
+ # When doing link-time code generation, we need to pass the compiler
+ # flags during linking stage too. This file is processed after
+ # default_post.prf, so the QMAKE_CXXFLAGS already contains
+ # QMAKE_CXXFLAGS_DEBUG or _RELEASE.
+ use_c_linker {
+ # use_c_linker.prf is in effect, use the C flags
+ QMAKE_LFLAGS_LTCG += $$QMAKE_CFLAGS $$QMAKE_CFLAGS_LTCG
+ QMAKE_LFLAGS_APP += $$QMAKE_CFLAGS_APP
+ QMAKE_LFLAGS_SHLIB += $$QMAKE_CFLAGS_SHLIB
+ } else {
+ QMAKE_LFLAGS_LTCG = $$QMAKE_CXXFLAGS $$QMAKE_LFLAGS_LTCG
+ QMAKE_LFLAGS_APP += $$QMAKE_CXXFLAGS_APP
+ QMAKE_LFLAGS_SHLIB += $$QMAKE_CXXFLAGS_SHLIB
+ }
+ }
+
+ QMAKE_CFLAGS *= $$QMAKE_CFLAGS_LTCG
+ QMAKE_CXXFLAGS *= $$QMAKE_CXXFLAGS_LTCG
+ QMAKE_LFLAGS *= $$QMAKE_LFLAGS_LTCG
+}