From a41ba055a5eb0d2dc584fe3046b4ed527b1cd934 Mon Sep 17 00:00:00 2001 From: kervala Date: Mon, 5 Aug 2013 10:32:17 +0200 Subject: [PATCH] Fixed: PCH with Qt 5 and CMake 2.8.11 --- code/CMakeModules/PCHSupport.cmake | 52 ++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/code/CMakeModules/PCHSupport.cmake b/code/CMakeModules/PCHSupport.cmake index 042f6b0cc..bcca9d877 100644 --- a/code/CMakeModules/PCHSupport.cmake +++ b/code/CMakeModules/PCHSupport.cmake @@ -10,7 +10,6 @@ IF(MSVC) SET(PCHSupport_FOUND TRUE) - SET(_PCH_include_prefix "/I") ELSE(MSVC) IF(CMAKE_COMPILER_IS_GNUCXX) EXEC_PROGRAM(${CMAKE_CXX_COMPILER} @@ -26,16 +25,14 @@ ELSE(MSVC) # TODO: make tests for other compilers than GCC SET(PCHSupport_FOUND TRUE) ENDIF(CMAKE_COMPILER_IS_GNUCXX) - - SET(_PCH_include_prefix "-I") ENDIF(MSVC) # Set PCH_FLAGS for common flags, PCH_ARCH_XXX_FLAGS for specific archs flags and PCH_ARCHS for archs MACRO(PCH_SET_COMPILE_FLAGS _target) SET(PCH_FLAGS) - SET(PCH_ARCHS) + SET(PCH_ARCHS) + SET(_FLAGS) - LIST(APPEND _FLAGS ${CMAKE_CXX_FLAGS}) STRING(TOUPPER "${CMAKE_BUILD_TYPE}" _UPPER_BUILD) @@ -46,24 +43,33 @@ MACRO(PCH_SET_COMPILE_FLAGS _target) IF(${_targetType} STREQUAL SHARED_LIBRARY OR ${_targetType} STREQUAL MODULE_LIBRARY) LIST(APPEND _FLAGS " -fPIC") ENDIF(${_targetType} STREQUAL SHARED_LIBRARY OR ${_targetType} STREQUAL MODULE_LIBRARY) + + GET_TARGET_PROPERTY(_pic ${_target} POSITION_INDEPENDENT_CODE) + IF(_pic) + LIST(APPEND _FLAGS " -fPIE") + ENDIF(_pic) ENDIF(NOT MSVC) GET_DIRECTORY_PROPERTY(DIRINC INCLUDE_DIRECTORIES) FOREACH(item ${DIRINC}) - LIST(APPEND _FLAGS " ${_PCH_include_prefix}\"${item}\"") + LIST(APPEND _FLAGS " -I\"${item}\"") ENDFOREACH(item) # Required for CMake 2.6 SET(GLOBAL_DEFINITIONS) GET_DIRECTORY_PROPERTY(DEFINITIONS COMPILE_DEFINITIONS) - FOREACH(item ${DEFINITIONS}) - LIST(APPEND GLOBAL_DEFINITIONS " -D${item}") - ENDFOREACH(item) + IF(DEFINITIONS) + FOREACH(item ${DEFINITIONS}) + LIST(APPEND GLOBAL_DEFINITIONS " -D${item}") + ENDFOREACH(item) + ENDIF(DEFINITIONS) GET_DIRECTORY_PROPERTY(DEFINITIONS COMPILE_DEFINITIONS_${_UPPER_BUILD}) - FOREACH(item ${DEFINITIONS}) - LIST(APPEND GLOBAL_DEFINITIONS " -D${item}") - ENDFOREACH(item) + IF(DEFINITIONS) + FOREACH(item ${DEFINITIONS}) + LIST(APPEND GLOBAL_DEFINITIONS " -D${item}") + ENDFOREACH(item) + ENDIF(DEFINITIONS) GET_TARGET_PROPERTY(oldProps ${_target} COMPILE_FLAGS) IF(oldProps) @@ -75,6 +81,27 @@ MACRO(PCH_SET_COMPILE_FLAGS _target) LIST(APPEND _FLAGS " ${oldPropsBuild}") ENDIF(oldPropsBuild) + GET_TARGET_PROPERTY(DIRINC ${_target} INCLUDE_DIRECTORIES) + IF(DIRINC) + FOREACH(item ${DIRINC}) + LIST(APPEND _FLAGS " -I\"${item}\"") + ENDFOREACH(item) + ENDIF(DIRINC) + + GET_TARGET_PROPERTY(DEFINITIONS ${_target} COMPILE_DEFINITIONS) + IF(DEFINITIONS) + FOREACH(item ${DEFINITIONS}) + LIST(APPEND GLOBAL_DEFINITIONS " -D${item}") + ENDFOREACH(item) + ENDIF(DEFINITIONS) + + GET_TARGET_PROPERTY(DEFINITIONS ${_target} COMPILE_DEFINITIONS_${_UPPER_BUILD}) + IF(DEFINITIONS) + FOREACH(item ${DEFINITIONS}) + LIST(APPEND GLOBAL_DEFINITIONS " -D${item}") + ENDFOREACH(item) + ENDIF(DEFINITIONS) + GET_DIRECTORY_PROPERTY(_directory_flags DEFINITIONS) GET_DIRECTORY_PROPERTY(_directory_definitions DIRECTORY ${CMAKE_SOURCE_DIR} DEFINITIONS) LIST(APPEND _FLAGS " ${GLOBAL_DEFINITIONS}") @@ -90,7 +117,6 @@ MACRO(PCH_SET_COMPILE_FLAGS _target) SEPARATE_ARGUMENTS(_FLAGS) ENDIF(MSVC) - IF(CLANG) # Determining all architectures and get common flags SET(_ARCH_NEXT)