-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
277 lines (238 loc) · 9.26 KB
/
Copy pathCMakeLists.txt
File metadata and controls
277 lines (238 loc) · 9.26 KB
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
277
cmake_minimum_required(VERSION 3.16)
project(quicer)
## NIF library ABI version
## Bump manually when ABI changes
set(QUICER_ABI_VERSION 1)
SET(Erlang_EI_INCLUDE_DIRS ${Erlang_OTP_LIB_DIR}/${Erlang_EI_DIR}/include)
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/priv/)
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR}/priv/ CACHE PATH "..." FORCE)
endif()
# For cerl picking up the OTP_ROOT
if (DEFINED ENV{Erlang_OTP_ROOT_DIR})
SET(Erlang_OTP_ROOT_DIR $ENV{Erlang_OTP_ROOT_DIR})
else()
EXECUTE_PROCESS(
COMMAND erl -noshell -eval "io:format(\"~s\", [code:root_dir()])" -s erlang halt
OUTPUT_VARIABLE Erlang_OTP_ROOT_DIR
)
endif()
if (DEFINED ENV{QUICER_VERSION})
set(QUICER_VERSION $ENV{QUICER_VERSION})
else()
set(QUICER_VERSION "0")
endif()
if (DEFINED ENV{CMAKE_BUILD_TYPE})
set(CMAKE_BUILD_TYPE $ENV{CMAKE_BUILD_TYPE})
else()
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
endif()
## QUICER_TLS_VER selects where libcrypto comes from:
## sys : link the libcrypto provided by the system (needs OpenSSL >= 3.0)
## quictls : build and link the bundled quictls submodule
## auto : sys when the system provides OpenSSL >= 3.0, quictls otherwise
##
## build.sh resolves 'auto' before calling cmake so that the pre-built package
## name matches what is built. Resolve it here too, for direct cmake calls.
if (DEFINED ENV{QUICER_TLS_VER})
set(QUICER_TLS_VER $ENV{QUICER_TLS_VER})
if (QUICER_TLS_VER STREQUAL "auto")
find_package(OpenSSL)
if (OPENSSL_FOUND AND NOT OPENSSL_VERSION VERSION_LESS "3.0")
set(QUICER_TLS_VER "sys")
else()
set(QUICER_TLS_VER "quictls")
endif()
message(STATUS "QUICER_TLS_VER=auto resolved to '${QUICER_TLS_VER}'")
endif()
if (QUICER_TLS_VER STREQUAL "sys")
## Link to sys libcrypto, auto openssl vsn
find_package(OpenSSL REQUIRED)
## MsQuic 2.5+ uses 'quictls' instead of 'openssl' or 'openssl3'
set(QUIC_TLS_LIB "quictls" CACHE STRING "QUIC_TLS_LIB")
set(QUIC_USE_SYSTEM_LIBCRYPTO "ON")
else()
set(QUIC_TLS_LIB ${QUICER_TLS_VER} CACHE STRING "QUIC_TLS_LIB")
endif()
endif()
if (DEFINED ENV{QUIC_ENABLE_LOGGING})
set(QUIC_ENABLE_LOGGING $ENV{QUIC_ENABLE_LOGGING})
set(QUIC_LOGGING_TYPE lttng)
else()
set(QUIC_ENABLE_LOGGING "OFF")
endif()
set(LIBNAME_SUFFIX "")
if (DEFINED ENV{QUIC_LOGGING_TYPE})
set(QUIC_ENABLE_LOGGING "ON")
set(QUIC_LOGGING_TYPE $ENV{QUIC_LOGGING_TYPE})
if (${QUIC_LOGGING_TYPE} STREQUAL "stdout")
add_compile_options(-DQUICER_LOGGING_STDOUT)
endif()
if (DEFINED ENV{BUILD_RELEASE})
set(LIBNAME_SUFFIX "-log${QUIC_LOGGING_TYPE}")
endif()
endif()
if (DEFINED ENV{QUICER_USE_LTTNG} AND DEFINED ENV{QUICER_USE_SNK})
message(FATAL_ERROR "QUICER_USE_LTTNG and QUICER_USE_SNK cannot be defined at same time")
endif()
if (DEFINED ENV{QUICER_USE_LTTNG})
message(STATUS "Test Build with LTTNG, some Snabbkaffe tests will fail")
add_compile_options(-DQUICER_USE_LTTNG)
endif()
if (DEFINED ENV{QUICER_USE_SNK})
message(STATUS "Test Build with Snabbkaffe")
add_compile_options(-DQUICER_USE_SNK)
endif()
if (DEFINED ENV{QUICER_USE_SANITIZERS})
set(QUIC_ENABLE_SANITIZERS "ON")
add_compile_options(-O1 -fno-omit-frame-pointer -fsanitize=address,leak,undefined)
add_link_options(-O1 -fno-omit-frame-pointer -fsanitize=address,leak,undefined)
endif()
# libFuzzer / ClusterFuzzLite harnesses (see test/fuzz/ and FUZZING.md).
# Opt-in: cmake -DBUILD_FUZZERS=ON. Under OSS-Fuzz/ClusterFuzzLite the engine
# and sanitizer flags arrive via CFLAGS/CXXFLAGS/$LIB_FUZZING_ENGINE instead.
option(BUILD_FUZZERS "Build libFuzzer harnesses under test/fuzz" OFF)
# Set by .clusterfuzzlite/build.sh: the CFL/OSS-Fuzz infra already injects the
# fuzzing engine and sanitizer through CFLAGS/CXXFLAGS/$LIB_FUZZING_ENGINE, so
# we must NOT add our own here (it would clash with e.g. memory sanitizer).
option(FUZZ_CFLITE "Fuzzers built under ClusterFuzzLite/OSS-Fuzz" OFF)
if (BUILD_FUZZERS)
# Export quicer_fuzz_init_atoms() and add coverage instrumentation to every
# target defined below (quicer_static and the msquic subdirectory).
add_compile_definitions(QUICER_FUZZ)
if (NOT FUZZ_CFLITE)
add_compile_options(-fsanitize=fuzzer-no-link)
add_link_options(-fsanitize=fuzzer-no-link)
if (NOT DEFINED ENV{QUICER_USE_SANITIZERS})
add_compile_options(-O1 -fno-omit-frame-pointer -fsanitize=address,undefined)
add_link_options(-O1 -fno-omit-frame-pointer -fsanitize=address,undefined)
endif()
endif()
endif()
set(QUIC_BUILD_TEST "OFF")
set(QUIC_BUILD_TOOLS "OFF")
set(QUIC_BUILD_PERF "OFF")
set(QUIC_TLS_SECRETS_SUPPORT "ON")
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/templates/quicer_vsn.hrl.in
${CMAKE_CURRENT_SOURCE_DIR}/include/quicer_vsn.hrl
)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/templates/quicer_vsn.h.in
${CMAKE_CURRENT_BINARY_DIR}/c_src/quicer_vsn.h
)
# src files
set(SOURCES
c_src/quicer_nif.c
c_src/quicer_nif.h
c_src/quicer_eterms.h
c_src/quicer_reg.c
c_src/quicer_reg.h
c_src/quicer_config.c
c_src/quicer_config.h
c_src/quicer_queue.c
c_src/quicer_queue.h
c_src/quicer_owner_queue.c
c_src/quicer_owner_queue.h
c_src/quicer_ctx.c
c_src/quicer_ctx.h
c_src/quicer_listener.c
c_src/quicer_listener.h
c_src/quicer_tls.c
c_src/quicer_tls.h
c_src/quicer_connection.c
c_src/quicer_connection.h
c_src/quicer_stream.c
c_src/quicer_stream.h
c_src/quicer_dgram.c
c_src/quicer_dgram.h
c_src/quicer_tp.c
c_src/quicer_tp.h
)
# @todo remove -DSO_ATTACH_REUSEPORT_CBPF=51
add_compile_options(-DSO_ATTACH_REUSEPORT_CBPF=51)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
string(REPLACE "." ";" set_version_list ${CMAKE_CXX_COMPILER_VERSION})
list(GET set_version_list 0 major_version)
# Check for Clang version >= 16.0
if (major_version GREATER_EQUAL 16)
message(STATUS "Clang version >= 16.0 detected, enabling '-Wno-invalid-unevaluated-string'.")
# Add the warning option
add_compile_options(-Wno-invalid-unevaluated-string)
else()
message(STATUS "Clang version < 16.0, skipping '-Wno-invalid-unevaluated-string'.")
endif()
endif()
# for lttng, quicer_tp.h
include_directories(c_src)
# for templ files
include_directories(${CMAKE_CURRENT_BINARY_DIR}/c_src/)
add_subdirectory(msquic)
add_library(quicer_static STATIC ${SOURCES})
target_include_directories(quicer_static PRIVATE ${Erlang_OTP_ROOT_DIR}/usr/include/ msquic/src/inc/)
if (OPENSSL_INCLUDE_DIR)
target_include_directories(quicer_static PRIVATE ${OPENSSL_INCLUDE_DIR})
else()
if (NOT DEFINED QUIC_TLS_LIB)
set(QUIC_TLS_LIB "quictls")
endif()
target_include_directories(quicer_static PRIVATE "${PROJECT_BINARY_DIR}/_deps/opensslquic-build/${QUIC_TLS_LIB}/include")
endif()
if (CMAKE_SYSTEM_NAME MATCHES Linux)
# note, the value of ${ATOMIC} and %{NUMA} will be set by msquic
if (NUMA)
set(MY_NUMA ${NUMA})
else()
set(MY_NUMA "")
endif()
target_link_libraries(quicer_static PRIVATE core msquic_platform inc warnings logging ${ATOMIC} ${MY_NUMA} "-Wl,--no-gc-sections")
elseif (CMAKE_SYSTEM_NAME MATCHES Darwin)
target_link_libraries(quicer_static PRIVATE core msquic_platform inc warnings "-Wl,-undefined,dynamic_lookup -Wl,-dead_strip")
endif()
# @todo clean compiler warnings in the code
target_compile_options(quicer_static PUBLIC "-ggdb3")
if (DEFINED ENV{QUICER_TEST_COVER})
add_compile_options("-fprofile-arcs" "-ftest-coverage")
add_link_options("-fprofile-arcs" "-lgcov")
endif()
add_library(quicer_nif SHARED ${SOURCES})
if (OPENSSL_INCLUDE_DIR)
# for sys crypto
target_include_directories(quicer_nif PUBLIC ${OPENSSL_INCLUDE_DIR})
else()
target_include_directories(quicer_nif PUBLIC "${PROJECT_BINARY_DIR}/_deps/opensslquic-build/${QUIC_TLS_LIB}/include")
endif()
if (CMAKE_SYSTEM_NAME MATCHES Linux)
target_link_libraries(quicer_nif PRIVATE quicer_static "-Wl,--no-gc-sections -pthread") # no gc because of erlang nif symbols
elseif (CMAKE_SYSTEM_NAME MATCHES Darwin)
target_link_libraries(quicer_nif PRIVATE quicer_static "-Wl,-undefined,dynamic_lookup -Wl,-dead_strip") # link enif lib
endif()
target_include_directories(quicer_nif PRIVATE ${Erlang_OTP_ROOT_DIR}/usr/include/ msquic/src/inc/)
add_dependencies(quicer_nif quicer_static)
add_dependencies(quicer_static msquic)
set_target_properties(quicer_nif
PROPERTIES
LIBRARY_OUTPUT_NAME quicer_nif${LIBNAME_SUFFIX}
VERSION ${QUICER_VERSION}
SOVERSION ${QUICER_ABI_VERSION}
SUFFIX .so
)
include(GNUInstallDirs)
install(TARGETS quicer_nif LIBRARY DESTINATION ${PROJECT_SOURCE_DIR}/priv/)
# Calculate relative path for symlink to avoid absolute path issues during packaging
file(RELATIVE_PATH QUICER_NIF_RELATIVE_PATH
"${PROJECT_SOURCE_DIR}/priv"
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libquicer_nif.so")
add_custom_command(
TARGET quicer_nif POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink
${QUICER_NIF_RELATIVE_PATH}
${PROJECT_SOURCE_DIR}/priv/libquicer_nif.so)
## workaround for emqx forked rebar3
## For none-emqx rebar3, it should be just a noop of 'Up-to-date' instead of 'installing'
if (DEFINED ENV{REBAR_DEPS_DIR})
install(TARGETS quicer_nif LIBRARY DESTINATION $ENV{REBAR_DEPS_DIR}/quicer/priv/)
endif()
if (BUILD_FUZZERS)
add_subdirectory(test/fuzz)
endif()