-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathCMakeLists.txt
276 lines (231 loc) · 10.4 KB
/
CMakeLists.txt
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
cmake_minimum_required(VERSION 3.5)
project(p4factory VERSION 9.13.4 LANGUAGES C CXX)
include(CheckCXXCompilerFlag)
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
MESSAGE(STATUS "Enabling ccache")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
FORCE)
endif()
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/install" CACHE PATH "..." FORCE)
endif()
# Add the install prefix as system and lib includes.
include_directories(SYSTEM ${CMAKE_INSTALL_PREFIX}/include)
link_directories(${CMAKE_INSTALL_PREFIX}/lib)
if(SDE_DEPENDENCIES)
if (NOT IS_ABSOLUTE ${SDE_DEPENDENCIES})
message(FATAL_ERROR "SDE_DEPENDENCIES should be an absolute path")
endif ()
set(CMAKE_FIND_ROOT_PATH ${SDE_DEPENDENCIES})
file(RELATIVE_PATH SDE_DEPENDENCIES ${CMAKE_INSTALL_PREFIX} ${SDE_DEPENDENCIES})
else()
set(SDE_DEPENDENCIES ".")
endif()
file(RELATIVE_PATH SDE ${CMAKE_INSTALL_PREFIX} ${CMAKE_CURRENT_SOURCE_DIR})
file(WRITE "${CMAKE_INSTALL_PREFIX}/share/environment" "SDE_DEPENDENCIES=${SDE_DEPENDENCIES}\n")
file(APPEND "${CMAKE_INSTALL_PREFIX}/share/environment" "SDE=${SDE}\n")
install(FILES "${CMAKE_CURRENT_LIST_DIR}/cmake/activate" DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
set(BF_PKG_DIR "pkgsrc")
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_PREFIX_PATH "${CMAKE_INSTALL_PREFIX}")
# p4 specific options
option(TOFINO "Architecture: Build P4 for tofino" OFF)
option(TOFINO2 "Architecture: Build P4 for tofino2" OFF)
option(TOFINO2M "Architecture: Build P4 for tofino2m" OFF)
# thrift settings
option(THRIFT-DRIVER "Drivers: Build with support for Thrift in bf-drivers and bf-platforms" ON)
option(THRIFT-DIAGS "BF-Diags: Build with support for Thrift in bf-diags" ON)
option(THRIFT-SWITCH "Switch: Build with support for Thrift in switch-p4-16" ON)
# driver options
option(GRPC "Drivers: Build with support for GRPC/protobuf" ON)
option(BFRT "Drivers: Build with BFRuntime support" ON)
option(BFRT-GENERIC-FLAGS "Drivers: Build BF-RT C API with generic flags support" ON)
option(PI "Drivers: Build with tofino PI backend support" OFF)
option(P4RT "Drivers: Build with P4Runtime server in bf_switchd support" OFF)
option(PER-PIPE-TBL-LOCK "Drivers: Build API with per pipe table lock enable" ON)
option(TDI "Drivers: Build with TDI support" OFF)
option(KERNEL-MODULES "Drivers: Build kernel modules" OFF)
option(SWITCH "Switch: Build switch-p4-16 package" OFF)
option(SAI "Switch: Build switch-p4-16 SAI implementation" ON)
option(BF-DIAGS "BF-Diags: Build bf-diags package" OFF)
# tools
option(COVERAGE "Build with gcov support" OFF)
option(TCMALLOC "Build with gperftools" ON)
option(PROFILER "Build with CPU profiler" OFF)
option(ASAN "Build with ASAN" OFF)
option(LTO "Build with LinkTimeOptimization" OFF)
option(FORCE32 "Force a 32bit compile on 64bit" OFF)
option(BF-PYTHON "Build and enable bf-python CLI" OFF)
# global
option(ASIC "Build for ASIC" OFF)
option(CPUVETH "Use CPU eth port, applicable for model" ON)
# bf-platform specific
option(BSP "BF-Platforms: Build with Intel reference platform code" OFF)
option(TCLONLY "BF-Platforms: Build only tcl server in bf-platforms" OFF)
option(NEWPORT "BF-Platforms: Build Newport Platform" OFF)
option(ACCTON-TF3 "BF-Platforms: Build Accton Tofino3 Platform" OFF)
option(ACCTON-DIAGS "BF-Platforms: Build Accton Diags" OFF)
option(NEWPORT-DIAGS "BF-Platforms: Build Newport Diags" OFF)
# uncommon
option(TARGETSYS-DEBUG-MODE "Build target-syslibs in debug mode" OFF)
# Note 1: This option adds to p4flags "--p4runtime-files <p4_name>/<target>/<p4_name>.p4info.pb.txt --p4runtime-force-std-externs"
# Note 2: This option will install a compiler generated *p4info.pb.txt to install/share/<target>pd/<p4_name>
option(WITH-P4INFO "Generate P4Runtime compatible p4info file" OFF)
include(ConfigureChecks)
include(PythonDependencies)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
if (THRIFT-DRIVER OR THRIFT-SWITCH OR THRIFT-DIAGS)
find_package(Thrift REQUIRED)
if ( THRIFT_VERSION_STRING VERSION_LESS 0.14.0 )
message(STATUS "\nThrift version (found ${THRIFT_VERSION_STRING}) is less than 0.14.0. Please update to avoid a known CVE in Thrift")
endif()
endif()
#ptf-utils and bf-pktpy
set(PTF_PKG_DIR "ptf-modules")
add_subdirectory(${BF_PKG_DIR}/${PTF_PKG_DIR}/ptf-utils)
set(PYTHON_SITE ${SDE_PYTHON_DEPENDENCIES_DIR})
install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/${BF_PKG_DIR}/${PTF_PKG_DIR}/ptf/ptf DESTINATION bin)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${BF_PKG_DIR}/${PTF_PKG_DIR}/ptf/src/ DESTINATION ${SDE_PYTHON_DEPENDENCIES_DIR})
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${BF_PKG_DIR}/${PTF_PKG_DIR}/bf-pktpy/bf_pktpy DESTINATION ${SDE_PYTHON_DEPENDENCIES_DIR})
if(NOT EXTRA_CPPFLAGS)
set(EXTRA_CPPFLAGS "" CACHE STRING "" FORCE)
else()
message(STATUS "\nEXTRA_CPPFLAGS: ${EXTRA_CPPFLAGS}")
endif()
set(C_CXX_FLAGS "-Wall -Wextra -Wno-shadow -Wno-missing-field-initializers -DBF_SYS_LOG_FORMAT_CHECK ${EXTRA_CPPFLAGS}")
CHECK_CXX_COMPILER_FLAG(-Wmisleading-indentation COMPILER_SUPPORTS_MISLEADING_INDENTATION)
if (COMPILER_SUPPORTS_MISLEADING_INDENTATION)
set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wno-misleading-indentation")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${C_CXX_FLAGS}")
# if lto is ready, build lto for all targets after this configruation
if(LTO)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -flto=thin -fno-fat-lto-objects")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto=thin -fno-fat-lto-objects")
endif()
if(COVERAGE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
endif()
if(FORCE32)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
endif()
if(CMAKE_COMPILER_IS_GNUCC AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0.0))
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error")
endif()
if(ASAN)
SET(TCMALLOC OFF CACHE BOOL "Use malloc from LIBC for ASAN" FORCE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-recover=address -fsanitize=leak")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-recover=address -fsanitize=leak")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address -fsanitize-recover=address -fsanitize=leak")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fsanitize=address -fsanitize-recover=address -fsanitize=leak")
endif()
if(NEWPORT)
SET(TOFINO OFF CACHE BOOL "Do not build Tofino platform for Newport" FORCE)
SET(TOFINO3 OFF CACHE BOOL "Do not build Tofino3 platform for Newport" FORCE)
if(NOT TOFINO2M)
SET(TOFINO2 ON CACHE BOOL "Build for Tofino2 ASIC" FORCE)
endif()
endif()
if(ACCTON-TF3)
SET(TOFINO OFF CACHE BOOL "Do not build Tofino platform for Tofino3" FORCE)
SET(TOFINO2 OFF CACHE BOOL "Do not build Tofino2 platform for Tofino3" FORCE)
SET(TOFINO2M OFF CACHE BOOL "Do not build Tofino2m platform for Tofino3" FORCE)
SET(TOFINO3 ON CACHE BOOL "Build for Tofino3 ASIC" FORCE)
endif()
if (NOT TOFINO AND NOT TOFINO2 AND NOT TOFINO2M AND NOT TOFINO3)
set(TOFINO ON CACHE BOOL "Enable Tofino as default" FORCE)
message(STATUS "\nTarget option missing. Using TOFINO\n")
endif()
if(ASIC)
SET(CPUVETH OFF CACHE BOOL "CPUVETH is disabled for ASIC" FORCE)
set(KERNEL-MODULES ON CACHE BOOL "Build kernel modules while using ASIC" FORCE)
endif()
if(TDI)
SET(BFRT ON CACHE BOOL "BFRT is enabled for TDI" FORCE)
endif()
if (P4RT)
set(PI ON CACHE BOOL "PI is enabled if P4RT is on" FORCE)
set(GRPC ON CACHE BOOL "GRPC is enabled if P4RT is on" FORCE)
endif()
if (BF-PYTHON)
set(CPYTHON ON CACHE BOOL "target-utils cpython option is required if BF_PYTHON is on" FORCE)
else()
set(CPYTHON OFF CACHE BOOL "target-utils cpython option should be off if BF_PYTHON is off" FORCE)
endif()
if (TARGETSYS-DEBUG-MODE)
add_definitions(-DTARGET_SYS_LIBS_DEBUG_MODE)
endif()
if (STATIC-LINK-LIB)
add_definitions(-DSTATIC_LINK_LIB)
endif()
# p4flags will be appended to internal compiler options
if(NOT P4FLAGS)
set(P4FLAGS "" CACHE STRING "" FORCE)
else()
message(STATUS "\nP4FLAGS: ${P4FLAGS}")
endif()
# p4ppflags will be appended to internal compiler options
if(NOT P4PPFLAGS)
set(P4PPFLAGS "" CACHE STRING "" FORCE)
else()
message(STATUS "\nP4PPFLAGS: ${P4PPFLAGS}")
endif()
include_directories(${BF_PKG_DIR})
#sys
message(STATUS "\nBegin target-syslibs setup")
include_directories(${BF_PKG_DIR}/target-syslibs/include)
add_subdirectory(${BF_PKG_DIR}/target-syslibs)
# bf-utils
message(STATUS "\nBegin bf-utils setup")
include_directories(${BF_PKG_DIR}/bf-utils/include)
add_subdirectory(${BF_PKG_DIR}/bf-utils)
#target-utils
message(STATUS "\nBegin target-utils setup")
include_directories(${BF_PKG_DIR}/target-utils/third-party/bigcode/include)
include_directories(${BF_PKG_DIR}/target-utils/third-party/klish)
include_directories(${BF_PKG_DIR}/target-utils/include)
add_subdirectory(${BF_PKG_DIR}/target-utils)
#drivers
message(STATUS "\nBegin bf-drivers setup")
include_directories(${BF_PKG_DIR}/bf-drivers)
include_directories(${BF_PKG_DIR}/bf-drivers/include)
add_subdirectory(${BF_PKG_DIR}/bf-drivers)
#compiler/model
include(FindP4CModel)
add_subdirectory(${BF_PKG_DIR}/p4-compilers)
if(ASIC AND BSP)
#platform
message(STATUS "\nBegin bf-platforms setup")
include_directories(${BF_PKG_DIR}/bf-diags/api/include)
add_subdirectory(${BF_PKG_DIR}/bf-platforms)
endif()
#diags
if(BF-DIAGS)
message(STATUS "\nBegin bf-diags setup")
add_subdirectory(${BF_PKG_DIR}/bf-diags)
endif()
#switch
if(SWITCH)
message(STATUS "\nBegin switch-p4-16 setup")
add_subdirectory(${BF_PKG_DIR}/switch-p4-16)
endif()
#p4-examples
message(STATUS "\nBegin p4-examples setup")
add_subdirectory(${BF_PKG_DIR}/p4-examples)
file(WRITE ${CMAKE_INSTALL_PREFIX}/share/VERSION ${PROJECT_VERSION})