From 2ca80486ba6a4e5acbdf0ff581d9754af17fa33b Mon Sep 17 00:00:00 2001 From: baranyaib90 <5031516+baranyaib90@users.noreply.github.com> Date: Mon, 24 Oct 2022 22:53:37 +0200 Subject: [PATCH] Allow external setting of GIT_VERSION --- CMakeLists.txt | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,22 +36,24 @@ endif() # VERSION -find_package(Git) -if(Git_FOUND) - execute_process( - COMMAND "${GIT_EXECUTABLE}" show --date=format:%Y.%m.%d --format=%ad-%h --no-patch - WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" - OUTPUT_VARIABLE GIT_VERSION - OUTPUT_STRIP_TRAILING_WHITESPACE) - message(STATUS "Version: ${GIT_VERSION}") +if(NOT GIT_VERSION) + find_package(Git) + if(Git_FOUND) + execute_process( + COMMAND "${GIT_EXECUTABLE}" show --date=format:%Y.%m.%d --format=%ad-%h --no-patch + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + OUTPUT_VARIABLE GIT_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE) + message(STATUS "Version: ${GIT_VERSION}") - # May not update version in some cases (example: git commit --amend) - set_property(GLOBAL APPEND - PROPERTY CMAKE_CONFIGURE_DEPENDS - "${CMAKE_SOURCE_DIR}/.git/index") -else() - set(GIT_VERSION "UNKNOWN") - message(WARNING "Could not find git command! Version is set to: ${GIT_VERSION}") + # May not update version in some cases (example: git commit --amend) + set_property(GLOBAL APPEND + PROPERTY CMAKE_CONFIGURE_DEPENDS + "${CMAKE_SOURCE_DIR}/.git/index") + else() + set(GIT_VERSION "UNKNOWN") + message(WARNING "Could not find git command! Version is set to: ${GIT_VERSION}") + endif() endif() # LIBRARY DEPENDENCIES