forked from awslabs/aws-crt-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
260 lines (212 loc) · 9.09 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
cmake_minimum_required(VERSION 3.1)
option(BUILD_DEPS "Builds aws common runtime dependencies as part of build, only do this if you don't want to control your dependency chain." OFF)
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()
set(AWS_CRT_CPP_VERSION "v0.3.0")
configure_file(include/aws/crt/Config.h.in ${CMAKE_CURRENT_LIST_DIR}/include/aws/crt/Config.h @ONLY)
if (BUILD_DEPS)
set(AWS_DEPS_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/deps CACHE STRING "If BUILD_DEPS is on, aws common runtime dependencies build in this directory.")
if (DEFINED CMAKE_INSTALL_PREFIX)
set(AWS_DEPS_INSTALL_DIR ${CMAKE_INSTALL_PREFIX})
else()
set(AWS_DEPS_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/deps/install)
endif()
if (NOT DEFINED CMAKE_PREFIX_PATH)
set(CMAKE_PREFIX_PATH ${AWS_DEPS_INSTALL_DIR})
endif()
file(MAKE_DIRECTORY ${AWS_DEPS_BUILD_DIR})
if(TARGET_ARCH STREQUAL "ANDROID")
execute_process(
COMMAND ${CMAKE_COMMAND} -G ${CMAKE_GENERATOR}
-DTARGET_ARCH=${TARGET_ARCH}
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
-DANDROID_NATIVE_API_LEVEL=${ANDROID_NATIVE_API_LEVEL}
-DANDROID_ABI=${ANDROID_ABI}
-DANDROID_TOOLCHAIN_NAME=${ANDROID_TOOLCHAIN_NAME}
-DANDROID_STANDALONE_TOOLCHAIN=${ANDROID_STANDALONE_TOOLCHAIN}
-DANDROID_STL=${ANDROID_STL}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
-DCMAKE_INSTALL_PREFIX=${AWS_DEPS_INSTALL_DIR}
-DCMAKE_PREFIX_PATH=${AWS_DEPS_INSTALL_DIR}
-DGIT_EXECUTABLE=${GIT_EXECUTABLE}
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
${CMAKE_CURRENT_SOURCE_DIR}/aws-common-runtime
WORKING_DIRECTORY ${AWS_DEPS_BUILD_DIR}
)
else()
execute_process(
COMMAND ${CMAKE_COMMAND} -G ${CMAKE_GENERATOR}
-DTARGET_ARCH=${TARGET_ARCH}
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
-DCMAKE_PREFIX_PATH=${AWS_DEPS_INSTALL_DIR}
-DCMAKE_INSTALL_PREFIX=${AWS_DEPS_INSTALL_DIR}
-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=${CMAKE_CURRENT_BINARY_DIR}/bin
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
${CMAKE_CURRENT_SOURCE_DIR}/aws-common-runtime
WORKING_DIRECTORY ${AWS_DEPS_BUILD_DIR}
RESULT_VARIABLE BUILD_AWSCRT_EXIT_CODE
)
endif()
if (NOT ${BUILD_AWSCRT_EXIT_CODE} EQUAL 0)
message(FATAL_ERROR "Failed to configure aws crt libraries.")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build ${AWS_DEPS_BUILD_DIR} --config ${CMAKE_BUILD_TYPE}
RESULT_VARIABLE BUILD_AWSCRT_EXIT_CODE)
if (NOT ${BUILD_AWSCRT_EXIT_CODE} EQUAL 0)
message(FATAL_ERROR "Failed to build aws crt libraries.")
endif()
message(STATUS "AWS Common Runtime is installed at: ${AWS_DEPS_INSTALL_DIR}")
#the following two lines are done in this branch intentionally, don't move it. project() does some magic that
#we don't want happening until we're done with the above code.
list(APPEND CMAKE_PREFIX_PATH "${AWS_DEPS_INSTALL_DIR}")
project(aws-crt-cpp CXX)
else()
#the following two lines are done in this branch intentionally, don't move it. project() does some magic that
#we want happening exactly right now.
project(aws-crt-cpp CXX)
endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_PREFIX_PATH}/${CMAKE_INSTALL_LIBDIR}/cmake")
include(AwsCFlags)
include(AwsSharedLibSetup)
file(GLOB AWS_CRT_HEADERS
"include/aws/crt/*.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_EXTERNAL_HEADERS
"include/aws/crt/external/*.h"
)
file(GLOB AWS_CRT_CPP_HEADERS
${AWS_CRT_HEADERS}
${AWS_CRT_CRYPTO_HEADERS}
${AWS_CRT_IO_HEADERS}
${AWS_CRT_IOT_HEADERS}
${AWS_CRT_MQTT_HEADERS}
${AWS_CRT_HTTP_HEADERS}
${AWS_CRT_EXTERNAL_HEADERS}
)
file(GLOB AWS_CRT_SRC
"source/*.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_EXTERNAL_CRC
"source/external/*.cpp"
)
file(GLOB AWS_CRT_CPP_SRC
${AWS_CRT_SRC}
${AWS_CRT_CRYPTO_SRC}
${AWS_CRT_IO_SRC}
${AWS_CRT_IOT_SRC}
${AWS_CRT_MQTT_SRC}
${AWS_CRT_HTTP_SRC}
${AWS_CRT_EXTERNAL_CRC}
)
if (WIN32)
if (MSVC)
source_group("Header Files\\aws\\crt" FILES ${AWS_CRT_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\\external" FILES ${AWS_CRT_EXTERNAL_HEADERS})
source_group("Source Files" FILES ${AWS_CRT_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\\external" FILES ${AWS_CRT_EXTERNAL_SRC})
endif ()
endif()
add_library(${CMAKE_PROJECT_NAME} ${AWS_CRT_CPP_SRC})
if (BUILD_SHARED_LIBS)
target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC -DAWS_CRT_CPP_USE_IMPORT_EXPORT)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE -DAWS_CRT_CPP_EXPORTS)
endif()
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES CXX_STANDARD ${CMAKE_CXX_STANDARD})
aws_prepare_symbol_visibility_args(${CMAKE_PROJECT_NAME} "AWS_CRT_CPP")
#set warnings
if (MSVC)
target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE /W4 /WX /wd4068)
else ()
target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE -Wall -Wno-long-long -pedantic -Werror)
endif ()
if (CMAKE_BUILD_TYPE STREQUAL "" OR CMAKE_BUILD_TYPE MATCHES Debug)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE "-DDEBUG_BUILD")
endif ()
target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
find_package(aws-c-http REQUIRED)
find_package(aws-c-mqtt REQUIRED)
find_package(aws-c-cal REQUIRED)
target_link_libraries(${CMAKE_PROJECT_NAME} AWS::aws-c-cal AWS::aws-c-http AWS::aws-c-mqtt)
install(FILES ${AWS_CRT_HEADERS} DESTINATION "include/aws/crt" 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_EXTERNAL_HEADERS} DESTINATION "include/aws/crt/external" COMPONENT Development)
install(
TARGETS ${CMAKE_PROJECT_NAME}
EXPORT ${CMAKE_PROJECT_NAME}-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Development
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Development
RUNTIME DESTINATION bin COMPONENT Runtime
)
install(EXPORT "${CMAKE_PROJECT_NAME}-targets"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/${CMAKE_PROJECT_NAME}/cmake/"
NAMESPACE AWS::
COMPONENT Development)
configure_file("cmake/${CMAKE_PROJECT_NAME}-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}-config.cmake"
@ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}-config.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/${CMAKE_PROJECT_NAME}/cmake/"
COMPONENT Development)
enable_testing()
add_subdirectory(tests)
add_subdirectory(samples/mqtt_pub_sub)