summaryrefslogtreecommitdiffstats
path: root/cicn-plugin/CMakeLists.txt
blob: 90a555752e421b4c175fd46ccc556a314fe3bab4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# Copyright (c) 2017 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.2)
project(cicn-plugin)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")

# Dependencies

find_package(Vpp REQUIRED)
find_package(VppDpdk REQUIRED)

set(CICN_PLUGIN_SOURCE_FILES
    cicn/cicn.c
    cicn/cicn_face.c
    cicn/cicn_fib.c
    cicn/cicn_hashtb.c
    cicn/cicn_hello.c
    cicn/cicn_mgmt.c
    cicn/cicn_parser.c
    cicn/cicn_pcs.c
    cicn/cicn_pg.c
    cicn/node.c)

set(CICN_PLUGIN_HEADER_FILES
    cicn/cicn_all_api_h.h
    cicn/cicn_api_handler.h
    cicn/cicn_fib.h
    cicn/cicn_hashtb.h
    cicn/cicn_hello_inlines.h
    cicn/cicn_mgmt.h
    cicn/cicn_params.h
    cicn/cicn_pcs.h
    cicn/cicn_rte_mbuf_inlines.h
    cicn/cicn_std.h
    cicn/cicn_api.h
    cicn/cicn_face.h
    cicn/cicn.h
    cicn/cicn_hello.h
    cicn/cicn_infra.h
    cicn/cicn_msg_enum.h
    cicn/cicn_parser.h
    cicn/cicn_rte_mbuf.h
    cicn/cicn_siphash.h
    cicn/cicn_types.h)

if(NOT NO_UNIT_TEST)
    list(APPEND CICN_PLUGIN_SOURCE_FILES
            cicn/test/test_cicn.c
            cicn/test/test_cicn_hash.c
            cicn/test/test_cicn_hash_cdata.c)
    list(APPEND CICN_PLUGIN_HEADER_FILES
            cicn/test/test_cicn.h
            cicn/test/test_cicn_hash.h)
endif(NOT NO_UNIT_TEST)

set(CICN_API_TEST_SOURCE_FILES
        cicn/cicn_api_test.c)

set(CICN_API_TEST_HEADER_FILES
        cicn/cicn_api.h)

execute_process(COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/cicn)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/cicn/cicn.api.h
        COMMAND
        $ENV{CC} $ENV{CPPFLAGS} -E -P -x c-header ${CMAKE_CURRENT_SOURCE_DIR}/cicn/cicn.api |
        vppapigen --input - --output ${CMAKE_CURRENT_BINARY_DIR}/cicn/cicn.api.h
        --show-name ${CMAKE_CURRENT_BINARY_DIR}/cicn/cicn.api.h
        DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/cicn/cicn.api)

include_directories(SYSTEM)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(./)
include_directories(cicn/test)
include_directories(${VPP_DPDK_INCLUDE_DIRS})

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -march=native -O3")
add_library(cicn_api_test_plugin SHARED
        ${CICN_API_TEST_SOURCE_FILES}
        ${CICN_API_TEST_HEADER_FILES}
        ${CMAKE_CURRENT_BINARY_DIR}/cicn/cicn.api.h)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DDPDK=1 -DCICN_VPP_PLUGIN=1")
add_library(cicn_plugin SHARED
        ${CICN_PLUGIN_SOURCE_FILES}
        ${CICN_PLUGIN_HEADER_FILES}
        ${CMAKE_CURRENT_BINARY_DIR}/cicn/cicn.api.h)

set_target_properties(cicn_plugin
        PROPERTIES
        LINKER_LANGUAGE C)
set_target_properties(cicn_api_test_plugin
        PROPERTIES
        LINKER_LANGUAGE C)

target_link_libraries(cicn_plugin)
target_link_libraries(cicn_api_test_plugin)

