Changed version detection to work at compile time instead of configure time
This commit is contained in:
parent
b5815149a3
commit
9a1856ace5
@ -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)
|
||||
|
||||
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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
|
||||
|
||||
3
include/version.h
Normal file
3
include/version.h
Normal file
@ -0,0 +1,3 @@
|
||||
//File generated by CMake. Do not edit!
|
||||
#define GIT_BRANCH_NAME "untested"
|
||||
#define GIT_COMMIT_HASH "b581514-dirty"
|
||||
8
scripts/git_branch_name.py
Executable file
8
scripts/git_branch_name.py
Executable file
@ -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 + '"')
|
||||
8
scripts/git_commit_hash.py
Executable file
8
scripts/git_commit_hash.py
Executable file
@ -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 + '"')
|
||||
9
scripts/git_tag_name.py
Executable file
9
scripts/git_tag_name.py
Executable file
@ -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:] + '"')
|
||||
Loading…
x
Reference in New Issue
Block a user