@ -10,22 +10,22 @@
IF ( MSVC )
IF ( MSVC )
SET ( PCHSupport_FOUND TRUE )
SET ( PCHSupport_FOUND TRUE )
ELSE ( MSVC )
ELSE ( )
IF ( CMAKE_COMPILER_IS_GNUCXX )
IF ( CMAKE_COMPILER_IS_GNUCXX )
EXEC_PROGRAM ( ${ CMAKE_CXX_COMPILER }
EXEC_PROGRAM ( ${ CMAKE_CXX_COMPILER }
A R G S $ { C M A K E _ C X X _ C O M P I L E R _ A R G 1 } - d u m p v e r s i o n
A R G S $ { C M A K E _ C X X _ C O M P I L E R _ A R G 1 } - d u m p v e r s i o n
O U T P U T _ V A R I A B L E g c c _ c o m p i l e r _ v e r s i o n )
O U T P U T _ V A R I A B L E g c c _ c o m p i l e r _ v e r s i o n )
IF ( gcc_compiler_version MATCHES "^4\\.1(\\.[0-9]+)? ")
IF ( gcc_compiler_version VERSION_LESS "4.2 ")
SET ( PCHSupport_FOUND FALSE )
SET ( PCHSupport_FOUND FALSE )
ELSE IF ( gcc_compiler_version MATCHES "^4\\.[0-9]+(\\.[0-9]+)?" )
ELSE ( )
SET ( PCHSupport_FOUND TRUE )
SET ( PCHSupport_FOUND TRUE )
ENDIF ( gcc_compiler_version MATCHES "^4\\.1(\\.[0-9]+)?" )
ENDIF ( )
ELSE ( CMAKE_COMPILER_IS_GNUCXX )
ELSE ( )
# T O D O : m a k e t e s t s f o r o t h e r c o m p i l e r s t h a n G C C
# T O D O : m a k e t e s t s f o r o t h e r c o m p i l e r s t h a n G C C
SET ( PCHSupport_FOUND TRUE )
SET ( PCHSupport_FOUND TRUE )
ENDIF ( CMAKE_COMPILER_IS_GNUCXX )
ENDIF ( )
ENDIF ( MSVC )
ENDIF ( )
# S e t P C H _ F L A G S f o r c o m m o n f l a g s , P C H _ A R C H _ X X X _ F L A G S f o r s p e c i f i c a r c h s f l a g s a n d P C H _ A R C H S f o r a r c h s
# S e t P C H _ F L A G S f o r c o m m o n f l a g s , P C H _ A R C H _ X X X _ F L A G S f o r s p e c i f i c a r c h s f l a g s a n d P C H _ A R C H S f o r a r c h s
MACRO ( PCH_SET_COMPILE_FLAGS _target )
MACRO ( PCH_SET_COMPILE_FLAGS _target )
@ -40,19 +40,21 @@ MACRO(PCH_SET_COMPILE_FLAGS _target)
GET_TARGET_PROPERTY ( _targetType ${ _target } TYPE )
GET_TARGET_PROPERTY ( _targetType ${ _target } TYPE )
IF ( ${ _targetType } STREQUAL SHARED_LIBRARY OR ${ _targetType } STREQUAL MODULE_LIBRARY )
SET ( _USE_PIC OFF )
IF ( ${ _targetType } STREQUAL "SHARED_LIBRARY" OR ${ _targetType } STREQUAL "MODULE_LIBRARY" )
LIST ( APPEND _FLAGS " ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}" )
LIST ( APPEND _FLAGS " ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}" )
ELSE ( ${ _targetType } STREQUAL SHARED_LIBRARY OR ${ _targetType } STREQUAL MODULE_LIBRARY )
ELSE ( )
GET_TARGET_PROPERTY ( _pic ${ _target } POSITION_INDEPENDENT_CODE )
GET_TARGET_PROPERTY ( _pic ${ _target } POSITION_INDEPENDENT_CODE )
IF ( _pic )
IF ( _pic )
LIST( APPEND _FLAGS " ${CMAKE_CXX_COMPILE_OPTIONS_PIE}" )
SET( _USE_PIC ON )
ENDIF ( _pic )
ENDIF ( )
ENDIF ( ${ _targetType } STREQUAL SHARED_LIBRARY OR ${ _targetType } STREQUAL MODULE_LIBRARY )
ENDIF ( )
GET_DIRECTORY_PROPERTY ( DIRINC INCLUDE_DIRECTORIES )
GET_DIRECTORY_PROPERTY ( DIRINC INCLUDE_DIRECTORIES )
FOREACH ( item ${ DIRINC } )
FOREACH ( item ${ DIRINC } )
LIST ( APPEND _FLAGS " -I\" ${ item } \"")
LIST ( APPEND _FLAGS " -I\" ${ item } \"")
ENDFOREACH ( item )
ENDFOREACH ( )
# R e q u i r e d f o r C M a k e 2 . 6
# R e q u i r e d f o r C M a k e 2 . 6
SET ( GLOBAL_DEFINITIONS )
SET ( GLOBAL_DEFINITIONS )
@ -60,61 +62,123 @@ MACRO(PCH_SET_COMPILE_FLAGS _target)
IF ( DEFINITIONS )
IF ( DEFINITIONS )
FOREACH ( item ${ DEFINITIONS } )
FOREACH ( item ${ DEFINITIONS } )
LIST ( APPEND GLOBAL_DEFINITIONS " -D${item}" )
LIST ( APPEND GLOBAL_DEFINITIONS " -D${item}" )
ENDFOREACH ( item )
ENDFOREACH ( )
ENDIF ( DEFINITIONS )
ENDIF ( )
GET_DIRECTORY_PROPERTY ( DEFINITIONS COMPILE_DEFINITIONS_ ${ _UPPER_BUILD } )
GET_DIRECTORY_PROPERTY ( DEFINITIONS COMPILE_DEFINITIONS_ ${ _UPPER_BUILD } )
IF ( DEFINITIONS )
IF ( DEFINITIONS )
FOREACH ( item ${ DEFINITIONS } )
FOREACH ( item ${ DEFINITIONS } )
LIST ( APPEND GLOBAL_DEFINITIONS " -D${item}" )
LIST ( APPEND GLOBAL_DEFINITIONS " -D${item}" )
ENDFOREACH ( item )
ENDFOREACH ( )
ENDIF ( DEFINITIONS )
ENDIF ( )
GET_DIRECTORY_PROPERTY ( DEFINITIONS DIRECTORY ${ CMAKE_SOURCE_DIR } COMPILE_DEFINITIONS )
IF ( DEFINITIONS )
FOREACH ( item ${ DEFINITIONS } )
LIST ( APPEND GLOBAL_DEFINITIONS " -D${item}" )
ENDFOREACH ( )
ENDIF ( )
GET_DIRECTORY_PROPERTY ( DEFINITIONS DIRECTORY ${ CMAKE_SOURCE_DIR } COMPILE_DEFINITIONS_ ${ _UPPER_BUILD } )
IF ( DEFINITIONS )
FOREACH ( item ${ DEFINITIONS } )
LIST ( APPEND GLOBAL_DEFINITIONS " -D${item}" )
ENDFOREACH ( )
ENDIF ( )
GET_TARGET_PROPERTY ( oldProps ${ _target } COMPILE_FLAGS )
GET_TARGET_PROPERTY ( oldProps ${ _target } COMPILE_FLAGS )
IF ( oldProps )
IF ( oldProps )
LIST ( APPEND _FLAGS " ${oldProps}" )
LIST ( APPEND _FLAGS " ${oldProps}" )
ENDIF ( oldProps )
ENDIF ( )
GET_TARGET_PROPERTY ( oldPropsBuild ${ _target } COMPILE_FLAGS_ ${ _UPPER_BUILD } )
GET_TARGET_PROPERTY ( oldPropsBuild ${ _target } COMPILE_FLAGS_ ${ _UPPER_BUILD } )
IF ( oldPropsBuild )
IF ( oldPropsBuild )
LIST ( APPEND _FLAGS " ${oldPropsBuild}" )
LIST ( APPEND _FLAGS " ${oldPropsBuild}" )
ENDIF ( oldPropsBuild )
ENDIF ( )
GET_TARGET_PROPERTY ( DIRINC ${ _target } INCLUDE_DIRECTORIES )
GET_TARGET_PROPERTY ( DIRINC ${ _target } INCLUDE_DIRECTORIES )
IF ( DIRINC )
IF ( DIRINC )
FOREACH ( item ${ DIRINC } )
FOREACH ( item ${ DIRINC } )
LIST ( APPEND _FLAGS " -I\" ${ item } \"")
LIST ( APPEND _FLAGS " -I\" ${ item } \"")
ENDFOREACH ( item )
ENDFOREACH ( )
ENDIF ( DIRINC )
ENDIF ( )
GET_TARGET_PROPERTY ( DEFINITIONS ${ _target } COMPILE_DEFINITIONS )
GET_TARGET_PROPERTY ( DEFINITIONS ${ _target } COMPILE_DEFINITIONS )
IF ( DEFINITIONS )
IF ( DEFINITIONS )
FOREACH ( item ${ DEFINITIONS } )
FOREACH ( item ${ DEFINITIONS } )
LIST ( APPEND GLOBAL_DEFINITIONS " -D${item}" )
LIST ( APPEND GLOBAL_DEFINITIONS " -D${item}" )
ENDFOREACH ( item )
ENDFOREACH ( )
ENDIF ( DEFINITIONS )
ENDIF ( )
GET_TARGET_PROPERTY ( DEFINITIONS ${ _target } COMPILE_DEFINITIONS_ ${ _UPPER_BUILD } )
GET_TARGET_PROPERTY ( DEFINITIONS ${ _target } COMPILE_DEFINITIONS_ ${ _UPPER_BUILD } )
IF ( DEFINITIONS )
IF ( DEFINITIONS )
FOREACH ( item ${ DEFINITIONS } )
FOREACH ( item ${ DEFINITIONS } )
LIST ( APPEND GLOBAL_DEFINITIONS " -D${item}" )
LIST ( APPEND GLOBAL_DEFINITIONS " -D${item}" )
ENDFOREACH ( item )
ENDFOREACH ( )
ENDIF ( DEFINITIONS )
ENDIF ( )
GET_TARGET_PROPERTY ( _LIBS ${ _target } INTERFACE_LINK_LIBRARIES )
IF ( _LIBS )
FOREACH ( _LIB ${ _LIBS } )
IF ( TARGET "${_LIB}" )
# u s e s a m e i n c l u d e d i r e c t o r i e s
GET_TARGET_PROPERTY ( _DIRS ${ _LIB } INTERFACE_INCLUDE_DIRECTORIES )
IF ( _DIRS )
FOREACH ( item ${ _DIRS } )
LIST ( APPEND GLOBAL_DEFINITIONS " -I\" ${ item } \"")
ENDFOREACH ( )
ENDIF ( )
# u s e s a m e c o m p i l e d e f i n i t i o n s
GET_TARGET_PROPERTY ( _DEFINITIONS ${ _LIB } INTERFACE_COMPILE_DEFINITIONS )
IF ( _DEFINITIONS )
FOREACH ( item ${ _DEFINITIONS } )
# d o n ' t u s e d y n a m i c e x p r e s s i o n s
IF ( NOT item MATCHES "\\$<" )
LIST ( APPEND GLOBAL_DEFINITIONS " -D${item}" )
ENDIF ( )
ENDFOREACH ( )
ENDIF ( )
ENDIF ( )
ENDFOREACH ( )
ENDIF ( )
# S p e c i a l Q t 5 c a s e s
IF ( GLOBAL_DEFINITIONS MATCHES "QT_CORE_LIB" )
# H a c k t o d e f i n e m i s s i n g Q T _ N O _ D E B U G w i t h Q t 5 . 2
IF ( _UPPER_BUILD STREQUAL "RELEASE" )
LIST ( APPEND GLOBAL_DEFINITIONS " -DQT_NO_DEBUG" )
ENDIF ( )
# Q t 5 _ P O S I T I O N _ I N D E P E N D E N T _ C O D E s h o u l d b e t r u e i f Q t w a s c o m p i l e d w i t h P I C
IF ( Qt5_POSITION_INDEPENDENT_CODE )
SET ( _USE_PIC ON )
ENDIF ( )
IF ( _USE_PIC )
LIST ( APPEND _FLAGS " ${CMAKE_CXX_COMPILE_OPTIONS_PIC}" )
ENDIF ( )
ENDIF ( )
GET_DIRECTORY_PROPERTY ( _directory_flags DEFINITIONS )
GET_DIRECTORY_PROPERTY ( _directory_definitions DIRECTORY ${ CMAKE_SOURCE_DIR } DEFINITIONS )
LIST ( APPEND _FLAGS " ${GLOBAL_DEFINITIONS}" )
LIST ( APPEND _FLAGS " ${GLOBAL_DEFINITIONS}" )
LIST ( APPEND _FLAGS " ${_directory_flags}" )
LIST ( APPEND _FLAGS " ${_directory_definitions}" )
IF ( CMAKE_VERSION VERSION_LESS "3.3.0" )
GET_DIRECTORY_PROPERTY ( _directory_flags DEFINITIONS )
GET_DIRECTORY_PROPERTY ( _directory_definitions DIRECTORY ${ CMAKE_SOURCE_DIR } DEFINITIONS )
LIST ( APPEND _FLAGS " ${_directory_flags}" )
LIST ( APPEND _FLAGS " ${_directory_definitions}" )
ENDIF ( )
# F o r m a t d e f i n i t i o n s
# F o r m a t d e f i n i t i o n s
IF ( MSVC )
IF ( MSVC )
# F i x p a t h w i t h s p a c e
# F i x p a t h w i t h s p a c e
SEPARATE_ARGUMENTS ( _FLAGS UNIX_COMMAND "${_FLAGS}" )
SEPARATE_ARGUMENTS ( _FLAGS UNIX_COMMAND "${_FLAGS}" )
ELSE ( MSVC )
ELSE ( )
STRING ( REGEX REPLACE " +" " " _FLAGS ${ _FLAGS } )
STRING ( REGEX REPLACE " +" " " _FLAGS ${ _FLAGS } )
SEPARATE_ARGUMENTS ( _FLAGS )
SEPARATE_ARGUMENTS ( _FLAGS )
ENDIF ( MSVC )
ENDIF ( )
IF ( CLANG )
IF ( CLANG )
# D e t e r m i n i n g a l l a r c h i t e c t u r e s a n d g e t c o m m o n f l a g s
# D e t e r m i n i n g a l l a r c h i t e c t u r e s a n d g e t c o m m o n f l a g s
@ -127,11 +191,11 @@ MACRO(PCH_SET_COMPILE_FLAGS _target)
LIST ( APPEND PCH_ARCHS ${ item } )
LIST ( APPEND PCH_ARCHS ${ item } )
STRING ( TOUPPER "${item}" _UPPER_ARCH )
STRING ( TOUPPER "${item}" _UPPER_ARCH )
SET ( PCH_ARCH_ ${ _UPPER_ARCH } _FLAGS "-arch" ${ item } )
SET ( PCH_ARCH_ ${ _UPPER_ARCH } _FLAGS "-arch" ${ item } )
ENDIF ( ITEM_FOUND EQUAL -1 )
ENDIF ( )
SET ( _ARCH_NEXT OFF )
SET ( _ARCH_NEXT OFF )
ELSEIF ( _XARCH_NEXT )
ELSEIF ( _XARCH_NEXT )
SET ( _XARCH_NEXT OFF )
SET ( _XARCH_NEXT OFF )
ELSE ( _ARCH_NEXT )
ELSE ( )
IF ( item MATCHES "^-arch" )
IF ( item MATCHES "^-arch" )
SET ( _ARCH_NEXT ON )
SET ( _ARCH_NEXT ON )
ELSEIF ( item MATCHES "^-Xarch_" )
ELSEIF ( item MATCHES "^-Xarch_" )
@ -141,13 +205,13 @@ MACRO(PCH_SET_COMPILE_FLAGS _target)
LIST ( APPEND PCH_ARCHS ${ item } )
LIST ( APPEND PCH_ARCHS ${ item } )
STRING ( TOUPPER "${item}" _UPPER_ARCH )
STRING ( TOUPPER "${item}" _UPPER_ARCH )
SET ( PCH_ARCH_ ${ _UPPER_ARCH } _FLAGS "-arch" ${ item } )
SET ( PCH_ARCH_ ${ _UPPER_ARCH } _FLAGS "-arch" ${ item } )
ENDIF ( ITEM_FOUND EQUAL -1 )
ENDIF ( )
SET ( _XARCH_NEXT ON )
SET ( _XARCH_NEXT ON )
ELSE ( item MATCHES "^-arch" )
ELSE ( )
LIST ( APPEND PCH_FLAGS ${ item } )
LIST ( APPEND PCH_FLAGS ${ item } )
ENDIF ( item MATCHES "^-arch" )
ENDIF ( )
ENDIF ( _ARCH_NEXT )
ENDIF ( )
ENDFOREACH ( item )
ENDFOREACH ( )
# G e t a r c h i t c t u r e s p e c i f i c f l a g s
# G e t a r c h i t c t u r e s p e c i f i c f l a g s
SET ( _XARCH_NEXT )
SET ( _XARCH_NEXT )
@ -156,25 +220,25 @@ MACRO(PCH_SET_COMPILE_FLAGS _target)
STRING ( TOUPPER "${_XARCH_NEXT}" _UPPER_XARCH )
STRING ( TOUPPER "${_XARCH_NEXT}" _UPPER_XARCH )
LIST ( APPEND PCH_ARCH_ ${ _UPPER_XARCH } _FLAGS ${ item } )
LIST ( APPEND PCH_ARCH_ ${ _UPPER_XARCH } _FLAGS ${ item } )
SET ( _XARCH_NEXT OFF )
SET ( _XARCH_NEXT OFF )
ELSE ( _XARCH_NEXT )
ELSE ( )
IF ( item MATCHES "^-Xarch_" )
IF ( item MATCHES "^-Xarch_" )
STRING ( SUBSTRING "${item}" 7 -1 _XARCH_NEXT )
STRING ( SUBSTRING "${item}" 7 -1 _XARCH_NEXT )
ENDIF ( item MATCHES "^-Xarch_" )
ENDIF ( )
ENDIF ( _XARCH_NEXT )
ENDIF ( )
ENDFOREACH ( item )
ENDFOREACH ( )
# R e m o v e d u p l i c a t e d a r c h i t e c t u r e s
# R e m o v e d u p l i c a t e d a r c h i t e c t u r e s
IF ( _ARCHS AND PCH_ARCHS )
IF ( _ARCHS AND PCH_ARCHS )
LIST ( REMOVE_DUPLICATES PCH_ARCHS )
LIST ( REMOVE_DUPLICATES PCH_ARCHS )
ENDIF ( _ARCHS AND PCH_ARCHS )
ENDIF ( )
ELSE ( CLANG )
ELSE ( )
SET ( PCH_FLAGS ${ _FLAGS } )
SET ( PCH_FLAGS ${ _FLAGS } )
ENDIF ( CLANG )
ENDIF ( )
IF ( PCH_FLAGS )
IF ( PCH_FLAGS )
LIST ( REMOVE_DUPLICATES PCH_FLAGS )
LIST ( REMOVE_DUPLICATES PCH_FLAGS )
ENDIF ( PCH_FLAGS )
ENDIF ( )
ENDMACRO ( PCH_SET_COMPILE_FLAGS )
ENDMACRO ( )
MACRO ( GET_PDB_FILENAME _out_filename _target )
MACRO ( GET_PDB_FILENAME _out_filename _target )
# d e t e r m i n e o u t p u t d i r e c t o r y b a s e d o n t a r g e t t y p e
# d e t e r m i n e o u t p u t d i r e c t o r y b a s e d o n t a r g e t t y p e
@ -201,9 +265,9 @@ MACRO(PCH_SET_COMPILE_COMMAND _inputcpp _compile_FLAGS)
IF ( CMAKE_CXX_COMPILER_ARG1 )
IF ( CMAKE_CXX_COMPILER_ARG1 )
# r e m o v e l e a d i n g s p a c e i n c o m p i l e r a r g u m e n t
# r e m o v e l e a d i n g s p a c e i n c o m p i l e r a r g u m e n t
STRING ( REGEX REPLACE "^ +" "" pchsupport_compiler_cxx_arg1 ${ CMAKE_CXX_COMPILER_ARG1 } )
STRING ( REGEX REPLACE "^ +" "" pchsupport_compiler_cxx_arg1 ${ CMAKE_CXX_COMPILER_ARG1 } )
ELSE ( CMAKE_CXX_COMPILER_ARG1 )
ELSE ( )
SET ( pchsupport_compiler_cxx_arg1 "" )
SET ( pchsupport_compiler_cxx_arg1 "" )
ENDIF ( CMAKE_CXX_COMPILER_ARG1 )
ENDIF ( )
IF ( MSVC )
IF ( MSVC )
GET_PDB_FILENAME ( PDB_FILE ${ _PCH_current_target } )
GET_PDB_FILENAME ( PDB_FILE ${ _PCH_current_target } )
@ -211,16 +275,16 @@ MACRO(PCH_SET_COMPILE_COMMAND _inputcpp _compile_FLAGS)
# N i n j a P C H S u p p o r t
# N i n j a P C H S u p p o r t
# h t t p : / / p u b l i c . k i t w a r e . c o m / p i p e r m a i l / c m a k e - d e v e l o p e r s / 2 0 1 2 - M a r c h / 0 0 3 6 5 3 . h t m l
# h t t p : / / p u b l i c . k i t w a r e . c o m / p i p e r m a i l / c m a k e - d e v e l o p e r s / 2 0 1 2 - M a r c h / 0 0 3 6 5 3 . h t m l
SET_SOURCE_FILES_PROPERTIES ( ${ _inputcpp } PROPERTIES OBJECT_OUTPUTS "${PCH_OUTPUT}.obj" )
SET_SOURCE_FILES_PROPERTIES ( ${ _inputcpp } PROPERTIES OBJECT_OUTPUTS "${PCH_OUTPUT}.obj" )
ELSE ( MSVC )
ELSE ( )
SET ( HEADER_FORMAT "c++-header" )
SET ( HEADER_FORMAT "c++-header" )
SET ( _FLAGS "" )
SET ( _FLAGS "" )
IF ( APPLE )
IF ( APPLE )
SET ( HEADER_FORMAT "objective-${HEADER_FORMAT}" )
SET ( HEADER_FORMAT "objective-${HEADER_FORMAT}" )
SET ( _FLAGS -fobjc-abi-version=2 -fobjc-legacy-dispatch )
SET ( _FLAGS -fobjc-abi-version=2 -fobjc-legacy-dispatch )
ENDIF ( APPLE )
ENDIF ( )
SET ( PCH_COMMAND ${ CMAKE_CXX_COMPILER } ${ pchsupport_compiler_cxx_arg1 } ${ _compile_FLAGS } ${ _FLAGS } -x ${ HEADER_FORMAT } -o ${ PCH_OUTPUT } -c ${ PCH_INPUT } )
SET ( PCH_COMMAND ${ CMAKE_CXX_COMPILER } ${ pchsupport_compiler_cxx_arg1 } ${ _compile_FLAGS } ${ _FLAGS } -x ${ HEADER_FORMAT } -o ${ PCH_OUTPUT } -c ${ PCH_INPUT } )
ENDIF ( MSVC )
ENDIF ( )
ENDMACRO ( PCH_SET_COMPILE_COMMAND )
ENDMACRO ( )
MACRO ( PCH_SET_PRECOMPILED_HEADER_OUTPUT _targetName _input _arch _language )
MACRO ( PCH_SET_PRECOMPILED_HEADER_OUTPUT _targetName _input _arch _language )
SET ( _OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/${_targetName}_pch" )
SET ( _OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/${_targetName}_pch" )
@ -230,14 +294,14 @@ MACRO(PCH_SET_PRECOMPILED_HEADER_OUTPUT _targetName _input _arch _language)
GET_FILENAME_COMPONENT ( _name ${ _input } NAME_WE )
GET_FILENAME_COMPONENT ( _name ${ _input } NAME_WE )
SET ( PCH_INPUT ${ _input } )
SET ( PCH_INPUT ${ _input } )
SET ( PCH_OUTPUT "${_OUTPUT_DIR}/${_name}.pch" )
SET ( PCH_OUTPUT "${_OUTPUT_DIR}/${_name}.pch" )
ELSE ( MSVC )
ELSE ( )
IF ( NOT "${_arch}" STREQUAL "" )
IF ( NOT "${_arch}" STREQUAL "" )
SET ( _OUTPUT_DIR "${_OUTPUT_DIR}_${_arch}" )
SET ( _OUTPUT_DIR "${_OUTPUT_DIR}_${_arch}" )
ENDIF ( NOT "${_arch}" STREQUAL "" )
ENDIF ( )
IF ( NOT "${_language}" STREQUAL "" )
IF ( NOT "${_language}" STREQUAL "" )
SET ( _OUTPUT_DIR "${_OUTPUT_DIR}_${_language}" )
SET ( _OUTPUT_DIR "${_OUTPUT_DIR}_${_language}" )
ENDIF ( NOT "${_language}" STREQUAL "" )
ENDIF ( )
GET_FILENAME_COMPONENT ( _name ${ _input } NAME )
GET_FILENAME_COMPONENT ( _name ${ _input } NAME )
@ -251,14 +315,14 @@ MACRO(PCH_SET_PRECOMPILED_HEADER_OUTPUT _targetName _input _arch _language)
IF ( CLANG )
IF ( CLANG )
SET ( PCH_EXT "pth" )
SET ( PCH_EXT "pth" )
ELSE ( CLANG )
ELSE ( )
SET ( PCH_EXT "gch" )
SET ( PCH_EXT "gch" )
ENDIF ( CLANG )
ENDIF ( )
# F o r G C C a n d C l a n g , P C H n e e d s t o b e i n t h e s a m e d i r e c t o r y a s . h
# F o r G C C a n d C l a n g , P C H n e e d s t o b e i n t h e s a m e d i r e c t o r y a s . h
SET ( PCH_OUTPUT "${_OUTPUT_DIR}/${_name}.${PCH_EXT}" )
SET ( PCH_OUTPUT "${_OUTPUT_DIR}/${_name}.${PCH_EXT}" )
ENDIF ( MSVC )
ENDIF ( )
ENDMACRO ( PCH_SET_PRECOMPILED_HEADER_OUTPUT )
ENDMACRO ( )
# A d d c o m m o n f l a g s
# A d d c o m m o n f l a g s
MACRO ( ADD_PRECOMPILED_HEADER_TO_TARGET _targetName )
MACRO ( ADD_PRECOMPILED_HEADER_TO_TARGET _targetName )
@ -266,7 +330,7 @@ MACRO(ADD_PRECOMPILED_HEADER_TO_TARGET _targetName)
IF ( ${ oldProps } MATCHES NOTFOUND )
IF ( ${ oldProps } MATCHES NOTFOUND )
SET ( oldProps "" )
SET ( oldProps "" )
ENDIF ( ${ oldProps } MATCHES NOTFOUND )
ENDIF ( )
IF ( MSVC )
IF ( MSVC )
SET ( _target_cflags "${oldProps} /Yu\" ${ PCH_INPUT } \" /FI\ "${PCH_INPUT}\" /Fp\ "${PCH_OUTPUT}\" " )
SET ( _target_cflags "${oldProps} /Yu\" ${ PCH_INPUT } \" /FI\ "${PCH_INPUT}\" /Fp\ "${PCH_OUTPUT}\" " )
@ -279,17 +343,17 @@ MACRO(ADD_PRECOMPILED_HEADER_TO_TARGET _targetName)
GET_TARGET_PROPERTY ( _STATIC_LIBRARY_FLAGS ${ _targetName } STATIC_LIBRARY_FLAGS )
GET_TARGET_PROPERTY ( _STATIC_LIBRARY_FLAGS ${ _targetName } STATIC_LIBRARY_FLAGS )
IF ( NOT _STATIC_LIBRARY_FLAGS )
IF ( NOT _STATIC_LIBRARY_FLAGS )
SET ( _STATIC_LIBRARY_FLAGS )
SET ( _STATIC_LIBRARY_FLAGS )
ENDIF ( NOT _STATIC_LIBRARY_FLAGS )
ENDIF ( )
SET ( _STATIC_LIBRARY_FLAGS "${PCH_OUTPUT}.obj ${_STATIC_LIBRARY_FLAGS}" )
SET ( _STATIC_LIBRARY_FLAGS "${PCH_OUTPUT}.obj ${_STATIC_LIBRARY_FLAGS}" )
GET_TARGET_PROPERTY ( _LINK_FLAGS ${ _targetName } LINK_FLAGS )
GET_TARGET_PROPERTY ( _LINK_FLAGS ${ _targetName } LINK_FLAGS )
IF ( NOT _LINK_FLAGS )
IF ( NOT _LINK_FLAGS )
SET ( _LINK_FLAGS )
SET ( _LINK_FLAGS )
ENDIF ( NOT _LINK_FLAGS )
ENDIF ( )
SET ( _LINK_FLAGS "${PCH_OUTPUT}.obj ${_LINK_FLAGS}" )
SET ( _LINK_FLAGS "${PCH_OUTPUT}.obj ${_LINK_FLAGS}" )
SET_TARGET_PROPERTIES ( ${ _targetName } PROPERTIES STATIC_LIBRARY_FLAGS ${ _STATIC_LIBRARY_FLAGS } LINK_FLAGS ${ _LINK_FLAGS } )
SET_TARGET_PROPERTIES ( ${ _targetName } PROPERTIES STATIC_LIBRARY_FLAGS ${ _STATIC_LIBRARY_FLAGS } LINK_FLAGS ${ _LINK_FLAGS } )
ELSE ( MSVC )
ELSE ( )
# f o r u s e w i t h d i s t c c a n d g c c > 4 . 0 . 1 i f p r e p r o c e s s e d f i l e s a r e a c c e s s i b l e
# f o r u s e w i t h d i s t c c a n d g c c > 4 . 0 . 1 i f p r e p r o c e s s e d f i l e s a r e a c c e s s i b l e
# o n a l l r e m o t e m a c h i n e s s e t
# o n a l l r e m o t e m a c h i n e s s e t
# P C H _ A D D I T I O N A L _ C O M P I L E R _ F L A G S t o - f p c h - p r e p r o c e s s
# P C H _ A D D I T I O N A L _ C O M P I L E R _ F L A G S t o - f p c h - p r e p r o c e s s
@ -299,21 +363,21 @@ MACRO(ADD_PRECOMPILED_HEADER_TO_TARGET _targetName)
# I f n o a r c h i s s p e c i f i e d , c r e a t e c o m m o n f l a g s
# I f n o a r c h i s s p e c i f i e d , c r e a t e c o m m o n f l a g s
IF ( PCH_ARCHS_COUNT LESS 2 )
IF ( PCH_ARCHS_COUNT LESS 2 )
SET ( PCH_ADDITIONAL_COMPILER_FLAGS "-include ${PCH_INPUT} ${PCH_ADDITIONAL_COMPILER_FLAGS}" )
SET ( PCH_ADDITIONAL_COMPILER_FLAGS "-include ${PCH_INPUT} ${PCH_ADDITIONAL_COMPILER_FLAGS}" )
ENDIF ( PCH_ARCHS_COUNT LESS 2 )
ENDIF ( )
IF ( APPLE )
IF ( APPLE )
SET ( PCH_ADDITIONAL_COMPILER_FLAGS "-fobjc-abi-version=2 -fobjc-legacy-dispatch -x objective-c++ ${PCH_ADDITIONAL_COMPILER_FLAGS}" )
SET ( PCH_ADDITIONAL_COMPILER_FLAGS "-fobjc-abi-version=2 -fobjc-legacy-dispatch -x objective-c++ ${PCH_ADDITIONAL_COMPILER_FLAGS}" )
ENDIF ( APPLE )
ENDIF ( )
IF ( WITH_PCH_DEBUG )
IF ( WITH_PCH_DEBUG )
SET ( PCH_ADDITIONAL_COMPILER_FLAGS "-H ${PCH_ADDITIONAL_COMPILER_FLAGS}" )
SET ( PCH_ADDITIONAL_COMPILER_FLAGS "-H ${PCH_ADDITIONAL_COMPILER_FLAGS}" )
ENDIF ( WITH_PCH_DEBUG )
ENDIF ( )
SET ( _target_cflags "${oldProps} ${PCH_ADDITIONAL_COMPILER_FLAGS} -Winvalid-pch" )
SET ( _target_cflags "${oldProps} ${PCH_ADDITIONAL_COMPILER_FLAGS} -Winvalid-pch" )
ENDIF ( MSVC )
ENDIF ( )
SET_TARGET_PROPERTIES ( ${ _targetName } PROPERTIES COMPILE_FLAGS ${ _target_cflags } )
SET_TARGET_PROPERTIES ( ${ _targetName } PROPERTIES COMPILE_FLAGS ${ _target_cflags } )
ENDMACRO ( ADD_PRECOMPILED_HEADER_TO_TARGET )
ENDMACRO ( )
# A d d s p e c i f i c f l a g s f o r a n a r c h
# A d d s p e c i f i c f l a g s f o r a n a r c h
MACRO ( ADD_PRECOMPILED_HEADER_TO_TARGET_ARCH _targetName _arch )
MACRO ( ADD_PRECOMPILED_HEADER_TO_TARGET_ARCH _targetName _arch )
@ -324,19 +388,19 @@ MACRO(ADD_PRECOMPILED_HEADER_TO_TARGET_ARCH _targetName _arch)
IF ( ${ _FLAGS } MATCHES NOTFOUND )
IF ( ${ _FLAGS } MATCHES NOTFOUND )
SET ( _FLAGS "" )
SET ( _FLAGS "" )
ENDIF ( ${ _FLAGS } MATCHES NOTFOUND )
ENDIF ( )
SET ( _FLAGS "${_FLAGS} -Xarch_${_arch} -include${PCH_INPUT}" )
SET ( _FLAGS "${_FLAGS} -Xarch_${_arch} -include${PCH_INPUT}" )
SET_TARGET_PROPERTIES ( ${ _targetName } PROPERTIES COMPILE_FLAGS ${ _FLAGS } )
SET_TARGET_PROPERTIES ( ${ _targetName } PROPERTIES COMPILE_FLAGS ${ _FLAGS } )
ENDIF ( PCH_ARCHS_COUNT GREATER 1 )
ENDIF ( )
ENDMACRO ( ADD_PRECOMPILED_HEADER_TO_TARGET_ARCH )
ENDMACRO ( )
MACRO ( PCH_CREATE_TARGET _targetName _targetNamePCH )
MACRO ( PCH_CREATE_TARGET _targetName _targetNamePCH )
ADD_CUSTOM_COMMAND ( OUTPUT ${ PCH_OUTPUT } COMMAND ${ PCH_COMMAND } COMMENT "Generating ${_targetNamePCH}" DEPENDS ${ PCH_INPUT } )
ADD_CUSTOM_COMMAND ( OUTPUT ${ PCH_OUTPUT } COMMAND ${ PCH_COMMAND } COMMENT "Generating ${_targetNamePCH}" DEPENDS ${ PCH_INPUT } )
ADD_CUSTOM_TARGET ( ${ _targetNamePCH } DEPENDS ${ PCH_INPUT } ${ PCH_OUTPUT } )
ADD_CUSTOM_TARGET ( ${ _targetNamePCH } DEPENDS ${ PCH_INPUT } ${ PCH_OUTPUT } )
ADD_DEPENDENCIES ( ${ _targetName } ${ _targetNamePCH } )
ADD_DEPENDENCIES ( ${ _targetName } ${ _targetNamePCH } )
ENDMACRO ( PCH_CREATE_TARGET _targetName _inputh _inputcpp )
ENDMACRO ( )
MACRO ( ADD_PRECOMPILED_HEADER _targetName _inputh _inputcpp )
MACRO ( ADD_PRECOMPILED_HEADER _targetName _inputh _inputcpp )
SET ( _PCH_current_target ${ _targetName } )
SET ( _PCH_current_target ${ _targetName } )
@ -346,7 +410,7 @@ MACRO(ADD_PRECOMPILED_HEADER _targetName _inputh _inputcpp)
" T h i s i s t h e A D D _ P R E C O M P I L E D _ H E A D E R m a c r o . "
" T h i s i s t h e A D D _ P R E C O M P I L E D _ H E A D E R m a c r o . "
" Y o u m u s t s e t C M A K E _ B U I L D _ T Y P E ! "
" Y o u m u s t s e t C M A K E _ B U I L D _ T Y P E ! "
)
)
ENDIF ( NOT CMAKE_BUILD_TYPE )
ENDIF ( )
PCH_SET_COMPILE_FLAGS ( ${ _targetName } )
PCH_SET_COMPILE_FLAGS ( ${ _targetName } )
@ -362,68 +426,67 @@ MACRO(ADD_PRECOMPILED_HEADER _targetName _inputh _inputcpp)
PCH_CREATE_TARGET ( ${ _targetName } ${ _targetName } _pch_ ${ _ARCH } )
PCH_CREATE_TARGET ( ${ _targetName } ${ _targetName } _pch_ ${ _ARCH } )
ADD_PRECOMPILED_HEADER_TO_TARGET_ARCH ( ${ _targetName } ${ _ARCH } )
ADD_PRECOMPILED_HEADER_TO_TARGET_ARCH ( ${ _targetName } ${ _ARCH } )
ENDFOREACH ( _ARCH )
ENDFOREACH ( )
ELSE ( PCH_ARCHS )
ELSE ( )
PCH_SET_PRECOMPILED_HEADER_OUTPUT ( ${ _targetName } ${ _inputh } "" "" )
PCH_SET_PRECOMPILED_HEADER_OUTPUT ( ${ _targetName } ${ _inputh } "" "" )
LIST ( APPEND PCH_OUTPUTS ${ PCH_OUTPUT } )
LIST ( APPEND PCH_OUTPUTS ${ PCH_OUTPUT } )
PCH_SET_COMPILE_COMMAND ( ${ _inputcpp } "${PCH_FLAGS}" )
PCH_SET_COMPILE_COMMAND ( ${ _inputcpp } "${PCH_FLAGS}" )
PCH_CREATE_TARGET ( ${ _targetName } ${ _targetName } _pch )
PCH_CREATE_TARGET ( ${ _targetName } ${ _targetName } _pch )
ENDIF ( PCH_ARCHS )
ENDIF ( )
ADD_PRECOMPILED_HEADER_TO_TARGET ( ${ _targetName } )
ADD_PRECOMPILED_HEADER_TO_TARGET ( ${ _targetName } )
SET_DIRECTORY_PROPERTIES ( PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${PCH_OUTPUTS}" )
SET_DIRECTORY_PROPERTIES ( PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${PCH_OUTPUTS}" )
ENDMACRO ( ADD_PRECOMPILED_HEADER )
ENDMACRO ( )
MACRO ( ADD_NATIVE_PRECOMPILED_HEADER _targetName _inputh _inputcpp )
MACRO ( ADD_NATIVE_PRECOMPILED_HEADER _targetName _inputh _inputcpp )
IF ( NOT PCHSupport_FOUND )
IF ( PCHSupport_FOUND )
# 0 = > c r e a t i n g a n e w t a r g e t f o r P C H , w o r k s f o r a l l m a k e f i l e s
# 1 = > s e t t i n g P C H f o r V C + + p r o j e c t , w o r k s f o r V C + + p r o j e c t s
# 2 = > s e t t i n g P C H f o r X C o d e p r o j e c t , w o r k s f o r X C o d e p r o j e c t s
IF ( CMAKE_GENERATOR MATCHES "Visual Studio" )
SET ( PCH_METHOD 1 )
ELSEIF ( CMAKE_GENERATOR MATCHES "Xcode" )
SET ( PCH_METHOD 2 )
ELSE ( )
SET ( PCH_METHOD 0 )
ENDIF ( )
IF ( PCH_METHOD EQUAL 1 )
# A u t o i n c l u d e t h e precompile ( useful for moc processing, since the use of
# p r e c o m p i l e d i s s p e c i f i e d a t t h e t a r g e t l e v e l
# a n d I d o n ' t w a n t t o s p e c i f i y / F - f o r e a c h m o c / r e s / u i g e n e r a t e d files ( using Qt )
GET_TARGET_PROPERTY ( oldProps ${ _targetName } COMPILE_FLAGS )
IF ( ${ oldProps } MATCHES NOTFOUND )
SET ( oldProps "" )
ENDIF ( )
SET ( newProperties "${oldProps} /Yu\" ${ _inputh } \" /FI\ "${_inputh}\" " )
SET_TARGET_PROPERTIES ( ${ _targetName } PROPERTIES COMPILE_FLAGS "${newProperties}" )
# a l s o i n l u d e $ { o l d P r o p s } t o h a v e t h e s a m e c o m p i l e o p t i o n s
SET_SOURCE_FILES_PROPERTIES ( ${ _inputcpp } PROPERTIES COMPILE_FLAGS "${oldProps} /Yc\" ${ _inputh } \"")
ELSEIF ( PCH_METHOD EQUAL 2 )
# F o r X c o d e , c m a k e n e e d s m y p a t c h t o p r o c e s s
# G C C _ P R E F I X _ H E A D E R a n d G C C _ P R E C O M P I L E _ P R E F I X _ H E A D E R a s t a r g e t p r o p e r t i e s
# W h e n b u i d i n g o u t o f t h e t r e e , p r e c o m p i l e d m a y n o t b e l o c a t e d
# U s e f u l l p a t h i n s t e a d .
GET_FILENAME_COMPONENT ( fullPath ${ _inputh } ABSOLUTE )
SET_TARGET_PROPERTIES ( ${ _targetName } PROPERTIES XCODE_ATTRIBUTE_GCC_PREFIX_HEADER "${fullPath}" )
SET_TARGET_PROPERTIES ( ${ _targetName } PROPERTIES XCODE_ATTRIBUTE_GCC_PRECOMPILE_PREFIX_HEADER "YES" )
ELSE ( )
# F a l l b a c k t o t h e " o l d " p r e c o m p i l e d s u p p p o r t
ADD_PRECOMPILED_HEADER ( ${ _targetName } ${ _inputh } ${ _inputcpp } )
ENDIF ( )
IF ( TARGET ${ _targetName } _static )
ADD_NATIVE_PRECOMPILED_HEADER ( ${ _targetName } _static ${ _inputh } ${ _inputcpp } )
ENDIF ( )
ELSE ( )
MESSAGE ( STATUS "PCH disabled because compiler doesn't support them" )
MESSAGE ( STATUS "PCH disabled because compiler doesn't support them" )
RETURN ( )
ENDIF ( )
ENDIF ( NOT PCHSupport_FOUND )
ENDMACRO ( )
# 0 = > c r e a t i n g a n e w t a r g e t f o r P C H , w o r k s f o r a l l m a k e f i l e s
# 1 = > s e t t i n g P C H f o r V C + + p r o j e c t , w o r k s f o r V C + + p r o j e c t s
# 2 = > s e t t i n g P C H f o r X C o d e p r o j e c t , w o r k s f o r X C o d e p r o j e c t s
IF ( CMAKE_GENERATOR MATCHES "Visual Studio" )
SET ( PCH_METHOD 1 )
ELSEIF ( CMAKE_GENERATOR MATCHES "Xcode" )
SET ( PCH_METHOD 2 )
ELSE ( CMAKE_GENERATOR MATCHES "Visual Studio" )
SET ( PCH_METHOD 0 )
ENDIF ( CMAKE_GENERATOR MATCHES "Visual Studio" )
IF ( PCH_METHOD EQUAL 1 )
# A u t o i n c l u d e t h e precompile ( useful for moc processing, since the use of
# p r e c o m p i l e d i s s p e c i f i e d a t t h e t a r g e t l e v e l
# a n d I d o n ' t w a n t t o s p e c i f i y / F - f o r e a c h m o c / r e s / u i g e n e r a t e d files ( using Qt )
GET_TARGET_PROPERTY ( oldProps ${ _targetName } COMPILE_FLAGS )
IF ( ${ oldProps } MATCHES NOTFOUND )
SET ( oldProps "" )
ENDIF ( ${ oldProps } MATCHES NOTFOUND )
SET ( newProperties "${oldProps} /Yu\" ${ _inputh } \" /FI\ "${_inputh}\" " )
SET_TARGET_PROPERTIES ( ${ _targetName } PROPERTIES COMPILE_FLAGS "${newProperties}" )
# a l s o i n l u d e $ { o l d P r o p s } t o h a v e t h e s a m e c o m p i l e o p t i o n s
SET_SOURCE_FILES_PROPERTIES ( ${ _inputcpp } PROPERTIES COMPILE_FLAGS "${oldProps} /Yc\" ${ _inputh } \"")
ELSEIF ( PCH_METHOD EQUAL 2 )
# F o r X c o d e , c m a k e n e e d s m y p a t c h t o p r o c e s s
# G C C _ P R E F I X _ H E A D E R a n d G C C _ P R E C O M P I L E _ P R E F I X _ H E A D E R a s t a r g e t p r o p e r t i e s
# W h e n b u i d i n g o u t o f t h e t r e e , p r e c o m p i l e d m a y n o t b e l o c a t e d
# U s e f u l l p a t h i n s t e a d .
GET_FILENAME_COMPONENT ( fullPath ${ _inputh } ABSOLUTE )
SET_TARGET_PROPERTIES ( ${ _targetName } PROPERTIES XCODE_ATTRIBUTE_GCC_PREFIX_HEADER "${fullPath}" )
SET_TARGET_PROPERTIES ( ${ _targetName } PROPERTIES XCODE_ATTRIBUTE_GCC_PRECOMPILE_PREFIX_HEADER "YES" )
ELSE ( PCH_METHOD EQUAL 1 )
# F a l l b a c k t o t h e " o l d " p r e c o m p i l e d s u p p p o r t
ADD_PRECOMPILED_HEADER ( ${ _targetName } ${ _inputh } ${ _inputcpp } )
ENDIF ( PCH_METHOD EQUAL 1 )
IF ( TARGET ${ _targetName } _static )
ADD_NATIVE_PRECOMPILED_HEADER ( ${ _targetName } _static ${ _inputh } ${ _inputcpp } )
ENDIF ( TARGET ${ _targetName } _static )
ENDMACRO ( ADD_NATIVE_PRECOMPILED_HEADER )