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