forked from ilejn/xdpbridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
112 lines (94 loc) · 3.33 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
cmake_minimum_required(VERSION 3.9)
project(xdpbridge)
find_program(CLANG_COMPILER clang)
find_program(LLVM_COMPILER llc)
set(KERNEL_TOP CACHE FILEPATH "path to the top of linux kernel sources")
if(NOT KERNEL_TOP)
message (FATAL_ERROR "KERNEL_TOP variable does not exist")
else()
message (STATUS "KERNEL_TOP is ${KERNEL_TOP}")
endif(NOT KERNEL_TOP)
set(KERNELINCLUDE
${KERNEL_TOP}/arch/x86/include
${KERNEL_TOP}/arch/x86/include/generated/uapi
${KERNEL_TOP}/arch/x86/include/generated
${KERNEL_TOP}/include
${KERNEL_TOP}/arch/x86/include/uapi
${KERNEL_TOP}/include/uapi
${KERNEL_TOP}/include/generated/uapi
# ${KERNEL_TOP}/include/linux/kconfig.h
${KERNEL_TOP}/tools/lib
${CMAKE_CURRENT_SOURCE_DIR}
)
set(USERINCLUDE
${KERNEL_TOP}/usr/include
# ${KERNEL_TOP}/usr/include/linux
${KERNEL_TOP}/tools/include
${KERNEL_TOP}/tools/lib
)
set(KERNELDEF
__KERNEL__
__ASM_SYSREG_H
__BPF_TRACING__
__TARGET_ARCH_$(ARCH)
)
FUNCTION(LIST_TRANSFORM_PREPEND var prefix)
SET(listVar "")
FOREACH(f ${ARGN})
LIST(APPEND listVar "${prefix}${f}")
ENDFOREACH(f)
SET(${var} "${listVar}" PARENT_SCOPE)
ENDFUNCTION(LIST_TRANSFORM_PREPEND)
# list(TRANSFORM KERNELINCLUDE PREPEND -I)
LIST_TRANSFORM_PREPEND(KERNELINCLUDE -I ${KERNELINCLUDE})
# list(TRANSFORM KERNELDEF PREPEND -D)
LIST_TRANSFORM_PREPEND(KERNELDEF -D ${KERNELDEF})
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xdpbridge_kern.ll
COMMAND ${CLANG_COMPILER}
${KERNELINCLUDE} ${KERNELDEF} -include ${KERNEL_TOP}/include/linux/kconfig.h -include asm_goto_workaround.h
-O2
-Wno-unused-but-set-variable -Wno-pointer-sign -Wno-compare-distinct-pointer-types -Wno-gnu-variable-sized-type-not-at-end -Wno-tautological-compare -Wno-unknown-warning-option -Wno-address-of-packed-member
-S -emit-llvm -c ${CMAKE_CURRENT_SOURCE_DIR}/xdpbridge_kern.c
-o ${CMAKE_CURRENT_BINARY_DIR}/xdpbridge_kern.ll
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/xdpbridge_kern.c
)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xdpbridge_kern.o
COMMAND ${LLVM_COMPILER}
-march=bpf -filetype=obj -o ${CMAKE_CURRENT_BINARY_DIR}/xdpbridge_kern.o ${CMAKE_CURRENT_BINARY_DIR}/xdpbridge_kern.ll
COMMENT "custom_command for xdpbridge_kern.o"
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/xdpbridge_kern.ll
)
add_custom_target(xdpbridge_kern ALL
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/xdpbridge_kern.o
COMMENT "custom_target xdpbridge_kern"
)
add_library(xdpbridge_user_object SHARED
xdpbridge_user.c
bpf_load.c
)
if(NO_ABORT_ON_LASSERT_MODE)
target_compile_definitions(xdpbridge_user_object PRIVATE NO_ABORT_WITH_LASSERT)
endif(NO_ABORT_ON_LASSERT_MODE)
add_executable(xdpbridge
xdpbridge_main.c
)
target_include_directories(xdpbridge PRIVATE
${USERINCLUDE}
)
target_include_directories(xdpbridge_user_object PUBLIC
${USERINCLUDE}
)
target_link_libraries(xdpbridge_user_object
PUBLIC pthread
#PUBLIC ${KERNEL_TOP}/tools/lib/bpf/bpf.o
#PUBLIC ${KERNEL_TOP}/tools/lib/bpf/btf.o
## ${KERNEL_TOP}/tools/lib/bpf/str_error.o
#PUBLIC ${KERNEL_TOP}/tools/lib/bpf/nlattr.o
#PUBLIC ${KERNEL_TOP}/tools/lib/bpf/libbpf.o
#PUBLIC ${KERNEL_TOP}/tools/lib/bpf/libbpf.a
PUBLIC bpf
PUBLIC elf
)
target_link_libraries(xdpbridge
xdpbridge_user_object
)