Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 1 | # 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 | |
YohanPipereau | 093dd7f | 2019-07-19 17:53:18 +0200 | [diff] [blame] | 14 | # name, vendor, description are macros, arguments are in ${ARGN} |
| 15 | macro(add_vpp_packaging) |
Damjan Marion | eeadc14 | 2018-09-13 20:02:12 +0200 | [diff] [blame] | 16 | cmake_parse_arguments(ARG |
| 17 | "" |
YohanPipereau | 093dd7f | 2019-07-19 17:53:18 +0200 | [diff] [blame] | 18 | "NAME;DESCRIPTION;VENDOR" |
Damjan Marion | eeadc14 | 2018-09-13 20:02:12 +0200 | [diff] [blame] | 19 | "" |
| 20 | ${ARGN} |
| 21 | ) |
Damjan Marion | 43b0606 | 2018-08-29 22:20:45 +0200 | [diff] [blame] | 22 | |
Damjan Marion | eeadc14 | 2018-09-13 20:02:12 +0200 | [diff] [blame] | 23 | # 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 Marion | a2e29e7 | 2019-01-25 11:22:58 +0100 | [diff] [blame] | 36 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
Damjan Marion | eeadc14 | 2018-09-13 20:02:12 +0200 | [diff] [blame] | 37 | 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 Marion | eeadc14 | 2018-09-13 20:02:12 +0200 | [diff] [blame] | 42 | 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() |
YohanPipereau | 093dd7f | 2019-07-19 17:53:18 +0200 | [diff] [blame] | 50 | 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 Marion | eeadc14 | 2018-09-13 20:02:12 +0200 | [diff] [blame] | 57 | endif() |
| 58 | |
YohanPipereau | 093dd7f | 2019-07-19 17:53:18 +0200 | [diff] [blame] | 59 | 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 Marion | eeadc14 | 2018-09-13 20:02:12 +0200 | [diff] [blame] | 66 | |
Andrew Yourtchenko | 534dfc1 | 2022-03-24 11:45:10 +0000 | [diff] [blame] | 67 | # Pure Debian does not set the "OS_ID_LIKE", it only sets "OS_ID" |
| 68 | if (OS_ID_LIKE MATCHES "") |
| 69 | set(OS_ID_LIKE "${OS_ID}") |
| 70 | endif() |
| 71 | |
Damjan Marion | eeadc14 | 2018-09-13 20:02:12 +0200 | [diff] [blame] | 72 | 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") |
YohanPipereau | 093dd7f | 2019-07-19 17:53:18 +0200 | [diff] [blame] | 77 | 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 Marion | eeadc14 | 2018-09-13 20:02:12 +0200 | [diff] [blame] | 83 | elseif(OS_ID_LIKE MATCHES "rhel") |
| 84 | set(CPACK_GENERATOR "RPM") |
| 85 | set(type "RPM") |
| 86 | set(CPACK_PACKAGE_VERSION "${rpm_ver}") |
YohanPipereau | 093dd7f | 2019-07-19 17:53:18 +0200 | [diff] [blame] | 87 | 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 Marion | eeadc14 | 2018-09-13 20:02:12 +0200 | [diff] [blame] | 93 | endif() |
| 94 | |
| 95 | if(CPACK_GENERATOR) |
Damjan Marion | eeadc14 | 2018-09-13 20:02:12 +0200 | [diff] [blame] | 96 | include(CPack) |
YohanPipereau | 093dd7f | 2019-07-19 17:53:18 +0200 | [diff] [blame] | 97 | else() |
| 98 | message(ERROR "CPACK_GENERATOR must be set") |
Damjan Marion | eeadc14 | 2018-09-13 20:02:12 +0200 | [diff] [blame] | 99 | endif() |
YohanPipereau | 093dd7f | 2019-07-19 17:53:18 +0200 | [diff] [blame] | 100 | |
Damjan Marion | eeadc14 | 2018-09-13 20:02:12 +0200 | [diff] [blame] | 101 | endmacro() |