TSG-7784 PacketAdapter支持CI自动构建RPM; 修改代码结构

This commit is contained in:
卢文朋
2021-09-13 02:12:29 +00:00
committed by luwenpeng
parent aa887fd382
commit ba21a53bb7
35 changed files with 2878 additions and 915 deletions

39
cmake/FindNFNETLINK.cmake Normal file
View File

@@ -0,0 +1,39 @@
# - Find nfnetlinkDaemon
# Find the nfnetlink daemon library
#
# This module defines the following variables:
# NFNETLINK_FOUND - True if library and include directory are found
# If set to TRUE, the following are also defined:
# NFNETLINK_INCLUDE_DIRS - The directory where to find the header file
# NFNETLINK_LIBRARIES - Where to find the library file
#
# For conveniance, these variables are also set. They have the same values
# than the variables above. The user can thus choose his/her prefered way
# to write them.
# NFNETLINK_LIBRARY
# NFNETLINK_INCLUDE_DIR
#
# This file is in the public domain
include(FindPkgConfig)
pkg_check_modules(NFNETLINK libnfnetlink)
if(NOT NFNETLINK_FOUND)
find_path(NFNETLINK_INCLUDE_DIRS NAMES nlibnfnetlink/libnfnetlink.h
DOC "The nfnetlink include directory")
find_library(NFNETLINK_LIBRARIES NAMES libnfnetlink
DOC "The nfnetlink library")
# Use some standard module to handle the QUIETLY and REQUIRED arguments, and
# set NFNETLINK_FOUND to TRUE if these two variables are set.
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(NFNETLINK REQUIRED_VARS NFNETLINK_LIBRARIES NFNETLINK_INCLUDE_DIRS)
if(NFNETLINK_FOUND)
set(NFNETLINK_LIBRARY ${NFNETLINK_LIBRARIES})
set(NFNETLINK_INCLUDE_DIR ${NFNETLINK_INCLUDE_DIRS})
endif()
endif()
mark_as_advanced(NFNETLINK_INCLUDE_DIRS NFNETLINK_LIBRARIES)

31
cmake/Package.cmake Normal file
View File

@@ -0,0 +1,31 @@
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CPACK_PACKAGE_NAME "packetadapter-debug")
else()
set(CPACK_PACKAGE_NAME "packetadapter")
endif()
message(STATUS "Package: ${CPACK_PACKAGE_NAME}")
set(CPACK_PACKAGE_VENDOR "MESASOFT")
set(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${VERSION_PATCH}.${DESCRIBE}")
set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
# RPM Build
set(CPACK_GENERATOR "RPM")
set(CPACK_RPM_AUTO_GENERATED_FILE_NAME ON)
set(CPACK_RPM_FILE_NAME "RPM-DEFAULT")
set(CPACK_RPM_PACKAGE_AUTOREQPROV "no")
set(CPACK_RPM_PACKAGE_RELEASE_DIST on)
set(CPACK_RPM_DEBUGINFO_PACKAGE on)
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE ${CMAKE_SOURCE_DIR}/cmake/PostInstall.in)
set(CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE ${CMAKE_SOURCE_DIR}/cmake/PostUninstall.in)
set(CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE ${CMAKE_SOURCE_DIR}/cmake/PreUninstall.in)
# Must uninstall the debug package before install release package
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CPACK_RPM_PACKAGE_CONFLICTS "packetadapter")
else()
set(CPACK_RPM_PACKAGE_CONFLICTS "packetadapter-debug")
endif()

2
cmake/PostInstall.in Normal file
View File

@@ -0,0 +1,2 @@
%systemd_post packetadapter.service
/sbin/ldconfig

2
cmake/PostUninstall.in Normal file
View File

@@ -0,0 +1,2 @@
%systemd_postun_with_restart packetadapter.service
/sbin/ldconfig

1
cmake/PreUninstall.in Normal file
View File

@@ -0,0 +1 @@
%systemd_preun packetadapter.service

49
cmake/Version.cmake Normal file
View File

@@ -0,0 +1,49 @@
# Using autorevision.sh to generate version information
set(__SOURCE_AUTORESIVISION ${CMAKE_SOURCE_DIR}/autorevision.sh)
set(__AUTORESIVISION ${CMAKE_BINARY_DIR}/autorevision.sh)
set(__VERSION_CACHE ${CMAKE_SOURCE_DIR}/version.txt)
set(__VERSION_CONFIG ${CMAKE_BINARY_DIR}/version.cmake)
file(COPY ${__SOURCE_AUTORESIVISION} DESTINATION ${CMAKE_BINARY_DIR}
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE)
# execute autorevision.sh to generate version information
execute_process(COMMAND ${__AUTORESIVISION} -t cmake -o ${__VERSION_CACHE} OUTPUT_FILE ${__VERSION_CONFIG})
include(${__VERSION_CONFIG})
# extract major, minor, patch version from git tag
string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${VCS_TAG}")
string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${VCS_TAG}")
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${VCS_TAG}")
string(REGEX REPLACE "[T\\:\\+\\-]" "" VERSION_DATE "${VCS_DATE}")
if(VERSION_DAILY_BUILD)
set(VERSION_PATCH ${VERSION_PATCH}.${VERSION_DATE})
endif()
if(NOT VERSION_MAJOR)
set(VERSION_MAJOR 1)
endif()
if(NOT VERSION_MINOR)
set(VERSION_MINOR 0)
endif()
if(NOT VERSION_PATCH)
set(VERSION_PATCH 0)
endif()
set(DESCRIBE "${VCS_SHORT_HASH}")
set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
set(GIT_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}-${DESCRIBE}")
# Replace .- with _
string(REGEX REPLACE "[\\.\\-]" "_" VAR_VERSION "${GIT_VERSION}")
# print information
message(STATUS "Welcome to Packet Adapter, Version: ${GIT_VERSION}")
add_definitions(-DGIT_VERSION=\"${GIT_VERSION}\")
add_definitions(-DVAR_VERSION=${VAR_VERSION})