forked from microsoft/msquic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
356 lines (299 loc) · 14.8 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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# Disable in-source builds to prevent source tree corruption.
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
message(FATAL_ERROR "
FATAL: In-source builds are not allowed.
You should create a separate directory for build files.
")
endif()
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
message(STATUS "Source Dir: ${CMAKE_CURRENT_SOURCE_DIR}")
message(STATUS "Host System name: ${CMAKE_HOST_SYSTEM_NAME}")
if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
set(CMAKE_SYSTEM_VERSION 10.0.18362.0 CACHE STRING INTERNAL FORCE)
set(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION 10.0.18362.0 CACHE STRING INTERNAL FORCE)
endif()
if (QUIC_TLS STREQUAL "mitls")
message(WARNING "Policy 0091 unsupported for miTLS.")
else()
if(POLICY CMP0091)
cmake_policy(SET CMP0091 NEW)
message(STATUS "Setting policy 0091")
else()
message(WARNING "CMake version too old to support Policy 0091; CRT static linking won't work")
endif()
endif()
project(msquic)
message(STATUS "System name: ${CMAKE_SYSTEM_NAME}")
message(STATUS "System version: ${CMAKE_SYSTEM_VERSION}")
message(STATUS "Platform version: ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# On Windows, we just need to set the destination variables
# This will allow the build to be picked up by other projects
set(msquic_dest ${CMAKE_INSTALL_PREFIX})
set(main_lib_dest lib)
set(include_dest include)
else()
# On unix platforms, we need to do rpath manipulation for the shared library
# In addition, we install into a subfolder of install to not polute the global namespace
# Setup for Install. We set this up in here rather then in the main library folder for future use.
# i.e. don't skip the full RPATH for the build tree
set(CMAKE_SKIP_BUILD_RPATH FALSE)
# When building, don't use the install RPATH already
# (but later on when installing)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/msquic/lib")
# Add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# The RPATH to be used when installing, but only if it's not a system directory
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/msquic/lib" isSystemDir)
if("${isSystemDir}" STREQUAL "-1")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/msquic/lib")
endif("${isSystemDir}" STREQUAL "-1")
set(msquic_dest msquic)
set(main_lib_dest msquic/lib)
set(include_dest msquic/include)
endif()
set(FILENAME_DEP_REPLACE "get_filename_component(SELF_DIR \"$\{CMAKE_CURRENT_LIST_FILE\}\" PATH)")
set(SELF_DIR "$\{SELF_DIR\}")
enable_testing()
# Set the default TLS method for each platform.
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(QUIC_TLS "schannel" CACHE STRING "TLS Library to use")
else()
set(QUIC_TLS "openssl" CACHE STRING "TLS Library to use")
endif()
option(QUIC_BUILD_TOOLS "Builds the tools code" ON)
option(QUIC_BUILD_TEST "Builds the test code" ON)
option(QUIC_ENABLE_LOGGING "Enables logging" ON)
option(QUIC_SANITIZE_ADDRESS "Enables address sanitizer" OFF)
option(QUIC_STATIC_LINK_CRT "Statically links the C runtime" ON)
option(QUIC_UWP_BUILD "Build for UWP" OFF)
option(QUIC_PGO "Enables profile guided optimizations" OFF)
# FindLTTngUST does not exist before CMake 3.6, so disable logging for older cmake versions
if (${CMAKE_VERSION} VERSION_LESS "3.6.0")
message(WARNING "Logging unsupported on this version of CMake. Please upgrade to 3.6 or later.")
set(QUIC_ENABLE_LOGGING OFF)
endif()
if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
set(QUIC_PLATFORM "windows")
elseif ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux")
set(QUIC_PLATFORM "linux")
elseif ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Darwin")
set(QUIC_PLATFORM "darwin")
endif()
set(QUIC_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(QUIC_OUTPUT_DIR ${QUIC_BUILD_DIR}/bin/$<IF:$<CONFIG:Debug>,Debug,Release> CACHE STRING "Output directory for build artifacts")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${QUIC_BUILD_DIR}/obj/$<IF:$<CONFIG:Debug>,Debug,Release>)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${QUIC_OUTPUT_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${QUIC_OUTPUT_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${QUIC_OUTPUT_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${QUIC_OUTPUT_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${QUIC_OUTPUT_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${QUIC_OUTPUT_DIR})
set(CMAKE_CLOG_OUTPUT_DIRECTORY ${QUIC_BUILD_DIR}/inc)
set(CMAKE_CLOG_BINS_DIRECTORY ${QUIC_BUILD_DIR}/submodules/clog)
set(CMAKE_CLOG_SIDECAR_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/manifest)
set(CLOG_SOURCE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/submodules/clog)
set(CLOG_INCLUDE_DIRECTORY ${CLOG_SOURCE_DIRECTORY}/inc)
set(CMAKE_CLOG_CONFIG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/manifest/msquic.clog_config)
set(MANIFESTED_HEADER_FILENAME ${QUIC_BUILD_DIR}/inc/MsQuicEtw.h)
add_custom_target(CLOG_GENERATED_FILES
COMMENT "CREATED CMAKE Target for CLOG generated files"
)
set(CLANG_GCC_WARNING_FLAGS -Werror -Wall -Wextra -Wformat=2 -Wno-type-limits -Wno-unknown-pragmas -Wno-unused-value CACHE INTERNAL "")
set(MSVC_WARNING_FLAGS /WX /W4 /sdl CACHE INTERNAL "")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# Generate the MsQuicEtw header file.
file(MAKE_DIRECTORY ${QUIC_BUILD_DIR}/inc)
file(WRITE ${QUIC_BUILD_DIR}/inc/MsQuicEtw.rc)
include_directories(${QUIC_BUILD_DIR}/inc)
add_custom_command(
OUTPUT ${QUIC_BUILD_DIR}/inc/MsQuicEtw.h
OUTPUT ${QUIC_BUILD_DIR}/inc/MsQuicEtw.rc
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/manifest/MsQuicEtw.man
COMMAND mc.exe -um -h ${QUIC_BUILD_DIR}/inc -r ${QUIC_BUILD_DIR}/inc ${CMAKE_CURRENT_SOURCE_DIR}/src/manifest/MsQuicEtw.man)
add_custom_target(MsQuicEtw
DEPENDS ${QUIC_BUILD_DIR}/inc/MsQuicEtw.h
DEPENDS ${QUIC_BUILD_DIR}/inc/MsQuicEtw.rc)
set_property(TARGET MsQuicEtw PROPERTY FOLDER "libraries")
# Custom build flags.
set(QUIC_COMMON_FLAGS "-DWIN32_LEAN_AND_MEAN -DSECURITY_WIN32 /MP")
if(QUIC_UWP_BUILD)
set(QUIC_COMMON_FLAGS "${QUIC_COMMON_FLAGS} -DWINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP -DQUIC_UWP_BUILD")
endif()
if(QUIC_ENABLE_LOGGING)
message(STATUS "Configuring for manifested ETW tracing")
set(CMAKE_CLOG_CONFIG_PROFILE windows)
set(QUIC_COMMON_FLAGS "${QUIC_COMMON_FLAGS} -DQUIC_EVENTS_MANIFEST_ETW -DQUIC_LOGS_MANIFEST_ETW")
else()
message(STATUS "Disabling tracing")
set(CMAKE_CLOG_CONFIG_PROFILE stubs)
set(QUIC_COMMON_FLAGS "${QUIC_COMMON_FLAGS} -DQUIC_EVENTS_STUB -DQUIC_LOGS_STUB")
endif()
if(QUIC_TLS STREQUAL "openssl")
# OpenSSL doesn't support session resumption yet.
message(STATUS "Disabling session resumption support")
set(QUIC_COMMON_FLAGS "${QUIC_COMMON_FLAGS} -DQUIC_DISABLE_RESUMPTION")
endif()
if(QUIC_TLS STREQUAL "openssl" OR QUIC_TLS STREQUAL "schannel")
# OpenSSL and SChannel don't support 0-RTT yet.
message(STATUS "Disabling 0-RTT support")
set(QUIC_COMMON_FLAGS "${QUIC_COMMON_FLAGS} -DQUIC_DISABLE_0RTT_TESTS")
endif()
if(QUIC_TLS STREQUAL "stub")
set(QUIC_COMMON_FLAGS "${QUIC_COMMON_FLAGS} -DQUIC_TLS_STUB")
endif()
if(QUIC_SANITIZE_ADDRESS)
message(STATUS "Address sanitizer unsupported on this platform.")
endif()
set(QUIC_C_FLAGS "${QUIC_COMMON_FLAGS}")
set(QUIC_CXX_FLAGS "${QUIC_COMMON_FLAGS} /std:c++17 /EHsc")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /GL /Zi")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GL /Zi")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG /DEBUG /OPT:REF /OPT:ICF")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG /DEBUG /OPT:REF /OPT:ICF")
# Configure PGO linker flags.
set(QUIC_PGO_FILE "${CMAKE_CURRENT_SOURCE_DIR}/src/bin/winuser/pgo_${CMAKE_GENERATOR_PLATFORM}/msquic.pgd")
if(QUIC_PGO)
# Configured for training mode. Use the previous PGD file if present.
if(EXISTS "${QUIC_PGO_FILE}")
message(STATUS "/GENPROFILE:PDG")
configure_file("${QUIC_PGO_FILE}" "${QUIC_OUTPUT_DIR}/msquic.pgd" COPYONLY)
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /GENPROFILE:PGD=${QUIC_OUTPUT_DIR}/msquic.pgd")
else()
message(STATUS "/GENPROFILE")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /GENPROFILE")
endif()
else()
# Just doing a normal build. Use the PGD file if present.
if(EXISTS "${QUIC_PGO_FILE}")
message(STATUS "Using profile-guided optimization")
configure_file("${QUIC_PGO_FILE}" "${QUIC_OUTPUT_DIR}/msquic.pgd" COPYONLY)
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /USEPROFILE:PGD=${QUIC_OUTPUT_DIR}/msquic.pgd")
endif()
endif()
if(QUIC_STATIC_LINK_CRT)
message(STATUS "Configuring for statically-linked CRT")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
else()
# Custom build flags.
set(QUIC_COMMON_FLAGS "-fms-extensions -fPIC -pthread")
if (QUIC_PLATFORM STREQUAL "darwin")
set(QUIC_COMMON_FLAGS "${QUIC_COMMON_FLAGS} -DQUIC_PLATFORM_DARWIN -Wno-microsoft-anon-tag -Wno-tautological-constant-out-of-range-compare -Wmissing-field-initializers")
else()
set(QUIC_COMMON_FLAGS "${QUIC_COMMON_FLAGS} -DQUIC_PLATFORM_LINUX -Wl,--no-as-needed -ldl")
endif()
if(QUIC_ENABLE_LOGGING)
message(STATUS "Configuring for LTTng tracing")
set(CMAKE_CLOG_CONFIG_PROFILE linux)
include(FindLTTngUST)
set(QUIC_COMMON_FLAGS "${QUIC_COMMON_FLAGS} -DQUIC_EVENTS_LTTNG -DQUIC_LOGS_STUB")
else()
message(STATUS "Disabling tracing")
set(CMAKE_CLOG_CONFIG_PROFILE stubs)
set(QUIC_COMMON_FLAGS "${QUIC_COMMON_FLAGS} -DQUIC_EVENTS_STUB -DQUIC_LOGS_STUB")
list(APPEND CLANG_GCC_WARNING_FLAGS -Wno-unused-parameter -Wno-unused-variable)
endif()
if(QUIC_TLS STREQUAL "openssl")
# OpenSSL doesn't support session resumption yet.
message(STATUS "Disabling session resumption support")
set(QUIC_COMMON_FLAGS "${QUIC_COMMON_FLAGS} -DQUIC_DISABLE_RESUMPTION")
# OpenSSL doesn't support 0-RTT yet.
message(STATUS "Disabling 0-RTT support")
set(QUIC_COMMON_FLAGS "${QUIC_COMMON_FLAGS} -DQUIC_DISABLE_0RTT_TESTS")
endif()
if(QUIC_SANITIZE_ADDRESS)
message(STATUS "Configuring address sanitizer")
set(QUIC_COMMON_FLAGS "${QUIC_COMMON_FLAGS} -fsanitize=address -fno-omit-frame-pointer -Wno-maybe-uninitialized -O0 -g")
endif()
if(QUIC_TLS STREQUAL "stub")
set(QUIC_COMMON_FLAGS "${QUIC_COMMON_FLAGS} -DQUIC_TLS_STUB")
endif()
set(QUIC_C_FLAGS "${QUIC_COMMON_FLAGS}")
set(QUIC_CXX_FLAGS "${QUIC_COMMON_FLAGS} -std=c++17 -g -Wno-reorder -Wno-sign-compare -Wno-format")
endif()
include_directories(${QUIC_BUILD_DIR}/inc)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/inc)
include_directories(${CLOG_INCLUDE_DIRECTORY})
include_directories(${CMAKE_CLOG_OUTPUT_DIRECTORY})
if(QUIC_TLS STREQUAL "openssl")
# Configure and build OpenSSL.
if (CMAKE_SYSTEM_PROCESSOR STREQUAL arm)
add_custom_command(
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/submodules/openssl
OUTPUT ${QUIC_BUILD_DIR}/openssl/include
OUTPUT ${QUIC_BUILD_DIR}/openssl/lib/libcrypto${CMAKE_STATIC_LIBRARY_SUFFIX}
OUTPUT ${QUIC_BUILD_DIR}/openssl/lib/libssl${CMAKE_STATIC_LIBRARY_SUFFIX}
COMMAND SYSTEM=${CMAKE_HOST_SYSTEM_NAME} ./Configure linux-armv4 --cross-compile-prefix=${GNU_MACHINE}${FLOAT_ABI_SUFFIX}- -DL_ENDIAN enable-tls1_3 --prefix=${QUIC_BUILD_DIR}/openssl
COMMAND make clean
COMMAND make -j$$(nproc)
COMMAND make install_sw)
else ()
add_custom_command(
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/submodules/openssl
OUTPUT ${QUIC_BUILD_DIR}/openssl/include
OUTPUT ${QUIC_BUILD_DIR}/openssl/lib/libcrypto${CMAKE_STATIC_LIBRARY_SUFFIX}
OUTPUT ${QUIC_BUILD_DIR}/openssl/lib/libssl${CMAKE_STATIC_LIBRARY_SUFFIX}
COMMAND SYSTEM=${CMAKE_HOST_SYSTEM_NAME} ./config enable-tls1_3 --prefix=${QUIC_BUILD_DIR}/openssl
COMMAND make -j$$(nproc)
COMMAND make install_sw)
endif()
add_custom_target(OpenSSL
DEPENDS ${QUIC_BUILD_DIR}/openssl/include
DEPENDS ${QUIC_BUILD_DIR}/openssl/lib/libcrypto${CMAKE_STATIC_LIBRARY_SUFFIX}
DEPENDS ${QUIC_BUILD_DIR}/openssl/lib/libssl${CMAKE_STATIC_LIBRARY_SUFFIX})
endif()
if(QUIC_TLS STREQUAL "mitls")
# Build Everest.
add_subdirectory(submodules/everest/msquic/msvc/kremlib)
add_subdirectory(submodules/everest/msquic/msvc/evercrypt)
add_subdirectory(submodules/everest/msquic/msvc/mitls)
add_subdirectory(submodules/everest/msquic/msvc/quiccrypto)
endif()
# CLOG target
add_subdirectory(submodules/clog/inc)
# Product code
add_subdirectory(src/core)
add_subdirectory(src/platform)
add_subdirectory(src/bin)
# Tool code
if(QUIC_BUILD_TOOLS)
add_subdirectory(src/tools/attack)
add_subdirectory(src/tools/interop)
add_subdirectory(src/tools/interopserver)
add_subdirectory(src/tools/ping)
add_subdirectory(src/tools/post)
add_subdirectory(src/tools/reach)
add_subdirectory(src/tools/sample)
add_subdirectory(src/tools/siduck)
add_subdirectory(src/tools/spin)
add_subdirectory(src/tools/void)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
add_subdirectory(src/tools/etwlib)
add_subdirectory(src/tools/etw)
endif()
endif()
# Test code
if(QUIC_BUILD_TEST)
# Build the googletest framework.
set(BUILD_GMOCK OFF CACHE BOOL "Builds the googlemock subproject")
set(INSTALL_GTEST OFF CACHE BOOL "Enable installation of googletest. (Projects embedding googletest may want to turn this OFF.)")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
option(gtest_force_shared_crt "Use shared (DLL) run-time lib even when Google Test is built as static lib." ON)
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
endif()
enable_testing()
add_subdirectory(submodules/googletest)
set_property(TARGET gtest PROPERTY FOLDER "tests")
set_property(TARGET gtest_main PROPERTY FOLDER "tests")
add_subdirectory(src/core/unittest)
add_subdirectory(src/platform/unittest)
add_subdirectory(src/test/lib)
add_subdirectory(src/test/bin)
endif()