From fbb2cde800f96c834400d29a624e3e4de2ddc6f3 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Mon, 3 Dec 2018 15:42:37 -0500 Subject: [PATCH] Make this be consistent with non-CMake builds --- CMakeLists.txt | 4 ++-- cmake/Modules/GitUtilities.cmake | 12 ++++++++++++ src/config.h.in | 2 -- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eb91866f0..c85f23743 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,10 +98,10 @@ add_subdirectory(assets) ## config.h generation set(GIT_EXECUTABLE "git" CACHE FILEPATH "Path to git binary") include(GitUtilities) -git_describe(SRB2_GIT_DESCRIBE "${CMAKE_SOURCE_DIR}") +git_latest_commit(SRB2_COMP_COMMIT "${CMAKE_SOURCE_DIR}") git_current_branch(SRB2_GIT_BRANCH "${CMAKE_SOURCE_DIR}") set(SRB2_COMP_BRANCH "${SRB2_GIT_BRANCH}") -set(SRB2_COMP_REVISION "${SRB2_GIT_DESCRIBE}") +set(SRB2_COMP_REVISION "${SRB2_COMP_COMMIT}") configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/src/config.h) ##### PACKAGE CONFIGURATION ##### diff --git a/cmake/Modules/GitUtilities.cmake b/cmake/Modules/GitUtilities.cmake index 683cf9b6b..d29e6b509 100644 --- a/cmake/Modules/GitUtilities.cmake +++ b/cmake/Modules/GitUtilities.cmake @@ -27,5 +27,17 @@ function(git_current_branch variable path) OUTPUT_STRIP_TRAILING_WHITESPACE ) + set(${variable} "${output}" PARENT_SCOPE) +endfunction() + +function(git_latest_commit variable path) + execute_process(COMMAND ${GIT_EXECUTABLE} "rev-parse" "--short" "HEAD" + WORKING_DIRECTORY "${path}" + RESULT_VARIABLE result + OUTPUT_VARIABLE output + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + set(${variable} "${output}" PARENT_SCOPE) endfunction() \ No newline at end of file diff --git a/src/config.h.in b/src/config.h.in index 5f06ec45d..7452ec80c 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -21,8 +21,6 @@ #define SRB2_COMP_REVISION "${SRB2_COMP_REVISION}" #define SRB2_COMP_BRANCH "${SRB2_COMP_BRANCH}" -#define SRB2_GIT_DESCRIBE "${SRB2_GIT_DESCRIBE}" -#define SRB2_GIT_BRANCH "${SRB2_GIT_BRANCH}" #define CMAKE_ASSETS_DIR "${CMAKE_SOURCE_DIR}/assets"