@ -27,23 +27,45 @@ ELSE()
ENDIF ( )
ENDIF ( )
MACRO ( APPEND_DEFINITION _NAME _VAL )
IF ( CMAKE_VERSION VERSION_LESS "2.8.12" )
# d o n ' t s u p p o r t l o g i c a l e x p r e s s i o n s , a p p e n d d e f i n i t i o n
LIST ( APPEND ${ _NAME } "-D${_VAL}" )
ELSE ( )
# s u p p o r t l o g i c a l e x p r e s s i o n s , u s e t h e m
LIST ( APPEND ${ _NAME } "$<$<BOOL:${_VAL}>:-D$<JOIN:${_VAL},-D>>" )
ENDIF ( )
ENDMACRO ( )
# 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 )
SET ( PCH_FLAGS )
SET ( PCH_ARCHS )
SET ( _FLAGS )
LIST ( APPEND _FLAGS ${ CMAKE_CXX_FLAGS } )
# C + + f l a g s
SET ( _FLAG ${ CMAKE_CXX_FLAGS } )
SEPARATE_ARGUMENTS ( _FLAG )
LIST ( APPEND _FLAGS ${ _FLAG } )
# C + + c o n f i g f l a g s
STRING ( TOUPPER "${CMAKE_BUILD_TYPE}" _UPPER_BUILD )
LIST ( APPEND _FLAGS " ${CMAKE_CXX_FLAGS_${_UPPER_BUILD}}" )
SET ( _FLAG ${ CMAKE_CXX_FLAGS_${_UPPER_BUILD } } )
SEPARATE_ARGUMENTS ( _FLAG )
LIST ( APPEND _FLAGS ${ _FLAG } )
GET_TARGET_PROPERTY ( _targetType ${ _target } TYPE )
SET ( _USE_PIC OFF )
IF ( ${ _targetType } STREQUAL "SHARED_LIBRARY" OR ${ _targetType } STREQUAL "MODULE_LIBRARY" )
LIST ( APPEND _FLAGS " ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}" )
SET ( _FLAG ${ CMAKE_SHARED_LIBRARY_CXX_FLAGS } )
SEPARATE_ARGUMENTS ( _FLAG )
LIST ( APPEND _FLAGS ${ _FLAG } )
ELSE ( )
GET_TARGET_PROPERTY ( _pic ${ _target } POSITION_INDEPENDENT_CODE )
IF ( _pic )
@ -53,67 +75,71 @@ MACRO(PCH_SET_COMPILE_FLAGS _target)
GET_DIRECTORY_PROPERTY ( DIRINC INCLUDE_DIRECTORIES )
FOREACH ( item ${ DIRINC } )
LIST ( APPEND _FLAGS " -I\" ${ item } \"" )
LIST ( APPEND _FLAGS -I "${item}" )
ENDFOREACH ( )
# N O T E : A s c m a k e files ( eg FindQT4 ) m a y n o w u s e g e n e r a t o r e x p r e s s i o n s a r o u n d t h e i r d e f i n e s t h a t e v a l u a t e
# t o a n e m p t y s t r i n g , w r a p a l l " i t e m s " i n a n e x p r e s s i o n t h a t o u t p u t s a - D I F F t h e g e n e r a t e d
# e x p r e s s i o n i s n o t e m p t y .
# R e q u i r e d f o r C M a k e 2 . 6
SET ( GLOBAL_DEFINITIONS )
GET_DIRECTORY_PROPERTY ( DEFINITIONS COMPILE_DEFINITIONS )
IF ( DEFINITIONS )
FOREACH ( item ${ DEFINITIONS } )
LIST( APPEND GLOBAL_DEFINITIONS " -D${item}" )
APPEND_DEFINITION( GLOBAL_DEFINITIONS ${ item } )
ENDFOREACH ( )
ENDIF ( )
GET_DIRECTORY_PROPERTY ( DEFINITIONS COMPILE_DEFINITIONS_ ${ _UPPER_BUILD } )
IF ( DEFINITIONS )
FOREACH ( item ${ DEFINITIONS } )
LIST( APPEND GLOBAL_DEFINITIONS " -D${item}" )
APPEND_DEFINITION( GLOBAL_DEFINITIONS ${ item } )
ENDFOREACH ( )
ENDIF ( )
GET_DIRECTORY_PROPERTY ( DEFINITIONS DIRECTORY ${ CMAKE_SOURCE_DIR } COMPILE_DEFINITIONS )
IF ( DEFINITIONS )
FOREACH ( item ${ DEFINITIONS } )
LIST( APPEND GLOBAL_DEFINITIONS " -D${item}" )
APPEND_DEFINITION( GLOBAL_DEFINITIONS ${ 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}" )
APPEND_DEFINITION( GLOBAL_DEFINITIONS ${ item } )
ENDFOREACH ( )
ENDIF ( )
GET_TARGET_PROPERTY ( oldProps ${ _target } COMPILE_FLAGS )
IF ( oldProps )
LIST ( APPEND _FLAGS " ${oldProps}" )
LIST ( APPEND _FLAGS ${ oldProps } )
ENDIF ( )
GET_TARGET_PROPERTY ( oldPropsBuild ${ _target } COMPILE_FLAGS_ ${ _UPPER_BUILD } )
IF ( oldPropsBuild )
LIST ( APPEND _FLAGS " ${oldPropsBuild}" )
LIST ( APPEND _FLAGS ${ oldPropsBuild } )
ENDIF ( )
GET_TARGET_PROPERTY ( DIRINC ${ _target } INCLUDE_DIRECTORIES )
IF ( DIRINC )
FOREACH ( item ${ DIRINC } )
LIST ( APPEND _FLAGS " -I\" ${ item } \"" )
LIST ( APPEND _FLAGS -I "${item}" )
ENDFOREACH ( )
ENDIF ( )
GET_TARGET_PROPERTY ( DEFINITIONS ${ _target } COMPILE_DEFINITIONS )
IF ( DEFINITIONS )
FOREACH ( item ${ DEFINITIONS } )
LIST( APPEND GLOBAL_DEFINITIONS " -D${item}" )
APPEND_DEFINITION( GLOBAL_DEFINITIONS ${ item } )
ENDFOREACH ( )
ENDIF ( )
GET_TARGET_PROPERTY ( DEFINITIONS ${ _target } COMPILE_DEFINITIONS_ ${ _UPPER_BUILD } )
IF ( DEFINITIONS )
FOREACH ( item ${ DEFINITIONS } )
LIST( APPEND GLOBAL_DEFINITIONS " -D${item}" )
APPEND_DEFINITION( GLOBAL_DEFINITIONS ${ item } )
ENDFOREACH ( )
ENDIF ( )
@ -126,7 +152,7 @@ MACRO(PCH_SET_COMPILE_FLAGS _target)
IF ( _DIRS )
FOREACH ( item ${ _DIRS } )
LIST ( APPEND GLOBAL_DEFINITIONS " -I\" ${ item } \"" )
LIST ( APPEND GLOBAL_DEFINITIONS -I "${item}" )
ENDFOREACH ( )
ENDIF ( )
@ -135,10 +161,7 @@ MACRO(PCH_SET_COMPILE_FLAGS _target)
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 ( )
APPEND_DEFINITION ( GLOBAL_DEFINITIONS ${ item } )
ENDFOREACH ( )
ENDIF ( )
ENDIF ( )
@ -149,7 +172,7 @@ MACRO(PCH_SET_COMPILE_FLAGS _target)
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")
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
@ -158,28 +181,39 @@ MACRO(PCH_SET_COMPILE_FLAGS _target)
ENDIF ( )
IF ( _USE_PIC )
LIST ( APPEND _FLAGS " ${CMAKE_CXX_COMPILE_OPTIONS_PIC}" )
LIST ( APPEND _FLAGS ${ CMAKE_CXX_COMPILE_OPTIONS_PIC } )
ENDIF ( )
ENDIF ( )
LIST ( APPEND _FLAGS " ${GLOBAL_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}" )
GET_DIRECTORY_PROPERTY ( _DIRECTORY_FLAGS DEFINITIONS )
IF ( _DIRECTORY_FLAGS )
SEPARATE_ARGUMENTS ( _DIRECTORY_FLAGS )
FOREACH ( item ${ _DIRECTORY_FLAGS } )
LIST ( APPEND _FLAGS "${item}" )
ENDFOREACH ( )
ENDIF ( )
GET_DIRECTORY_PROPERTY ( _DIRECTORY_DEFINITIONS DIRECTORY ${ CMAKE_SOURCE_DIR } DEFINITIONS )
IF ( _DIRECTORY_DEFINITIONS )
SEPARATE_ARGUMENTS ( _DIRECTORY_DEFINITIONS )
FOREACH ( item ${ _DIRECTORY_DEFINITIONS } )
LIST ( APPEND _FLAGS "${item}" )
ENDFOREACH ( )
ENDIF ( )
ENDIF ( )
# F o r m a t d e f i n i t i o n s
IF ( MSVC )
# F i x p a t h w i t h s p a c e
SEPARATE_ARGUMENTS ( _FLAGS UNIX_COMMAND "${_FLAGS}" )
ELSE ( )
STRING ( REGEX REPLACE " +" " " _FLAGS ${ _FLAGS } )
SEPARATE_ARGUMENTS ( _FLAGS )
ENDIF ( )
# A l r e a d y i n l i s t f o r m a n d i t e m s m a y c o n t a i n n o n - l e a d i n g s p a c e s t h a t s h o u l d n o t b e s p l i t o n
LIST ( INSERT _FLAGS 0 "${GLOBAL_DEFINITIONS}" )
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
SET ( _ARCH_NEXT )
@ -236,6 +270,7 @@ MACRO(PCH_SET_COMPILE_FLAGS _target)
ENDIF ( )
IF ( PCH_FLAGS )
LIST ( REMOVE_ITEM PCH_FLAGS "" )
LIST ( REMOVE_DUPLICATES PCH_FLAGS )
ENDIF ( )
ENDMACRO ( )
@ -247,16 +282,16 @@ MACRO(GET_PDB_FILENAME _out_filename _target)
SET ( _targetOutput ${ CMAKE_RUNTIME_OUTPUT_DIRECTORY } )
ELSEIF ( ${ _targetType } STREQUAL STATIC_LIBRARY )
SET ( _targetOutput ${ CMAKE_ARCHIVE_OUTPUT_DIRECTORY } )
ELSE ( ${ _targetType } STREQUAL EXECUTABLE )
ELSE ( )
SET ( _targetOutput ${ CMAKE_LIBRARY_OUTPUT_DIRECTORY } )
ENDIF ( ${ _targetType } STREQUAL EXECUTABLE )
ENDIF ( )
# d e t e r m i n e t a r g e t p o s t f i x
STRING ( TOUPPER "${CMAKE_BUILD_TYPE}_POSTFIX" _postfix_var_name )
GET_TARGET_PROPERTY ( _targetPostfix ${ _target } ${ _postfix_var_name } )
IF ( ${ _targetPostfix } MATCHES NOTFOUND )
SET ( _targetPostfix "" )
ENDIF ( ${ _targetPostfix } MATCHES NOTFOUND )
ENDIF ( )
SET ( ${ _out_filename } "${_targetOutput}/${_target}${_targetPostfix}.pdb" )
ENDMACRO ( GET_PDB_FILENAME )
@ -270,8 +305,9 @@ MACRO(PCH_SET_COMPILE_COMMAND _inputcpp _compile_FLAGS)
ENDIF ( )
IF ( MSVC )
GET_PDB_FILENAME ( PDB_FILE ${ _PCH_current_target } )
SET ( PCH_COMMAND ${ CMAKE_CXX_COMPILER } ${ pchsupport_compiler_cxx_arg1 } ${ _compile_FLAGS } /Yc /Fp "${PCH_OUTPUT}" ${ _inputcpp } /Fd "${PDB_FILE}" /c /Fo "${PCH_OUTPUT}.obj" )
GET_PDB_FILENAME ( _PDB_FILE ${ _PCH_current_target } )
SET ( PCH_COMMAND ${ CMAKE_CXX_COMPILER } ${ pchsupport_compiler_cxx_arg1 } ${ _compile_FLAGS } /Yc /Fp "${PCH_OUTPUT}" ${ _inputcpp } /Fd "${_PDB_FILE}" /c /Fo "${PCH_OUTPUT}.obj" )
# 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
SET_SOURCE_FILES_PROPERTIES ( ${ _inputcpp } PROPERTIES OBJECT_OUTPUTS "${PCH_OUTPUT}.obj" )