Skip to content

Commit

Permalink
Revert some changes in light of GCC 4 -fPIE reversal
Browse files Browse the repository at this point in the history
The -fPIE option is now accepted when using GCC 4, which means it
is available for backward compatibility for clients using
CMake 2.8.11 or older which makes use of the
POSITION_INDEPENDENT_CODE feature.

Conditionally use that feature for old versions of cmake with
GCC 4. Restore the tests for those versions, and clarify the
situation in the ChangeLog.

Change-Id: I5a06b155dda7db559d86841a2b34fd8ed95acbd0
Reviewed-by: Thiago Macieira <[email protected]>
  • Loading branch information
steveire authored and thiagomacieira committed May 29, 2015
1 parent 95b6c4f commit e3983c8
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 12 deletions.
20 changes: 13 additions & 7 deletions dist/changes-5.4.2
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,20 @@ information about a particular change.
- 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
Qt's option "reduce relocations" is active. Note that Clang is known
to generate incompatible code even with -fPIC if the -flto option is
active.
enough with GCC 5.x. Applications now need to be compiled with
the -fPIC option if Qt's option "reduce relocations" is active. For
backward compatibility only, Qt accepts the use of -fPIE for GCC 4.x
versions.
Note that Clang is known to generate incompatible code even with -fPIC if
the -flto option is active.
Applications using qmake or cmake >= 2.8.12 as their build system will
adapt automatically. Applications using an older release of cmake need to
change their CMakeLists.txt to add Qt5Core_EXECUTABLE_COMPILE_FLAGS to
CMAKE_CXX_FLAGS.
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.


****************************************************************************
* Library *
Expand Down
8 changes: 7 additions & 1 deletion src/corelib/Qt5CoreConfigExtras.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ 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 APPEND PROPERTY INTERFACE_COMPILE_OPTIONS $$QMAKE_CXXFLAGS_APP)
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))
set_property(TARGET Qt5::Core APPEND PROPERTY INTERFACE_POSITION_INDEPENDENT_CODE \"ON\")
else()
set_property(TARGET Qt5::Core APPEND PROPERTY INTERFACE_COMPILE_OPTIONS $$QMAKE_CXXFLAGS_APP)
endif()

!!IF !isEmpty(QT_NAMESPACE)
list(APPEND Qt5Core_DEFINITIONS -DQT_NAMESPACE=$$QT_NAMESPACE)
Expand Down
6 changes: 6 additions & 0 deletions src/corelib/Qt5CoreMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,12 @@ 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
AND (CMAKE_VERSION VERSION_LESS 2.8.12
AND (NOT CMAKE_CXX_COMPILER_ID STREQUAL \"GNU\"
OR CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)))
set_property(TARGET ${_target} PROPERTY POSITION_INDEPENDENT_CODE ${Qt5_POSITION_INDEPENDENT_CODE})
endif()
endforeach()
endmacro()
endif()
5 changes: 4 additions & 1 deletion tests/auto/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,11 @@ if (QT_WITH_ANGLE OR (NOT WIN32 AND NOT APPLE AND NOT NO_EGL))
endif()
expect_pass(test_opengl_lib)

if (NOT CMAKE_VERSION VERSION_LESS 2.8.12)
if (NOT CMAKE_VERSION VERSION_LESS 2.8.11)
expect_pass(test_interface)
endif()

if (NOT CMAKE_VERSION VERSION_LESS 2.8.12)
expect_pass(test_interface_link_libraries)
expect_pass(test_moc_macro_target)
endif()
2 changes: 1 addition & 1 deletion tests/auto/cmake/test_interface/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

cmake_minimum_required(VERSION 2.8.12)
cmake_minimum_required(VERSION 2.8.11)

project(test_interface)

Expand Down
2 changes: 0 additions & 2 deletions tests/auto/cmake/test_use_modules_function/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,5 @@ add_executable(three three.cpp)

find_package(Qt5Core)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")

qt5_use_modules(two Test)
qt5_use_modules(three Gui Test)

0 comments on commit e3983c8

Please sign in to comment.