msardara | 8f554b7 | 2018-12-11 18:36:55 +0100 | [diff] [blame] | 1 | # Copyright (c) 2017 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 | cmake_minimum_required(VERSION 3.5 FATAL_ERROR) |
| 15 | |
| 16 | project(memif) |
| 17 | set(CMAKE_C_STANDARD 11) |
| 18 | |
| 19 | include(CheckCCompilerFlag) |
| 20 | include(CheckFunctionExists) |
| 21 | |
msardara | 8f554b7 | 2018-12-11 18:36:55 +0100 | [diff] [blame] | 22 | if (NOT CMAKE_BUILD_TYPE) |
| 23 | message(STATUS "No build type selected, default to Release") |
| 24 | set(CMAKE_BUILD_TYPE "Release") |
| 25 | endif () |
| 26 | |
| 27 | set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -DMEMIF_DBG -DICMP_DBG") |
| 28 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
| 29 | set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib) |
| 30 | set(CMAKE_INSTALL_MESSAGE NEVER) |
| 31 | |
| 32 | find_package(Threads REQUIRED) |
| 33 | include_directories(${CMAKE_THREADS_INCLUDE_DIRS}) |
| 34 | |
| 35 | check_function_exists(memfd_create HAVE_MEMFD_CREATE) |
| 36 | if(${HAVE_MEMFD_CREATE}) |
| 37 | add_definitions(-DHAVE_MEMFD_CREATE) |
| 38 | endif() |
| 39 | |
| 40 | include_directories(src) |
msardara | 8f554b7 | 2018-12-11 18:36:55 +0100 | [diff] [blame] | 41 | |
| 42 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") |
| 43 | find_package(Check 0.10.0) |
| 44 | if (CHECK_FOUND) |
| 45 | include_directories(${CHECK_INCLUDE_DIR}) |
| 46 | add_definitions(-DMEMIF_UNIT_TEST) |
| 47 | add_subdirectory(test) |
| 48 | enable_testing() |
| 49 | endif () |
| 50 | |
| 51 | add_subdirectory(src) |
| 52 | add_subdirectory(examples) |
| 53 | |
Damjan Marion | 599efc6 | 2020-05-07 16:49:45 +0200 | [diff] [blame] | 54 | ############################################################################## |
| 55 | # Packaging |
| 56 | ############################################################################## |
| 57 | |
| 58 | # parse /etc/os-release |
| 59 | file(READ "/etc/os-release" os_version) |
| 60 | string(REPLACE "\n" ";" os_version ${os_version}) |
| 61 | foreach(_ver ${os_version}) |
| 62 | string(REPLACE "=" ";" _ver ${_ver}) |
| 63 | list(GET _ver 0 _name) |
| 64 | list(GET _ver 1 _value) |
| 65 | set(OS_${_name} ${_value}) |
| 66 | endforeach() |
| 67 | |
| 68 | # extract version from git |
| 69 | execute_process( |
| 70 | COMMAND git describe --long --match v* |
| 71 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
| 72 | OUTPUT_VARIABLE VER |
| 73 | OUTPUT_STRIP_TRAILING_WHITESPACE |
msardara | 8f554b7 | 2018-12-11 18:36:55 +0100 | [diff] [blame] | 74 | ) |
Damjan Marion | 599efc6 | 2020-05-07 16:49:45 +0200 | [diff] [blame] | 75 | string(REGEX REPLACE "v(.*)-([0-9]+)-(g[0-9a-f]+)" "\\1;\\2;\\3" VER ${VER}) |
| 76 | list(GET VER 0 tag) |
| 77 | list(GET VER 1 commit_num) |
| 78 | list(GET VER 2 commit_name) |
| 79 | |
| 80 | #define DEB and RPM version numbers |
| 81 | if(${commit_num} EQUAL 0) |
| 82 | set(deb_ver "${tag}") |
| 83 | set(rpm_ver "${tag}") |
| 84 | else() |
| 85 | if (DEFINED ENV{BUILD_NUMBER}) |
| 86 | set(deb_ver "${tag}~${commit_num}-${commit_name}~b$ENV{BUILD_NUMBER}") |
| 87 | set(rpm_ver "${tag}~${commit_num}_${commit_name}~b$ENV{BUILD_NUMBER}") |
| 88 | else() |
| 89 | set(deb_ver "${tag}~${commit_num}-${commit_name}") |
| 90 | set(rpm_ver "${tag}~${commit_num}_${commit_name}") |
| 91 | endif() |
| 92 | endif() |
| 93 | |
| 94 | set(CPACK_PACKAGE_NAME "memif") |
| 95 | set(CPACK_STRIP_FILES OFF) |
| 96 | set(CPACK_PACKAGE_VENDOR "fd.io") |
| 97 | set(CPACK_COMPONENTS_IGNORE_GROUPS 1) |
| 98 | set(CPACK_${CPACK_GENERATOR}_COMPONENT_INSTALL ON) |
| 99 | set(CPACK_${type}_PACKAGE_DESCRIPTION "memif Shared Memory Interface") |
| 100 | set(CPACK_${type}_PACKAGE_RELEASE 1) |
| 101 | |
| 102 | if(OS_ID_LIKE MATCHES "debian") |
| 103 | set(CPACK_GENERATOR "DEB") |
| 104 | set(type "DEBIAN") |
| 105 | set(CPACK_PACKAGE_VERSION "${deb_ver}") |
| 106 | set(CPACK_DEBIAN_PACKAGE_MAINTAINER "VPP Team") |
| 107 | execute_process( |
| 108 | COMMAND dpkg --print-architecture |
| 109 | OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE |
| 110 | OUTPUT_STRIP_TRAILING_WHITESPACE |
| 111 | ) |
| 112 | set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}) |
| 113 | elseif(OS_ID_LIKE MATCHES "rhel") |
| 114 | set(CPACK_GENERATOR "RPM") |
| 115 | set(type "RPM") |
| 116 | set(CPACK_PACKAGE_VERSION "${rpm_ver}") |
| 117 | execute_process( |
| 118 | COMMAND uname -m |
| 119 | OUTPUT_VARIABLE CPACK_RPM_PACKAGE_ARCHITECTURE |
| 120 | OUTPUT_STRIP_TRAILING_WHITESPACE |
| 121 | ) |
| 122 | set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.${CPACK_RPM_PACKAGE_ARCHITECTURE}) |
| 123 | endif() |
| 124 | |
| 125 | if(CPACK_GENERATOR) |
| 126 | include(CPack) |
| 127 | else() |
| 128 | message(ERROR "CPACK_GENERATOR must be set") |
| 129 | endif() |
| 130 | |