forked from questdb/questdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
334 lines (287 loc) · 11.1 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
cmake_minimum_required(VERSION 3.5)
project(questdb)
include(ExternalProject)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_C_VISIBILITY_PRESET hidden)
# use this is for debug purposes
#set(CMAKE_VERBOSE_MAKEFILE ON)
# deal with windows slashes in JAVA_HOME
if ($ENV{JAVA_HOME})
FILE(TO_CMAKE_PATH $ENV{JAVA_HOME} JAVA_HOME)
endif ($ENV{JAVA_HOME})
set(
VCL_FILES
src/main/c/share/vec_agg.cpp
src/main/c/share/vec_ts_agg.cpp
src/main/c/share/ooo_dispatch.cpp
src/main/c/share/geohash_dispatch.cpp
)
set(
VCL_FILES_SSE2
src/main/c/share/vcl/instrset_detect.cpp
src/main/c/share/rosti.cpp
src/main/c/share/vec_agg_vanilla.cpp
src/main/c/share/vec_agg.cpp
src/main/c/share/vec_int_key_agg.cpp
src/main/c/share/vec_ts_agg.cpp
src/main/c/share/ooo_dispatch.cpp
src/main/c/share/geohash_dispatch.cpp
)
set(
SOURCE_FILES
src/main/c/share/simd.h
src/main/c/share/files.h
src/main/c/share/zip.h
src/main/c/share/net.h
src/main/c/share/zip.c
src/main/c/share/os.h
src/main/c/share/vec_agg_vanilla.h
src/main/c/share/util.cpp
src/main/c/share/ooo.cpp
src/main/c/share/txn_board.cpp
src/main/c/share/bitmap_index_utils.h
src/main/c/share/bitmap_index_utils.cpp
src/main/c/share/geohash.cpp
src/main/c/share/jit/compiler.h
src/main/c/share/jit/compiler.cpp
src/main/c/share/cpprt_overrides.h
src/main/c/share/cpprt_overrides.cpp
src/main/c/share/dedup.cpp
src/main/c/share/byte_sink.cpp
src/main/c/share/byte_sink.h
)
# JNI includes
include_directories($ENV{JAVA_HOME}/include/)
if (APPLE)
include_directories($ENV{JAVA_HOME}/include/darwin/)
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^arm64")
set(AARCH64 1)
set(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/main/resources/io/questdb/bin/armosx)
else()
set(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/main/resources/io/questdb/bin/osx)
endif()
set(
SOURCE_FILES ${SOURCE_FILES}
src/main/c/osx/kqueue.c
src/main/c/share/net.c
src/main/c/osx/affinity.c
src/main/c/osx/accept.c
src/main/c/freebsd/files.c
)
elseif (UNIX)
if (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
MESSAGE("Building for FreeBSD")
include_directories($ENV{JAVA_HOME}/include/freebsd/)
set(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/main/resources/io/questdb/bin/freebsd)
set(
SOURCE_FILES ${SOURCE_FILES}
src/main/c/freebsd/kqueue.c
src/main/c/share/net.c
src/main/c/freebsd/affinity.c
src/main/c/freebsd/accept.c
src/main/c/freebsd/files.c
)
else (CMAKE_SYSTEM_NAME MATCHES "Linux")
MESSAGE("Building for GNU/Linux")
include_directories($ENV{JAVA_HOME}/include/linux/)
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64")
set(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/main/resources/io/questdb/bin/armlinux)
set(AARCH64 1)
else ()
set(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/main/resources/io/questdb/bin/linux)
endif ()
set(
SOURCE_FILES ${SOURCE_FILES}
src/main/c/share/net.c
src/main/c/linux/epoll.c
src/main/c/linux/recvmmsg.c
src/main/c/linux/affinity.c
src/main/c/linux/accept.c
src/main/c/linux/files.c
src/main/c/linux/io_uring.c
)
endif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
endif (APPLE)
if (WIN32)
include_directories($ENV{JAVA_HOME}/include/win32/)
set(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/main/resources/io/questdb/bin/windows)
set(
SOURCE_FILES ${SOURCE_FILES}
src/main/c/windows/files.c
src/main/c/windows/files.h
src/main/c/windows/os.c
src/main/c/windows/net.c
src/main/c/windows/select.h
src/main/c/windows/errno.h
src/main/c/windows/select.c
src/main/c/windows/timer.c
src/main/c/windows/timer.h
src/main/c/windows/accept.c
src/main/c/share/fs.h
)
else ()
set(
SOURCE_FILES ${SOURCE_FILES}
src/main/c/share/files.c
src/main/c/share/os.c
)
endif (WIN32)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${OUTPUT})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OUTPUT})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OUTPUT})
#asmjit
if (NOT DEFINED ASMJIT_EMBED)
set(ASMJIT_EMBED TRUE)
endif()
include(FetchContent)
FetchContent_Declare(
asmjit
GIT_REPOSITORY https://github.com/questdb/asmjit.git
GIT_TAG 4ec760a3d1f69e32ba460ecd2513f29b8428700b # Fixed typos in documentation
)
FetchContent_GetProperties(asmjit)
if (NOT asmjit_POPULATED)
FetchContent_Populate(asmjit)
endif()
include("${asmjit_SOURCE_DIR}/CMakeLists.txt")
include_directories(${asmjit_SOURCE_DIR}/src SYSTEM)
add_compile_definitions(ASMJIT_NO_STDCXX)
# use this is for debug purposes
#add_compile_definitions(ASMJIT_BUILD_DEBUG)
if (NOT DEFINED JIT_TEST)
set(JIT_TEST FALSE)
endif()
if(JIT_TEST)
include_directories(${asmjit_SOURCE_DIR}/test SYSTEM)
add_executable(jittests src/test/c/jittests/test_app.cpp)
target_link_libraries(jittests questdb)
endif()
#zlib
set(ZLIB_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/main/c/share/zlib-1.2.8)
include(${ZLIB_SOURCE_DIR}/CMakeLists.txt)
#liburing
if (UNIX AND NOT APPLE AND CMAKE_SYSTEM_NAME MATCHES "Linux")
MESSAGE("Downloading io_uring")
ExternalProject_Add(
liburing_git
GIT_REPOSITORY http://github.com/axboe/liburing.git
GIT_TAG liburing-2.2
BUILD_IN_SOURCE 1
BUILD_BYPRODUCTS "<SOURCE_DIR>/src/liburing.a"
BUILD_COMMAND make "CC=${CMAKE_C_COMPILER}" "CXX=${CMAKE_CXX_COMPILER}" "AR=${CMAKE_AR}" "RANLIB=${CMAKE_RANLIB}"
CONFIGURE_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
LOG_BUILD ON
)
ExternalProject_Get_Property(liburing_git SOURCE_DIR)
add_library(liburing INTERFACE)
add_dependencies(liburing liburing_git)
target_include_directories(liburing INTERFACE ${SOURCE_DIR}/src/include)
target_link_libraries(liburing INTERFACE ${SOURCE_DIR}/src/liburing.a)
endif ()
# ZLIB_SRCS is defined in Zlib Cmake config
add_library(questdb SHARED ${SOURCE_FILES} ${ZLIB_SRCS} ${ASMJIT_SRC})
set(COMMON_OPTIONS "-Wno-gnu-anonymous-struct;-Wno-nested-anon-types;-Wno-unused-parameter;-fPIC;-fno-rtti;-fno-exceptions")
set(DEBUG_OPTIONS "-Wall;-pedantic;-Wextra;-g;-O0")
set(RELEASE_OPTIONS "-O3")
list(APPEND DEBUG_OPTIONS "${ASMJIT_CFLAGS};${COMMON_OPTIONS}")
list(APPEND RELEASE_OPTIONS "${ASMJIT_CFLAGS};${COMMON_OPTIONS}")
if (UNIX AND NOT APPLE AND CMAKE_SYSTEM_NAME MATCHES "Linux")
target_link_libraries(questdb liburing)
add_dependencies(questdb liburing)
endif ()
if (AARCH64)
add_compile_definitions(__aarch64__)
## on ARM64 we use vanilla arithmetic functions for now
set(
AARCH64_FILES
src/main/c/share/rosti.cpp
src/main/c/aarch64/vect.cpp
src/main/c/share/vec_int_key_agg.cpp
src/main/c/share/vec_agg_vanilla.cpp
src/main/c/share/ooo_dispatch_vanilla.cpp
src/main/c/share/geohash_dispatch_vanilla.cpp
)
add_library(questdb-aarch64 OBJECT ${AARCH64_FILES})
target_compile_options(questdb-aarch64 PRIVATE "-fPIC"
"$<$<CONFIG:DEBUG>:${DEBUG_OPTIONS}>"
"$<$<CONFIG:RELEASE>:${RELEASE_OPTIONS}>")
target_link_libraries(
questdb
questdb-aarch64
)
target_compile_options(questdb PRIVATE
"$<$<CONFIG:DEBUG>:${DEBUG_OPTIONS}>"
"$<$<CONFIG:RELEASE>:${RELEASE_OPTIONS}>")
else ()
#assembler subroutines by Agner Fog
set(ASMLIB_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/main/c/share/asmlib/)
include(${ASMLIB_SOURCE_DIR}CMakeLists.txt)
## We need to compile VCL four different times with different CXX options
## for different instruction sets. As vect.cpp compiles it will produce
## different function names for corresponding instruction sets.
## Results of these compilations are then combined together in a single library.
## This way same library will have a set of functions for each instruction sets.
## Java will then call a dispatcher, which will check instruction set for the runtime
## and fetch method pointer to the relevant implementation.
# SSE 4.1 lib
add_library(questdb-sse4 OBJECT ${VCL_FILES})
target_compile_options(questdb-sse4 PRIVATE "-m64;-msse4.1;-fPIC"
"$<$<CONFIG:DEBUG>:${DEBUG_OPTIONS}>"
"$<$<CONFIG:RELEASE>:${RELEASE_OPTIONS}>")
# AVX2 lib
add_library(questdb-avx2 OBJECT ${VCL_FILES})
target_compile_options(questdb-avx2 PRIVATE "-m64;-mavx2;-fPIC;-mfma"
"$<$<CONFIG:DEBUG>:${DEBUG_OPTIONS}>"
"$<$<CONFIG:RELEASE>:${RELEASE_OPTIONS}>")
#AVX512 lib
add_library(questdb-avx512 OBJECT ${VCL_FILES})
# A_memset, A_memcpy are faster on avx512 but slower on other CPU's on Linux
target_compile_definitions(questdb-avx512 PRIVATE ENABLE_ASMLIB)
target_compile_options(questdb-avx512 PRIVATE "-m64;-mavx512f;-fPIC;-mfma;-mavx512vl;-mavx512bw;-mavx512dq"
"$<$<CONFIG:DEBUG>:${DEBUG_OPTIONS}>"
"$<$<CONFIG:RELEASE>:${RELEASE_OPTIONS}>")
#SSE2 lib
add_library(questdb-sse2 OBJECT ${VCL_FILES_SSE2})
target_link_libraries(
questdb-sse2
questdb-sse4
questdb-avx2
questdb-avx512
)
if (WIN32)
target_compile_options(questdb-sse2 PRIVATE "-m64;-march=core2;-msse2;-Wno-attributes"
"$<$<CONFIG:DEBUG>:${DEBUG_OPTIONS}>"
"$<$<CONFIG:RELEASE>:${RELEASE_OPTIONS}>")
else ()
target_compile_options(questdb-sse2 PRIVATE "-m64;-march=core2;-msse2;-fPIC"
"$<$<CONFIG:DEBUG>:${DEBUG_OPTIONS}>"
"$<$<CONFIG:RELEASE>:${RELEASE_OPTIONS}>")
endif (WIN32)
target_compile_options(questdb PRIVATE "-m64"
"$<$<CONFIG:DEBUG>:${DEBUG_OPTIONS}>"
"$<$<CONFIG:RELEASE>:${RELEASE_OPTIONS}>")
## Uncomment to measure time of ooo.cpp methods
## add_compile_definitions(OOO_CPP_PROFILE_TIMING)
target_link_libraries(
questdb
questdb-sse2
questdb-sse4
questdb-avx2
questdb-avx512
asm
)
endif (AARCH64)
if (WIN32)
target_link_libraries(questdb wsock32 ws2_32 secur32 shlwapi psapi -s -static-libgcc)
target_compile_options(questdb PRIVATE -fno-threadsafe-statics)
elseif (APPLE)
target_link_libraries(questdb -nostdlib++ -dead_strip -lc++)
else ()
target_compile_options(questdb PRIVATE -fno-threadsafe-statics -ffunction-sections -fdata-sections)
target_link_libraries(questdb rt -Wl,--gc-sections -Wl,--exclude-libs=ALL -static-libgcc)
endif (WIN32)