-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathCMakeLists.txt
223 lines (179 loc) · 7.11 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
cmake_minimum_required(VERSION 3.25)
project(sqlflite)
set(CMAKE_CXX_STANDARD 17)
# Function to retrieve the latest Git tag
function(get_latest_git_tag OUTPUT_VARIABLE)
execute_process(
COMMAND git describe --tags --abbrev=0
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE RETURN_VALUE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(${OUTPUT_VARIABLE} ${RETURN_VALUE} PARENT_SCOPE)
endfunction()
# Set the version
get_latest_git_tag(LATEST_TAG)
set(PROJECT_VERSION ${LATEST_TAG})
# Display variable values using message
message(STATUS "PROJECT_VERSION: ${PROJECT_VERSION}")
# Configure a header file with the version
configure_file(
${CMAKE_SOURCE_DIR}/src/library/include/version.h.in
${CMAKE_SOURCE_DIR}/src/library/include/version.h
)
# --------------------- Arrow ---------------------
configure_file(third_party/Arrow_CMakeLists.txt.in arrow/CMakeLists.txt)
execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/arrow"
)
execute_process(COMMAND "${CMAKE_COMMAND}" --build .
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/arrow"
)
set(ARROW_INSTALL_DIR "${CMAKE_BINARY_DIR}/third_party/arrow")
find_package(Arrow REQUIRED PATHS ${ARROW_INSTALL_DIR} NO_DEFAULT_PATH)
find_package(ArrowFlight REQUIRED PATHS ${ARROW_INSTALL_DIR} NO_DEFAULT_PATH)
find_package(ArrowFlightSql REQUIRED PATHS ${ARROW_INSTALL_DIR} NO_DEFAULT_PATH)
# --------------------- SQLite ---------------------
configure_file(third_party/SQLite_CMakeLists.txt.in sqlite/CMakeLists.txt)
execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/sqlite"
)
execute_process(COMMAND "${CMAKE_COMMAND}" --build .
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/sqlite"
)
set(SQLITE_INCLUDE_DIR "${CMAKE_BINARY_DIR}/third_party/sqlite/src/sqlite_project")
set(SQLITE_LIBRARY_PATH "${CMAKE_BINARY_DIR}/third_party/sqlite/src/sqlite_project-build/sqlite3-sqlite3.o")
add_library(sqlite STATIC IMPORTED)
set_property(TARGET sqlite PROPERTY IMPORTED_LOCATION ${SQLITE_LIBRARY_PATH})
# --------------------- DuckDB ---------------------
configure_file(third_party/DuckDB_CMakeLists.txt.in duckdb/CMakeLists.txt)
execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/duckdb"
)
execute_process(COMMAND "${CMAKE_COMMAND}" --build .
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/duckdb"
)
set(DUCKDB_INSTALL_DIR "${CMAKE_BINARY_DIR}/third_party/duckdb")
set(DUCKDB_LIBRARY_PATH "${DUCKDB_INSTALL_DIR}/lib/libduckdb_static.a")
set(DUCKDB_INCLUDE_DIR "${DUCKDB_INSTALL_DIR}/include")
add_library(duckdb STATIC IMPORTED)
set_property(TARGET duckdb PROPERTY IMPORTED_LOCATION ${DUCKDB_LIBRARY_PATH})
set_property(TARGET duckdb APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${DUCKDB_INCLUDE_DIR})
target_link_libraries(duckdb
INTERFACE
"${DUCKDB_INSTALL_DIR}/lib/libduckdb_fastpforlib.a"
"${DUCKDB_INSTALL_DIR}/lib/libduckdb_fmt.a"
"${DUCKDB_INSTALL_DIR}/lib/libduckdb_fsst.a"
"${DUCKDB_INSTALL_DIR}/lib/libduckdb_hyperloglog.a"
"${DUCKDB_INSTALL_DIR}/lib/libduckdb_mbedtls.a"
"${DUCKDB_INSTALL_DIR}/lib/libduckdb_miniz.a"
"${DUCKDB_INSTALL_DIR}/lib/libduckdb_pg_query.a"
"${DUCKDB_INSTALL_DIR}/lib/libduckdb_re2.a"
"${DUCKDB_INSTALL_DIR}/lib/libduckdb_skiplistlib.a"
"${DUCKDB_INSTALL_DIR}/lib/libduckdb_utf8proc.a"
"${DUCKDB_INSTALL_DIR}/lib/libduckdb_yyjson.a"
"${DUCKDB_INSTALL_DIR}/lib/libparquet_extension.a"
)
# Only link jemalloc_extension on Linux x86_64 and i386 (not arm64)
if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
target_link_libraries(duckdb
INTERFACE
"${DUCKDB_INSTALL_DIR}/lib/libjemalloc_extension.a"
)
endif()
# --------------------- JWT-CPP ---------------------
configure_file(third_party/JWTCPP_CMakeLists.txt.in jwt-cpp/CMakeLists.txt)
execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/jwt-cpp"
)
execute_process(COMMAND "${CMAKE_COMMAND}" --build .
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/jwt-cpp"
)
set(JWT_CPP_INCLUDE_DIR "${CMAKE_BINARY_DIR}/third_party/jwt-cpp/include")
# --------------------------------------------------
find_package(Threads REQUIRED)
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost COMPONENTS program_options REQUIRED)
set(SQLFLITE_SQLITE_SERVER_SRCS
src/sqlite/sqlite_sql_info.cc
src/sqlite/sqlite_type_info.cc
src/sqlite/sqlite_statement.cc
src/sqlite/sqlite_statement_batch_reader.cc
src/sqlite/sqlite_server.cc
src/sqlite/sqlite_tables_schema_batch_reader.cc)
set(SQLFLITE_DUCKDB_SERVER_SRCS
src/duckdb/duckdb_sql_info.cpp
src/duckdb/duckdb_statement.cpp
src/duckdb/duckdb_statement_batch_reader.cpp
src/duckdb/duckdb_server.cpp
src/duckdb/duckdb_tables_schema_batch_reader.cpp)
# Add header file
set(HEADER_FILES src/library/include/sqlflite_library.h)
# Add a library target
add_library(sqlfliteserver STATIC
src/library/sqlflite_library.cpp
src/library/sqlflite_security.cpp
${SQLFLITE_SQLITE_SERVER_SRCS}
${SQLFLITE_DUCKDB_SERVER_SRCS}
)
set_target_properties(sqlfliteserver PROPERTIES PUBLIC_HEADER ${HEADER_FILES})
target_include_directories(sqlfliteserver PRIVATE
src/sqlite
src/duckdb
src/library/include
${SQLITE_INCLUDE_DIR}
${DUCKDB_INCLUDE_DIR}
${JWT_CPP_INCLUDE_DIR}
)
target_link_libraries(sqlfliteserver
PRIVATE
Threads::Threads
ArrowFlightSql::arrow_flight_sql_static
sqlite
duckdb
${Boost_LIBRARIES}
"-lresolv"
)
if (APPLE)
# macOS-specific libraries and options
target_link_libraries(sqlfliteserver PRIVATE "-framework CoreFoundation")
elseif (UNIX AND NOT APPLE)
target_link_libraries(sqlfliteserver PRIVATE "-lssl -lcrypto")
endif ()
# Specify the installation directory for the library
install(TARGETS sqlfliteserver
LIBRARY DESTINATION lib
PUBLIC_HEADER DESTINATION include
)
# ------------ Server Executable section ------------
add_executable(sqlflite_server
src/sqlflite_server.cpp
)
target_link_libraries(sqlflite_server PRIVATE
sqlfliteserver
${Boost_LIBRARIES}
)
target_compile_options(sqlflite_server PRIVATE "-static")
install(TARGETS sqlflite_server
DESTINATION bin
)
# ------------ Client Executable section ------------
add_executable(sqlflite_client
src/sqlflite_client.cpp
)
target_link_libraries(sqlflite_client PRIVATE
Threads::Threads
ArrowFlightSql::arrow_flight_sql_static
${Boost_LIBRARIES}
"-lresolv"
)
if (APPLE)
# macOS-specific libraries and options
target_link_libraries(sqlflite_client PRIVATE "-framework CoreFoundation")
elseif (UNIX AND NOT APPLE)
target_link_libraries(sqlflite_client PRIVATE "-lssl -lcrypto")
endif ()
target_compile_options(sqlflite_client PRIVATE "-static")
install(TARGETS sqlflite_client
DESTINATION bin
)