summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2018-09-13 20:02:12 +0200
committerMarco Varlese <marco.varlese@suse.de>2018-09-14 14:00:51 +0000
commiteeadc14ee2c945eb53ae4cc3c6262499e896afb5 (patch)
tree544d348cf19b7635dee5eb266b83827ecd8801ce /src
parent77bc1a5fb1d5b08e9fc24fc1190a5d640aabd2a1 (diff)
cpack: add deb/rpm packaging to VPP module
This allows easy packaging of external projects, including VOM and sample plugin. i.e. $ make -C build-root PLATFORM=vpp TAG=vpp sample-plugin-install $ ninja -C build-root/build-vpp-native/sample-plugin package ninja: Entering directory `build-root/build-vpp-native/sample-plugin' [0/1] Run CPack packaging tool... CPack: Create package using DEB CPack: Install projects CPack: - Install project: sample-plugin CPack: - Install component: vpp-plugin-sample CPack: - Install component: vpp-plugin-sample-dev CPack: Create package CPack: - package: build-root/build-vpp-native/sample-plugin/vpp-plugin-sample_18.10~rc0~413~g1433e9d1-1_amd64.deb generated. CPack: - package: build-root/build-vpp-native/sample-plugin/vpp-plugin-sample-dev_18.10~rc0~413~g1433e9d1-1_amd64.deb generated. Change-Id: I6b3ec2433961e53edd976b19659ce214d272c40a Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt9
-rw-r--r--src/cmake/CMakeLists.txt1
-rw-r--r--src/cmake/VPPConfig.cmake1
-rw-r--r--src/cmake/library.cmake2
-rw-r--r--src/cmake/pack.cmake94
-rw-r--r--src/cmake/plugin.cmake12
-rw-r--r--src/examples/sample-plugin/CMakeLists.txt6
-rw-r--r--src/examples/sample-plugin/sample/CMakeLists.txt2
8 files changed, 108 insertions, 19 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 05457ebe40c..f6bad2ce133 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -87,7 +87,16 @@ foreach(DIR ${SUBDIRS})
add_subdirectory(${DIR})
endforeach()
+##############################################################################
+# packaging
+##############################################################################
include(cmake/pack.cmake)
+add_vpp_packaging(
+ NAME "vpp"
+ VENDOR "fd.io"
+ DESCRIPTION "Vector Packet Processor"
+)
+
##############################################################################
# detect if we are inside git repo and add configure dependency
##############################################################################
diff --git a/src/cmake/CMakeLists.txt b/src/cmake/CMakeLists.txt
index 7eb1790f2e8..fdee40c61c1 100644
--- a/src/cmake/CMakeLists.txt
+++ b/src/cmake/CMakeLists.txt
@@ -16,6 +16,7 @@ install(
api.cmake
cpu.cmake
library.cmake
+ pack.cmake
plugin.cmake
VPPConfig.cmake
diff --git a/src/cmake/VPPConfig.cmake b/src/cmake/VPPConfig.cmake
index 767fe34c189..c6fd9fa3ded 100644
--- a/src/cmake/VPPConfig.cmake
+++ b/src/cmake/VPPConfig.cmake
@@ -36,3 +36,4 @@ include(${CMAKE_CURRENT_LIST_DIR}/cpu.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/api.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/library.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/plugin.cmake)
+include(${CMAKE_CURRENT_LIST_DIR}/pack.cmake)
diff --git a/src/cmake/library.cmake b/src/cmake/library.cmake
index b9e4f9b4bd8..984d6eb8d75 100644
--- a/src/cmake/library.cmake
+++ b/src/cmake/library.cmake
@@ -66,7 +66,7 @@ macro(add_vpp_library lib)
install(
FILES ${file}
DESTINATION include/${lib}/${dir}
- COMPONENT vpp-dev
+ COMPONENT ${ARG_COMPONENT}-dev
)
endforeach()
endif()
diff --git a/src/cmake/pack.cmake b/src/cmake/pack.cmake
index 328896610d0..1df19811f5b 100644
--- a/src/cmake/pack.cmake
+++ b/src/cmake/pack.cmake
@@ -14,19 +14,81 @@
##############################################################################
# DEB Packaging
##############################################################################
-set(CPACK_GENERATOR "DEB")
-set(CPACK_DEBIAN_PACKAGE_MAINTAINER "VPP Team")
-set(CPACK_PACKAGE_NAME "vpp")
-set(CPACK_PACKAGE_VENDOR "fd.io")
-set(CPACK_PACKAGE_VERSION "18.10")
-set(CPACK_DEB_COMPONENT_INSTALL ON)
-set(CPACK_COMPONENTS_IGNORE_GROUPS 1)
-
-get_cmake_property(components COMPONENTS)
-foreach(lc ${components})
- string(TOUPPER ${lc} uc)
- set(CPACK_DEBIAN_${uc}_PACKAGE_NAME "${lc}")
- set(CPACK_DEBIAN_${uc}_FILE_NAME "${lc}.deb")
-endforeach()
-
-include(CPack)
+
+macro(add_vpp_packaging name)
+ cmake_parse_arguments(ARG
+ ""
+ "NAME;DESCRIPION;VENDOR"
+ ""
+ ${ARGN}
+ )
+
+ # parse /etc/os-release
+ file(READ "/etc/os-release" os_version)
+ string(REPLACE "\n" ";" os_version ${os_version})
+ foreach(_ver ${os_version})
+ string(REPLACE "=" ";" _ver ${_ver})
+ list(GET _ver 0 _name)
+ list(GET _ver 1 _value)
+ set(OS_${_name} ${_value})
+ endforeach()
+
+ # extract version from git
+ execute_process(
+ COMMAND git describe --long --match v*
+ OUTPUT_VARIABLE VER
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ string(REGEX REPLACE "v(.*)-([0-9]+)-(g[0-9a-f]+)" "\\1;\\2;\\3" VER ${VER})
+ list(GET VER 0 tag)
+ string(REPLACE "-" "~" tag ${tag})
+ list(GET VER 1 commit_num)
+ list(GET VER 2 commit_name)
+
+ #define DEB and RPM version numbers
+ if(${commit_num} EQUAL 0)
+ set(deb_ver "${tag}")
+ set(rpm_ver "${tag}")
+ else()
+ set(deb_ver "${tag}~${commit_num}~${commit_name}")
+ set(rpm_ver "${tag}~${commit_num}_${commit_name}")
+ endif()
+
+ get_cmake_property(components COMPONENTS)
+
+ if(OS_ID_LIKE MATCHES "debian")
+ set(CPACK_GENERATOR "DEB")
+ set(type "DEBIAN")
+ set(CPACK_PACKAGE_VERSION "${deb_ver}")
+ set(CPACK_DEBIAN_PACKAGE_MAINTAINER "VPP Team")
+ set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
+ foreach(lc ${components})
+ string(TOUPPER ${lc} uc)
+ set(CPACK_DEBIAN_${uc}_PACKAGE_NAME "${lc}")
+ endforeach()
+ elseif(OS_ID_LIKE MATCHES "rhel")
+ set(CPACK_GENERATOR "RPM")
+ set(type "RPM")
+ set(CPACK_PACKAGE_VERSION "${rpm_ver}")
+ set(CPACK_RPM_FILE_NAME RPM-DEFAULT)
+ foreach(lc ${components})
+ string(TOUPPER ${lc} uc)
+ if(${lc} MATCHES ".*-dev")
+ set(CPACK_RPM_${uc}_DEBUGINFO_PACKAGE ON)
+ set(lc ${lc}el)
+ endif()
+ set(CPACK_RPM_${uc}_PACKAGE_NAME "${lc}")
+ endforeach()
+ endif()
+
+ if(CPACK_GENERATOR)
+ set(CPACK_PACKAGE_NAME ${ARG_NAME})
+ set(CPACK_STRIP_FILES OFF)
+ set(CPACK_PACKAGE_VENDOR "${ARG_VENDOR}")
+ set(CPACK_COMPONENTS_IGNORE_GROUPS 1)
+ set(CPACK_${CPACK_GENERATOR}_COMPONENT_INSTALL ON)
+ set(CPACK_${type}_PACKAGE_DESCRIPTION "${ARG_DESCRIPTION}")
+ set(CPACK_${type}_PACKAGE_RELEASE 1)
+ include(CPack)
+ endif()
+endmacro()
diff --git a/src/cmake/plugin.cmake b/src/cmake/plugin.cmake
index f68c955f64f..1cff910db5f 100644
--- a/src/cmake/plugin.cmake
+++ b/src/cmake/plugin.cmake
@@ -14,7 +14,7 @@
macro(add_vpp_plugin name)
cmake_parse_arguments(PLUGIN
""
- "LINK_FLAGS;COMPONENT"
+ "LINK_FLAGS;COMPONENT;DEV_COMPONENT"
"SOURCES;API_FILES;MULTIARCH_SOURCES;LINK_LIBRARIES;INSTALL_HEADERS;API_TEST_SOURCES"
${ARGN}
)
@@ -23,6 +23,14 @@ macro(add_vpp_plugin name)
if(NOT PLUGIN_COMPONENT)
set(PLUGIN_COMPONENT vpp-plugin-misc)
endif()
+ if(NOT PLUGIN_DEV_COMPONENT)
+ if(NOT VPP_EXTERNAL_PROJECT)
+ set(PLUGIN_DEV_COMPONENT vpp-dev)
+ else()
+ set(PLUGIN_DEV_COMPONENT ${PLUGIN_COMPONENT}-dev)
+ endif()
+ endif()
+
file(RELATIVE_PATH rpath ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
foreach(f ${PLUGIN_API_FILES})
get_filename_component(dir ${f} DIRECTORY)
@@ -32,7 +40,7 @@ macro(add_vpp_plugin name)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${f}.h
DESTINATION include/vpp_plugins/${name}/${dir}
- COMPONENT vpp-dev
+ COMPONENT ${PLUGIN_DEV_COMPONENT}
)
endforeach()
add_library(${plugin_name} SHARED ${PLUGIN_SOURCES} ${api_includes})
diff --git a/src/examples/sample-plugin/CMakeLists.txt b/src/examples/sample-plugin/CMakeLists.txt
index eac58fbc258..462e7221a94 100644
--- a/src/examples/sample-plugin/CMakeLists.txt
+++ b/src/examples/sample-plugin/CMakeLists.txt
@@ -8,3 +8,9 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
find_package(VPP)
add_subdirectory(sample)
+
+add_vpp_packaging(
+ NAME "sample-plugin"
+ VENDOR "fd.io"
+ DESCRIPTION "VPP Sample Plugin"
+)
diff --git a/src/examples/sample-plugin/sample/CMakeLists.txt b/src/examples/sample-plugin/sample/CMakeLists.txt
index f2fc1434492..fb159d12ef6 100644
--- a/src/examples/sample-plugin/sample/CMakeLists.txt
+++ b/src/examples/sample-plugin/sample/CMakeLists.txt
@@ -29,4 +29,6 @@ add_vpp_plugin(sample
API_TEST_SOURCES
sample_test.c
+
+ COMPONENT vpp-plugin-sample
)