@@ -50,35 +50,49 @@ if (VTR_ENABLE_DEBUG_LOGGING)
5050 set (VTR_BUILD_INFO "${VTR_BUILD_INFO} debug_logging" )
5151endif ()
5252
53- # We always update the vtr_version.cpp file every time the project is built,
54- # to ensure the git revision and dirty status are up to date.
55- #
56- # We need to do this in two stages:
57- #
58- # 1) We a custom target 'version' (which is always out of date) so it will always be run.
59- # It touches the unprocessed version input file so it too will always be out of date.
60- #
61- # 2) The custom command depends on the touched version input file and generates the processed
62- # version file, with updated values. The custom command uses the configure_version.cmake
63- # script to generate the up-to-date vtr_version.cpp
64- add_custom_target (version ALL
65- COMMAND ${CMAKE_COMMAND} -E touch ${VTR_VERSION_FILE_IN} )
66-
67- add_custom_command (OUTPUT ${VTR_VERSION_FILE_OUT}
68- COMMAND ${CMAKE_COMMAND}
69- -D IN_FILE=${VTR_VERSION_FILE_IN}
70- -D OUT_FILE=${VTR_VERSION_FILE_OUT}
71- -D VTR_VERSION_MAJOR=${VTR_VERSION_MAJOR}
72- -D VTR_VERSION_MINOR=${VTR_VERSION_MINOR}
73- -D VTR_VERSION_PATCH=${VTR_VERSION_PATCH}
74- -D VTR_VERSION_PRERELEASE=${VTR_VERSION_PRERELEASE}
75- -D VTR_COMPILER_INFO=${VTR_COMPILER_INFO}
76- -D VTR_BUILD_INFO=${VTR_BUILD_INFO}
77- -P ${CMAKE_CURRENT_SOURCE_DIR} /cmake/modules/configure_version.cmake
78- MAIN_DEPENDENCY ${VTR_VERSION_FILE_IN}
79- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
80- VERBATIM )
53+ list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} /cmake/modules" )
54+ include (GetGitRevisionDescription)
55+
56+ # Get the VCS revision.
57+ git_describe_working_tree(VTR_VCS_REVISION --tags --always --long)
58+ string (FIND ${VTR_VCS_REVISION} "NOTFOUND" GIT_DESCRIBE_VTR_REVISION_NOTFOUND)
59+ if (NOT ${GIT_DESCRIBE_VTR_REVISION_NOTFOUND} EQUAL -1)
60+ # Git describe failed, usually this means we
61+ # aren't in a git repo -- so don't set a VCS
62+ # revision
63+ set (VTR_VCS_REVISION "unknown" )
64+ endif ()
65+
66+ # Get the short VCS revision
67+ git_describe_working_tree(VTR_VCS_REVISION_SHORT --tags --always --long --exclude '*')
68+ string (FIND "${VTR_VCS_REVISION_SHORT} " "NOTFOUND" GIT_DESCRIBE_VTR_REVISION_SHORT_NOTFOUND)
69+ if (NOT ${GIT_DESCRIBE_VTR_REVISION_SHORT_NOTFOUND} EQUAL -1)
70+ # Git describe failed, usually this means we
71+ # aren't in a git repo -- so don't set a VCS
72+ # revision
73+ set (VTR_VCS_REVISION_SHORT "unknown" )
74+ endif ()
8175
76+ # Set the version according to semver.org
77+ set (VTR_VERSION "${VTR_VERSION_MAJOR} .${VTR_VERSION_MINOR} .${VTR_VERSION_PATCH} " )
78+ if (VTR_VERSION_PRERELEASE)
79+ set (VTR_VERSION "${VTR_VERSION} -${VTR_VERSION_PRERELEASE} " )
80+ endif ()
81+ set (VTR_VERSION_SHORT ${VTR_VERSION} )
82+ if (VTR_VCS_REVISION)
83+ set (VTR_VERSION "${VTR_VERSION} +${VTR_VCS_REVISION_SHORT} " )
84+ endif ()
85+
86+ # Other build meta-data
87+ string (TIMESTAMP VTR_BUILD_TIMESTAMP)
88+ set (VTR_BUILD_TIMESTAMP "${VTR_BUILD_TIMESTAMP} " )
89+ set (VTR_BUILD_INFO "${VTR_BUILD_INFO} " )
90+
91+ message (STATUS "VTR Version: ${VTR_VERSION} " )
92+ message (STATUS "VTR Revision: ${VTR_VCS_REVISION} " )
93+ message (STATUS "VTR Short Revision: ${VTR_VCS_REVISION_SHORT} " )
94+
95+ configure_file (${VTR_VERSION_FILE_IN} ${VTR_VERSION_FILE_OUT} )
8296
8397#
8498# Source files and library
@@ -97,9 +111,6 @@ add_library(libvtrutil STATIC
97111target_include_directories (libvtrutil PUBLIC ${LIB_INCLUDE_DIRS} )
98112set_target_properties (libvtrutil PROPERTIES PREFIX "" ) #Avoid extra 'lib' prefix
99113
100- #Ensure version is always up to date by requiring version to be run first
101- add_dependencies (libvtrutil version )
102-
103114#Specify link-time dependencies
104115target_link_libraries (libvtrutil
105116 liblog)
0 commit comments