blob: 790d6a204777a36f5977dae32ed7cc08da6acb5a (
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
# Copyright (c) 2018 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.5 FATAL_ERROR)
project(vpp C)
include(CheckCCompilerFlag)
##############################################################################
# Highlight WARNING and ERROR messages
##############################################################################
function(message)
list(GET ARGV 0 type)
string(ASCII 27 esc)
set(red "${esc}[1;31m")
set(yellow "${esc}[1;33m")
set(reset "${esc}[m")
if(type STREQUAL FATAL_ERROR OR type STREQUAL SEND_ERROR)
list(REMOVE_AT ARGV 0)
_message(${type} "${red}${ARGV}${reset}")
elseif(type STREQUAL WARNING)
list(REMOVE_AT ARGV 0)
_message(STATUS "${yellow}${ARGV}${reset}")
elseif(type STREQUAL STATUS)
list(REMOVE_AT ARGV 0)
_message(STATUS "${ARGV}")
else()
_message(${ARGV})
endif()
endfunction()
##############################################################################
# CPU optimizations and multiarch support
##############################################################################
if(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*")
set(CMAKE_C_FLAGS "-march=corei7 -mtune=corei7-avx ${CMAKE_C_FLAGS}")
check_c_compiler_flag("-march=core-avx2" AVX2)
if(AVX2)
list(APPEND MARCH_VARIANTS "avx2\;-march=core-avx2 -mtune=core-avx2")
endif()
check_c_compiler_flag("-march=skylake-avx512" AVX512)
if(AVX512)
list(APPEND MARCH_VARIANTS "avx512\;-march=skylake-avx512 -mtune=skylake-avx512")
endif()
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*)")
set(CMAKE_C_FLAGS "-march=armv8-a+crc ${CMAKE_C_FLAGS}")
endif()
macro(vpp_library_set_multiarch_sources lib)
foreach(V ${MARCH_VARIANTS})
list(GET V 0 VARIANT)
list(GET V 1 VARIANT_FLAGS)
set(l ${lib}_${VARIANT})
add_library(${l} OBJECT ${ARGN})
set_target_properties(${l} PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_compile_options(${l} PUBLIC "-DCLIB_MARCH_VARIANT=${VARIANT}")
separate_arguments(VARIANT_FLAGS)
target_compile_options(${l} PUBLIC ${VARIANT_FLAGS})
target_sources(${lib} PRIVATE $<TARGET_OBJECTS:${l}>)
endforeach()
endmacro()
##############################################################################
# build config
##############################################################################
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_C_FLAGS_COMMON "-DFORTIFY_SOURCE=2 -fstack-protector-all -Werror")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${CMAKE_C_FLAGS_COMMON} -DCLIB_DEBUG")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${CMAKE_C_FLAGS_COMMON}")
##############################################################################
# ccache
##############################################################################
option(VPP_USE_CCACHE "Use ccache compiler cache." ON)
if(VPP_USE_CCACHE)
find_program(CCACHE_FOUND ccache)
message(STATUS "Looking for ccache")
if(CCACHE_FOUND)
message(STATUS "Looking for ccache - found")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
else(CCACHE_FOUND)
message(STATUS "Looking for ccache - not found")
endif(CCACHE_FOUND)
endif(VPP_USE_CCACHE)
##############################################################################
# install config
##############################################################################
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_INSTALL_MESSAGE NEVER)
message(STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")
message(STATUS "We are on a ${CMAKE_SYSTEM_NAME} system")
message(STATUS "The host processor is ${CMAKE_HOST_SYSTEM_PROCESSOR}")
include_directories (
${CMAKE_SOURCE_DIR}
${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}/include
)
set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "vpp")
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
find_package(OpenSSL REQUIRED)
include_directories(${OPENSSL_INCLUDE_DIR})
add_definitions(-DHAVE_MEMFD_CREATE -DVPP_API_TEST_BUILTIN=1)
##############################################################################
# API
##############################################################################
function(vpp_generate_api_header file)
set (output_name ${CMAKE_CURRENT_BINARY_DIR}/${file}.h)
get_filename_component(output_dir ${output_name} DIRECTORY)
add_custom_command (OUTPUT ${output_name}
COMMAND mkdir -p ${output_dir}
COMMAND ${CMAKE_SOURCE_DIR}/tools/vppapigen/vppapigen
ARGS --includedir ${CMAKE_SOURCE_DIR} --input ${CMAKE_CURRENT_SOURCE_DIR}/${file} --output ${output_name}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file}
COMMENT "Generating API header ${file}.h"
)
endfunction()
function(vpp_add_api_files target)
unset(header_files)
foreach(file ${ARGN})
vpp_generate_api_header (${file})
list (APPEND header_files ${file}.h)
endforeach()
add_custom_target(${target} DEPENDS ${header_files})
endfunction()
add_custom_target(api_headers
DEPENDS vlibmemory_api_headers vnet_api_headers vpp_api_headers
)
##############################################################################
# header files
##############################################################################
function (vpp_add_header_files path)
foreach(file ${ARGN})
get_filename_component(dir ${file} DIRECTORY)
install(FILES ${file} DESTINATION include/${path}/${dir})
endforeach()
endfunction()
##############################################################################
# subdirs
##############################################################################
foreach (DIR vppinfra svm vlib vlibmemory vnet vpp vpp-api vcl plugins)
add_subdirectory(${DIR})
endforeach ()
##############################################################################
# DEB Packaging
##############################################################################
set(CPACK_GENERATOR "DEB")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "VPP Team")
set(CPACK_PACKAGE_NAME "vpp")
set(CPACK_PACKAGE_VENDOR "fd.io")
set(CPACK_PACKAGE_VERSION "18.08")
set(CPACK_DEB_COMPONENT_INSTALL ON)
set(CPACK_COMPONENTS_IGNORE_GROUPS 1)
set(CPACK_DEBIAN_VPP_PACKAGE_NAME "vpp")
set(CPACK_DEBIAN_VPP_FILE_NAME "vpp.deb")
set(CPACK_DEBIAN_DEV_PACKAGE_NAME "vpp-dev")
set(CPACK_DEBIAN_DEV_FILE_NAME "vpp-dev.deb")
set(CPACK_DEBIAN_PLUGINS_PACKAGE_NAME "vpp-plugins")
set(CPACK_DEBIAN_PLUGINS_FILE_NAME "vpp-plugins.deb")
include(CPack)
|