Debian Codegraph @

CMakeLists.txt

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 # SPDX-License-Identifier: BSD-2-Clause
2 #
3 # Copyright (C) 2020-2025 Linutronix GmbH
4 # Author Kurt Kanzenbach <[email protected]>
5 #
6
7 cmake_minimum_required(VERSION 3.10)
8 project(rtc-testbench)
9
10 set(VERSION "5.4")
11
12 include(CheckIncludeFiles)
13 include(CheckFunctionExists)
14 include(CheckSymbolExists)
15 include(GNUInstallDirs)
16
17 find_package(PkgConfig REQUIRED)
18
19 set(THREADS_PREFER_PTHREAD_FLAG ON)
20 find_package(Threads REQUIRED)
21
22 pkg_search_module(YAML yaml-0.1 REQUIRED)
23 pkg_search_module(LIBBPF libbpf REQUIRED)
24 pkg_search_module(LIBXDP libxdp REQUIRED)
25 pkg_search_module(LIBCRYPTO libcrypto>=3.0 REQUIRED)
26
27 check_symbol_exists(SO_BUSY_POLL "sys/socket.h" HAVE_SO_BUSY_POLL)
28 check_symbol_exists(SO_PREFER_BUSY_POLL "sys/socket.h" HAVE_SO_PREFER_BUSY_POLL)
29 check_symbol_exists(SO_BUSY_POLL_BUDGET "sys/socket.h" HAVE_SO_BUSY_POLL_BUDGET)
30 check_symbol_exists(XDP_TXMD_FLAGS_LAUNCH_TIME "linux/if_xdp.h" HAVE_XDP_FLAGS_TX_TIME)
31 check_symbol_exists(XDP_TXMD_FLAGS_TIMESTAMP "linux/if_xdp.h" HAVE_XDP_FLAGS_TX_HWTSTAMP)
32
33 add_executable(reference
34 src/reference.c
35 src/config.c
36 src/utils.c
37 src/log.c
38 src/log_mqtt.c
39 src/log_json.c
40 src/stat.c
41 src/ring_buffer.c
42 src/thread.c
43 src/tsn_thread.c
44 src/rtc_thread.c
45 src/rta_thread.c
46 src/dcp_thread.c
47 src/lldp_thread.c
48 src/udp_thread.c
49 src/layer2_thread.c
50 src/net.c
51 src/xdp.c
52 src/tx_time.c
53 src/security.c
54 src/packet.c
55 src/hist.c
56 src/workload.c
57 src/print.c)
58 add_executable(mirror
59 src/mirror.c
60 src/config.c
61 src/utils.c
62 src/log.c
63 src/log_mqtt.c
64 src/log_json.c
65 src/stat.c
66 src/ring_buffer.c
67 src/thread.c
68 src/tsn_thread.c
69 src/rtc_thread.c
70 src/rta_thread.c
71 src/dcp_thread.c
72 src/lldp_thread.c
73 src/udp_thread.c
74 src/layer2_thread.c
75 src/net.c
76 src/xdp.c
77 src/tx_time.c
78 src/security.c
79 src/packet.c
80 src/hist.c
81 src/workload.c
82 src/print.c)
83
84 option(WITH_MQTT, "Enable/Disable logging via MQTT" OFF)
85 if (WITH_MQTT)
86 pkg_search_module(MOSQUITTO libmosquitto REQUIRED)
87 target_link_libraries(reference ${MOSQUITTO_LIBRARIES})
88 target_link_libraries(mirror ${MOSQUITTO_LIBRARIES})
89 target_include_directories(reference PUBLIC ${MOSQUITTO_INCLUDE_DIRS})
90 target_include_directories(mirror PUBLIC ${MOSQUITTO_INCLUDE_DIRS})
91 endif()
92
93 option(RX_TIMESTAMP "Enable RX timestamp support (requires libbpf >= 1.2)" OFF)
94 option(TX_TIMESTAMP "Enable TX timestamp support (requires libxdp >= 1.4.1)" OFF)
95
96 if(RX_TIMESTAMP)
97 pkg_check_modules(LIBBPF_REQUIRED_FOR_RX_TIMESTAMP libbpf>=1.2)
98 if(NOT LIBBPF_REQUIRED_FOR_RX_TIMESTAMP_FOUND)
99 message(FATAL_ERROR "RX_TIMESTAMP requires libbpf >= 1.2, but version ${LIBBPF_VERSION} was found.")
100 endif()
101 endif()
102
103 if(TX_TIMESTAMP)
104 if(NOT ((${LIBXDP_VERSION} GREATER_EQUAL 1.4.1) AND (${HAVE_XDP_FLAGS_TX_HWTSTAMP})))
105 message(FATAL_ERROR "TX_TIMESTAMP requires libxdp >= 1.4.1 and kernel support for XDP_TXMD_FLAGS_TIMESTAMP")
106 endif()
107 endif()
108
109 target_compile_options(reference PRIVATE -Wall -Wshadow -std=gnu99 -Wvla)
110 target_compile_options(mirror PRIVATE -Wall -Wshadow -std=gnu99 -Wvla)
111
112 target_compile_definitions(reference PRIVATE -D_GNU_SOURCE)
113 target_compile_definitions(mirror PRIVATE -D_GNU_SOURCE)
114
115 option(WITH_ASAN, "Build with AddressSanitizer for debugging" OFF)
116 if (WITH_ASAN)
117 target_compile_options(reference PRIVATE -fsanitize=address)
118 target_compile_options(mirror PRIVATE -fsanitize=address)
119
120 target_link_options(reference PRIVATE -fsanitize=address)
121 target_link_options(mirror PRIVATE -fsanitize=address)
122 endif()
123
124 # Export symbols for dynamically loaded workloads
125 target_link_options(mirror PRIVATE -Wl,--export-dynamic)
126
127 target_link_libraries(reference Threads::Threads)
128 target_link_libraries(reference ${YAML_LIBRARIES})
129 target_link_libraries(reference ${LIBBPF_LIBRARIES})
130 target_link_libraries(reference ${LIBXDP_LIBRARIES})
131 target_link_libraries(reference ${LIBCRYPTO_LIBRARIES})
132
133 target_link_libraries(mirror Threads::Threads)
134 target_link_libraries(mirror ${YAML_LIBRARIES})
135 target_link_libraries(mirror ${LIBBPF_LIBRARIES})
136 target_link_libraries(mirror ${LIBXDP_LIBRARIES})
137 target_link_libraries(mirror ${LIBCRYPTO_LIBRARIES})
138
139 target_include_directories(reference PRIVATE "${PROJECT_BINARY_DIR}")
140 target_include_directories(reference PRIVATE "src")
141 target_include_directories(reference PUBLIC ${YAML_INCLUDE_DIRS})
142 target_include_directories(reference PUBLIC ${LIBBPF_INCLUDE_DIRS})
143 target_include_directories(reference PUBLIC ${LIBXDP_INCLUDE_DIRS})
144 target_include_directories(reference PUBLIC ${LIBCRYPTO_INCLUDE_DIRS})
145 target_include_directories(mirror PRIVATE "${PROJECT_BINARY_DIR}")
146 target_include_directories(mirror PRIVATE "src")
147 target_include_directories(mirror PUBLIC ${YAML_INCLUDE_DIRS})
148 target_include_directories(mirror PUBLIC ${LIBBPF_INCLUDE_DIRS})
149 target_include_directories(mirror PUBLIC ${LIBXDP_INCLUDE_DIRS})
150 target_include_directories(mirror PUBLIC ${LIBCRYPTO_INCLUDE_DIRS})
151
152 #
153 # Check for XDP and Tx Launch Time support. It requires: libxdp >= 1.5.0 and Linux v6.15.
154 #
155 if ((${LIBXDP_VERSION} GREATER_EQUAL 1.5.0) AND (${HAVE_XDP_FLAGS_TX_TIME}))
156 message(STATUS "XDP and Tx Launch Time support available using libxdp version: ${LIBXDP_VERSION}")
157 set(HAVE_XDP_TX_TIME ${HAVE_XDP_FLAGS_TX_TIME})
158 endif()
159
160 #
161 # Check for XDP and Tx HW Timestamp support. It requires: libxdp >= 1.4.1 and Linux v6.8.
162 #
163 if ((${LIBXDP_VERSION} GREATER_EQUAL 1.4.1) AND (${HAVE_XDP_FLAGS_TX_HWTSTAMP}))
164 message(STATUS "XDP and Tx HW Timestamp support available using libxdp version: ${LIBXDP_VERSION}")
165 endif()
166
167 set(INSTALL_EBPF_DIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/rtc-testbench/ebpf)
168 configure_file(
169 "${PROJECT_SOURCE_DIR}/app_config.in"
170 "${PROJECT_BINARY_DIR}/app_config.h"
171 )
172 include_directories("${PROJECT_BINARY_DIR}")
173
174 #
175 # Add code for compiling XDP eBPF programes.
176 #
177 set(ASM_INCLUDE "/usr/include/${CMAKE_C_LIBRARY_ARCHITECTURE}")
178 set(CLANG_FLAGS -Wall -O2 -fno-stack-protector
179 -I ${ASM_INCLUDE}
180 -I ${PROJECT_BINARY_DIR} # required for app_config.h
181 )
182
183 function(add_xdp_prog name)
184 add_custom_target(${name} ALL
185 COMMAND clang ${CLANG_FLAGS} -target bpf -c -g -o ${CMAKE_BINARY_DIR}/${name}.o ${name}.c
186 DEPENDS reference
187 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src
188 SOURCES src/${name}.c
189 )
190
191 install(FILES ${CMAKE_BINARY_DIR}/${name}.o DESTINATION ${CMAKE_INSTALL_LIBDIR}/rtc-testbench/ebpf)
192 endfunction()
193
194 add_xdp_prog(xdp_kern_profinet_vid100)
195 add_xdp_prog(xdp_kern_opcua_vid100)
196 add_xdp_prog(xdp_kern_profinet_vid200)
197 add_xdp_prog(xdp_kern_opcua_vid200)
198 add_xdp_prog(xdp_kern_opcua_vid300)
199 add_xdp_prog(xdp_kern_avtp_vid400)
200 add_xdp_prog(xdp_kern_profinet_veth_dispatch)
201
202 install(TARGETS reference DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT binaries)
203 install(TARGETS mirror DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT binaries)
204 install(DIRECTORY ${CMAKE_SOURCE_DIR}/tests/ DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/rtc-testbench/tests)
205
206 # Add workloads subdirectory for automatic compilation
207 add_subdirectory(tests/workloads)