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 | |
| 14 | ############################################################################## |
| 15 | # DEB Packaging |
| 16 | ############################################################################## |
Damjan Marion | 43b0606 | 2018-08-29 22:20:45 +0200 | [diff] [blame] | 17 | |
Damjan Marion | eeadc14 | 2018-09-13 20:02:12 +0200 | [diff] [blame^] | 18 | macro(add_vpp_packaging name) |
| 19 | cmake_parse_arguments(ARG |
| 20 | "" |
| 21 | "NAME;DESCRIPION;VENDOR" |
| 22 | "" |
| 23 | ${ARGN} |
| 24 | ) |
Damjan Marion | 43b0606 | 2018-08-29 22:20:45 +0200 | [diff] [blame] | 25 | |
Damjan Marion | eeadc14 | 2018-09-13 20:02:12 +0200 | [diff] [blame^] | 26 | # 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* |
| 39 | OUTPUT_VARIABLE VER |
| 40 | OUTPUT_STRIP_TRAILING_WHITESPACE |
| 41 | ) |
| 42 | string(REGEX REPLACE "v(.*)-([0-9]+)-(g[0-9a-f]+)" "\\1;\\2;\\3" VER ${VER}) |
| 43 | list(GET VER 0 tag) |
| 44 | string(REPLACE "-" "~" tag ${tag}) |
| 45 | list(GET VER 1 commit_num) |
| 46 | list(GET VER 2 commit_name) |
| 47 | |
| 48 | #define DEB and RPM version numbers |
| 49 | if(${commit_num} EQUAL 0) |
| 50 | set(deb_ver "${tag}") |
| 51 | set(rpm_ver "${tag}") |
| 52 | else() |
| 53 | set(deb_ver "${tag}~${commit_num}~${commit_name}") |
| 54 | set(rpm_ver "${tag}~${commit_num}_${commit_name}") |
| 55 | endif() |
| 56 | |
| 57 | get_cmake_property(components COMPONENTS) |
| 58 | |
| 59 | if(OS_ID_LIKE MATCHES "debian") |
| 60 | set(CPACK_GENERATOR "DEB") |
| 61 | set(type "DEBIAN") |
| 62 | set(CPACK_PACKAGE_VERSION "${deb_ver}") |
| 63 | set(CPACK_DEBIAN_PACKAGE_MAINTAINER "VPP Team") |
| 64 | set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT) |
| 65 | foreach(lc ${components}) |
| 66 | string(TOUPPER ${lc} uc) |
| 67 | set(CPACK_DEBIAN_${uc}_PACKAGE_NAME "${lc}") |
| 68 | endforeach() |
| 69 | elseif(OS_ID_LIKE MATCHES "rhel") |
| 70 | set(CPACK_GENERATOR "RPM") |
| 71 | set(type "RPM") |
| 72 | set(CPACK_PACKAGE_VERSION "${rpm_ver}") |
| 73 | set(CPACK_RPM_FILE_NAME RPM-DEFAULT) |
| 74 | foreach(lc ${components}) |
| 75 | string(TOUPPER ${lc} uc) |
| 76 | if(${lc} MATCHES ".*-dev") |
| 77 | set(CPACK_RPM_${uc}_DEBUGINFO_PACKAGE ON) |
| 78 | set(lc ${lc}el) |
| 79 | endif() |
| 80 | set(CPACK_RPM_${uc}_PACKAGE_NAME "${lc}") |
| 81 | endforeach() |
| 82 | endif() |
| 83 | |
| 84 | if(CPACK_GENERATOR) |
| 85 | set(CPACK_PACKAGE_NAME ${ARG_NAME}) |
| 86 | set(CPACK_STRIP_FILES OFF) |
| 87 | set(CPACK_PACKAGE_VENDOR "${ARG_VENDOR}") |
| 88 | set(CPACK_COMPONENTS_IGNORE_GROUPS 1) |
| 89 | set(CPACK_${CPACK_GENERATOR}_COMPONENT_INSTALL ON) |
| 90 | set(CPACK_${type}_PACKAGE_DESCRIPTION "${ARG_DESCRIPTION}") |
| 91 | set(CPACK_${type}_PACKAGE_RELEASE 1) |
| 92 | include(CPack) |
| 93 | endif() |
| 94 | endmacro() |