OCT 1. 更新工程版本管理

2. 增加工程发布打包功能
This commit is contained in:
黄昕 2022-12-23 14:04:51 +08:00
parent 85deb1ae4a
commit c7c4975983
7 changed files with 75 additions and 30 deletions

View File

@ -1,8 +1,7 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.10 FATAL_ERROR) CMAKE_MINIMUM_REQUIRED(VERSION 3.10 FATAL_ERROR)
PROJECT(vCPE VERSION "1.0.0") SET(VCPE_VERSION "1.0.0")
PROJECT(vCPE VERSION "${VCPE_VERSION}")
CONFIGURE_FILE(prj_config.h.in prj_config.h)
OPTION(VCPE_AGENT "Enable vCPE agent test application" OFF) OPTION(VCPE_AGENT "Enable vCPE agent test application" OFF)
OPTION(USED_LWIP "PPPoE of LWIP support for vCPE" OFF) OPTION(USED_LWIP "PPPoE of LWIP support for vCPE" OFF)
@ -17,18 +16,54 @@ OPTION(USED_SQLITE "Add sqlite3 database support for vCPE" OFF)
SET(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig") SET(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig")
SET(URI_HOME "${CMAKE_SOURCE_DIR}/libs") SET(URI_HOME "${CMAKE_SOURCE_DIR}/libs")
EXECUTE_PROCESS(COMMAND git describe --tags --always --dirty=-dev SET(VERSION_GIT_TAG "")
OUTPUT_VARIABLE GIT_TAG) SET(VERSION_GIT_HASH "")
SET(VERSION_GIT_HASH_SHORT "")
SET(VERSION_GIT_BRANCH "")
FIND_PACKAGE(Git QUIET)
IF (GIT_FOUND)
EXECUTE_PROCESS(
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
OUTPUT_VARIABLE VERSION_GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
EXECUTE_PROCESS(
COMMAND ${GIT_EXECUTABLE} rev-parse --short=8 HEAD
OUTPUT_VARIABLE VERSION_GIT_HASH_SHORT
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
EXECUTE_PROCESS(
COMMAND ${GIT_EXECUTABLE} symbolic-ref --short -q HEAD
OUTPUT_VARIABLE VERSION_GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
EXECUTE_PROCESS(
COMMAND ${GIT_EXECUTABLE} describe --tags --always --dirty=-dev
OUTPUT_VARIABLE GIT_TAG
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
ENDIF ()
IF ("${GIT_TAG}" STREQUAL "") IF ("${GIT_TAG}" STREQUAL "")
STRING(TIMESTAMP COMPILE_TIME %Y-%m-%d_%H:%M:%S) STRING(TIMESTAMP COMPILE_TIME %Y-%m-%d_%H:%M:%S)
SET(GIT_VERSION ${COMPILE_TIME}) SET(VERSION_GIT_TAG ${COMPILE_TIME})
ELSE () ELSE ()
STRING(REGEX REPLACE "\n$" "" GIT_TAG ${GIT_TAG}) SET(VERSION_GIT_TAG ${GIT_TAG})
SET(GIT_VERSION ${GIT_TAG})
ENDIF () ENDIF ()
MESSAGE("Version: " ${GIT_VERSION}) CONFIGURE_FILE(prj_config.h.in prj_config.h)
MESSAGE("Version: " ${VERSION_GIT_TAG})
IF (USED_LWIP) IF (USED_LWIP)
LIST(APPEND COMMON_DEFINE "-DLWIP_ON") LIST(APPEND COMMON_DEFINE "-DLWIP_ON")

View File

@ -5,6 +5,10 @@
#ifndef VCPE_PRG_CONFIG_H_IN #ifndef VCPE_PRG_CONFIG_H_IN
#define VCPE_PRG_CONFIG_H_IN #define VCPE_PRG_CONFIG_H_IN
#define VCPE_GIT_VERSION "@VERSION_GIT_TAG@"
#define VCPE_GIT_HASH "@VERSION_GIT_HASH@"
#define VCPE_GIT_HASH_SHORT "@VERSION_GIT_HASH_SHORT@"
#define VCPE_GIT_BRANCH "@VERSION_GIT_BRANCH@"
#define VCPE_PROJECT_NAME "@PROJECT_NAME@" #define VCPE_PROJECT_NAME "@PROJECT_NAME@"
#define VCPE_PROJECT_VER "@PROJECT_VERSION@" #define VCPE_PROJECT_VER "@PROJECT_VERSION@"
#define VCPE_PROJECT_VER_MAJOR "@PROJECT_VERSION_MAJOR@" #define VCPE_PROJECT_VER_MAJOR "@PROJECT_VERSION_MAJOR@"

View File

@ -55,7 +55,7 @@ ENDIF ()
IF (USED_OPENDHCPD) IF (USED_OPENDHCPD)
TARGET_LINK_LIBRARIES(${PROJECT_TARGET} opendhcpd) TARGET_LINK_LIBRARIES(${PROJECT_TARGET} opendhcpd)
ENDIF() ENDIF ()
TARGET_LINK_LIBRARIES(${PROJECT_TARGET} common) TARGET_LINK_LIBRARIES(${PROJECT_TARGET} common)
TARGET_LINK_LIBRARIES(${PROJECT_TARGET} ${COMMON_LIBS}) TARGET_LINK_LIBRARIES(${PROJECT_TARGET} ${COMMON_LIBS})
@ -69,13 +69,19 @@ ENDIF ()
ADD_CUSTOM_COMMAND(TARGET ${PROJECT_TARGET} ADD_CUSTOM_COMMAND(TARGET ${PROJECT_TARGET}
POST_BUILD POST_BUILD
COMMENT "!!!!!! Notice: Automatic upgreade configuration files after build project." COMMENT "!!!!!! Notice: Automatic upgreade configuration files after build project."
COMMAND ${CMAKE_COMMAND} -E COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/config/"
make_directory "${CMAKE_CURRENT_BINARY_DIR}/config/" COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/log/"
COMMAND ${CMAKE_COMMAND} -E COMMAND ${CMAKE_COMMAND} -E copy_if_different "${PROJECT_SOURCE_DIR}/../config/vcpe.cfg" "${CMAKE_CURRENT_BINARY_DIR}/config/"
make_directory "${CMAKE_CURRENT_BINARY_DIR}/log/" COMMAND ${CMAKE_COMMAND} -E copy_if_different "${PROJECT_SOURCE_DIR}/../config/zlog.conf" "${CMAKE_CURRENT_BINARY_DIR}/config/"
COMMAND ${CMAKE_COMMAND} -E COMMAND ${CMAKE_COMMAND} -E copy_if_different "${PROJECT_SOURCE_DIR}/../config/banner.txt" "${CMAKE_CURRENT_BINARY_DIR}/config/")
copy_if_different "${PROJECT_SOURCE_DIR}/../config/vcpe.cfg" "${CMAKE_CURRENT_BINARY_DIR}/config/"
COMMAND ${CMAKE_COMMAND} -E SET(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install/")
copy_if_different "${PROJECT_SOURCE_DIR}/../config/zlog.conf" "${CMAKE_CURRENT_BINARY_DIR}/config/" install(FILES ../config/vcpe.cfg ../config/vcpe.service ../config/banner.txt ../config/zlog.conf
COMMAND ${CMAKE_COMMAND} -E DESTINATION config)
copy_if_different "${PROJECT_SOURCE_DIR}/../config/banner.txt" "${CMAKE_CURRENT_BINARY_DIR}/config/") INSTALL(TARGETS ${PROJECT_TARGET}
RUNTIME PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
RUNTIME DESTINATION bin)
SET(CPACK_GENERATOR "TGZ")
SET(CPACK_PACKAGE_FILE_NAME "vCPE-${VCPE_VERSION}-linux-amd64_${VERSION_GIT_HASH_SHORT}")
INCLUDE(CPack)

View File

@ -6,9 +6,8 @@ CONFIGURE_FILE(lib_config.h.in lib_config.h)
INCLUDE_DIRECTORIES(include INCLUDE_DIRECTORIES(include
./ ./include ../lwip/src/include ../lwip/src/arch_linux/include ../include ./ ./include ../lwip/src/include ../lwip/src/arch_linux/include ../include
../httpserver/include ../httpserver/src/haywire ../httpserver/src/haywire/configuration ../httpserver/include ../httpserver/src/haywire ../httpserver/src/haywire/configuration)
${PROJECT_BINARY_DIR}/srcs/libs) FILE(GLOB C_HEADS include/*.h include/uthash/*.h include/s2j/*.h vector/*.h ${CMAKE_BINARY_DIR}/*.h)
FILE(GLOB C_HEADS include/*.h include/uthash/*.h include/s2j/*.h vector/*.h ${PROJECT_BINARY_DIR}/srcs/libs/*.h)
AUX_SOURCE_DIRECTORY(json C_SRC) AUX_SOURCE_DIRECTORY(json C_SRC)
@ -51,7 +50,7 @@ IF (USED_SQLITE)
-DSQLITE_HAVE_ZLIB=1 -DSQLITE_TEMP_STORE=2") -DSQLITE_HAVE_ZLIB=1 -DSQLITE_TEMP_STORE=2")
ENDIF () ENDIF ()
ADD_DEFINITIONS(-DBUILD_VERSION="${GIT_VERSION}" ${COMMON_DEFINE}) ADD_DEFINITIONS(${COMMON_DEFINE})
LINK_LIBRARIES(${COMMON_LIBS}) LINK_LIBRARIES(${COMMON_LIBS})
ADD_LIBRARY(${LIB_PROJECT_TARGET} ${C_SRC} ${C_HEADS}) ADD_LIBRARY(${LIB_PROJECT_TARGET} ${C_SRC} ${C_HEADS})
@ -62,4 +61,4 @@ IF (USED_OPENDHCPD)
TARGET_LINK_LIBRARIES(${LIB_PROJECT_TARGET} opendhcpd) TARGET_LINK_LIBRARIES(${LIB_PROJECT_TARGET} opendhcpd)
ENDIF() ENDIF()
TARGET_INCLUDE_DIRECTORIES(${LIB_PROJECT_TARGET} PUBLIC ${PROJECT_BINARY_DIR}/) TARGET_INCLUDE_DIRECTORIES(${LIB_PROJECT_TARGET} PUBLIC ${PROJECT_BINARY_DIR}/ ${CMAKE_BINARY_DIR}/)

View File

@ -20,6 +20,7 @@
#include "s2j/s2j.h" #include "s2j/s2j.h"
#include "msg_queue.h" #include "msg_queue.h"
#include "../../open_dhcp/dhcpd.h" #include "../../open_dhcp/dhcpd.h"
#include "prj_config.h"
#define REG_ICASE (ARG_REX_ICASE) #define REG_ICASE (ARG_REX_ICASE)
@ -436,7 +437,7 @@ static int on_cmd_(void *pTbl[], const char *pName, void *pInfo) {
show_help(pName); show_help(pName);
} else { } else {
printf("Application information: %s (Build: %s %s GCC Ver:%s) With %lu(bits) OS\n", printf("Application information: %s (Build: %s %s GCC Ver:%s) With %lu(bits) OS\n",
BUILD_VERSION, VCPE_GIT_VERSION,
__DATE__, __DATE__,
__TIME__, __TIME__,
__VERSION__, __VERSION__,
@ -547,7 +548,7 @@ int menu_run(int argc, char **argv) {
void *pArgTbl6[] = {cmd6, keyGen, helpCmd6, end6}; void *pArgTbl6[] = {cmd6, keyGen, helpCmd6, end6};
int errCode6 = 0; int errCode6 = 0;
#if OPENDHCPD_ON #ifdef OPENDHCPD_ON
arg_rex_t *cmd7 = arg_rex1(NULL, NULL, "dhcpd", NULL, REG_ICASE, NULL); arg_rex_t *cmd7 = arg_rex1(NULL, NULL, "dhcpd", NULL, REG_ICASE, NULL);
arg_lit_t *operate7 = arg_lit0("m", "mode", "\tService works on verbatim mode."); arg_lit_t *operate7 = arg_lit0("m", "mode", "\tService works on verbatim mode.");
arg_file_t *cfgfile7 = arg_file1("c", "config", "<file>", "\tSpecify the current application configuration file path"); arg_file_t *cfgfile7 = arg_file1("c", "config", "<file>", "\tSpecify the current application configuration file path");
@ -573,7 +574,7 @@ int menu_run(int argc, char **argv) {
ARG_TBL_INFO argTblInfo[] = { ARG_TBL_INFO argTblInfo[] = {
{pArgTbl1, ARRAY_SIZE(pArgTbl1), &errCode1, on_cmd1, cmdn_help, "\r \033[1;4;36mstart\033[0m: \033[1mRun agent service normally.\033[0m\n"}, {pArgTbl1, ARRAY_SIZE(pArgTbl1), &errCode1, on_cmd1, cmdn_help, "\r \033[1;4;36mstart\033[0m: \033[1mRun agent service normally.\033[0m\n"},
#if OPENDHCPD_ON #ifdef OPENDHCPD_ON
{pArgTbl7, ARRAY_SIZE(pArgTbl7), &errCode7, on_cmd7, cmdn_help, "\n \033[1;4;36mdhcpd\033[0m: \033[1mRun DHCP service normally.\033[0m\n"}, {pArgTbl7, ARRAY_SIZE(pArgTbl7), &errCode7, on_cmd7, cmdn_help, "\n \033[1;4;36mdhcpd\033[0m: \033[1mRun DHCP service normally.\033[0m\n"},
#endif #endif
{pArgTbl2, ARRAY_SIZE(pArgTbl2), &errCode2, on_cmd2, cmd2_help, "\n \033[1;4;36mif\033[0m: \033[1mRun agent interface tools.\033[0m\n"}, {pArgTbl2, ARRAY_SIZE(pArgTbl2), &errCode2, on_cmd2, cmd2_help, "\n \033[1;4;36mif\033[0m: \033[1mRun agent interface tools.\033[0m\n"},

View File

@ -19,6 +19,7 @@
#include "http_svr.h" #include "http_svr.h"
#include "haywire.h" #include "haywire.h"
#include "lib_config.h" #include "lib_config.h"
#include "prj_config.h"
#define DEFAULT_CONFIG_FILE ("vcpe.cfg") #define DEFAULT_CONFIG_FILE ("vcpe.cfg")
#define DEFAULT_CONFIG_DIR ("config") #define DEFAULT_CONFIG_DIR ("config")
@ -97,7 +98,7 @@ int user_init(const char *pAppCfgFile, const char *pCfgDirectory, const char *pK
dzlog_info("%s library version %s information: %s (Build: %s %s GCC Ver:%s) With %lu(bits) OS\n", dzlog_info("%s library version %s information: %s (Build: %s %s GCC Ver:%s) With %lu(bits) OS\n",
VCPE_LIB_NAME, VCPE_LIB_NAME,
VCPE_LIB_VER, VCPE_LIB_VER,
BUILD_VERSION, VCPE_GIT_VERSION,
__DATE__, __DATE__,
__TIME__, __TIME__,
__VERSION__, __VERSION__,

View File

@ -18,7 +18,6 @@
#endif #endif
#ifdef OPENDHCPD_ON #ifdef OPENDHCPD_ON
#include "user_errno.h"
#include "proto.h" #include "proto.h"
#endif #endif