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>
This commit is contained in:
parent
959f09bbc5
commit
9871c3d8bd
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user