Fixed: PCH with Qt 5 and CMake 2.8.11

This commit is contained in:
kervala 2013-08-05 10:32:17 +02:00
parent e74913f589
commit f9b70173ce

View file

@ -10,7 +10,6 @@
IF(MSVC) IF(MSVC)
SET(PCHSupport_FOUND TRUE) SET(PCHSupport_FOUND TRUE)
SET(_PCH_include_prefix "/I")
ELSE(MSVC) ELSE(MSVC)
IF(CMAKE_COMPILER_IS_GNUCXX) IF(CMAKE_COMPILER_IS_GNUCXX)
EXEC_PROGRAM(${CMAKE_CXX_COMPILER} EXEC_PROGRAM(${CMAKE_CXX_COMPILER}
@ -26,16 +25,14 @@ ELSE(MSVC)
# TODO: make tests for other compilers than GCC # TODO: make tests for other compilers than GCC
SET(PCHSupport_FOUND TRUE) SET(PCHSupport_FOUND TRUE)
ENDIF(CMAKE_COMPILER_IS_GNUCXX) ENDIF(CMAKE_COMPILER_IS_GNUCXX)
SET(_PCH_include_prefix "-I")
ENDIF(MSVC) ENDIF(MSVC)
# Set PCH_FLAGS for common flags, PCH_ARCH_XXX_FLAGS for specific archs flags and PCH_ARCHS for archs # 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) MACRO(PCH_SET_COMPILE_FLAGS _target)
SET(PCH_FLAGS) SET(PCH_FLAGS)
SET(PCH_ARCHS) SET(PCH_ARCHS)
SET(_FLAGS)
SET(_FLAGS)
LIST(APPEND _FLAGS ${CMAKE_CXX_FLAGS}) LIST(APPEND _FLAGS ${CMAKE_CXX_FLAGS})
STRING(TOUPPER "${CMAKE_BUILD_TYPE}" _UPPER_BUILD) 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) IF(${_targetType} STREQUAL SHARED_LIBRARY OR ${_targetType} STREQUAL MODULE_LIBRARY)
LIST(APPEND _FLAGS " -fPIC") LIST(APPEND _FLAGS " -fPIC")
ENDIF(${_targetType} STREQUAL SHARED_LIBRARY OR ${_targetType} STREQUAL MODULE_LIBRARY) 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) ENDIF(NOT MSVC)
GET_DIRECTORY_PROPERTY(DIRINC INCLUDE_DIRECTORIES) GET_DIRECTORY_PROPERTY(DIRINC INCLUDE_DIRECTORIES)
FOREACH(item ${DIRINC}) FOREACH(item ${DIRINC})
LIST(APPEND _FLAGS " ${_PCH_include_prefix}\"${item}\"") LIST(APPEND _FLAGS " -I\"${item}\"")
ENDFOREACH(item) ENDFOREACH(item)
# Required for CMake 2.6 # Required for CMake 2.6
SET(GLOBAL_DEFINITIONS) SET(GLOBAL_DEFINITIONS)
GET_DIRECTORY_PROPERTY(DEFINITIONS COMPILE_DEFINITIONS) GET_DIRECTORY_PROPERTY(DEFINITIONS COMPILE_DEFINITIONS)
IF(DEFINITIONS)
FOREACH(item ${DEFINITIONS}) FOREACH(item ${DEFINITIONS})
LIST(APPEND GLOBAL_DEFINITIONS " -D${item}") LIST(APPEND GLOBAL_DEFINITIONS " -D${item}")
ENDFOREACH(item) ENDFOREACH(item)
ENDIF(DEFINITIONS)
GET_DIRECTORY_PROPERTY(DEFINITIONS COMPILE_DEFINITIONS_${_UPPER_BUILD}) GET_DIRECTORY_PROPERTY(DEFINITIONS COMPILE_DEFINITIONS_${_UPPER_BUILD})
IF(DEFINITIONS)
FOREACH(item ${DEFINITIONS}) FOREACH(item ${DEFINITIONS})
LIST(APPEND GLOBAL_DEFINITIONS " -D${item}") LIST(APPEND GLOBAL_DEFINITIONS " -D${item}")
ENDFOREACH(item) ENDFOREACH(item)
ENDIF(DEFINITIONS)
GET_TARGET_PROPERTY(oldProps ${_target} COMPILE_FLAGS) GET_TARGET_PROPERTY(oldProps ${_target} COMPILE_FLAGS)
IF(oldProps) IF(oldProps)
@ -75,6 +81,27 @@ MACRO(PCH_SET_COMPILE_FLAGS _target)
LIST(APPEND _FLAGS " ${oldPropsBuild}") LIST(APPEND _FLAGS " ${oldPropsBuild}")
ENDIF(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_flags DEFINITIONS)
GET_DIRECTORY_PROPERTY(_directory_definitions DIRECTORY ${CMAKE_SOURCE_DIR} DEFINITIONS) GET_DIRECTORY_PROPERTY(_directory_definitions DIRECTORY ${CMAKE_SOURCE_DIR} DEFINITIONS)
LIST(APPEND _FLAGS " ${GLOBAL_DEFINITIONS}") LIST(APPEND _FLAGS " ${GLOBAL_DEFINITIONS}")
@ -90,7 +117,6 @@ MACRO(PCH_SET_COMPILE_FLAGS _target)
SEPARATE_ARGUMENTS(_FLAGS) SEPARATE_ARGUMENTS(_FLAGS)
ENDIF(MSVC) ENDIF(MSVC)
IF(CLANG) IF(CLANG)
# Determining all architectures and get common flags # Determining all architectures and get common flags
SET(_ARCH_NEXT) SET(_ARCH_NEXT)