Added CMake building system for libmemif
[vpp.git] / extras / libmemif / CMakeLists.txt
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
22 set(VPP_SRC "${CMAKE_CURRENT_SOURCE_DIR}/../../src")
23 execute_process(
24   COMMAND find ${VPP_SRC} -type d -name "cmake"
25   OUTPUT_VARIABLE CMAKE_DEPS_FOLDER
26   OUTPUT_STRIP_TRAILING_WHITESPACE
27 )
28 include(${CMAKE_DEPS_FOLDER}/library.cmake)
29 include(${CMAKE_DEPS_FOLDER}/pack.cmake)
30
31 if (NOT CMAKE_BUILD_TYPE)
32   message(STATUS "No build type selected, default to Release")
33   set(CMAKE_BUILD_TYPE "Release")
34 endif ()
35
36 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -DMEMIF_DBG -DICMP_DBG")
37 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
38 set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
39 set(CMAKE_INSTALL_MESSAGE NEVER)
40
41 find_package(Threads REQUIRED)
42 include_directories(${CMAKE_THREADS_INCLUDE_DIRS})
43
44 check_function_exists(memfd_create HAVE_MEMFD_CREATE)
45 if(${HAVE_MEMFD_CREATE})
46   add_definitions(-DHAVE_MEMFD_CREATE)
47 endif()
48
49 include_directories(src)
50 set(LIBMEMIF memif)
51
52 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
53 find_package(Check 0.10.0)
54 if (CHECK_FOUND)
55   include_directories(${CHECK_INCLUDE_DIR})
56   add_definitions(-DMEMIF_UNIT_TEST)
57   add_subdirectory(test)
58   enable_testing()
59 endif ()
60
61 add_subdirectory(src)
62 add_subdirectory(examples)
63
64 add_vpp_packaging(
65   NAME "memif"
66   VENDOR "fd.io"
67   DESCRIPTION "Shared Memory Interface"
68 )