-
Notifications
You must be signed in to change notification settings - Fork 67
/
CMakeLists.txt
418 lines (336 loc) · 13.9 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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
cmake_minimum_required(VERSION 3.9)
if(POLICY CMP0077)
cmake_policy(SET CMP0077 NEW)
endif()
option(BUILD_DEPS "Builds aws common runtime dependencies as part of build. Turn off if you want to control your dependency chain." ON)
option(BYO_CRYPTO "Don't build a tls implementation or link against a crypto interface. This feature is only for unix builds currently" OFF)
option(USE_OPENSSL "Set this if you want to use your system's OpenSSL 1.0.2/1.1.1 compatible libcrypto" OFF)
# Let aws-iot-device-sdk-cpp-v2 report its own version in MQTT connections (instead of reporting aws-crt-cpp's version).
option(AWS_IOT_SDK_VERSION "Set the version reported by Aws::Iot::MqttClientConnectionConfigBuilder")
# Tests require environment variables setup in order to run properly.
# See https://github.com/awslabs/aws-crt-builder/blob/main/builder/actions/setup_cross_ci_crt_environment.py
# for how environment variables are setup.
# NOTE: Some environment variables use Mosquitto or Proxy servers, which are assumed to be installed
# locally if running the testing outside of CI/CD.
option(ENABLE_PROXY_INTEGRATION_TESTS "Whether or not to build and run the proxy integration tests that rely on a proxy server installed and running locally" OFF)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(AwsGetVersion)
aws_get_version(SIMPLE_VERSION FULL_VERSION GIT_HASH)
message(STATUS "AWS CRT C++ ${FULL_VERSION}")
project("aws-crt-cpp"
LANGUAGES CXX C
VERSION ${SIMPLE_VERSION})
include(CTest)
if(DEFINED CMAKE_PREFIX_PATH)
file(TO_CMAKE_PATH "${CMAKE_PREFIX_PATH}" CMAKE_PREFIX_PATH)
endif()
if(DEFINED CMAKE_INSTALL_PREFIX)
file(TO_CMAKE_PATH "${CMAKE_INSTALL_PREFIX}" CMAKE_INSTALL_PREFIX)
endif()
if(UNIX AND NOT APPLE)
include(GNUInstallDirs)
elseif(NOT DEFINED CMAKE_INSTALL_LIBDIR)
set(CMAKE_INSTALL_LIBDIR "lib")
endif()
if(${CMAKE_INSTALL_LIBDIR} STREQUAL "lib64")
set(FIND_LIBRARY_USE_LIB64_PATHS true)
endif()
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
endif()
if(NOT CMAKE_BUILD_TYPE)
# setting this breaks C++ builds in visualc++, so don't do it.
if(NOT WIN32)
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
endif()
endif()
set(GENERATED_ROOT_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated")
set(GENERATED_INCLUDE_DIR "${GENERATED_ROOT_DIR}/include")
set(GENERATED_CONFIG_HEADER "${GENERATED_INCLUDE_DIR}/aws/crt/Config.h")
configure_file(include/aws/crt/Config.h.in ${GENERATED_CONFIG_HEADER} @ONLY)
# This is required in order to append /lib/cmake to each element in CMAKE_PREFIX_PATH
set(AWS_MODULE_DIR "/${CMAKE_INSTALL_LIBDIR}/cmake")
string(REPLACE ";" "${AWS_MODULE_DIR};" AWS_MODULE_PATH "${CMAKE_PREFIX_PATH}${AWS_MODULE_DIR}")
# Append that generated list to the module search path
list(APPEND CMAKE_MODULE_PATH ${AWS_MODULE_PATH})
if(BUILD_DEPS)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/crt/aws-c-common/cmake")
include(AwsFindPackage)
set(IN_SOURCE_BUILD ON)
set(BUILD_TESTING_PREV ${BUILD_TESTING})
set(BUILD_TESTING OFF)
add_subdirectory(crt/aws-c-common)
if(UNIX AND NOT APPLE AND NOT BYO_CRYPTO)
if(NOT USE_OPENSSL)
include(AwsPrebuildDependency)
set(AWSLC_CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
# temporarily disable certain warnings as errors for the aws-lc build
if(NOT MSVC)
check_c_compiler_flag(-Wno-stringop-overflow HAS_WNO_STRINGOP_OVERFLOW)
if(HAS_WNO_STRINGOP_OVERFLOW)
set(AWSLC_CMAKE_C_FLAGS "${AWSLC_CMAKE_C_FLAGS} -Wno-stringop-overflow")
endif()
check_c_compiler_flag(-Wno-array-parameter HAS_WNO_ARRAY_PARAMETER)
if(HAS_WNO_ARRAY_PARAMETER)
set(AWSLC_CMAKE_C_FLAGS "${AWSLC_CMAKE_C_FLAGS} -Wno-array-parameter")
endif()
endif()
# s2n-tls uses libcrypto during its configuration, so we need to prebuild aws-lc.
aws_prebuild_dependency(
DEPENDENCY_NAME AWSLC
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/crt/aws-lc
CMAKE_ARGUMENTS
-DDISABLE_GO=ON
-DDISABLE_PERL=ON
-DBUILD_LIBSSL=OFF
-DBUILD_TESTING=OFF
-DCMAKE_C_FLAGS=${AWSLC_CMAKE_C_FLAGS}
)
endif()
set(UNSAFE_TREAT_WARNINGS_AS_ERRORS OFF CACHE BOOL "Disable warnings-as-errors when building S2N")
add_subdirectory(crt/s2n)
endif()
add_subdirectory(crt/aws-c-sdkutils)
add_subdirectory(crt/aws-c-io)
add_subdirectory(crt/aws-c-cal)
add_subdirectory(crt/aws-c-compression)
add_subdirectory(crt/aws-c-http)
add_subdirectory(crt/aws-c-auth)
add_subdirectory(crt/aws-c-mqtt)
add_subdirectory(crt/aws-checksums)
add_subdirectory(crt/aws-c-event-stream)
add_subdirectory(crt/aws-c-s3)
set(BUILD_TESTING ${BUILD_TESTING_PREV})
else()
include(AwsFindPackage)
set(IN_SOURCE_BUILD OFF)
endif()
include(AwsCFlags)
include(AwsSharedLibSetup)
file(GLOB AWS_CRT_HEADERS
"include/aws/crt/*.h"
${GENERATED_CONFIG_HEADER}
)
file(GLOB AWS_CRT_AUTH_HEADERS
"include/aws/crt/auth/*.h"
)
file(GLOB AWS_CRT_CHECKSUM_HEADERS
"include/aws/crt/checksum/*.h"
)
file(GLOB AWS_CRT_CRYPTO_HEADERS
"include/aws/crt/crypto/*.h"
)
file(GLOB AWS_CRT_IO_HEADERS
"include/aws/crt/io/*.h"
)
file(GLOB AWS_CRT_IOT_HEADERS
"include/aws/iot/*.h"
)
file(GLOB AWS_CRT_MQTT_HEADERS
"include/aws/crt/mqtt/*.h"
)
file(GLOB AWS_CRT_HTTP_HEADERS
"include/aws/crt/http/*.h"
)
file(GLOB AWS_CRT_ENDPOINT_HEADERS
"include/aws/crt/endpoints/*.h"
)
file(GLOB AWS_CRT_CBOR_HEADERS
"include/aws/crt/cbor/*.h"
)
file(GLOB AWS_CRT_PUBLIC_HEADERS
${AWS_CRT_HEADERS}
${AWS_CRT_AUTH_HEADERS}
${AWS_CRT_CHECKSUM_HEADERS}
${AWS_CRT_CRYPTO_HEADERS}
${AWS_CRT_IO_HEADERS}
${AWS_CRT_IOT_HEADERS}
${AWS_CRT_MQTT_HEADERS}
${AWS_CRT_HTTP_HEADERS}
${AWS_CRT_ENDPOINT_HEADERS}
${AWS_CRT_CBOR_HEADERS}
)
if(BUILD_DEPS)
include(AwsCheckHeaders)
aws_check_headers(${PROJECT_NAME} IS_CXX ${AWS_CRT_PUBLIC_HEADERS})
endif()
file(GLOB AWS_CRT_CPP_HEADERS
${AWS_CRT_PUBLIC_HEADERS}
)
file(GLOB AWS_CRT_SRC
"source/*.cpp"
)
file(GLOB AWS_CRT_AUTH_SRC
"source/auth/*.cpp"
)
file(GLOB AWS_CRT_CHECKSUM_SRC
"source/checksum/*.cpp"
)
file(GLOB AWS_CRT_CRYPTO_SRC
"source/crypto/*.cpp"
)
file(GLOB AWS_CRT_IO_SRC
"source/io/*.cpp"
)
file(GLOB AWS_CRT_IOT_SRC
"source/iot/*.cpp"
)
file(GLOB AWS_CRT_MQTT_SRC
"source/mqtt/*.cpp"
)
file(GLOB AWS_CRT_HTTP_SRC
"source/http/*.cpp"
)
file(GLOB AWS_CRT_ENDPOINTS_SRC
"source/endpoints/*.cpp"
)
file(GLOB AWS_CRT_CBOR_SRC
"source/cbor/*.cpp"
)
file(GLOB AWS_CRT_CPP_SRC
${AWS_CRT_SRC}
${AWS_CRT_AUTH_SRC}
${AWS_CRT_CHECKSUM_SRC}
${AWS_CRT_CRYPTO_SRC}
${AWS_CRT_IO_SRC}
${AWS_CRT_IOT_SRC}
${AWS_CRT_MQTT_SRC}
${AWS_CRT_HTTP_SRC}
${AWS_CRT_ENDPOINTS_SRC}
${AWS_CRT_CBOR_SRC}
)
if(WIN32)
if(MSVC)
source_group("Header Files\\aws\\crt" FILES ${AWS_CRT_HEADERS})
source_group("Header Files\\aws\\crt\\auth" FILES ${AWS_CRT_AUTH_HEADERS})
source_group("Header Files\\aws\\crt\\checksum" FILES ${AWS_CRT_CHECKSUM_HEADERS})
source_group("Header Files\\aws\\crt\\crypto" FILES ${AWS_CRT_CRYPTO_HEADERS})
source_group("Header Files\\aws\\crt\\io" FILES ${AWS_CRT_IO_HEADERS})
source_group("Header Files\\aws\\iot" FILES ${AWS_CRT_IOT_HEADERS})
source_group("Header Files\\aws\\crt\\mqtt" FILES ${AWS_CRT_MQTT_HEADERS})
source_group("Header Files\\aws\\crt\\http" FILES ${AWS_CRT_HTTP_HEADERS})
source_group("Header Files\\aws\\crt\\endpoints" FILES ${AWS_CRT_ENDPOINT_HEADERS})
source_group("Header Files\\aws\\crt\\cbor" FILES ${AWS_CRT_CBOR_HEADERS})
source_group("Source Files" FILES ${AWS_CRT_SRC})
source_group("Source Files\\auth" FILES ${AWS_CRT_AUTH_SRC})
source_group("Source Files\\checksum" FILES ${AWS_CRT_CHECKSUM_SRC})
source_group("Source Files\\crypto" FILES ${AWS_CRT_CRYPTO_SRC})
source_group("Source Files\\io" FILES ${AWS_CRT_IO_SRC})
source_group("Source Files\\iot" FILES ${AWS_CRT_IOT_SRC})
source_group("Source Files\\mqtt" FILES ${AWS_CRT_MQTT_SRC})
source_group("Source Files\\http" FILES ${AWS_CRT_HTTP_SRC})
source_group("Source Files\\endpoints" FILES ${AWS_CRT_ENDPOINTS_SRC})
source_group("Source Files\\cbor" FILES ${AWS_CRT_CBOR_SRC})
endif()
endif()
add_library(${PROJECT_NAME} ${AWS_CRT_CPP_HEADERS} ${AWS_CRT_CPP_SRC})
target_compile_definitions(${PROJECT_NAME} PRIVATE -DCJSON_HIDE_SYMBOLS)
if(AWS_IOT_SDK_VERSION)
target_compile_definitions(${PROJECT_NAME} PRIVATE "-DAWS_IOT_SDK_VERSION=\"${AWS_IOT_SDK_VERSION}\"")
endif()
if(BUILD_SHARED_LIBS)
target_compile_definitions(${PROJECT_NAME} PUBLIC -DAWS_CRT_CPP_USE_IMPORT_EXPORT)
target_compile_definitions(${PROJECT_NAME} PRIVATE -DAWS_CRT_CPP_EXPORTS)
endif()
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD ${CMAKE_CXX_STANDARD})
# Hide symbols by default
# Except where it causes problems, and the situation is weird enough that it's not worth investigating further.
#
# We've seen people set _GLIBCXX_USE_CXX11_ABI=0 which forces GCC to use it's pre-C++11 string implementation,
# which leads to crashes on shared-lib builds. Search every variant of CXX_FLAGS to see if it's set.
string(FIND "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG} ${CMAKE_CXX_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${CMAKE_CXX_FLAGS_MINSIZEREL}"
"-D_GLIBCXX_USE_CXX11_ABI=0" found_ancient_abi_flag)
if(found_ancient_abi_flag GREATER -1)
message(WARNING "_GLIBCXX_USE_CXX11_ABI=0 is set. Making all symbols visible to prevent weird crashes")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.0")
# Ancient GCC leads to crashes in shared-lib builds
# see: https://github.com/awslabs/aws-crt-cpp/pull/675
message(WARNING "Ancient compiler (${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}). Making all symbols visible to prevent weird crashes")
else()
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN ON)
endif()
aws_prepare_symbol_visibility_args(${PROJECT_NAME} "AWS_CRT_CPP")
# set runtime library
if(MSVC)
if(AWS_STATIC_MSVC_RUNTIME_LIBRARY OR STATIC_CRT)
target_compile_options(${PROJECT_NAME} PRIVATE "/MT$<$<CONFIG:Debug>:d>")
else()
target_compile_options(${PROJECT_NAME} PRIVATE "/MD$<$<CONFIG:Debug>:d>")
endif()
endif()
target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<CONFIG:Debug>:DEBUG_BUILD>)
# set extra warning flags
if(AWS_WARNINGS_ARE_ERRORS)
if(MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX /wd4068)
else()
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wno-long-long -pedantic -Werror)
endif()
endif()
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${GENERATED_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>)
aws_use_package(aws-c-http)
aws_use_package(aws-c-mqtt)
aws_use_package(aws-c-cal)
aws_use_package(aws-c-auth)
aws_use_package(aws-c-common)
aws_use_package(aws-c-io)
aws_use_package(aws-checksums)
aws_use_package(aws-c-event-stream)
aws_use_package(aws-c-s3)
include(AwsSanitizers)
aws_add_sanitizers(${PROJECT_NAME})
target_link_libraries(${PROJECT_NAME} PUBLIC ${DEP_AWS_LIBS})
install(FILES ${AWS_CRT_HEADERS} DESTINATION "include/aws/crt" COMPONENT Development)
install(FILES ${AWS_CRT_AUTH_HEADERS} DESTINATION "include/aws/crt/auth" COMPONENT Development)
install(FILES ${AWS_CRT_CHECKSUM_HEADERS} DESTINATION "include/aws/crt/checksum" COMPONENT Development)
install(FILES ${AWS_CRT_CRYPTO_HEADERS} DESTINATION "include/aws/crt/crypto" COMPONENT Development)
install(FILES ${AWS_CRT_IO_HEADERS} DESTINATION "include/aws/crt/io" COMPONENT Development)
install(FILES ${AWS_CRT_IOT_HEADERS} DESTINATION "include/aws/iot" COMPONENT Development)
install(FILES ${AWS_CRT_MQTT_HEADERS} DESTINATION "include/aws/crt/mqtt" COMPONENT Development)
install(FILES ${AWS_CRT_HTTP_HEADERS} DESTINATION "include/aws/crt/http" COMPONENT Development)
install(FILES ${AWS_CRT_ENDPOINT_HEADERS} DESTINATION "include/aws/crt/endpoints" COMPONENT Development)
install(FILES ${AWS_CRT_CBOR_HEADERS} DESTINATION "include/aws/crt/cbor" COMPONENT Development)
install(
TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Development
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Development
RUNTIME DESTINATION bin COMPONENT Runtime
)
if(BUILD_SHARED_LIBS)
set(TARGET_DIR "shared")
else()
set(TARGET_DIR "static")
endif()
install(EXPORT "${PROJECT_NAME}-targets"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/cmake/${TARGET_DIR}"
NAMESPACE AWS::
COMPONENT Development)
configure_file("cmake/${PROJECT_NAME}-config.cmake"
"${GENERATED_ROOT_DIR}/${PROJECT_NAME}-config.cmake"
@ONLY)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${GENERATED_ROOT_DIR}/${PROJECT_NAME}-config-version.cmake"
COMPATIBILITY ExactVersion
)
install(FILES "${GENERATED_ROOT_DIR}/${PROJECT_NAME}-config.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/cmake/"
COMPONENT Development)
install(FILES "${GENERATED_ROOT_DIR}/${PROJECT_NAME}-config-version.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/cmake/"
COMPONENT Development)
if(NOT CMAKE_CROSSCOMPILING)
if(BUILD_TESTING)
add_subdirectory(tests)
if(NOT BYO_CRYPTO)
add_subdirectory(bin/elasticurl_cpp)
add_subdirectory(bin/mqtt5_app)
add_subdirectory(bin/mqtt5_canary)
endif()
endif()
endif()