forked from awslabs/aws-crt-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
220 lines (180 loc) · 7.45 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
cmake_minimum_required(VERSION 3.1)
project(aws-crt-jni C)
option(BUILD_DEPS "Builds aws common runtime dependencies as part of build" ON)
if (POLICY CMP0069)
cmake_policy(SET CMP0069 NEW) # Enable LTO/IPO if available in the compiler, see AwsCFlags
endif()
if (POLICY CMP0077)
cmake_policy(SET CMP0077 NEW) # Enable options to get their values from normal variables
endif()
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 WIN32 AND NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
endif()
# 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})
# Local CMake scripts
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
set(AWS_LIBRARY_OUTPUT_DIR "${CMAKE_BINARY_DIR}/lib")
if (ANDROID)
set(ANDROID_DEPS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/target/cmake-build/deps/${ANDROID_ABI})
set(AWS_LIBRARY_OUTPUT_DIR "${CMAKE_BINARY_DIR}/../../../lib")
endif()
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 OFF)
add_subdirectory(crt/aws-c-common)
if (UNIX AND NOT APPLE)
set(BUILD_LIBSSL OFF CACHE BOOL "Don't need libssl, only need libcrypto")
set(DISABLE_PERL ON CACHE BOOL "Disable codegen")
set(DISABLE_GO ON CACHE BOOL "Disable codegen")
# temporarily disable certain warnings as errors for the aws-lc build
set(OLD_CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
if (NOT MSVC)
check_c_compiler_flag(-Wno-stringop-overflow HAS_WNO_STRINGOP_OVERFLOW)
if (HAS_WNO_STRINGOP_OVERFLOW)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-stringop-overflow")
endif()
check_c_compiler_flag(-Wno-array-parameter HAS_WNO_ARRAY_PARAMETER)
if (HAS_WNO_ARRAY_PARAMETER)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-array-parameter")
endif()
endif()
add_subdirectory(crt/aws-lc)
# restore previous build flags
set(CMAKE_C_FLAGS "${OLD_CMAKE_C_FLAGS}")
set(SEARCH_LIBCRYPTO OFF CACHE BOOL "Let S2N use libcrypto from AWS-LC.")
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)
else()
include(AwsFindPackage)
include(AwsCFlags)
set(IN_SOURCE_BUILD OFF)
endif()
include(UseJava)
include(AwsPlatformDetect)
include(AwsSharedLibSetup)
file(GLOB AWS_CRT_JAVA_HEADERS
"include/aws/jni/*.h"
)
file(GLOB AWS_CRT_JAVA_SRC
"src/native/*.c"
)
if (WIN32)
file(GLOB AWS_CRT_JAVA_OS_SRC
"src/native/windows/*.c"
)
if (MSVC)
source_group("Header Files\\aws\\jni" FILES ${AWS_CRT_JAVA_HEADERS})
source_group("Source Files" FILES ${AWS_CRT_JAVA_SRC})
source_group("Source Files\\windows" FILES ${AWS_CRT_JAVA_OS_SRC})
endif ()
elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux")
file(GLOB AWS_CRT_JAVA_OS_SRC
"src/native/linux/*.c"
"src/native/posix/*.c"
)
elseif (APPLE)
file(GLOB AWS_CRT_JAVA_OS_SRC
"src/native/bsd/*.c"
"src/native/posix/*.c"
"src/native/darwin/*.c"
)
elseif (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
file(GLOB AWS_CRT_JAVA_OS_SRC
"src/native/bsd/*.c"
"src/native/posix/*.c"
)
endif()
file(GLOB CRT_JAVA_HEADERS
${AWS_CRT_JAVA_HEADERS}
)
file(GLOB CRT_JAVA_SRC
${AWS_CRT_JAVA_SRC}
${AWS_CRT_JAVA_OS_SRC}
)
# figure out the target platform info and output the lib there
aws_detect_target_platform(TARGET_OS TARGET_ARCH)
message(STATUS "Compiling for ${TARGET_OS}-${TARGET_ARCH}")
set(TARGET_LIB_DIR "${AWS_LIBRARY_OUTPUT_DIR}/${TARGET_OS}/${TARGET_ARCH}")
# shared lib that contains the CRT and JNI bindings, to be loaded by java
add_library(${PROJECT_NAME} SHARED ${CRT_JAVA_HEADERS} ${CRT_JAVA_SRC})
aws_use_package(aws-c-http)
aws_use_package(aws-c-mqtt)
aws_use_package(aws-c-auth)
aws_use_package(aws-c-event-stream)
aws_use_package(aws-c-s3)
target_link_libraries(${PROJECT_NAME} ${DEP_AWS_LIBS})
if (NOT MSVC AND NOT APPLE)
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-z noexecstack")
endif()
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE C)
# for non-msvc, library output will control the shared lib output
set_target_properties(${PROJECT_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${TARGET_LIB_DIR})
# for msvc, runtime controls where dlls are output
set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${TARGET_LIB_DIR})
set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${TARGET_LIB_DIR})
set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${TARGET_LIB_DIR})
set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${TARGET_LIB_DIR})
aws_set_common_properties(${PROJECT_NAME})
set(CMAKE_C_FLAGS_DEBUGOPT "")
set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 99)
#set warnings
if (MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX -D_CRT_SECURE_NO_WARNINGS)
else ()
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wno-long-long -pedantic -Werror)
endif ()
# find JNI and add the include path (except on android where gradle injects it)
if (NOT ANDROID)
if (NOT APPLE)
set(JAVA_AWT_LIBRARY NotNeeded)
set(JAVA_AWT_INCLUDE_PATH NotNeeded)
endif()
if (DEFINED ENV{OVERRIDE_JAVA_HOME})
# This override might be set by builder to avoid using the JAVA_HOME modified by gradle
file(TO_CMAKE_PATH "$ENV{OVERRIDE_JAVA_HOME}" OVERRIDE_JAVA_HOME)
set(JAVA_HOME "${OVERRIDE_JAVA_HOME}")
message(STATUS "Overriding JAVA_HOME to ${OVERRIDE_JAVA_HOME}")
endif()
message(STATUS "JAVA_HOME=$ENV{JAVA_HOME}")
find_package(JNI REQUIRED)
target_include_directories(${PROJECT_NAME} PRIVATE ${JNI_INCLUDE_DIRS})
endif()
target_include_directories(${PROJECT_NAME} PRIVATE "src/native")
if (CMAKE_BUILD_TYPE STREQUAL "" OR CMAKE_BUILD_TYPE MATCHES Debug)
target_compile_definitions(${PROJECT_NAME} PRIVATE "-DDEBUG_BUILD")
endif ()
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
aws_split_debug_info(${PROJECT_NAME})