forked from duckdb/duckdb-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
231 lines (197 loc) · 11.4 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
cmake_minimum_required(VERSION 2.8.12)
# Set extension name here
set(TARGET_NAME aws)
set(EXTENSION_NAME ${TARGET_NAME}_extension)
project(${TARGET_NAME})
include_directories(src/include)
set(EXTENSION_SOURCES src/aws_extension.cpp)
add_library(${EXTENSION_NAME} STATIC ${EXTENSION_SOURCES})
set(PARAMETERS "-warnings")
build_loadable_extension(${TARGET_NAME} ${PARAMETERS} ${EXTENSION_SOURCES})
include(ExternalProject)
########### CURL ###########
if(WIN32)
set(CURL_LIBNAME libcurl.lib)
else()
set(CURL_LIBNAME libcurl.a)
endif()
ExternalProject_Add(curl
GIT_REPOSITORY "https://github.com/curl/curl"
GIT_TAG "curl-7_88_1"
GIT_CONFIG advice.detachedHead=false
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/curl"
CMAKE_CACHE_ARGS
"-DBUILD_SHARED_LIBS:BOOL=OFF"
"-DBUILD_CURL_EXE:BOOL=OFF"
"-DCURL_USE_OPENSSL:BOOL=ON"
# This crap we don't need?
"-DCURL_USE_LIBSSH2:BOOL=OFF"
"-DCURL_DISABLE_LDAP:BOOL=ON"
"-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON"
"-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/curl_install"
"-DCMAKE_INSTALL_LIBDIR:STRING=lib"
"-DOPENSSL_USE_STATIC_LIBS:BOOL=ON"
"-DOPENSSL_ROOT_DIR:STRING=/opt/homebrew/Cellar/[email protected]"
"-DCMAKE_OSX_ARCHITECTURES:STRING=${CMAKE_OSX_ARCHITECTURES}"
BUILD_BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/curl_install/lib/${CURL_LIBNAME}"
)
add_library(curl_static STATIC IMPORTED)
set_property(TARGET curl_static PROPERTY IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/curl_install/lib/${CURL_LIBNAME}")
########### ZLIB ###########
if(WIN32)
set(ZLIB_LIBNAME zlib.lib)
else()
set(ZLIB_LIBNAME libz.a)
endif()
ExternalProject_Add(zlib
GIT_REPOSITORY https://github.com/madler/zlib.git
GIT_TAG v1.2.11
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/zlib-src"
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/zlib-build"
CMAKE_CACHE_ARGS
"-DBUILD_SHARED_LIBS:BOOL=OFF"
"-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/zlib_install"
"-DCMAKE_OSX_ARCHITECTURES:STRING=${CMAKE_OSX_ARCHITECTURES}"
"-DCMAKE_INSTALL_LIBDIR:STRING=lib"
"-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON"
BUILD_BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/zlib_install/lib/${ZLIB_LIBNAME}"
)
add_library(zlib_static STATIC IMPORTED)
set_property(TARGET zlib_static PROPERTY IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/zlib_install/lib/${ZLIB_LIBNAME}")
########### AWS SDK ###########
if (OSX_BUILD_UNIVERSAL)
set(CMAKE_OSX_ARCHITECTURES_PIPESEPARATOR "x86_64|arm64")
endif()
ExternalProject_Add(awssdk
GIT_REPOSITORY https://github.com/aws/aws-sdk-cpp.git
GIT_TAG 1.11.35
LIST_SEPARATOR "|"
CMAKE_ARGS -DBUILD_SHARED_LIBS=OFF
# -DBUILD_ONLY=core;s3;s3-crt;transfer
-DBUILD_ONLY=core
-DENABLE_TESTING=OFF
-DCMAKE_INSTALL_LIBDIR=lib
-DSIMPLE_INSTALL=ON
-DCMAKE_INSTALL_PREFIX=install
-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES_PIPESEPARATOR}
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
# Note: there's options in the aws sdk build `BUILD_ZLIB` and `BUILD_CURL`, which would be nice here, but I
# couldn't get them to work for the life of me, so instead we use the external projects above instead
BUILD_ALWAYS TRUE
TEST_COMMAND ""
BUILD_BYPRODUCTS
"${CMAKE_CURRENT_BINARY_DIR}/awssdk-prefix/src/awssdk-build/install/lib/${CMAKE_STATIC_LIBRARY_PREFIX}aws-cpp-sdk-core${CMAKE_STATIC_LIBRARY_SUFFIX}"
"${CMAKE_CURRENT_BINARY_DIR}/awssdk-prefix/src/awssdk-build/install/lib/${CMAKE_STATIC_LIBRARY_PREFIX}aws-crt-cpp${CMAKE_STATIC_LIBRARY_SUFFIX}"
"${CMAKE_CURRENT_BINARY_DIR}/awssdk-prefix/src/awssdk-build/install/lib/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-s3${CMAKE_STATIC_LIBRARY_SUFFIX}"
"${CMAKE_CURRENT_BINARY_DIR}/awssdk-prefix/src/awssdk-build/install/lib/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-auth${CMAKE_STATIC_LIBRARY_SUFFIX}"
"${CMAKE_CURRENT_BINARY_DIR}/awssdk-prefix/src/awssdk-build/install/lib/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-event-stream${CMAKE_STATIC_LIBRARY_SUFFIX}"
"${CMAKE_CURRENT_BINARY_DIR}/awssdk-prefix/src/awssdk-build/install/lib/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-http${CMAKE_STATIC_LIBRARY_SUFFIX}"
"${CMAKE_CURRENT_BINARY_DIR}/awssdk-prefix/src/awssdk-build/install/lib/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-mqtt${CMAKE_STATIC_LIBRARY_SUFFIX}"
"${CMAKE_CURRENT_BINARY_DIR}/awssdk-prefix/src/awssdk-build/install/lib/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-sdkutils${CMAKE_STATIC_LIBRARY_SUFFIX}"
"${CMAKE_CURRENT_BINARY_DIR}/awssdk-prefix/src/awssdk-build/install/lib/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-io${CMAKE_STATIC_LIBRARY_SUFFIX}"
"${CMAKE_CURRENT_BINARY_DIR}/awssdk-prefix/src/awssdk-build/install/lib/${CMAKE_STATIC_LIBRARY_PREFIX}aws-checksums${CMAKE_STATIC_LIBRARY_SUFFIX}"
"${CMAKE_CURRENT_BINARY_DIR}/awssdk-prefix/src/awssdk-build/install/lib/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-compression${CMAKE_STATIC_LIBRARY_SUFFIX}"
"${CMAKE_CURRENT_BINARY_DIR}/awssdk-prefix/src/awssdk-build/install/lib/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-cal${CMAKE_STATIC_LIBRARY_SUFFIX}"
"${CMAKE_CURRENT_BINARY_DIR}/awssdk-prefix/src/awssdk-build/install/lib/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-common${CMAKE_STATIC_LIBRARY_SUFFIX}"
"${CMAKE_CURRENT_BINARY_DIR}/awssdk-prefix/src/awssdk-build/install/lib/${CMAKE_STATIC_LIBRARY_PREFIX}s2n${CMAKE_STATIC_LIBRARY_SUFFIX}"
)
add_library(awssdk_core STATIC IMPORTED)
add_dependencies(awssdk_core awssdk_project)
set_target_properties(awssdk_core PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/awssdk-prefix/src/awssdk-build/install/lib/${CMAKE_STATIC_LIBRARY_PREFIX}aws-cpp-sdk-core${CMAKE_STATIC_LIBRARY_SUFFIX}")
add_library(awssdk_crt STATIC IMPORTED)
add_dependencies(awssdk_crt awssdk_project)
set_target_properties(awssdk_crt PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/awssdk-prefix/src/awssdk-build/install/lib/${CMAKE_STATIC_LIBRARY_PREFIX}aws-crt-cpp${CMAKE_STATIC_LIBRARY_SUFFIX}")
add_library(awssdk_c_s3 STATIC IMPORTED)
add_dependencies(awssdk_c_s3 awssdk_project)
set_target_properties(awssdk_c_s3 PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/awssdk-prefix/src/awssdk-build/install/lib/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-s3${CMAKE_STATIC_LIBRARY_SUFFIX}")
add_library(awssdk_c_auth STATIC IMPORTED)
add_dependencies(awssdk_c_auth awssdk_project)
set_target_properties(awssdk_c_auth PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/awssdk-prefix/src/awssdk-build/install/lib/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-auth${CMAKE_STATIC_LIBRARY_SUFFIX}")
add_library(awssdk_c_eventstream STATIC IMPORTED)
add_dependencies(awssdk_c_eventstream awssdk_project)
set_target_properties(awssdk_c_eventstream PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/awssdk-prefix/src/awssdk-build/install/lib/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-event-stream${CMAKE_STATIC_LIBRARY_SUFFIX}")
add_library(awssdk_c_http STATIC IMPORTED)
add_dependencies(awssdk_c_http awssdk_project)
set_target_properties(awssdk_c_http PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/awssdk-prefix/src/awssdk-build/install/lib/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-http${CMAKE_STATIC_LIBRARY_SUFFIX}")
add_library(awssdk_c_mqtt STATIC IMPORTED)
add_dependencies(awssdk_c_mqtt awssdk_project)
set_target_properties(awssdk_c_mqtt PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/awssdk-prefix/src/awssdk-build/install/lib/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-mqtt${CMAKE_STATIC_LIBRARY_SUFFIX}")
add_library(awssdk_c_io STATIC IMPORTED)
add_dependencies(awssdk_c_io awssdk_project)
set_target_properties(awssdk_c_io PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/awssdk-prefix/src/awssdk-build/install/lib/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-io${CMAKE_STATIC_LIBRARY_SUFFIX}")
add_library(awssdk_c_sdkutils STATIC IMPORTED)
add_dependencies(awssdk_c_sdkutils awssdk_project)
set_target_properties(awssdk_c_sdkutils PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/awssdk-prefix/src/awssdk-build/install/lib/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-sdkutils${CMAKE_STATIC_LIBRARY_SUFFIX}")
add_library(awssdk_checksums STATIC IMPORTED)
add_dependencies(awssdk_checksums awssdk_project)
set_target_properties(awssdk_checksums PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/awssdk-prefix/src/awssdk-build/install/lib/${CMAKE_STATIC_LIBRARY_PREFIX}aws-checksums${CMAKE_STATIC_LIBRARY_SUFFIX}")
add_library(awssdk_c_compression STATIC IMPORTED)
add_dependencies(awssdk_c_compression awssdk_project)
set_target_properties(awssdk_c_compression PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/awssdk-prefix/src/awssdk-build/install/lib/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-compression${CMAKE_STATIC_LIBRARY_SUFFIX}")
add_library(awssdk_c_cal STATIC IMPORTED)
add_dependencies(awssdk_c_cal awssdk_project)
set_target_properties(awssdk_c_cal PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/awssdk-prefix/src/awssdk-build/install/lib/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-cal${CMAKE_STATIC_LIBRARY_SUFFIX}")
add_library(awssdk_c_common STATIC IMPORTED)
add_dependencies(awssdk_c_common awssdk_project)
set_target_properties(awssdk_c_common PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/awssdk-prefix/src/awssdk-build/install/lib/${CMAKE_STATIC_LIBRARY_PREFIX}aws-c-common${CMAKE_STATIC_LIBRARY_SUFFIX}")
add_library(awssdk_libs2n STATIC IMPORTED)
add_dependencies(awssdk_libs2n awssdk_project)
set_target_properties(awssdk_libs2n PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/awssdk-prefix/src/awssdk-build/install/lib/${CMAKE_STATIC_LIBRARY_PREFIX}s2n${CMAKE_STATIC_LIBRARY_SUFFIX}")
add_dependencies(${EXTENSION_NAME} awssdk)
######################
SET(OPENSSL_USE_STATIC_LIBS ON)
find_package(OpenSSL REQUIRED)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/awssdk-prefix/src/awssdk-build/install/include)
message(${CMAKE_CURRENT_BINARY_DIR})
if(APPLE)
# somehow aws-sdk doesn't build libs2n on apple/clang
# seems not needed on mac with security framework,
# otherwise can build from https://github.com/aws/s2n-tls
set(AWS_FRAMEWORK "-framework corefoundation -framework SystemConfiguration -framework security")
set(AWS_S2N_LIBRARY "")
elseif(WIN32)
set(AWS_S2N_LIBRARY "")
else()
set(AWS_S2N_LIBRARY awssdk_libs2n)
endif()
if(WIN32)
target_link_libraries(${EXTENSION_NAME}
wininet.lib
winhttp.lib
bcrypt.lib
ncrypt.lib
userenv.lib
rpcrt4.lib
secur32.lib
advapi32.lib
shLwApi.lib
Version.lib
)
endif()
target_link_libraries(${EXTENSION_NAME}
awssdk_core
awssdk_crt
awssdk_c_s3
awssdk_c_auth
awssdk_c_eventstream
awssdk_c_http
awssdk_c_mqtt
awssdk_c_sdkutils
awssdk_c_io
awssdk_checksums
awssdk_c_compression
awssdk_c_cal
awssdk_c_common
${AWS_S2N_LIBRARY}
curl_static
zlib_static
OpenSSL::SSL
OpenSSL::Crypto
${AWS_FRAMEWORK}
${AWS_WIN_LIBS}
)
install(
TARGETS ${EXTENSION_NAME}
EXPORT "${DUCKDB_EXPORT_SET}"
LIBRARY DESTINATION "${INSTALL_LIB_DIR}"
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}")