blob: 7f4915b5d707493de9e61c66519239b7431bbc25 [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
42set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
43find_package(Check 0.10.0)
44if (CHECK_FOUND)
45 include_directories(${CHECK_INCLUDE_DIR})
46 add_definitions(-DMEMIF_UNIT_TEST)
47 add_subdirectory(test)
48 enable_testing()
49endif ()
50
51add_subdirectory(src)
52add_subdirectory(examples)
53
Damjan Marion599efc62020-05-07 16:49:45 +020054##############################################################################
55# Packaging
56##############################################################################
57
58# parse /etc/os-release
59file(READ "/etc/os-release" os_version)
60string(REPLACE "\n" ";" os_version ${os_version})
61foreach(_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})
66endforeach()
67
68 # extract version from git
69execute_process(
70 COMMAND git describe --long --match v*
71 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
72 OUTPUT_VARIABLE VER
73 OUTPUT_STRIP_TRAILING_WHITESPACE
msardara8f554b72018-12-11 18:36:55 +010074)
Damjan Marion599efc62020-05-07 16:49:45 +020075string(REGEX REPLACE "v(.*)-([0-9]+)-(g[0-9a-f]+)" "\\1;\\2;\\3" VER ${VER})
76list(GET VER 0 tag)
77list(GET VER 1 commit_num)
78list(GET VER 2 commit_name)
79
80#define DEB and RPM version numbers
81if(${commit_num} EQUAL 0)
82 set(deb_ver "${tag}")
83 set(rpm_ver "${tag}")
84else()
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()
92endif()
93
94set(CPACK_PACKAGE_NAME "memif")
95set(CPACK_STRIP_FILES OFF)
96set(CPACK_PACKAGE_VENDOR "fd.io")
97set(CPACK_COMPONENTS_IGNORE_GROUPS 1)
98set(CPACK_${CPACK_GENERATOR}_COMPONENT_INSTALL ON)
99set(CPACK_${type}_PACKAGE_DESCRIPTION "memif Shared Memory Interface")
100set(CPACK_${type}_PACKAGE_RELEASE 1)
101
102if(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})
113elseif(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})
123endif()
124
125if(CPACK_GENERATOR)
126 include(CPack)
127else()
128 message(ERROR "CPACK_GENERATOR must be set")
129endif()
130