blob: a89a90c452c584bbf8e5788e3d17e3514b2079a1 [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
67 if(OS_ID_LIKE MATCHES "debian")
68 set(CPACK_GENERATOR "DEB")
69 set(type "DEBIAN")
70 set(CPACK_PACKAGE_VERSION "${deb_ver}")
71 set(CPACK_DEBIAN_PACKAGE_MAINTAINER "VPP Team")
YohanPipereau093dd7f2019-07-19 17:53:18 +020072 execute_process(
73 COMMAND dpkg --print-architecture
74 OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
75 OUTPUT_STRIP_TRAILING_WHITESPACE
76 )
77 set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE})
Damjan Marioneeadc142018-09-13 20:02:12 +020078 elseif(OS_ID_LIKE MATCHES "rhel")
79 set(CPACK_GENERATOR "RPM")
80 set(type "RPM")
81 set(CPACK_PACKAGE_VERSION "${rpm_ver}")
YohanPipereau093dd7f2019-07-19 17:53:18 +020082 execute_process(
83 COMMAND uname -m
84 OUTPUT_VARIABLE CPACK_RPM_PACKAGE_ARCHITECTURE
85 OUTPUT_STRIP_TRAILING_WHITESPACE
86 )
87 set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.${CPACK_RPM_PACKAGE_ARCHITECTURE})
Damjan Marioneeadc142018-09-13 20:02:12 +020088 endif()
89
90 if(CPACK_GENERATOR)
Damjan Marioneeadc142018-09-13 20:02:12 +020091 include(CPack)
YohanPipereau093dd7f2019-07-19 17:53:18 +020092 else()
93 message(ERROR "CPACK_GENERATOR must be set")
Damjan Marioneeadc142018-09-13 20:02:12 +020094 endif()
YohanPipereau093dd7f2019-07-19 17:53:18 +020095
Damjan Marioneeadc142018-09-13 20:02:12 +020096endmacro()