mirror of
https://github.com/google/benchmark.git
synced 2025-03-29 13:30:38 +08:00
Merge pull request #42 from mattyclarkson/versioning
Implemented git versioning
This commit is contained in:
commit
4940eebf65
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,6 +3,7 @@
|
|||||||
*.so.?*
|
*.so.?*
|
||||||
*.dylib
|
*.dylib
|
||||||
*.cmake
|
*.cmake
|
||||||
|
!/cmake/*.cmake
|
||||||
*~
|
*~
|
||||||
/test/benchmark_test
|
/test/benchmark_test
|
||||||
/test/re_test
|
/test/re_test
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
cmake_minimum_required (VERSION 2.8)
|
cmake_minimum_required (VERSION 2.8)
|
||||||
project (benchmark)
|
project (benchmark)
|
||||||
|
|
||||||
|
# Make sure we can import out CMake functions
|
||||||
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||||
|
|
||||||
|
# We need threads in this project
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
|
|
||||||
# Import and build Google Test
|
# Import and build Google Test
|
||||||
@ -38,9 +42,17 @@ if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86")
|
|||||||
add_definitions(-DARCH_X86)
|
add_definitions(-DARCH_X86)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Read the git tags to determine the project version
|
||||||
|
include(GetGitVersion)
|
||||||
|
get_git_version(GIT_VERSION)
|
||||||
|
|
||||||
|
# Tell the user what versions we are using
|
||||||
|
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" VERSION ${GIT_VERSION})
|
||||||
|
message("-- Version: ${VERSION}")
|
||||||
|
|
||||||
# The version of the libraries
|
# The version of the libraries
|
||||||
set(GENERIC_LIB_VERSION "0.0.0")
|
set(GENERIC_LIB_VERSION ${VERSION})
|
||||||
set(GENERIC_LIB_SOVERSION "0")
|
string(SUBSTRING ${VERSION} 0 1 GENERIC_LIB_SOVERSION)
|
||||||
|
|
||||||
# Set up directories
|
# Set up directories
|
||||||
include_directories(${PROJECT_SOURCE_DIR}/include)
|
include_directories(${PROJECT_SOURCE_DIR}/include)
|
||||||
|
45
cmake/GetGitVersion.cmake
Normal file
45
cmake/GetGitVersion.cmake
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
# - Returns a version string from Git tags
|
||||||
|
#
|
||||||
|
# This function inspects the annotated git tags for the project and returns a string
|
||||||
|
# into a CMake variable
|
||||||
|
#
|
||||||
|
# get_git_version(<var>)
|
||||||
|
#
|
||||||
|
# - Example
|
||||||
|
#
|
||||||
|
# include(GetGitVersion)
|
||||||
|
# get_git_version(GIT_VERSION)
|
||||||
|
#
|
||||||
|
# Requires CMake 2.6+
|
||||||
|
|
||||||
|
if(__get_git_version)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
set(__get_git_version INCLUDED)
|
||||||
|
|
||||||
|
function(get_git_version var)
|
||||||
|
execute_process(COMMAND git describe --match "v[0-9]*.[0-9]*.[0-9]*" --abbrev=8
|
||||||
|
RESULT_VARIABLE status
|
||||||
|
OUTPUT_VARIABLE GIT_VERSION
|
||||||
|
ERROR_QUIET)
|
||||||
|
if(${status})
|
||||||
|
set(GIT_VERSION "v0.0.0")
|
||||||
|
else()
|
||||||
|
string(STRIP ${GIT_VERSION} GIT_VERSION)
|
||||||
|
string(REGEX REPLACE "-[0-9]+-g" "-" GIT_VERSION ${GIT_VERSION})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Work out if the repository is dirty
|
||||||
|
execute_process(COMMAND git update-index -q --refresh
|
||||||
|
OUTPUT_QUIET
|
||||||
|
ERROR_QUIET)
|
||||||
|
execute_process(COMMAND git diff-index --name-only HEAD --
|
||||||
|
OUTPUT_VARIABLE GIT_DIFF_INDEX
|
||||||
|
ERROR_QUIET)
|
||||||
|
string(COMPARE NOTEQUAL "${GIT_DIFF_INDEX}" "" GIT_DIRTY)
|
||||||
|
if (${GIT_DIRTY})
|
||||||
|
string(CONCAT GIT_VERSION ${GIT_VERSION} "-dirty")
|
||||||
|
endif()
|
||||||
|
message("-- git Version: ${GIT_VERSION}")
|
||||||
|
set(${var} ${GIT_VERSION} PARENT_SCOPE)
|
||||||
|
endfunction()
|
Loading…
Reference in New Issue
Block a user