build: auto generate version header file

This commit is contained in:
eeff
2022-05-31 14:43:15 +08:00
parent 65c3c2b311
commit 21e941de06
4 changed files with 89 additions and 0 deletions
+1
View File
@@ -10,6 +10,7 @@ compile_commands.json
*.tar.gz
ft/reports
include/csptr/
include/neuron/version.h
__pycache__
tmp
*.deb
+5
View File
@@ -32,6 +32,10 @@ if(NOT DEFINED CMAKE_SUPPRESS_DEVELOPER_WARNINGS)
CACHE INTERNAL "No dev warnings")
endif()
add_custom_target(neuron-version
COMMAND ${CMAKE_COMMAND} -P
${CMAKE_CURRENT_SOURCE_DIR}/cmake/neuron-version.cmake)
configure_file(extern/uthash/include/uthash.h ${CMAKE_SOURCE_DIR}/include/neuron/utils/uthash.h)
configure_file(extern/uthash/include/utarray.h ${CMAKE_SOURCE_DIR}/include/neuron/utils/utarray.h)
configure_file(extern/uthash/include/utlist.h ${CMAKE_SOURCE_DIR}/include/neuron/utils/utlist.h)
@@ -171,6 +175,7 @@ target_include_directories(neuron-base PRIVATE ${CMAKE_STAGING_PREFIX})
target_compile_definitions(neuron-base PRIVATE MQTT_USE_BIO)
target_link_libraries(neuron-base nng libzlog.so vector-static csptr jansson crypto ssl mqttc jwt
${CMAKE_THREAD_LIBS_INIT})
add_dependencies(neuron-base neuron-version)
#copy file for run
file(COPY ${CMAKE_SOURCE_DIR}/zlog.conf DESTINATION ${CMAKE_BINARY_DIR}/config)
+42
View File
@@ -0,0 +1,42 @@
set(HEADER_FILE ${CMAKE_CURRENT_LIST_DIR}/../include/neuron/version.h)
set(HEADER_TMPL ${CMAKE_CURRENT_LIST_DIR}/../version.h.in)
set(VERSION_FILE ${CMAKE_CURRENT_LIST_DIR}/../version)
# versions
file(STRINGS ${VERSION_FILE} NEURON_VERSION)
string(REPLACE "." ";" VERSION_LIST ${NEURON_VERSION})
list(GET VERSION_LIST 0 NEURON_VERSION_MAJOR)
list(GET VERSION_LIST 1 NEURON_VERSION_MINOR)
list(GET VERSION_LIST 2 NEURON_VERSION_MICRO)
# git revisions
execute_process(COMMAND git log --pretty=format:'%h' -n 1
OUTPUT_VARIABLE GIT_REV
ERROR_QUIET)
if ("${GIT_REV}" STREQUAL "")
set(GIT_REV "N/A")
set(GIT_DIFF "")
set(GIT_TAG "N/A")
set(GIT_BRANCH "N/A")
else()
execute_process(COMMAND bash -c "git diff --quiet --exit-code || echo +dirty"
OUTPUT_VARIABLE GIT_DIFF)
execute_process(COMMAND git describe --exact-match --tags
OUTPUT_VARIABLE GIT_TAG
ERROR_QUIET)
execute_process(COMMAND git rev-parse --abbrev-ref HEAD
OUTPUT_VARIABLE GIT_BRANCH)
string(STRIP "${GIT_REV}" GIT_REV)
string(SUBSTRING "${GIT_REV}" 1 7 GIT_REV)
string(STRIP "${GIT_DIFF}" GIT_DIFF)
string(STRIP "${GIT_TAG}" GIT_TAG)
string(STRIP "${GIT_BRANCH}" GIT_BRANCH)
endif()
# build date
string(TIMESTAMP NEURON_BUILD_DATE "%Y-%m-%d")
# generate the header file
configure_file(${HEADER_TMPL} ${HEADER_FILE} @ONLY)
+41
View File
@@ -0,0 +1,41 @@
/**
* NEURON IIoT System for Industry 4.0
* Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
/*
* DO NOT EDIT THIS FILE MANUALLY!
* It was automatically generated by `neuron-version.cmake`
*/
#ifndef NEURON_VERSION_H
#define NEURON_VERSION_H
#define NEURON_VERSION "@NEURON_VERSION@"
#define NEURON_VERSION_MAJOR @NEURON_VERSION_MAJOR@
#define NEURON_VERSION_MINOR @NEURON_VERSION_MINOR@
#define NEURON_VERSION_MICRO @NEURON_VERSION_MICRO@
#define NEURON_GIT_REV "@GIT_REV@"
#define NEURON_GIT_TAG "@GET_TAG@"
#define NEURON_GIT_DIFF "@GIT_DIFF@"
#define NEURON_GIT_BRANCH "@GIT_BRANCH@"
#define NEURON_BUILD_DATE "@NEURON_BUILD_DATE@"
#endif