@ -30,54 +30,62 @@ FUNCTION(EXECUTE_PROCESS_AND_CHECK_RESULT)
ENDIF ( )
ENDFUNCTION ( )
macro ( make_target_name target source )
if ( BUILDING_FROM_VCS )
set ( TGT_BUILD_SOURCE_DIR ${ CMAKE_BINARY_DIR } )
set ( TGT_CURRENT_BUILD_SOURCE_DIR ${ CMAKE_CURRENT_BINARY_DIR } )
else ( )
set ( TGT_BUILD_SOURCE_DIR ${ CMAKE_SOURCE_DIR } )
set ( TGT_CURRENT_BUILD_SOURCE_DIR ${ CMAKE_CURRENT_SOURCE_DIR } )
endif ( )
file ( RELATIVE_PATH rel_file ${ TGT_BUILD_SOURCE_DIR } ${ TGT_CURRENT_BUILD_SOURCE_DIR } / ${ source } )
string ( REPLACE "/" "-" target_tmp ${ rel_file } )
string ( REPLACE "_" "-" target_tmp2 ${ target_tmp } )
string ( REPLACE "." "-" ${ target } dist- ${ target_tmp2 } )
endmacro ( )
# T h e s e m a c r o s c a n b e c a l l e d t o a d d g e n e r a t e d files ( as opposed to source files )
# T h e s e f u n c t i o n s c a n b e c a l l e d t o a d d g e n e r a t e d files ( as opposed to source files )
# t o t h e d i s t r i b u t i o n t a r b a l l
# - d i s t _ a d d _ c o n f i g u r e d w i l l o n l y a d d t h e f i l e s t o t h e t a r b a l l . T h i s ma c r o
# - d i s t _ a d d _ c o n f i g u r e d w i l l o n l y a d d t h e f i l e s t o t h e t a r b a l l . T h i s f u n c t i o n
# s h o u l d b e u s e d f o r f i l e s t h a t a r e g e n e r a t e d d u r i n g a c m a k e run ( for example with configure_file )
# - d i s t _ a d d _ g e n e r a t e d w i l l a d d t h e f i l e s t o t h e t a r b a l l a n d g e n e r a t e a d e p e n d e n c y
# f o r e a c h f i l e t o t h e d i s t t a r g e t . T h i s ma c r o s h o u l d b e u s e d f o r a l l f i l e s t h a t
# f o r e a c h f i l e t o t h e d i s t t a r g e t . T h i s f u n c t i o n s h o u l d b e u s e d f o r a l l f i l e s t h a t
# w i l l b e g e n e r a t e d d u r i n g a " m a k e " o r " n i n j a - b u i l d " run ( for example those that are
# t h e r e s u l t o f a n a d d _ c u s t o m _ c o m m a n d )
macro ( dist_add_configured )
if ( BUILDING_FROM_VCS )
set ( CONF_BUILD_SOURCE_DIR ${ CMAKE_BINARY_DIR } )
set ( CONF_CURRENT_BUILD_SOURCE_DIR ${ CMAKE_CURRENT_BINARY_DIR } )
#
# N o t e t h a t t h e f i l e s p a s s e d i n t h e s e f u n c t i o n s c a n s t i l l b e i n t h e s o u r c e d i r e c t o r y
# T h i s d e p e n d s o n w h e t h e r o r n o t t h e s o u r c e i s a g i t w o r k t r e e o r n o t a n d w h i c h
# o p t i o n s w e r e p a s s e d t o c m a k e .
# T o d e t e r m i n e t h i s , t h e f i r s t p a r a m e t e r p a s s e d t o t h i s f u n c t i o n s h o u l d
# b e a n i n d i c a t o r w h e t h e r o r n o t t h e f i l e s i n t h e l i s t a r e a c t u a l l y b u i l t
# i n t h i s c o n f i g u r a t i o n . A t t h e t i m e o f t h i s w r i t i n g t h e r e a r e t w o
# c m a k e v a r i a b l e s t h a t c o n t r o l t h i s , a n d h e n c e c a n b e u s e d h e r e :
# B U I L D I N G _ F R O M _ V C S : i s Y E S w h e n b u i l d i n g f r o m a g i t s o u r c e t r e e
# G E N E R A T E _ S W I G _ W R A P P E R S : i s Y E S w h e n t h e s w i g w r a p p e r s s h o u l d b e b u i l t
function ( dist_add_generated_internal _needs_target _is_built )
if ( _is_built )
set ( DIST_BUILD_SOURCE_DIR ${ CMAKE_BINARY_DIR } )
set ( DIST_CURRENT_BUILD_SOURCE_DIR ${ CMAKE_CURRENT_BINARY_DIR } )
else ( )
set ( CONF_BUILD_SOURCE_DIR ${ CMAKE_SOURCE_DIR } )
set ( CONF_CURRENT_BUILD_SOURCE_DIR ${ CMAKE_CURRENT_SOURCE_DIR } )
set ( DIST _BUILD_SOURCE_DIR ${ CMAKE_SOURCE_DIR } )
set ( DIST _CURRENT_BUILD_SOURCE_DIR ${ CMAKE_CURRENT_SOURCE_DIR } )
endif ( )
set ( local_generated ${ dist_generated } )
foreach ( conf_file ${ ARGN } )
file ( RELATIVE_PATH rel_conf ${ CONF_BUILD_SOURCE_DIR } ${ CONF_CURRENT_BUILD_SOURCE_DIR } / ${ conf_file } )
list ( APPEND local_generated ${ rel_conf } )
set ( local_generated ${ dist_generated } )
foreach ( conf_file ${ ARGN } )
file ( RELATIVE_PATH rel_conf ${ DIST_BUILD_SOURCE_DIR} ${ DIST _CURRENT_BUILD_SOURCE_DIR} / ${ conf_file } )
list ( APPEND local_generated ${ rel_conf } )
endforeach ( )
set ( dist_generated ${ local_generated } CACHE INTERNAL "generated files that will be included in the distribution tarball" )
endmacro ( )
set ( dist_generated ${ local_generated }
C A C H E I N T E R N A L " g e n e r a t e d f i l e s t h a t w i l l b e i n c l u d e d i n t h e d i s t r i b u t i o n t a r b a l l " )
macro ( dist_add_generated )
dist_add_configured ( ${ ARGN } )
if ( _needs_target )
set ( local_generated_depends ${ dist_generated_depends } )
foreach ( gen_file ${ ARGN } )
file ( RELATIVE_PATH rel_file ${ DIST_BUILD_SOURCE_DIR } ${ DIST_CURRENT_BUILD_SOURCE_DIR } / ${ gen_file } )
string ( REPLACE "/" "-" target_tmp ${ rel_file } )
string ( REPLACE "_" "-" target_tmp2 ${ target_tmp } )
string ( REPLACE "." "-" dist_target dist- ${ target_tmp2 } )
set ( local_generated_depends ${ dist_generated_depends } )
foreach ( gen_file ${ ARGN } )
make_target_name ( dist_target ${ gen_file } )
add_custom_target ( ${ dist_target } DEPENDS ${ TGT_CURRENT_BUILD_SOURCE_DIR } / ${ gen_file } ) # N o t e T G T _ C U R R E N T _ B U I L D _ S O U R C E _ D I R t r i c k l e s d o w n f r o m t h e m a k e _ t a r g e t m a c r o
list ( APPEND local_generated_depends ${ dist_target } )
endforeach ( )
set ( dist_generated_depends ${ local_generated_depends } CACHE INTERNAL "global targets for generated files that will be included in the distribution tarball" )
endmacro ( )
add_custom_target ( ${ dist_target }
D E P E N D S $ { D I S T _ C U R R E N T _ B U I L D _ S O U R C E _ D I R } / $ { g e n _ f i l e } )
list ( APPEND local_generated_depends ${ dist_target } )
endforeach ( )
set ( dist_generated_depends ${ local_generated_depends }
C A C H E I N T E R N A L " g l o b a l t a r g e t s f o r g e n e r a t e d f i l e s t h a t w i l l b e i n c l u d e d i n t h e d i s t r i b u t i o n t a r b a l l " )
endif ( )
endfunction ( )
function ( dist_add_configured _is_built )
dist_add_generated_internal ( NO ${ _is_built } ${ ARGN } )
endfunction ( )
function ( dist_add_generated _is_built )
dist_add_generated_internal ( YES ${ _is_built } ${ ARGN } )
endfunction ( )