Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
benchmark
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
benchmark
Commits
c927845d
Commit
c927845d
authored
Aug 01, 2014
by
Matt Clarkson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get_git_version CMake function
parent
d591edf5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
23 deletions
+52
-23
.gitignore
.gitignore
+1
-0
CMakeLists.txt
CMakeLists.txt
+6
-23
GetGitVersion.cmake
cmake/GetGitVersion.cmake
+45
-0
No files found.
.gitignore
View file @
c927845d
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
*.so.?*
*.so.?*
*.dylib
*.dylib
*.cmake
*.cmake
!/cmake/*.cmake
*~
*~
/test/benchmark_test
/test/benchmark_test
/test/re_test
/test/re_test
...
...
CMakeLists.txt
View file @
c927845d
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
...
@@ -39,31 +43,10 @@ if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86")
...
@@ -39,31 +43,10 @@ if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86")
endif
()
endif
()
# Read the git tags to determine the project version
# Read the git tags to determine the project version
execute_process
(
COMMAND git describe --match
"v[0-9]*.[0-9]*.[0-9]*"
--abbrev=8
include
(
GetGitVersion
)
RESULT_VARIABLE status
get_git_version
(
GIT_VERSION
)
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
()
# Tell the user what versions we are using
# Tell the user what versions we are using
message
(
"-- git Version:
${
GIT_VERSION
}
"
)
string
(
REGEX MATCH
"[0-9]+
\\
.[0-9]+
\\
.[0-9]+"
VERSION
${
GIT_VERSION
}
)
string
(
REGEX MATCH
"[0-9]+
\\
.[0-9]+
\\
.[0-9]+"
VERSION
${
GIT_VERSION
}
)
message
(
"-- Version:
${
VERSION
}
"
)
message
(
"-- Version:
${
VERSION
}
"
)
...
...
cmake/GetGitVersion.cmake
0 → 100644
View file @
c927845d
# - 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
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment