blob: 88b62548211191d26d54aa66704c2c0a7bdf12ff [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
YohanPipereau093dd7f2019-07-19 17:53:18 +020014# name, vendor, description are macros, arguments are in ${ARGN}
15macro(add_vpp_packaging)
Damjan Marioneeadc142018-09-13 20:02:12 +020016 cmake_parse_arguments(ARG
17 ""
YohanPipereau093dd7f2019-07-19 17:53:18 +020018 "NAME;DESCRIPTION;VENDOR"
Damjan Marioneeadc142018-09-13 20:02:12 +020019 ""
20 ${ARGN}
21 )
Damjan Marion43b06062018-08-29 22:20:45 +020022
Damjan Marioneeadc142018-09-13 20:02:12 +020023 # parse /etc/os-release
24 file(READ "/etc/os-release" os_version)
25 string(REPLACE "\n" ";" os_version ${os_version})
26 foreach(_ver ${os_version})
27 string(REPLACE "=" ";" _ver ${_ver})
28 list(GET _ver 0 _name)
29 list(GET _ver 1 _value)
30 set(OS_${_name} ${_value})
31 endforeach()
32
33 # extract version from git
34 execute_process(
35 COMMAND git describe --long --match v*
Damjan Mariona2e29e72019-01-25 11:22:58 +010036 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
Damjan Marioneeadc142018-09-13 20:02:12 +020037 OUTPUT_VARIABLE VER
38 OUTPUT_STRIP_TRAILING_WHITESPACE
39 )
40 string(REGEX REPLACE "v(.*)-([0-9]+)-(g[0-9a-f]+)" "\\1;\\2;\\3" VER ${VER})
41 list(GET VER 0 tag)
Damjan Marioneeadc142018-09-13 20:02:12 +020042 list(GET VER 1 commit_num)
43 list(GET VER 2 commit_name)
44
45 #define DEB and RPM version numbers
46 if(${commit_num} EQUAL 0)
47 set(deb_ver "${tag}")
48 set(rpm_ver "${tag}")
49 else()
YohanPipereau093dd7f2019-07-19 17:53:18 +020050 if (DEFINED ENV{BUILD_NUMBER})
51 set(deb_ver "${tag}~${commit_num}-${commit_name}~b$ENV{BUILD_NUMBER}")
52 set(rpm_ver "${tag}~${commit_num}_${commit_name}~b$ENV{BUILD_NUMBER}")
53 else()
54 set(deb_ver "${tag}~${commit_num}-${commit_name}")
55 set(rpm_ver "${tag}~${commit_num}_${commit_name}")
56 endif()
Damjan Marioneeadc142018-09-13 20:02:12 +020057 endif()
58
YohanPipereau093dd7f2019-07-19 17:53:18 +020059 set(CPACK_PACKAGE_NAME ${ARG_NAME})
60 set(CPACK_STRIP_FILES OFF)
61 set(CPACK_PACKAGE_VENDOR "${ARG_VENDOR}")
62 set(CPACK_COMPONENTS_IGNORE_GROUPS 1)
63 set(CPACK_${CPACK_GENERATOR}_COMPONENT_INSTALL ON)
64 set(CPACK_${type}_PACKAGE_DESCRIPTION "${ARG_DESCRIPTION}")
65 set(CPACK_${type}_PACKAGE_RELEASE 1)
Damjan Marioneeadc142018-09-13 20:02:12 +020066
Andrew Yourtchenko534dfc12022-03-24 11:45:10 +000067 # Pure Debian does not set the "OS_ID_LIKE", it only sets "OS_ID"
BenoƮt Ganne934f9b02022-08-31 11:45:17 +020068 if (NOT DEFINED OS_ID_LIKE)
Andrew Yourtchenko534dfc12022-03-24 11:45:10 +000069 set(OS_ID_LIKE "${OS_ID}")
70 endif()
71
Damjan Marioneeadc142018-09-13 20:02:12 +020072 if(OS_ID_LIKE MATCHES "debian")
73 set(CPACK_GENERATOR "DEB")
74 set(type "DEBIAN")
75 set(CPACK_PACKAGE_VERSION "${deb_ver}")
76 set(CPACK_DEBIAN_PACKAGE_MAINTAINER "VPP Team")
YohanPipereau093dd7f2019-07-19 17:53:18 +020077 execute_process(
78 COMMAND dpkg --print-architecture
79 OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
80 OUTPUT_STRIP_TRAILING_WHITESPACE
81 )
82 set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE})
Damjan Marioneeadc142018-09-13 20:02:12 +020083 elseif(OS_ID_LIKE MATCHES "rhel")
84 set(CPACK_GENERATOR "RPM")
85 set(type "RPM")
86 set(CPACK_PACKAGE_VERSION "${rpm_ver}")
YohanPipereau093dd7f2019-07-19 17:53:18 +020087 execute_process(
88 COMMAND uname -m
89 OUTPUT_VARIABLE CPACK_RPM_PACKAGE_ARCHITECTURE
90 OUTPUT_STRIP_TRAILING_WHITESPACE
91 )
92 set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.${CPACK_RPM_PACKAGE_ARCHITECTURE})
Damjan Marioneeadc142018-09-13 20:02:12 +020093 endif()
94
95 if(CPACK_GENERATOR)
Damjan Marioneeadc142018-09-13 20:02:12 +020096 include(CPack)
YohanPipereau093dd7f2019-07-19 17:53:18 +020097 else()
98 message(ERROR "CPACK_GENERATOR must be set")
Damjan Marioneeadc142018-09-13 20:02:12 +020099 endif()
YohanPipereau093dd7f2019-07-19 17:53:18 +0200100
Damjan Marioneeadc142018-09-13 20:02:12 +0200101endmacro()