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) |
Daniel Béreš | 9853342 | 2023-01-19 10:19:27 +0100 | [diff] [blame] | 21 | find_package(Git REQUIRED) |
| 22 | |
| 23 | include(ExternalProject) |
| 24 | set(UNITY unity_project) |
| 25 | |
| 26 | ExternalProject_Add( |
| 27 | unity_project |
| 28 | GIT_REPOSITORY https://github.com/ThrowTheSwitch/Unity.git |
| 29 | GIT_TAG cf949f45ca6d172a177b00da21310607b97bc7a7 |
| 30 | PREFIX ${PROJECT_BINARY_DIR}/external/${UNITY} |
| 31 | INSTALL_COMMAND cmake --install . --prefix ${PROJECT_BINARY_DIR} |
| 32 | |
| 33 | ) |
| 34 | set_source_files_properties( |
| 35 | ${PROJECT_BINARY_DIR}/external/${UNITY}/src/${UNITY}/src/unity.c |
| 36 | ${PROJECT_BINARY_DIR}/external/${UNITY}/src/${UNITY}/extras/fixture/src/unity_fixture.c |
| 37 | ${PROJECT_BINARY_DIR}/external/${UNITY}/src/${UNITY}/extras/memory/src/unity_memory.c |
| 38 | PROPERTIES GENERATED TRUE) |
| 39 | add_library(unity STATIC |
| 40 | ${PROJECT_BINARY_DIR}/external/${UNITY}/src/${UNITY}/src/unity.c |
| 41 | ${PROJECT_BINARY_DIR}/external/${UNITY}/src/${UNITY}/extras/fixture/src/unity_fixture.c |
| 42 | ${PROJECT_BINARY_DIR}/external/${UNITY}/src/${UNITY}/extras/memory/src/unity_memory.c |
| 43 | ) |
| 44 | target_include_directories(unity PUBLIC |
| 45 | ${PROJECT_BINARY_DIR}/external/${UNITY}/src/${UNITY}/src/ |
| 46 | ${PROJECT_BINARY_DIR}/external/${UNITY}/src/${UNITY}/extras/fixture/src/ |
| 47 | ${PROJECT_BINARY_DIR}/external/${UNITY}/src/${UNITY}/extras/memory/src/ |
| 48 | ) |
| 49 | add_dependencies(unity unity_project) |
msardara | 8f554b7 | 2018-12-11 18:36:55 +0100 | [diff] [blame] | 50 | |
msardara | 8f554b7 | 2018-12-11 18:36:55 +0100 | [diff] [blame] | 51 | if (NOT CMAKE_BUILD_TYPE) |
| 52 | message(STATUS "No build type selected, default to Release") |
| 53 | set(CMAKE_BUILD_TYPE "Release") |
| 54 | endif () |
| 55 | |
| 56 | set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -DMEMIF_DBG -DICMP_DBG") |
| 57 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
| 58 | set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib) |
| 59 | set(CMAKE_INSTALL_MESSAGE NEVER) |
| 60 | |
| 61 | find_package(Threads REQUIRED) |
| 62 | include_directories(${CMAKE_THREADS_INCLUDE_DIRS}) |
| 63 | |
| 64 | check_function_exists(memfd_create HAVE_MEMFD_CREATE) |
| 65 | if(${HAVE_MEMFD_CREATE}) |
| 66 | add_definitions(-DHAVE_MEMFD_CREATE) |
| 67 | endif() |
| 68 | |
| 69 | include_directories(src) |
msardara | 8f554b7 | 2018-12-11 18:36:55 +0100 | [diff] [blame] | 70 | |
msardara | 8f554b7 | 2018-12-11 18:36:55 +0100 | [diff] [blame] | 71 | add_subdirectory(src) |
| 72 | add_subdirectory(examples) |
| 73 | |
Daniel Béreš | 9853342 | 2023-01-19 10:19:27 +0100 | [diff] [blame] | 74 | enable_testing() |
| 75 | include(CTest) |
| 76 | add_subdirectory(test) |
Damjan Marion | 599efc6 | 2020-05-07 16:49:45 +0200 | [diff] [blame] | 77 | ############################################################################## |
| 78 | # Packaging |
| 79 | ############################################################################## |
| 80 | |
| 81 | # parse /etc/os-release |
| 82 | file(READ "/etc/os-release" os_version) |
| 83 | string(REPLACE "\n" ";" os_version ${os_version}) |
| 84 | foreach(_ver ${os_version}) |
| 85 | string(REPLACE "=" ";" _ver ${_ver}) |
| 86 | list(GET _ver 0 _name) |
| 87 | list(GET _ver 1 _value) |
| 88 | set(OS_${_name} ${_value}) |
| 89 | endforeach() |
| 90 | |
| 91 | # extract version from git |
| 92 | execute_process( |
| 93 | COMMAND git describe --long --match v* |
| 94 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
| 95 | OUTPUT_VARIABLE VER |
| 96 | OUTPUT_STRIP_TRAILING_WHITESPACE |
msardara | 8f554b7 | 2018-12-11 18:36:55 +0100 | [diff] [blame] | 97 | ) |
Damjan Marion | 599efc6 | 2020-05-07 16:49:45 +0200 | [diff] [blame] | 98 | string(REGEX REPLACE "v(.*)-([0-9]+)-(g[0-9a-f]+)" "\\1;\\2;\\3" VER ${VER}) |
| 99 | list(GET VER 0 tag) |
| 100 | list(GET VER 1 commit_num) |
| 101 | list(GET VER 2 commit_name) |
| 102 | |
| 103 | #define DEB and RPM version numbers |
| 104 | if(${commit_num} EQUAL 0) |
| 105 | set(deb_ver "${tag}") |
| 106 | set(rpm_ver "${tag}") |
| 107 | else() |
| 108 | if (DEFINED ENV{BUILD_NUMBER}) |
| 109 | set(deb_ver "${tag}~${commit_num}-${commit_name}~b$ENV{BUILD_NUMBER}") |
| 110 | set(rpm_ver "${tag}~${commit_num}_${commit_name}~b$ENV{BUILD_NUMBER}") |
| 111 | else() |
| 112 | set(deb_ver "${tag}~${commit_num}-${commit_name}") |
| 113 | set(rpm_ver "${tag}~${commit_num}_${commit_name}") |
| 114 | endif() |
| 115 | endif() |
| 116 | |
| 117 | set(CPACK_PACKAGE_NAME "memif") |
| 118 | set(CPACK_STRIP_FILES OFF) |
| 119 | set(CPACK_PACKAGE_VENDOR "fd.io") |
| 120 | set(CPACK_COMPONENTS_IGNORE_GROUPS 1) |
| 121 | set(CPACK_${CPACK_GENERATOR}_COMPONENT_INSTALL ON) |
| 122 | set(CPACK_${type}_PACKAGE_DESCRIPTION "memif Shared Memory Interface") |
| 123 | set(CPACK_${type}_PACKAGE_RELEASE 1) |
| 124 | |
| 125 | if(OS_ID_LIKE MATCHES "debian") |
| 126 | set(CPACK_GENERATOR "DEB") |
| 127 | set(type "DEBIAN") |
| 128 | set(CPACK_PACKAGE_VERSION "${deb_ver}") |
| 129 | set(CPACK_DEBIAN_PACKAGE_MAINTAINER "VPP Team") |
| 130 | execute_process( |
| 131 | COMMAND dpkg --print-architecture |
| 132 | OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE |
| 133 | OUTPUT_STRIP_TRAILING_WHITESPACE |
| 134 | ) |
| 135 | set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}) |
| 136 | elseif(OS_ID_LIKE MATCHES "rhel") |
| 137 | set(CPACK_GENERATOR "RPM") |
| 138 | set(type "RPM") |
| 139 | set(CPACK_PACKAGE_VERSION "${rpm_ver}") |
| 140 | execute_process( |
| 141 | COMMAND uname -m |
| 142 | OUTPUT_VARIABLE CPACK_RPM_PACKAGE_ARCHITECTURE |
| 143 | OUTPUT_STRIP_TRAILING_WHITESPACE |
| 144 | ) |
| 145 | set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.${CPACK_RPM_PACKAGE_ARCHITECTURE}) |
| 146 | endif() |
| 147 | |
| 148 | if(CPACK_GENERATOR) |
| 149 | include(CPack) |
| 150 | else() |
| 151 | message(ERROR "CPACK_GENERATOR must be set") |
| 152 | endif() |
| 153 | |