myx/MyxCMake/lib/generators/GitInfo.cmake

33 lines
1.1 KiB
CMake
Raw Normal View History

2022-10-04 19:53:44 +00:00
cmake_policy(PUSH)
cmake_policy(SET CMP0053 NEW) # IN_LIST operator
set(ARG_PREFIX "${PREFIX}")
set(GIT_REV "N/A")
set(GIT_DIFF "")
set(GIT_TAG "N/A")
set(GIT_BRANCH "N/A")
find_package(Git QUIET)
2022-10-04 19:53:44 +00:00
if(GIT_EXECUTABLE)
execute_process(COMMAND ${GIT_EXECUTABLE} log --pretty=format:'%h' -n 1 OUTPUT_VARIABLE GIT_REV ERROR_QUIET)
# Check whether we got any revision (which isn't always the case,
# e.g. when someone downloaded a zip file from Github instead of a checkout)
if(NOT "${GIT_REV}" STREQUAL "")
execute_process(COMMAND bash -c "${GIT_EXECUTABLE} diff --quiet --exit-code || echo +" OUTPUT_VARIABLE GIT_DIFF)
execute_process(COMMAND ${GIT_EXECUTABLE} describe --exact-match --tags OUTPUT_VARIABLE GIT_TAG ERROR_QUIET)
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD OUTPUT_VARIABLE GIT_BRANCH)
string(STRIP "${GIT_REV}" GIT_REV)
string(SUBSTRING "${GIT_REV}" 1 7 GIT_REV)
string(STRIP "${GIT_DIFF}" GIT_DIFF)
string(STRIP "${GIT_TAG}" GIT_TAG)
string(STRIP "${GIT_BRANCH}" GIT_BRANCH)
endif()
endif()
configure_file("GitInfo.hpp.in" "${GIT_INFO_FILE}")
cmake_policy(POP)