blob: 0da3093b1a03d23f88184406d49de54e668644c4 [file] [log] [blame]
Damjan Mariond16004d2018-08-26 10:14:52 +02001# Copyright (c) 2018 Cisco and/or its affiliates.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at:
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14##############################################################################
15# DEB Packaging
16##############################################################################
Damjan Marion43b06062018-08-29 22:20:45 +020017
Damjan Marioneeadc142018-09-13 20:02:12 +020018macro(add_vpp_packaging name)
19 cmake_parse_arguments(ARG
20 ""
21 "NAME;DESCRIPION;VENDOR"
22 ""
23 ${ARGN}
24 )
Damjan Marion43b06062018-08-29 22:20:45 +020025
Damjan Marioneeadc142018-09-13 20:02:12 +020026 # parse /etc/os-release
27 file(READ "/etc/os-release" os_version)
28 string(REPLACE "\n" ";" os_version ${os_version})
29 foreach(_ver ${os_version})
30 string(REPLACE "=" ";" _ver ${_ver})
31 list(GET _ver 0 _name)
32 list(GET _ver 1 _value)
33 set(OS_${_name} ${_value})
34 endforeach()
35
36 # extract version from git
37 execute_process(
38 COMMAND git describe --long --match v*
Damjan Mariona2e29e72019-01-25 11:22:58 +010039 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
Damjan Marioneeadc142018-09-13 20:02:12 +020040 OUTPUT_VARIABLE VER
41 OUTPUT_STRIP_TRAILING_WHITESPACE
42 )
43 string(REGEX REPLACE "v(.*)-([0-9]+)-(g[0-9a-f]+)" "\\1;\\2;\\3" VER ${VER})
44 list(GET VER 0 tag)
45 string(REPLACE "-" "~" tag ${tag})
46 list(GET VER 1 commit_num)
47 list(GET VER 2 commit_name)
48
49 #define DEB and RPM version numbers
50 if(${commit_num} EQUAL 0)
51 set(deb_ver "${tag}")
52 set(rpm_ver "${tag}")
53 else()
54 set(deb_ver "${tag}~${commit_num}~${commit_name}")
55 set(rpm_ver "${tag}~${commit_num}_${commit_name}")
56 endif()
57
58 get_cmake_property(components COMPONENTS)
59
60 if(OS_ID_LIKE MATCHES "debian")
61 set(CPACK_GENERATOR "DEB")
62 set(type "DEBIAN")
63 set(CPACK_PACKAGE_VERSION "${deb_ver}")
64 set(CPACK_DEBIAN_PACKAGE_MAINTAINER "VPP Team")
65 set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
66 foreach(lc ${components})
67 string(TOUPPER ${lc} uc)
68 set(CPACK_DEBIAN_${uc}_PACKAGE_NAME "${lc}")
69 endforeach()
70 elseif(OS_ID_LIKE MATCHES "rhel")
71 set(CPACK_GENERATOR "RPM")
72 set(type "RPM")
73 set(CPACK_PACKAGE_VERSION "${rpm_ver}")
74 set(CPACK_RPM_FILE_NAME RPM-DEFAULT)
75 foreach(lc ${components})
76 string(TOUPPER ${lc} uc)
77 if(${lc} MATCHES ".*-dev")
78 set(CPACK_RPM_${uc}_DEBUGINFO_PACKAGE ON)
79 set(lc ${lc}el)
80 endif()
81 set(CPACK_RPM_${uc}_PACKAGE_NAME "${lc}")
82 endforeach()
83 endif()
84
85 if(CPACK_GENERATOR)
86 set(CPACK_PACKAGE_NAME ${ARG_NAME})
87 set(CPACK_STRIP_FILES OFF)
88 set(CPACK_PACKAGE_VENDOR "${ARG_VENDOR}")
89 set(CPACK_COMPONENTS_IGNORE_GROUPS 1)
90 set(CPACK_${CPACK_GENERATOR}_COMPONENT_INSTALL ON)
91 set(CPACK_${type}_PACKAGE_DESCRIPTION "${ARG_DESCRIPTION}")
92 set(CPACK_${type}_PACKAGE_RELEASE 1)
93 include(CPack)
94 endif()
95endmacro()