From 361cd9f9b2222ecde33f909c53d7574046a247b6 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 21 Feb 2012 12:06:54 +0100 Subject: [PATCH] Give the compile flags an EXECUTABLE_ prefix. The fPIE flag should only be used with executables. Change-Id: If799ae4a7fe2492af3aac67651659a52d365024a Reviewed-by: Alexander Neundorf Reviewed-by: Stephen Kelly --- mkspecs/cmake/Qt5BasicConfig.cmake.in | 4 ++++ src/corelib/Qt5CoreConfigExtras.cmake.in | 2 +- tests/manual/cmake/fail4/CMakeLists.txt | 2 ++ tests/manual/cmake/fail5/CMakeLists.txt | 2 ++ .../cmake/pass(needsquoting)6/CMakeLists.txt | 2 ++ tests/manual/cmake/pass1/CMakeLists.txt | 18 +++++++++++++++++- tests/manual/cmake/pass2/CMakeLists.txt | 2 ++ tests/manual/cmake/pass3/CMakeLists.txt | 2 ++ tests/manual/cmake/pass7/CMakeLists.txt | 2 ++ 9 files changed, 34 insertions(+), 2 deletions(-) diff --git a/mkspecs/cmake/Qt5BasicConfig.cmake.in b/mkspecs/cmake/Qt5BasicConfig.cmake.in index 77d1f5dbf3..b3d33d62d1 100644 --- a/mkspecs/cmake/Qt5BasicConfig.cmake.in +++ b/mkspecs/cmake/Qt5BasicConfig.cmake.in @@ -21,10 +21,14 @@ foreach(_module_dep ${_Qt5_MODULE_DEPENDENCIES}) list(APPEND Qt5$${CMAKE_MODULE_NAME}_INCLUDE_DIRS ${Qt5${_module_dep}_INCLUDE_DIRS}) list(APPEND Qt5$${CMAKE_MODULE_NAME}_DEFINITIONS ${Qt5${_module_dep}_DEFINITIONS}) list(APPEND Qt5$${CMAKE_MODULE_NAME}_COMPILE_DEFINITIONS ${Qt5${_module_dep}_COMPILE_DEFINITIONS}) + list(APPEND Qt5$${CMAKE_MODULE_NAME}_EXECUTABLE_COMPILE_FLAGS ${Qt5${_module_dep}_EXECUTABLE_COMPILE_FLAGS}) endforeach() list(REMOVE_DUPLICATES Qt5$${CMAKE_MODULE_NAME}_INCLUDE_DIRS) list(REMOVE_DUPLICATES Qt5$${CMAKE_MODULE_NAME}_DEFINITIONS) list(REMOVE_DUPLICATES Qt5$${CMAKE_MODULE_NAME}_COMPILE_DEFINITIONS) +if (Qt5$${CMAKE_MODULE_NAME}_EXECUTABLE_COMPILE_FLAGS) + list(REMOVE_DUPLICATES Qt5$${CMAKE_MODULE_NAME}_EXECUTABLE_COMPILE_FLAGS) +endif() if (NOT _Qt5$${CMAKE_MODULE_NAME}_target) set(_Qt5$${CMAKE_MODULE_NAME}_target 1) diff --git a/src/corelib/Qt5CoreConfigExtras.cmake.in b/src/corelib/Qt5CoreConfigExtras.cmake.in index 440d5e92bb..37af42d6bd 100644 --- a/src/corelib/Qt5CoreConfigExtras.cmake.in +++ b/src/corelib/Qt5CoreConfigExtras.cmake.in @@ -9,7 +9,7 @@ set(QT_RCC_EXECUTABLE \"${_qt5_corelib_install_prefix}/$$CMAKE_BIN_DIR/rcc$$CMAK list(APPEND Qt5Core_INCLUDE_DIRS \"${_qt5_corelib_install_prefix}/mkspecs/default\") if (NOT \"$${CMAKE_ADD_FPIE_FLAGS}\" STREQUAL \"\") - set(Qt5Core_COMPILE_FLAGS "-fPIE") + set(Qt5Core_EXECUTABLE_COMPILE_FLAGS "-fPIE") endif() if (NOT \"$$QT_NAMESPACE\" STREQUAL \"\") diff --git a/tests/manual/cmake/fail4/CMakeLists.txt b/tests/manual/cmake/fail4/CMakeLists.txt index 2466e24d3a..fdf90e17a7 100644 --- a/tests/manual/cmake/fail4/CMakeLists.txt +++ b/tests/manual/cmake/fail4/CMakeLists.txt @@ -16,5 +16,7 @@ qt5_wrap_cpp(moc_files myobject.h) # in the add_executable call. qt5_add_resources(rcc_files "pass4.qrc" OPTIONS -binary) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}") + add_executable(myobject myobject.cpp ${moc_files} ${rcc_files}) target_link_libraries(myobject ${Qt5Core_LIBRARIES}) diff --git a/tests/manual/cmake/fail5/CMakeLists.txt b/tests/manual/cmake/fail5/CMakeLists.txt index 9aedf4a008..962314c818 100644 --- a/tests/manual/cmake/fail5/CMakeLists.txt +++ b/tests/manual/cmake/fail5/CMakeLists.txt @@ -13,5 +13,7 @@ add_definitions(${Qt5Core_DEFINITIONS}) # causing a compile failure. -> Options work qt5_wrap_cpp(moc_files myobject.h OPTIONS -i) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}") + add_executable(myobject myobject.cpp ${moc_files}) target_link_libraries(myobject ${Qt5Core_LIBRARIES}) diff --git a/tests/manual/cmake/pass(needsquoting)6/CMakeLists.txt b/tests/manual/cmake/pass(needsquoting)6/CMakeLists.txt index fb971f9ebd..63f675df18 100644 --- a/tests/manual/cmake/pass(needsquoting)6/CMakeLists.txt +++ b/tests/manual/cmake/pass(needsquoting)6/CMakeLists.txt @@ -16,5 +16,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) qt5_wrap_cpp(moc_files mywidget.h) qt5_wrap_ui(ui_files mywidget.ui) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}") + add_executable(mywidget mywidget.cpp ${moc_files} ${ui_files}) target_link_libraries(mywidget ${Qt5Widgets_LIBRARIES}) diff --git a/tests/manual/cmake/pass1/CMakeLists.txt b/tests/manual/cmake/pass1/CMakeLists.txt index b1922c075b..cbe3afc7c4 100644 --- a/tests/manual/cmake/pass1/CMakeLists.txt +++ b/tests/manual/cmake/pass1/CMakeLists.txt @@ -18,7 +18,23 @@ macro(qt5_use_package _target _package) # set_property(TARGET ${_target} APPEND PROPERTY INCLUDE_DIRECTORIES ${Qt5${_package}_INCLUDE_DIRS}) include_directories(${Qt5${_package}_INCLUDE_DIRS}) set_property(TARGET ${_target} APPEND PROPERTY COMPILE_DEFINITIONS ${Qt5${_package}_COMPILE_DEFINITIONS}) - set_property(TARGET ${_target} APPEND PROPERTY COMPILE_FLAGS ${Qt5${_package}_COMPILE_FLAGS}) + + # We can't just append to the COMPILE_FLAGS property. That creats a ';' separated list + # which breaks the compile commmand line. + # Ensure non-duplication here manually instead. + get_property(_taget_type TARGET ${_target} PROPERTY TYPE) + if ("${_taget_type}" STREQUAL "EXECUTABLE") + get_target_property(_flags ${_target} COMPILE_FLAGS) + if (_flags) + list(APPEND _flags ${Qt5${_package}_EXECUTABLE_COMPILE_FLAGS}) + list(REMOVE_DUPLICATES _flags) + else() + set(_flags ${Qt5${_package}_EXECUTABLE_COMPILE_FLAGS}) + endif() + if (_flags) + set_target_properties(${_target} PROPERTIES COMPILE_FLAGS ${_flags}) + endif() + endif() else() message(FATAL_ERROR "NOT FOUND: Qt5${_package}") endif() diff --git a/tests/manual/cmake/pass2/CMakeLists.txt b/tests/manual/cmake/pass2/CMakeLists.txt index a52744623e..c859f13fff 100644 --- a/tests/manual/cmake/pass2/CMakeLists.txt +++ b/tests/manual/cmake/pass2/CMakeLists.txt @@ -13,5 +13,7 @@ qt5_wrap_cpp(moc_files myobject.h) qt5_add_resources(rcc_files "pass2.qrc") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}") + add_executable(myobject myobject.cpp ${moc_files} ${rcc_files}) target_link_libraries(myobject ${Qt5Core_LIBRARIES}) diff --git a/tests/manual/cmake/pass3/CMakeLists.txt b/tests/manual/cmake/pass3/CMakeLists.txt index b836161813..7fa6731f9b 100644 --- a/tests/manual/cmake/pass3/CMakeLists.txt +++ b/tests/manual/cmake/pass3/CMakeLists.txt @@ -15,5 +15,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) qt5_wrap_cpp(moc_files mywidget.h) qt5_wrap_ui(ui_files mywidget.ui) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}") + add_executable(mywidget mywidget.cpp ${moc_files} ${ui_files}) target_link_libraries(mywidget ${Qt5Widgets_LIBRARIES}) diff --git a/tests/manual/cmake/pass7/CMakeLists.txt b/tests/manual/cmake/pass7/CMakeLists.txt index e7c9b46ead..ecf6b3649e 100644 --- a/tests/manual/cmake/pass7/CMakeLists.txt +++ b/tests/manual/cmake/pass7/CMakeLists.txt @@ -8,4 +8,6 @@ find_package(Qt5Core REQUIRED) include_directories(${Qt5Core_INCLUDE_DIRS}) add_definitions(${Qt5Core_DEFINITIONS}) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}") + add_executable(myobject main.cpp)