Squashed 'cmake/cable/' changes from 36b6cb6..a0c88f9

a0c88f9 Cable 0.2.7
94bf242 buildinfo: Export buildinfo.json file
c013495 gitinfo: Include branch name and origin URL

git-subtree-dir: cmake/cable
git-subtree-split: a0c88f96fb70bb897ac59335be1a173a1c3be8d8
This commit is contained in:
Paweł Bylica 2018-08-07 16:31:07 +02:00
parent fb4d6fa81c
commit 90ad8e58f5
4 changed files with 48 additions and 7 deletions

View File

@ -10,7 +10,7 @@
#
# This is internal variable automaticaly updated with external tools.
# Use CABLE_VERSION variable if you need this information.
set(version 0.2.6)
set(version 0.2.7)
# For conveniance, add the project CMake module dir to module path.
set(module_dir ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

View File

@ -10,13 +10,16 @@ string(TIMESTAMP TIMESTAMP)
# Read the git info from a file. The gitinfo is suppose to update the file
# only if the information has changed.
file(READ ${OUTPUT_DIR}/gitinfo.txt GIT_INFO)
file(STRINGS ${OUTPUT_DIR}/gitinfo.txt gitinfo)
list(GET gitinfo 0 describe)
list(GET gitinfo 1 GIT_BRANCH)
list(GET gitinfo 2 GIT_ORIGIN_URL)
# The output of `git describe --always --long --tags --match=v*`.
string(REGEX MATCH "(v(.+)-([0-9]+)-g)?([0-9a-f]+)(-dirty)?" match "${GIT_INFO}")
string(REGEX MATCH "(v(.+)-([0-9]+)-g)?([0-9a-f]+)(-dirty)?" match "${describe}")
if(NOT match)
message(WARNING "Cannot parse git describe: ${GIT_INFO}")
message(WARNING "Cannot parse git describe: ${describe}")
endif()
set(GIT_LATEST_PROJECT_VERSION ${CMAKE_MATCH_2})
@ -67,5 +70,6 @@ message(
)
configure_file(${CMAKE_CURRENT_LIST_DIR}/buildinfo.c.in ${OUTPUT_DIR}/buildinfo.c)
configure_file(${CMAKE_CURRENT_LIST_DIR}/buildinfo.json.in ${OUTPUT_DIR}/buildinfo.json)
configure_file(${CMAKE_CURRENT_LIST_DIR}/buildinfo.sh.in ${OUTPUT_DIR}/buildinfo.sh)
configure_file(${CMAKE_CURRENT_LIST_DIR}/buildinfo.ps1.in ${OUTPUT_DIR}/buildinfo.ps1)

View File

@ -0,0 +1,10 @@
{
"name": "@PROJECT_NAME@",
"version": "@PROJECT_VERSION@",
"is_prerelease": @PROJECT_VERSION_IS_PRERELEASE@,
"commit": "@GIT_COMMIT_HASH@",
"branch": "@GIT_BRANCH@",
"repo": "@GIT_ORIGIN_URL@",
"system_name": "@SYSTEM_NAME@",
"system_processor": "@SYSTEM_PROCESSOR@"
}

View File

@ -12,10 +12,37 @@ if(GIT)
ERROR_VARIABLE error
ERROR_STRIP_TRAILING_WHITESPACE
)
endif()
if(error)
message(WARNING "Git ${error}")
endif()
if(error)
message(WARNING "Git ${error}")
execute_process(
COMMAND ${GIT} rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${SOURCE_DIR}
OUTPUT_VARIABLE gitbranch
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_VARIABLE error
ERROR_STRIP_TRAILING_WHITESPACE
)
if(error)
message(WARNING "Git ${error}")
else()
set(gitinfo "${gitinfo}\n${gitbranch}")
endif()
execute_process(
COMMAND ${GIT} config --get remote.origin.url
WORKING_DIRECTORY ${SOURCE_DIR}
OUTPUT_VARIABLE gitorigin
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_VARIABLE error
ERROR_STRIP_TRAILING_WHITESPACE
)
if(error)
message(WARNING "Git ${error}")
else()
set(gitinfo "${gitinfo}\n${gitorigin}\n")
endif()
endif()
set(gitinfo_file ${OUTPUT_DIR}/gitinfo.txt)