-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
205 lines (160 loc) · 4.85 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
cmake_minimum_required(VERSION 3.12)
project(SecureGateway)
option(BAREMETAL "Baremetal build" OFF)
option(USE_XOR "Use XOR for encryption" OFF)
option(USE_CONSOLE "Use console for logging" OFF)
if(BAREMETAL)
message(STATUS "Secure MAVLink Gateway baremetal build")
else()
message(STATUS "Secure MAVLink Gateway Linux build")
endif()
if (NOT BAREMETAL)
set(CMAKE_CXX_STANDARD 11)
endif()
set(CMAKE_C_STANDARD 11)
include_directories(
lib
inc
inc/mavlink/ardupilotmega
inc/mavlink
)
include(FindPython3)
set(MAVGEN ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}/mavlink:$ENV{PYTHONPATH}"
${Python3_EXECUTABLE} -m pymavlink.tools.mavgen)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/mavlink.h.tstamp
COMMAND ${MAVGEN} --lang=C --wire-protocol 2.0
--output=${CMAKE_CURRENT_SOURCE_DIR}/inc/mavlink
${CMAKE_CURRENT_SOURCE_DIR}/mavlink/message_definitions/v1.0/ardupilotmega.xml
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/mavlink.h.tstamp
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/mavlink/message_definitions/v1.0/ardupilotmega.xml
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/mavlink
COMMENT "Generating MAVLink headers"
VERBATIM
)
add_custom_target(
mavlink_headers
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/mavlink.h.tstamp
)
if (USE_XOR)
add_definitions(-DUSE_XOR)
set(TRANSFORMER_SRC lib/transformer_xor.c)
else()
set(TRANSFORMER_SRC lib/transformer_none.c)
endif()
if (BAREMETAL)
add_compile_options(-nostdlib -nostdinc -ffreestanding -fno-builtin
-fno-common -fno-exceptions -fno-stack-protector
-fno-unwind-tables -fno-asynchronous-unwind-tables -fno-strict-aliasing
-fno-omit-frame-pointer -fno-strict-overflow -fno-delete-null-pointer-checks
-fno-PIE -fno-pic -fno-pie -fno-pic -fno-stack-protector -fno-unwind-tables
-fno-asynchronous-unwind-tables -fno-exceptions -fno-omit-frame-pointer
-fno-delete-null-pointer-checks)
add_link_options(
-nostdlib -nostdinc -ffreestanding -fno-builtin
-fno-common -fno-exceptions -fno-stack-protector
-fno-unwind-tables -fno-asynchronous-unwind-tables -fno-strict-aliasing
-fno-omit-frame-pointer -fno-strict-overflow -fno-delete-null-pointer-checks
-fno-PIE -fno-pic -fno-pie -fno-pic -fno-stack-protector -fno-unwind-tables
-fno-asynchronous-unwind-tables -fno-exceptions -fno-omit-frame-pointer
-fno-delete-null-pointer-checks
)
execute_process(COMMAND ${CMAKE_C_COMPILER} -print-file-name=libgcc.a
OUTPUT_VARIABLE C_LIBGCC_FILE
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${CMAKE_C_COMPILER} -print-file-name=libm.a
OUTPUT_VARIABLE C_LIBM_FILE
OUTPUT_STRIP_TRAILING_WHITESPACE)
link_libraries(
${C_LIBGCC_FILE}
${C_LIBM_FILE}
)
include_directories(
inc/baremetal
)
set (source_sink_list
lib/source_stdio.c)
else()
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-DDEBUG)
add_compile_options(-fsanitize=address,undefined -rdynamic)
add_link_options(-fsanitize=address,undefined -rdynamic)
endif()
add_compile_definitions(
_STD_LIBC_
)
link_libraries(
pthread
)
set (source_sink_list
lib/source_tcp.c
lib/source_tcpout.c
lib/source_udp.c
lib/source_stdio.c
lib/source_uart.c
)
endif()
option(HAS_CERTIKOS_THINROS "Build with CertiKOS ThinROS / User" OFF)
option(HAS_CERTIKOS_UART "Build with CertiKOS UART / User" OFF)
if (HAS_CERTIKOS_THINROS)
message(STATUS "Building with CertiKOS ThinROS / User")
add_definitions(-D_CERTIKOS_)
include_directories(${USER_DIR}/include)
link_libraries(user_lib ringleader)
list(APPEND source_sink_list
lib/source_thinros_certikos.c
lib/source_certikos_uart.c
lib/source_ringleader.c
)
endif()
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -g -Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-function")
add_compile_options(-Wno-address-of-packed-member)
add_compile_options(-Wno-missing-field-initializers)
add_compile_options(${EXTRA_C_FLAGS})
if (USE_CONSOLE)
add_definitions(-DUSE_CONSOLE)
message(STATUS "USE_CONSOLE: yes")
list(APPEND plugins
lib/plugins/console.c
)
endif()
add_library(gateway
STATIC
lib/secure_gateway.c
lib/route_table.c
lib/security_policies.c
${plugins}
${source_sink_list}
${TRANSFORMER_SRC}
)
add_dependencies(gateway mavlink_headers)
add_executable(secure_gateway
main.c
)
target_link_libraries(secure_gateway
PRIVATE
gateway
)
add_executable(main-sim
test/main-sim.c
)
target_link_libraries(main-sim
PRIVATE
gateway
)
add_executable(main-dump
test/main-dump.c
)
target_link_libraries(main-dump
PRIVATE
gateway
)
add_executable(main-xor
test/main-xor.c
)
target_link_libraries(main-xor
PRIVATE
gateway
)
add_executable(tcp_bridge
tools/tcp_bridge.cc)