set(VPP_INSTALL_PLUGIN ${CMAKE_INSTALL_PREFIX}/lib/vpp_plugins)
set(VPP_INSTALL_API_TEST_PLUGIN ${CMAKE_INSTALL_PREFIX}/lib/vpp_api_test_plugins)

install(DIRECTORY DESTINATION ${VPP_INSTALL_PLUGIN})
install(TARGETS cicn_plugin
        DESTINATION
        ${VPP_INSTALL_PLUGIN})

install(DIRECTORY DESTINATION ${VPP_INSTALL_API_TEST_PLUGIN})
install(TARGETS cicn_api_test_plugin
        DESTINATION
        ${VPP_INSTALL_API_TEST_PLUGIN})

# Generate DEB / RPM packages

option(DEB_PACKAGE "Create deb package" OFF)
option(RPM_PACKAGE "Create deb package" OFF)

SET(VENDOR "Cisco Systems" CACHE STRING "Vendor")
SET(CONTACT "msardara@cisco.com" CACHE STRING "Contact")
SET(DISTRIBUTION "xenial" CACHE STRING "Distribution")
SET(ARCHITECTURE "amd64" CACHE STRING "Architecture")
SET(PACKAGE_MAINTAINER "Mauro Sardara (msardara@cisco.com)" CACHE STRING "Maintainer")
SET(BUILD_NUMBER "1" CACHE STRING "Build Number")
STRING(TOLOWER ${CMAKE_PROJECT_NAME} PACKAGE_NAME)

SET(CPACK_PACKAGING_INSTALL_PREFIX "/usr")
SET(CPACK_PACKAGE_VENDOR ${VENDOR})
SET(CPACK_PACKAGE_CONTACT ${CONTACT})

# Get the version
execute_process(COMMAND bash ${CMAKE_SOURCE_DIR}/scripts/version
                OUTPUT_VARIABLE PACKAGE_VERSION)
string(STRIP ${PACKAGE_VERSION} PACKAGE_VERSION)

if (DEB_PACKAGE)
    SET(TYPE "DEBIAN")
    SET(GENERATOR "DEB")
    SET(CPACK_PACKAGE_FILE_NAME "${PACKAGE_NAME}_${PACKAGE_VERSION}_${ARCHITECTURE}")
    SET(CPACK_${TYPE}_PACKAGE_DEPENDS "vpp (= 17.01), vpp-lib (= 17.01), vpp-dpdk-dkms (= 17.01)")
elseif (RPM_PACKAGE)
    SET(TYPE "RPM")
    SET(GENERATOR "RPM")
    SET(CPACK_PACKAGE_FILE_NAME "${PACKAGE_NAME}-${PACKAGE_VERSION}.${ARCHITECTURE}")
    SET(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/usr/etc" "/usr/lib/python2.7" "/usr/lib/python2.7/site-packages")
    SET(CPACK_${TYPE}_PACKAGE_REQUIRES "vpp = 17.01, vpp-dpdk-devel = 17.01")
else ()
    RETURN()
endif ()

SET(CPACK_GENERATOR ${GENERATOR})
SET(CPACK_${TYPE}_PACKAGE_MAINTAINER ${PACKAGE_MAINTAINER})
SET(CPACK_${TYPE}_PACKAGE_NAME ${PACKAGE_NAME})
SET(CPACK_${TYPE}_PACKAGE_VERSION ${PACKAGE_VERSION})
SET(CPACK_${TYPE}_PACKAGE_ARCHITECTURE ${ARCHITECTURE})
SET(CPACK_${TYPE}_PACKAGE_RELEASE 1)
SET(CPACK_${TYPE}_PACKAGE_VENDOR ${VENDOR})
SET(CPACK_${TYPE}_PACKAGE_DESCRIPTION "High-performance CCNx ICN forwarder as a plugin to VPP.")
SET(CPACK_${TYPE}_PACKAGE_HOMEPAGE "https://wiki.fd.io/view/Cicn-plugin")

INCLUDE(CPack)