cmake: add COMPVERSION_UNCOMMITTED

This commit is contained in:
Eidolon 2022-10-08 21:19:04 -05:00
parent 4db2c48cc3
commit d80db6f51d
4 changed files with 34 additions and 11 deletions

View file

@ -117,20 +117,21 @@ set(SRB2_SDL2_EXE_NAME ringracers CACHE STRING "Executable binary output name")
include_directories(${CMAKE_CURRENT_BINARY_DIR}/src)
add_subdirectory(src)
if(NOT ${SRB2_CONFIG_DEV_BUILD})
add_subdirectory(assets)
endif()
## config.h generation
set(GIT_EXECUTABLE "git" CACHE FILEPATH "Path to git binary")
include(GitUtilities)
git_latest_commit(SRB2_COMP_COMMIT "${CMAKE_SOURCE_DIR}")
git_current_branch(SRB2_GIT_BRANCH "${CMAKE_SOURCE_DIR}")
git_working_tree_dirty(SRB2_COMP_UNCOMMITTED "${CMAKE_SOURCE_DIR}")
set(SRB2_COMP_BRANCH "${SRB2_GIT_BRANCH}")
set(SRB2_COMP_REVISION "${SRB2_COMP_COMMIT}")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/src/config.h)
add_subdirectory(src)
if(NOT ${SRB2_CONFIG_DEV_BUILD})
add_subdirectory(assets)
endif()
##### PACKAGE CONFIGURATION #####
set(SRB2_CPACK_GENERATOR "" CACHE STRING "Generator to use for making a package. E.g., ZIP, TGZ, DragNDrop (OSX only). Leave blank for default generator.")

View file

@ -40,4 +40,20 @@ function(git_latest_commit variable path)
)
set(${variable} "${output}" PARENT_SCOPE)
endfunction()
function(git_working_tree_dirty variable path)
execute_process(COMMAND ${GIT_EXECUTABLE} "status" "--porcelain" "-uno"
WORKING_DIRECTORY "${path}"
RESULT_VARIABLE result
OUTPUT_VARIABLE output
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(output STREQUAL "")
set(${variable} FALSE PARENT_SCOPE)
else()
set(${variable} TRUE PARENT_SCOPE)
endif()
endfunction()

View file

@ -15,6 +15,12 @@ const char *comprevision = SRB2_COMP_REVISION;
#elif (defined(COMPVERSION))
#include "comptime.h"
#else
const char *compbranch = "Unknown";
const char *comprevision = "illegal";
#endif
const int compuncommitted =
#if (defined(COMPVERSION_UNCOMMITTED))
1;
@ -22,11 +28,5 @@ const int compuncommitted =
0;
#endif
#else
const char *compbranch = "Unknown";
const char *comprevision = "illegal";
#endif
const char *compdate = __DATE__;
const char *comptime = __TIME__;

View file

@ -22,6 +22,12 @@
#define SRB2_COMP_REVISION "${SRB2_COMP_REVISION}"
#define SRB2_COMP_BRANCH "${SRB2_COMP_BRANCH}"
// This is done with configure_file instead of defines in order to avoid
// recompiling the whole target whenever the working directory state changes
#cmakedefine SRB2_COMP_UNCOMMITTED
#ifdef SRB2_COMP_UNCOMMITTED
#define COMPVERSION_UNCOMMITTED
#endif
#define CMAKE_ASSETS_DIR "${CMAKE_SOURCE_DIR}/assets"