Skip to content

Commit

Permalink
Freshen version number when building with CMake
Browse files Browse the repository at this point in the history
Fixes #979
  • Loading branch information
ISSOtm committed Mar 11, 2022
1 parent da66eeb commit a4ead0c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
16 changes: 10 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,19 @@ endif()
# Use versioning consistent with Makefile
# the git revision is used but uses the fallback in an archive

execute_process(COMMAND git describe --tags --dirty --always
OUTPUT_VARIABLE GIT_REV
ERROR_QUIET)
string(STRIP "${GIT_REV}" GIT_REV)
find_program(GIT git)
if(GIT)
execute_process(COMMAND ${GIT} describe --tags --dirty --always
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_REV OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET)
message(STATUS "RGBDS version: ${GIT_REV}")
else(GIT)
message(STATUS "Cannot determine RGBDS version (Git not installed), falling back")
endif(GIT)

include_directories("${PROJECT_SOURCE_DIR}/include")

add_definitions(-DBUILD_VERSION_STRING="${GIT_REV}")

set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED True)

Expand Down
2 changes: 2 additions & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Generated by CMake
/.version.c
4 changes: 3 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
# SPDX-License-Identifier: MIT
#

configure_file(version.c _version.c ESCAPE_QUOTES)

set(common_src
"error.c"
"extern/getopt.c"
"version.c"
"_version.c"
)

find_package(PkgConfig)
Expand Down
7 changes: 7 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
#include "helpers.h"
#include "version.h"

// This variable is passed via `-D` from the Makefile, but not from CMake
// (in which `configure_file()` is used on this file to replace some syntax)
#ifndef BUILD_VERSION_STRING
// CMake-specific syntax here
#define BUILD_VERSION_STRING "@GIT_REV@"
#endif

char const *get_package_version_string(void)
{
// The following conditional should be simplified by the compiler.
Expand Down

0 comments on commit a4ead0c

Please sign in to comment.