changed version output to print branch and commit when not on a precise version tag

This commit is contained in:
rexy712 2018-12-10 16:33:14 -08:00
parent 1d5a5d9d69
commit b5815149a3
3 changed files with 28 additions and 6 deletions

View File

@ -2,9 +2,30 @@ include(CMakeDependentOption)
cmake_minimum_required(VERSION 3.0.2)
project(rexbacklight)
execute_process(COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND git log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND git tag --points-at HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_TAG
OUTPUT_STRIP_TRAILING_WHITESPACE)
#setup common defines for C files
set(rexbacklight_VERSION_MAJOR 1)
set(rexbacklight_VERSION_MINOR 3)
if(GIT_TAG)
set(rexbacklight_VERSION_MAJOR \"1\")
set(rexbacklight_VERSION_MINOR \"3\")
set(rexbacklight_VERSION_CONNECTOR \".\")
else()
set(rexbacklight_VERSION_MAJOR \"${GIT_BRANCH}\")
set(rexbacklight_VERSION_MINOR \"${GIT_COMMIT}\")
set(rexbacklight_VERSION_CONNECTOR \"-\")
endif()
set(INCLUDE_PATH ${CMAKE_SOURCE_DIR}/include)
#set project include directory
@ -32,10 +53,9 @@ if(ENABLE_RESTORE_FILE)
find_path(RJP_HEADER_DIR rjp.h)
#temporary library (no actual library generated)
add_library(common_srcs OBJECT src/cmd.c src/common.c src/restore.c)
set(enable_RESTORE_FILE "#define ENABLE_RESTORE_FILE")
add_definitions("-DENABLE_RESTORE_FILE")
else()
add_library(common_srcs OBJECT src/cmd.c src/common.c)
set(enable_RESTORE_FILE "")
endif()
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DREXBACKLIGHT_DEBUG")

View File

@ -22,6 +22,8 @@
#define REXBACKLIGHT_VERSION_MAJOR @rexbacklight_VERSION_MAJOR@
#define REXBACKLIGHT_VERSION_MINOR @rexbacklight_VERSION_MINOR@
#define REXBACKLIGHT_VERSION (REXBACKLIGHT_VERSION_MAJOR @rexbacklight_VERSION_CONNECTOR@ REXBACKLIGHT_VERSION_MINOR)
@enable_RESTORE_FILE@
#endif

View File

@ -49,13 +49,13 @@ void mem_error(void){
}
_Noreturn void version(void){
printf("%s version %d.%d\n", executable_name(), REXBACKLIGHT_VERSION_MAJOR, REXBACKLIGHT_VERSION_MINOR);
printf("%s version %s\n", executable_name(), REXBACKLIGHT_VERSION);
exit(return_value);
}
_Noreturn void usage(int exit_val){
int i;
printf("%s version %d.%d\n\n", executable_name(), REXBACKLIGHT_VERSION_MAJOR, REXBACKLIGHT_VERSION_MINOR);
printf("%s version %s\n\n", executable_name(), REXBACKLIGHT_VERSION);
printf("Usage: %s [argument] [options] [argument]\n\n", executable_name());
printf("Options:\n");