2018-05-02 20:02:28 +00:00
|
|
|
# Cable: CMake Bootstrap Library.
|
2018-04-10 14:28:36 +00:00
|
|
|
# Copyright 2018 Pawel Bylica.
|
|
|
|
# Licensed under the Apache License, Version 2.0. See the LICENSE file.
|
|
|
|
|
|
|
|
# Execute git only if the tool is available.
|
|
|
|
if(GIT)
|
|
|
|
execute_process(
|
2018-09-06 12:04:58 +00:00
|
|
|
COMMAND ${GIT} describe --always --long --tags --first-parent --match=v* --abbrev=40 --dirty
|
2018-04-10 14:28:36 +00:00
|
|
|
WORKING_DIRECTORY ${SOURCE_DIR}
|
2018-05-02 20:02:28 +00:00
|
|
|
OUTPUT_VARIABLE gitinfo
|
2018-04-10 14:28:36 +00:00
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
2018-05-02 20:02:28 +00:00
|
|
|
ERROR_VARIABLE error
|
|
|
|
ERROR_STRIP_TRAILING_WHITESPACE
|
2018-04-10 14:28:36 +00:00
|
|
|
)
|
2018-08-07 14:31:07 +00:00
|
|
|
if(error)
|
|
|
|
message(WARNING "Git ${error}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
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()
|
2018-04-10 14:28:36 +00:00
|
|
|
|
2018-08-07 14:31:07 +00:00
|
|
|
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()
|
2018-05-02 20:02:28 +00:00
|
|
|
endif()
|
|
|
|
|
2018-07-26 07:51:52 +00:00
|
|
|
set(gitinfo_file ${OUTPUT_DIR}/gitinfo.txt)
|
2018-04-10 14:28:36 +00:00
|
|
|
|
2018-05-02 20:02:28 +00:00
|
|
|
if(EXISTS ${gitinfo_file})
|
|
|
|
file(READ ${gitinfo_file} prev_gitinfo)
|
2018-04-10 14:28:36 +00:00
|
|
|
else()
|
|
|
|
# Create empty file, because other targets expect it to exist.
|
2018-05-02 20:02:28 +00:00
|
|
|
file(WRITE ${gitinfo_file} "")
|
2018-04-10 14:28:36 +00:00
|
|
|
endif()
|
|
|
|
|
2018-05-02 20:02:28 +00:00
|
|
|
if(NOT "${gitinfo}" STREQUAL "${prev_gitinfo}")
|
|
|
|
file(WRITE ${gitinfo_file} ${gitinfo})
|
2018-04-10 14:28:36 +00:00
|
|
|
endif()
|