summaryrefslogtreecommitdiffstats
path: root/src/corelib/Qt5CoreConfigExtras.cmake.in
diff options
context:
space:
mode:
authorKevin Funk <kevin.funk@kdab.com>2015-11-02 09:41:01 +0100
committerKevin Funk <kfunk@kde.org>2015-12-28 22:39:58 +0000
commit9871c3d8bd71ab265d7394495a3a9f0c2963f6ab (patch)
treed383e053a27868f3c14bdbd1ac6b2d58314eab98 /src/corelib/Qt5CoreConfigExtras.cmake.in
parent959f09bbc5757bc42db603b2c085ad46fc12af96 (diff)
CMake: Add -fPIC to CXX flags only where necessary
Before this patch, Qt5Core_EXECUTABLE_COMPILE_FLAGS was populated with -fPIC unconditionally. This causes warnings on MSVC, since the compiler does not understand this flag. In fact, -fPIC is only required in case an older release of CMake is being used and the compiler is GCC 5.x (according to documentation), so let's really add it just in this case. Task-number: QTBUG-47942 Change-Id: I9d09b8b257a0647235d6d781ee5c023af34f8f88 Reviewed-by: Stephen Kelly <steveire@gmail.com>
Diffstat (limited to 'src/corelib/Qt5CoreConfigExtras.cmake.in')
-rw-r--r--src/corelib/Qt5CoreConfigExtras.cmake.in23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/corelib/Qt5CoreConfigExtras.cmake.in b/src/corelib/Qt5CoreConfigExtras.cmake.in
index 65fd1f9383..91a4eb619a 100644
--- a/src/corelib/Qt5CoreConfigExtras.cmake.in
+++ b/src/corelib/Qt5CoreConfigExtras.cmake.in
@@ -70,7 +70,14 @@ set(_qt5_corelib_extra_includes)
# Qt5_POSITION_INDEPENDENT_CODE variable is used in the # qt5_use_module
# macro to add it.
set(Qt5_POSITION_INDEPENDENT_CODE True)
-set(Qt5Core_EXECUTABLE_COMPILE_FLAGS \"-fPIC\")
+
+# On x86 and x86-64 systems with ELF binaries (especially Linux), due to
+# a new optimization in GCC 5.x in combination with a recent version of
+# GNU binutils, compiling Qt applications with -fPIE is no longer
+# enough.
+# Applications now need to be compiled with the -fPIC option if the Qt option
+# \"reduce relocations\" is active. For backward compatibility only, Qt accepts
+# the use of -fPIE for GCC 4.x versions.
if (CMAKE_VERSION VERSION_LESS 2.8.12
AND (NOT CMAKE_CXX_COMPILER_ID STREQUAL \"GNU\"
OR CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0))
@@ -79,6 +86,20 @@ else()
set_property(TARGET Qt5::Core APPEND PROPERTY INTERFACE_COMPILE_OPTIONS $$QMAKE_CXXFLAGS_APP)
endif()
+# Applications using qmake or cmake >= 2.8.12 as their build system will
+# adapt automatically. Applications using an older release of cmake in
+# combination with GCC 5.x need to change their CMakeLists.txt to add
+# Qt5Core_EXECUTABLE_COMPILE_FLAGS to CMAKE_CXX_FLAGS. In particular,
+# applications using cmake >= 2.8.9 and < 2.8.11 will continue to build
+# with the -fPIE option and invoke the special compatibility mode if using
+# GCC 4.x.
+set(Qt5Core_EXECUTABLE_COMPILE_FLAGS \"\")
+if (CMAKE_VERSION VERSION_LESS 2.8.12
+ AND (CMAKE_CXX_COMPILER_ID STREQUAL \"GNU\"
+ AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0))
+ set(Qt5Core_EXECUTABLE_COMPILE_FLAGS \"-fPIC\")
+endif()
+
!!IF !isEmpty(QT_NAMESPACE)
list(APPEND Qt5Core_DEFINITIONS -DQT_NAMESPACE=$$QT_NAMESPACE)
list(APPEND Qt5Core_COMPILE_DEFINITIONS QT_NAMESPACE=$$QT_NAMESPACE)