@ -290,8 +290,22 @@ function(go_library TARGET_NAME)
set ( ${ TARGET_NAME } _LIB_NAME "${CMAKE_STATIC_LIBRARY_PREFIX}${TARGET_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}" CACHE STRING "output library name for target ${TARGET_NAME}" )
endif ( )
# A d d d u m m y c o d e t o s u p p o r t ` m a k e t a r g e t _ n a m e ` u n d e r T e r m i n a l C o m m a n d
set ( dummyfile ${ CMAKE_CURRENT_BINARY_DIR } / ${ TARGET_NAME } _dummy.c )
# T h i s c u s t o m c o m m a n d w i l l a l w a y s r u n s i n c e i t d e p e n d s o n a n o t
# e x i s t i n g f i l e .
add_custom_command (
O U T P U T d u m m y _ r e b u l i d _ $ { T A R G E T _ N A M E }
C O M M A N D c m a k e - E t o u c h $ { d u m m y f i l e }
)
# C r e a t e a c u s t o m t a r g e t t h a t d e p e n d s o n t h e c u s t o m c o m m a n d o u t p u t
# f i l e , s o t h e c u s t o m c o m m a n d c a n b e r e f e r e n c e d a s a d e p e n d e n c y b y
# ` a d d _ d e p e n d e n c i e s ` .
add_custom_target ( rebuild_ ${ TARGET_NAME }
D E P E N D S d u m m y _ r e b u l i d _ $ { T A R G E T _ N A M E }
)
# A d d d u m m y c o d e t o s u p p o r t ` m a k e t a r g e t _ n a m e ` u n d e r T e r m i n a l C o m m a n d
file ( WRITE ${ dummyfile } "const char * dummy = \" ${ dummyfile } \";")
if ( go_library_SHARED OR go_library_shared )
add_library ( ${ TARGET_NAME } SHARED ${ dummyfile } )
@ -302,6 +316,12 @@ function(go_library TARGET_NAME)
add_dependencies ( ${ TARGET_NAME } ${ go_library_DEPS } )
endif ( go_library_DEPS )
# T h e " s o u r c e f i l e " o f t h e l i b r a r y i s ` $ { d u m m y f i l e } ` w h i c h n e v e r
# c h a n g e , s o t h e t a r g e t w i l l n e v e r r e b u i l d . M a k e t h e t a r g e t d e p e n d s
# o n t h e c u s t o m c o m m a n d t h a t t o u c h e s t h e l i b r a r y " s o u r c e f i l e " , s o
# r e b u i l d w i l l a l w a y s h a p p e n .
add_dependencies ( ${ TARGET_NAME } rebuild_ ${ TARGET_NAME } )
set ( ${ TARGET_NAME } _LIB_PATH "${CMAKE_CURRENT_BINARY_DIR}/${${TARGET_NAME}_LIB_NAME}" CACHE STRING "output library path for target ${TARGET_NAME}" )
file ( GLOB GO_SOURCE RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.go" )