2022-05-26 16:25:55 +00:00
# We do this via a custom command that re-invokes a cmake script because we need the DEPENDS on .git/index so that we will re-run it (to regenerate the commit tag in the version) whenever the current commit changes. If we used a configure_file directly here, it would only re-run when something else causes cmake to re-run.
2019-12-12 02:32:27 +00:00
2022-05-31 01:07:36 +00:00
if ( LOKINET_VERSIONTAG )
set ( VERSIONTAG "${LOKINET_VERSIONTAG}" )
2022-05-26 16:25:55 +00:00
configure_file ( "${CMAKE_CURRENT_SOURCE_DIR}/constants/version.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/constants/version.cpp" @ONLY )
2022-05-31 01:07:36 +00:00
else ( )
set ( VERSIONTAG "${GIT_VERSION}" )
set ( GIT_INDEX_FILE "${PROJECT_SOURCE_DIR}/.git/index" )
find_package ( Git )
if ( EXISTS "${GIT_INDEX_FILE}" AND ( GIT_FOUND OR Git_FOUND ) )
message ( STATUS "Found Git: ${GIT_EXECUTABLE}" )
set ( genversion_args "-DGIT=${GIT_EXECUTABLE}" )
foreach ( v lokinet_VERSION lokinet_VERSION_MAJOR lokinet_VERSION_MINOR lokinet_VERSION_PATCH RELEASE_MOTTO )
list ( APPEND genversion_args "-D${v}=${${v}}" )
endforeach ( )
add_custom_command (
O U T P U T " $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / c o n s t a n t s / v e r s i o n . c p p "
C O M M A N D " $ { C M A K E _ C O M M A N D } "
$ { g e n v e r s i o n _ a r g s }
" - D " " S R C = $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / c o n s t a n t s / v e r s i o n . c p p . i n "
" - D " " D E S T = $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / c o n s t a n t s / v e r s i o n . c p p "
" - P " " $ { C M A K E _ C U R R E N T _ L I S T _ D I R } / G e n V e r s i o n . c m a k e "
D E P E N D S " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / c o n s t a n t s / v e r s i o n . c p p . i n "
" $ { G I T _ I N D E X _ F I L E } " )
else ( )
configure_file ( "${CMAKE_CURRENT_SOURCE_DIR}/constants/version.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/constants/version.cpp" @ONLY )
endif ( )
2022-05-30 17:59:12 +00:00
endif ( )
if ( WIN32 )
foreach ( exe IN ITEMS lokinet lokinet-vpn lokinet-bootstrap )
set ( lokinet_EXE_NAME "${exe}.exe" )
configure_file ( "${CMAKE_CURRENT_SOURCE_DIR}/win32/version.rc.in" "${CMAKE_BINARY_DIR}/${exe}.rc" @ONLY )
set_property ( SOURCE "${CMAKE_BINARY_DIR}/${exe}.rc" PROPERTY GENERATED 1 )
endforeach ( )
2019-12-12 02:32:27 +00:00
endif ( )
2022-05-26 16:25:55 +00:00
add_custom_target ( genversion_cpp DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/constants/version.cpp" )
if ( WIN32 )
2022-05-27 14:14:31 +00:00
add_custom_target ( genversion_rc DEPENDS "${CMAKE_BINARY_DIR}/lokinet.rc" "${CMAKE_BINARY_DIR}/lokinet-vpn.rc" "${CMAKE_BINARY_DIR}/lokinet-bootstrap.rc" )
2022-05-26 16:25:55 +00:00
else ( )
add_custom_target ( genversion_rc )
endif ( )
add_custom_target ( genversion DEPENDS genversion_cpp genversion_rc )