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 | |
Mohsin Kazmi | c60266d | 2024-01-17 12:00:16 +0000 | [diff] [blame] | 64 | if(DEFINED LIBMEMIF_CACHELINE_SIZE) |
| 65 | # Cache line size assigned via cmake args |
| 66 | elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*)") |
| 67 | set(LIBMEMIF_CACHELINE_SIZE 128) |
| 68 | else() |
| 69 | set(LIBMEMIF_CACHELINE_SIZE 64) |
| 70 | endif() |
| 71 | |
| 72 | message(STATUS "System Architecture: ${CMAKE_SYSTEM_PROCESSOR}") |
| 73 | message(STATUS "Libmemif Cacheline Size: ${LIBMEMIF_CACHELINE_SIZE}") |
| 74 | |
msardara | 8f554b7 | 2018-12-11 18:36:55 +0100 | [diff] [blame] | 75 | check_function_exists(memfd_create HAVE_MEMFD_CREATE) |
| 76 | if(${HAVE_MEMFD_CREATE}) |
| 77 | add_definitions(-DHAVE_MEMFD_CREATE) |
| 78 | endif() |
| 79 | |
| 80 | include_directories(src) |
msardara | 8f554b7 | 2018-12-11 18:36:55 +0100 | [diff] [blame] | 81 | |
msardara | 8f554b7 | 2018-12-11 18:36:55 +0100 | [diff] [blame] | 82 | add_subdirectory(src) |
| 83 | add_subdirectory(examples) |
| 84 | |
Daniel Béreš | 9853342 | 2023-01-19 10:19:27 +0100 | [diff] [blame] | 85 | enable_testing() |
| 86 | include(CTest) |
| 87 | add_subdirectory(test) |
Damjan Marion | 599efc6 | 2020-05-07 16:49:45 +0200 | [diff] [blame] | 88 | ############################################################################## |
| 89 | # Packaging |
| 90 | ############################################################################## |
| 91 | |
| 92 | # parse /etc/os-release |
| 93 | file(READ "/etc/os-release" os_version) |
| 94 | string(REPLACE "\n" ";" os_version ${os_version}) |
| 95 | foreach(_ver ${os_version}) |
| 96 | string(REPLACE "=" ";" _ver ${_ver}) |
| 97 | list(GET _ver 0 _name) |
| 98 | list(GET _ver 1 _value) |
| 99 | set(OS_${_name} ${_value}) |
| 100 | endforeach() |
| 101 | |
| 102 | # extract version from git |
| 103 | execute_process( |
| 104 | COMMAND git describe --long --match v* |
| 105 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
| 106 | OUTPUT_VARIABLE VER |
| 107 | OUTPUT_STRIP_TRAILING_WHITESPACE |
msardara | 8f554b7 | 2018-12-11 18:36:55 +0100 | [diff] [blame] | 108 | ) |
Damjan Marion | 599efc6 | 2020-05-07 16:49:45 +0200 | [diff] [blame] | 109 | string(REGEX REPLACE "v(.*)-([0-9]+)-(g[0-9a-f]+)" "\\1;\\2;\\3" VER ${VER}) |
| 110 | list(GET VER 0 tag) |
| 111 | list(GET VER 1 commit_num) |
| 112 | list(GET VER 2 commit_name) |
| 113 | |
| 114 | #define DEB and RPM version numbers |
| 115 | if(${commit_num} EQUAL 0) |
| 116 | set(deb_ver "${tag}") |
| 117 | set(rpm_ver "${tag}") |
| 118 | else() |
| 119 | if (DEFINED ENV{BUILD_NUMBER}) |
| 120 | set(deb_ver "${tag}~${commit_num}-${commit_name}~b$ENV{BUILD_NUMBER}") |
| 121 | set(rpm_ver "${tag}~${commit_num}_${commit_name}~b$ENV{BUILD_NUMBER}") |
| 122 | else() |
| 123 | set(deb_ver "${tag}~${commit_num}-${commit_name}") |
| 124 | set(rpm_ver "${tag}~${commit_num}_${commit_name}") |
| 125 | endif() |
| 126 | endif() |
| 127 | |
| 128 | set(CPACK_PACKAGE_NAME "memif") |
| 129 | set(CPACK_STRIP_FILES OFF) |
| 130 | set(CPACK_PACKAGE_VENDOR "fd.io") |
| 131 | set(CPACK_COMPONENTS_IGNORE_GROUPS 1) |
| 132 | set(CPACK_${CPACK_GENERATOR}_COMPONENT_INSTALL ON) |
| 133 | set(CPACK_${type}_PACKAGE_DESCRIPTION "memif Shared Memory Interface") |
| 134 | set(CPACK_${type}_PACKAGE_RELEASE 1) |
| 135 | |
| 136 | if(OS_ID_LIKE MATCHES "debian") |
| 137 | set(CPACK_GENERATOR "DEB") |
| 138 | set(type "DEBIAN") |
| 139 | set(CPACK_PACKAGE_VERSION "${deb_ver}") |
| 140 | set(CPACK_DEBIAN_PACKAGE_MAINTAINER "VPP Team") |
| 141 | execute_process( |
| 142 | COMMAND dpkg --print-architecture |
| 143 | OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE |
| 144 | OUTPUT_STRIP_TRAILING_WHITESPACE |
| 145 | ) |
| 146 | set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}) |
| 147 | elseif(OS_ID_LIKE MATCHES "rhel") |
| 148 | set(CPACK_GENERATOR "RPM") |
| 149 | set(type "RPM") |
| 150 | set(CPACK_PACKAGE_VERSION "${rpm_ver}") |
| 151 | execute_process( |
| 152 | COMMAND uname -m |
| 153 | OUTPUT_VARIABLE CPACK_RPM_PACKAGE_ARCHITECTURE |
| 154 | OUTPUT_STRIP_TRAILING_WHITESPACE |
| 155 | ) |
| 156 | set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.${CPACK_RPM_PACKAGE_ARCHITECTURE}) |
| 157 | endif() |
| 158 | |
| 159 | if(CPACK_GENERATOR) |
| 160 | include(CPack) |
| 161 | else() |
| 162 | message(ERROR "CPACK_GENERATOR must be set") |
| 163 | endif() |
| 164 | |