Only add -fPIC flags for compilers known to require it.

Commit 083c9269 (Try to ensure that -fPIC is used in CMake
builds, 2015-05-11) added a raw -fPIC to the INTERFACE_COMPILE_OPTIONS
of Qt5::Core, which affects all consuming compilers.

Use the qmake variable $$QMAKE_CXXFLAGS_APP instead, which at least
currently contains only the -fPIC variable or harmlessly expands to
nothing.  If the content of that qmake variable changes in the
future, a $$QMAKE_CXXFLAGS_APP_PIC variable should be extracted in
qmake and used here.

Don't use the POSITION_INDEPENDENT_CODE feature of CMake.  That adds
the -fPIE flag for executables, which is explicitly what qglobal.h
forbids since commit 3eca75de (Make qglobal.h complain if you
use -fPIE, 2015-05-11).  The current behavior of that CMake feature is
tracked here:

 http://public.kitware.com/Bug/view.php?id=15570

Change-Id: I5c5bcc40fe4b310b55a681a3505f45c50adfa054
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
This commit is contained in:
Stephen Kelly 2015-05-25 14:55:38 +02:00 committed by Jani Heikkinen
parent 7a4f3645f4
commit 8829ce67d8
2 changed files with 1 additions and 6 deletions

View File

@ -71,8 +71,7 @@ set(_qt5_corelib_extra_includes)
# macro to add it.
set(Qt5_POSITION_INDEPENDENT_CODE True)
set(Qt5Core_EXECUTABLE_COMPILE_FLAGS \"-fPIC\")
set_property(TARGET Qt5::Core PROPERTY INTERFACE_POSITION_INDEPENDENT_CODE \"ON\")
set_property(TARGET Qt5::Core APPEND PROPERTY INTERFACE_COMPILE_OPTIONS ${Qt5Core_EXECUTABLE_COMPILE_FLAGS})
set_property(TARGET Qt5::Core APPEND PROPERTY INTERFACE_COMPILE_OPTIONS $$QMAKE_CXXFLAGS_APP)
!!IF !isEmpty(QT_NAMESPACE)
list(APPEND Qt5Core_DEFINITIONS -DQT_NAMESPACE=$$QT_NAMESPACE)

View File

@ -281,10 +281,6 @@ if (NOT CMAKE_VERSION VERSION_LESS 2.8.9)
set_property(TARGET ${_target} APPEND PROPERTY COMPILE_DEFINITIONS_RELEASE QT_NO_DEBUG)
set_property(TARGET ${_target} APPEND PROPERTY COMPILE_DEFINITIONS_RELWITHDEBINFO QT_NO_DEBUG)
set_property(TARGET ${_target} APPEND PROPERTY COMPILE_DEFINITIONS_MINSIZEREL QT_NO_DEBUG)
if (Qt5_POSITION_INDEPENDENT_CODE)
set_property(TARGET ${_target} PROPERTY POSITION_INDEPENDENT_CODE ${Qt5_POSITION_INDEPENDENT_CODE})
endif()
endforeach()
endmacro()
endif()