From 0ed2cc445131663b07b547cf5aefac893b619e9a Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sat, 27 Aug 2011 09:25:30 -0700 Subject: Generate version number information from git history. Due to the svn import structure, a special case is currently implemented to look for the 1.1.0 branchpoint instead of the most recent tag on the master branch. This will be removed after the first release is tagged on the master branch in git. Specific details: autogen.sh: More aggressively clean autoconf cache. This is needed to ensure the version number is actually regenerated. Don't generate PACKAGE_PATCHLEVEL or PACKAGE_BUILD variables. The genversion program now parses PACKAGE_VERSION directly. For Mkfiles builds, YASM-VERSION.h is generated and included by the custom config.h. This avoids the need to edit config.h for versioning. --- cmake/modules/VersionGen.cmake | 78 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 cmake/modules/VersionGen.cmake (limited to 'cmake') diff --git a/cmake/modules/VersionGen.cmake b/cmake/modules/VersionGen.cmake new file mode 100644 index 00000000..340455b3 --- /dev/null +++ b/cmake/modules/VersionGen.cmake @@ -0,0 +1,78 @@ +# Redistribution and use is allowed according to the terms of the BSD license. +# +# Copyright (c) 2011 Peter Johnson + +macro (VERSION_GEN _version _version_file _default_version) + set (_vn "v${_default_version}") + + # First see if there is a version file (included in release tarballs), + # then try git-describe, then default. + if (EXISTS "${CMAKE_SOURCE_DIR}/version") + file (STRINGS "${CMAKE_SOURCE_DIR}/version" _version_strs LIMIT_COUNT 1) + list (GET _version_strs 0 _version_strs0) + if (NOT (${_version_strs0} STREQUAL "")) + set (_vn "v${_version_strs0}") + endif (${_version_strs0}) + elseif (EXISTS "${CMAKE_SOURCE_DIR}/.git") + execute_process (COMMAND git describe --match "v[0-9]*" --abbrev=4 HEAD + RESULT_VARIABLE _git_result + OUTPUT_VARIABLE _git_vn + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + + if (_git_result EQUAL 0) + # Special handling until we get a more recent tag on the master + # branch + if (_git_vn MATCHES "^v0[.]1[.]0") + execute_process (COMMAND git merge-base v${_default_version} HEAD + OUTPUT_VARIABLE _merge_base + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + #message (STATUS "Merge base: ${_merge_base}") + + execute_process (COMMAND git rev-list ${_merge_base}..HEAD + OUTPUT_VARIABLE _rev_list + ERROR_QUIET) + string (REGEX MATCHALL "[^\n]*\n" _rev_list_lines "${_rev_list}") + #message (STATUS "Rev list: ${_rev_list_lines}") + list (LENGTH _rev_list_lines _vn1) + + execute_process (COMMAND git rev-list --max-count=1 --abbrev-commit --abbrev=4 HEAD + OUTPUT_VARIABLE _vn2 + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + + set (_git_vn "v${_default_version}-${_vn1}-g${_vn2}") + endif (_git_vn MATCHES "^v0[.]1[.]0") + + # Append -dirty if there are local changes + execute_process (COMMAND git update-index -q --refresh) + execute_process (COMMAND git diff-index --name-only HEAD -- + OUTPUT_VARIABLE _git_vn_dirty) + if (_git_vn_dirty) + set (_git_vn "${_git_vn}-dirty") + endif (_git_vn_dirty) + + # Substitute . for - in the result + string (REPLACE "-" "." _vn "${_git_vn}") + endif (_git_result EQUAL 0) + endif (EXISTS "${CMAKE_SOURCE_DIR}/version") + + # Strip leading "v" from version + #message (STATUS "_vn: ${_vn}") + string (REGEX REPLACE "^v*(.+)" "\\1" _vn "${_vn}") + + # Update version file if required + if (EXISTS ${_version_file}) + file (STRINGS ${_version_file} _version_strs LIMIT_COUNT 1) + list (GET _version_strs 0 _vc) + else (EXISTS ${_version_file}) + set (_vc "unset") + endif (EXISTS ${_version_file}) + if (NOT ("${_vn}" STREQUAL "${_vc}")) + file (WRITE ${_version_file} "${_vn}") + endif (NOT ("${_vn}" STREQUAL "${_vc}")) + + # Set output version variable + set (${_version} ${_vn}) +endmacro (VERSION_GEN) -- cgit v1.2.1