diff --git a/CMakeLists.txt b/CMakeLists.txt index d79b0e3..74c5a88 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,36 +1,28 @@ include(CMakeDependentOption) -cmake_minimum_required(VERSION 3.0.2) +cmake_minimum_required(VERSION 3.1) 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 -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(SCRIPT_DIR ${CMAKE_SOURCE_DIR}/scripts) #set project include directory +set(INCLUDE_PATH ${CMAKE_SOURCE_DIR}/include) include_directories("${INCLUDE_PATH}") +set(GIT_VERSION_FILE ${CMAKE_SOURCE_DIR}/include/version.h) +set(GIT_VERSION_TMP_FILE ${CMAKE_SOURCE_DIR}/include/verison.h.tmp) + +add_custom_command( + OUTPUT ${GIT_VERSION_TMP_FILE} + COMMAND ${CMAKE_COMMAND} -E echo "//File generated by CMake. Do not edit!" > ${GIT_VERSION_TMP_FILE} + COMMAND python ${SCRIPT_DIR}/git_branch_name.py >> ${GIT_VERSION_TMP_FILE} + COMMAND python ${SCRIPT_DIR}/git_commit_hash.py >> ${GIT_VERSION_TMP_FILE} + COMMAND python ${SCRIPT_DIR}/git_tag_name.py >> ${GIT_VERSION_TMP_FILE} + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${GIT_VERSION_TMP_FILE} ${GIT_VERSION_FILE} + COMMAND ${CMAKE_COMMAND} -E remove ${GIT_VERSION_TMP_FILE} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + VERBATIM +) + #setup cmake options option(BUILD_REXLEDCTL "Build led control program" ON) option(BUILD_REXBACKLIGHT "Build backlight control program" ON) @@ -44,7 +36,7 @@ set(UDEV_DIR "/etc/udev/rules.d" CACHE STRING "Set the output directory for udev mark_as_advanced(UDEV_DIR) if(XBACKLIGHT_COMPAT) - add_definitions(-DXBACKLIGHT_COMPAT_OPTIONS) + add_definitions("-DXBACKLIGHT_COMPAT_OPTIONS") endif() #locate rjp library requirements @@ -57,14 +49,11 @@ if(ENABLE_RESTORE_FILE) else() add_library(common_srcs OBJECT src/cmd.c src/common.c) endif() +target_sources(common_srcs PUBLIC ${GIT_VERSION_TMP_FILE}) set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DREXBACKLIGHT_DEBUG") -configure_file( - "${INCLUDE_PATH}/config.h.in" - "${INCLUDE_PATH}/config.h" -) - +#build led control program if(BUILD_REXLEDCTL) add_executable (rexledctl src/rexbacklight.c) add_dependencies(rexledctl common_srcs) #force common_srcs to be built first @@ -79,6 +68,7 @@ if(BUILD_REXLEDCTL) install(FILES ${CMAKE_SOURCE_DIR}/rules/91-leds.rules DESTINATION ${UDEV_DIR}) endif() endif() +#build backlight control program if(BUILD_REXBACKLIGHT) add_executable (rexbacklight src/rexbacklight.c) add_dependencies(rexledctl common_srcs) diff --git a/include/config.h.in b/include/config.h.in deleted file mode 100644 index 6566b9b..0000000 --- a/include/config.h.in +++ /dev/null @@ -1,30 +0,0 @@ -/** - rexbacklight - Copyright (C) 2018 rexy712 - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef CONFIG_H -#define CONFIG_H - -#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 - diff --git a/include/version.h b/include/version.h new file mode 100644 index 0000000..644c192 --- /dev/null +++ b/include/version.h @@ -0,0 +1,3 @@ +//File generated by CMake. Do not edit! +#define GIT_BRANCH_NAME "untested" +#define GIT_COMMIT_HASH "b581514-dirty" diff --git a/scripts/git_branch_name.py b/scripts/git_branch_name.py new file mode 100755 index 0000000..aebbe12 --- /dev/null +++ b/scripts/git_branch_name.py @@ -0,0 +1,8 @@ +#!/usr/bin/python + +import subprocess + +output = subprocess.run(['git', 'rev-parse', "--abbrev-ref", "HEAD"], stdout=subprocess.PIPE).stdout.decode('utf-8').rstrip() + +if output: + print("#define GIT_BRANCH_NAME " + '"' + output + '"') diff --git a/scripts/git_commit_hash.py b/scripts/git_commit_hash.py new file mode 100755 index 0000000..54d1c13 --- /dev/null +++ b/scripts/git_commit_hash.py @@ -0,0 +1,8 @@ +#!/usr/bin/python + +import subprocess + +output = subprocess.run(['git', 'describe', "--always", "--dirty", "--abbrev", "--match=\"NeVeRmAtCh\""], stdout=subprocess.PIPE).stdout.decode('utf-8').rstrip() + +if output: + print("#define GIT_COMMIT_HASH " + '"' + output + '"') diff --git a/scripts/git_tag_name.py b/scripts/git_tag_name.py new file mode 100755 index 0000000..1da4889 --- /dev/null +++ b/scripts/git_tag_name.py @@ -0,0 +1,9 @@ +#!/usr/bin/python + +import subprocess + +output = subprocess.run(['git', 'tag', "--points-at", "HEAD"], stdout=subprocess.PIPE).stdout.decode('utf-8').rstrip() + +if output: + if output[0] == 'v' or output[0] == 'V': + print("#define GIT_TAG_NAME " + '"' + output[1:] + '"')