Add configure flag to optimize Qt for size

Adds default off configure flag to use compiler optimizations
for size instead of the default speed/size trade-off.

Change-Id: I36702064ef2cc743d2d03a386adf5cefd5371b6e
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
This commit is contained in:
Allan Sandfeld Jensen 2017-04-07 15:49:10 +02:00 committed by Simon Hausmann
parent 425986acf3
commit dd03817ab6
7 changed files with 35 additions and 5 deletions

View File

@ -83,6 +83,7 @@ Build options:
debugging turned on [yes] (Apple and Windows only)
-optimize-debug ...... Enable debug-friendly optimizations in debug builds
[auto] (Not supported with MSVC)
-optimize-size ....... Optimize release builds for size instead of speed [no]
-optimized-tools ..... Build optimized host tools even in debug build [no]
-force-debug-info .... Create symbol files for release builds [no]
-separate-debug-info . Split off debug information to separate files [no]

View File

@ -93,6 +93,7 @@
"nomake": { "type": "addString", "values": [ "examples", "tests", "tools" ] },
"opensource": { "type": "void", "name": "commercial", "value": "no" },
"optimize-debug": { "type": "boolean", "name": "optimize_debug" },
"optimize-size": { "type": "boolean", "name": "optimize_size" },
"optimized-qmake": { "type": "boolean", "name": "release_tools" },
"optimized-tools": { "type": "boolean", "name": "release_tools" },
"pch": { "type": "boolean", "name": "precompile_header" },
@ -485,6 +486,12 @@
"condition": "!config.msvc && (features.debug || features.debug_and_release) && tests.optimize_debug",
"output": [ "privateConfig" ]
},
"optimize_size": {
"label": "Optimize release build for size",
"autoDetect": false,
"condition": "!features.debug || features.debug_and_release",
"output": [ "privateConfig" ]
},
"architecture": {
"label": "Architecture",
"output": [ "architecture" ]
@ -1090,6 +1097,11 @@ Configure with '-qreal float' to create a build that is binary-compatible with 5
"args": "optimize_debug",
"condition": "!config.msvc && (features.debug || features.debug_and_release)"
},
{
"type": "feature",
"args": "optimize_size",
"condition": "!features.debug || features.debug_and_release"
},
"shared",
{
"message": "Using C++ standard",

View File

@ -34,6 +34,7 @@
QMAKE_CFLAGS_OPTIMIZE = -O2
QMAKE_CFLAGS_OPTIMIZE_FULL = -O3
QMAKE_CFLAGS_OPTIMIZE_DEBUG = -Og
QMAKE_CFLAGS_OPTIMIZE_SIZE = -Os
QMAKE_CFLAGS += -pipe
QMAKE_CFLAGS_DEPS += -M

View File

@ -19,6 +19,9 @@ contains(QMAKE_TARGET.arch, x86_64) {
QMAKE_COMPILER_DEFINES += _WIN64
}
QMAKE_CFLAGS_OPTIMIZE = -O2
QMAKE_CFLAGS_OPTIMIZE_SIZE = -O1
QMAKE_CC = cl
QMAKE_LEX = flex
QMAKE_LEXFLAGS =
@ -27,8 +30,8 @@ QMAKE_YACCFLAGS = -d
QMAKE_CFLAGS = -nologo -Zc:wchar_t
QMAKE_CFLAGS_WARN_ON = -W3
QMAKE_CFLAGS_WARN_OFF = -W0
QMAKE_CFLAGS_RELEASE = -O2 -MD
QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MD -Zi
QMAKE_CFLAGS_RELEASE = $$QMAKE_CFLAGS_OPTIMIZE -MD
QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += $$QMAKE_CFLAGS_OPTIMIZE -MD -Zi
QMAKE_CFLAGS_DEBUG = -Zi -MDd
QMAKE_CFLAGS_YACC =
QMAKE_CFLAGS_LTCG = -GL

View File

@ -38,7 +38,14 @@ force_debug_info {
QMAKE_LFLAGS_RELEASE = $$QMAKE_LFLAGS_RELEASE_WITH_DEBUGINFO
}
optimize_full {
optimize_size {
!isEmpty(QMAKE_CFLAGS_OPTIMIZE):!isEmpty(QMAKE_CFLAGS_OPTIMIZE_SIZE) {
QMAKE_CFLAGS_RELEASE -= $$QMAKE_CFLAGS_OPTIMIZE
QMAKE_CXXFLAGS_RELEASE -= $$QMAKE_CFLAGS_OPTIMIZE
QMAKE_CFLAGS_RELEASE += $$QMAKE_CFLAGS_OPTIMIZE_SIZE
QMAKE_CXXFLAGS_RELEASE += $$QMAKE_CFLAGS_OPTIMIZE_SIZE
}
} else: optimize_full {
!isEmpty(QMAKE_CFLAGS_OPTIMIZE):!isEmpty(QMAKE_CFLAGS_OPTIMIZE_FULL) {
QMAKE_CFLAGS_RELEASE -= $$QMAKE_CFLAGS_OPTIMIZE
QMAKE_CXXFLAGS_RELEASE -= $$QMAKE_CFLAGS_OPTIMIZE

View File

@ -6,6 +6,9 @@ MAKEFILE_GENERATOR = UNIX
QMAKE_COMPILER = gcc intel_icc # icc pretends to be gcc
QMAKE_CFLAGS_OPTIMIZE = -O2
QMAKE_CFLAGS_OPTIMIZE_SIZE = -Os
QMAKE_CC = icc
QMAKE_LEX = flex
QMAKE_LEXFLAGS =
@ -16,7 +19,7 @@ QMAKE_CFLAGS_APP = -fPIC
QMAKE_CFLAGS_DEPS = -M
QMAKE_CFLAGS_WARN_ON = -w1 -Wall -Wcheck -wd1572,873,2259,2261,3373
QMAKE_CFLAGS_WARN_OFF = -w
QMAKE_CFLAGS_RELEASE = -O2
QMAKE_CFLAGS_RELEASE = $$QMAKE_CFLAGS_OPTIMIZE
QMAKE_CFLAGS_DEBUG = -O0 -g
QMAKE_CFLAGS_SHLIB = -fPIC
QMAKE_CFLAGS_STATIC_LIB = $$QMAKE_CFLAGS_SHLIB

View File

@ -11,12 +11,15 @@ QMAKE_COMPILER_DEFINES += __APPLE__ __GNUC__
QMAKE_COMPILER = gcc clang intel_icc # icc pretends to be gcc and clang
QMAKE_CFLAGS_OPTIMIZE = -O2
QMAKE_CFLAGS_OPTIMIZE_SIZE = -Os
QMAKE_CC = icc
QMAKE_CFLAGS =
QMAKE_CFLAGS_DEPS = -M
QMAKE_CFLAGS_WARN_ON = -w1 -Wcheck -wd654,1572,411,873,1125,2259,2261,3280,3373
QMAKE_CFLAGS_WARN_OFF = -w
QMAKE_CFLAGS_RELEASE = -O2
QMAKE_CFLAGS_RELEASE = $$QMAKE_CFLAGS_OPTIMIZE
QMAKE_CFLAGS_DEBUG = -g -O0
QMAKE_CFLAGS_SHLIB = -fPIC
QMAKE_CFLAGS_STATIC_LIB = $$QMAKE_CFLAGS_SHLIB