forked from utelle/SQLite3MultipleCiphers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
408 lines (359 loc) · 13.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
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
cmake_minimum_required(VERSION 3.24.0.0)
project(sqlite3mc)
# Helper macro
macro(_Enable_MT _target)
target_compile_options(${_target} PRIVATE
$<$<CONFIG:Release>:/MT>$<$<CONFIG:Debug>:/MTd>
)
endmacro()
set(_SQLITE3MC_REQUIRE_ZLIB OFF)
OPTION(SQLITE3MC_STATIC_RUNTIME_LINK "Link the c++ runtime statically" OFF)
OPTION(SQLITE3MC_STATIC "Build SQLITE3MC as a static library" OFF)
OPTION(SQLITE3MC_BUILD_SHELL "Builds the SQLITE3MC Shell" ON)
OPTION(SQLITE3MC_WITH_ICU "Builds SQLITE3MC with the ICU library. Will use the FindICU function to locate the library. (https://cmake.org/cmake/help/latest/module/FindICU.html)" OFF)
OPTION(SQLITE_ENABLE_DEBUG "Enable SQLite debugging" OFF)
OPTION(SQLITE_SOUNDEX "Enable the soundex() SQL function" ON)
OPTION(SQLITE_ENABLE_COLUMN_METADATA "Enable convenient access to meta-data about tables and queries" ON)
OPTION(SQLITE_SECURE_DELETE "Enable secure delete to overwrite deleted content with zeros" ON)
OPTION(SQLITE_ENABLE_FTS3 "Enable version 3 of the full-text search engine" ON)
OPTION(SQLITE_ENABLE_FTS3_PARENTHESIS "Support operators AND and NOT and nested parenthesis" ON)
OPTION(SQLITE_ENABLE_FTS4 "Enable version 4 of the full-text search engine" ON)
OPTION(SQLITE_ENABLE_FTS5 "Enable version 5 of the full-text search engine" ON)
OPTION(SQLITE_ENABLE_CARRAY "Enable extension 'carray'" ON)
OPTION(SQLITE_ENABLE_CSV "Enable extension 'csv'" ON)
OPTION(SQLITE_ENABLE_EXTFUNC "Enable extension 'extfunc'" ON)
OPTION(SQLITE_ENABLE_GEOPOLY "Enable extension 'geopoly'" ON)
OPTION(SQLITE_ENABLE_JSON1 "Enable extension 'json1'" ON)
OPTION(SQLITE_ENABLE_RTREE "Enable extension 'rtree'" ON)
OPTION(SQLITE_ENABLE_UUID "Enable extension 'uuid'" ON)
OPTION(SQLITE_USE_URI "Enable the URI filename process logic" ON)
OPTION(SQLITE_USER_AUTHENTICATION "Enable extension 'user authentication'" OFF)
OPTION(SQLITE_ENABLE_PREUPDATE_HOOK "Enable preupdate hooks" OFF)
OPTION(SQLITE_ENABLE_SESSION "Enable session extension" OFF)
OPTION(SQLITE_SHELL_IS_UTF8 "Shell command line arguments in UTF-8 encoding" ON)
# Options for library only
OPTION(SQLITE_ENABLE_FILEIO "Enable extension 'fileio'" ON)
OPTION(SQLITE_ENABLE_REGEXP "Enable extension 'regexp'" ON)
OPTION(SQLITE_ENABLE_SERIES "Enable extension 'series'" ON)
OPTION(SQLITE_ENABLE_SHA3 "Enable extension 'sha3'" ON)
# Options for shell only (compatibility with official SQLite shell)
OPTION(SQLITE_ENABLE_EXPLAIN_COMMENTS "Insert comment text into the output of EXPLAIN (shell only)" ON)
OPTION(SQLITE_ENABLE_DBPAGE_VTAB "Enable the SQLITE_DBPAGE virtual table (shell only)" ON)
OPTION(SQLITE_ENABLE_DBSTAT_VTAB "Enable the dbstat virtual table (shell only)" ON)
OPTION(SQLITE_ENABLE_STMTVTAB "Enable the SQLITE_STMT virtual table (shell only)" ON)
OPTION(SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION "Suppress 'unknown function' errors when running an EXPLAIN or EXPLAIN QUERY PLAN (shell only)" ON)
# Embedded Compression
OPTION(SQLITE3MC_USE_MINIZ "Use builtin ZLIB replacement" OFF)
# Compression/Options that require ZLIB
OPTION(SQLITE_ENABLE_COMPRESS "Enable extension 'compress'" OFF)
OPTION(SQLITE_ENABLE_SQLAR "Enable extension 'sqlar'" OFF)
OPTION(SQLITE_ENABLE_ZIPFILE "Enable extension 'zipfile'" OFF)
# Legacy Encryption Extensions
OPTION(SQLITE3MC_USE_SQLEET_LEGACY "Use sqleet legacy mode as default" OFF)
OPTION(SQLITE3MC_USE_SQLCIPHER_LEGACY "Use sqlcipher legacy mode as default" OFF)
# Additional memory security (filling freed memory allocations with zeros or random data)
OPTION(SQLITE3MC_SECURE_MEMORY "Enable pragma to secure freed memory" OFF)
# Omit AES hardware support
OPTION(SQLITE3MC_OMIT_AES_HARDWARE_SUPPORT "Omit AES hardware support" OFF)
# TCL
#OPTION(SQLITE_ENABLE_TCL "Enable TCL interface" OFF)
set(SQLITE_MAX_ATTACHED "10" CACHE STRING "Max number of attached files (must be in the range 0..125)")
set(SQLITE_DQS "0" CACHE STRING "Allow double-quoted string literals")
set_property(CACHE SQLITE_DQS PROPERTY STRINGS 0 1 2 3)
set(SQLITE_THREADSAFE 1 CACHE STRING "Set threading mode (0 = single-threaded, 1 = serialized, 2 = multi-threaded)")
set_property(CACHE SQLITE_THREADSAFE PROPERTY STRINGS 0 1 2)
set(CODEC_TYPE CHACHA20 CACHE STRING "Set default codec type")
set_property(CACHE CODEC_TYPE PROPERTY STRINGS AES128 AES256 CHACHA20 SQLCIPHER RC4 ASCON128)
if(SQLITE_ENABLE_COMPRESS OR SQLITE_ENABLE_SQLAR OR SQLITE_ENABLE_ZIPFILE)
if(NOT SQLITE3MC_USE_MINIZ)
set(_SQLITE3MC_REQUIRE_ZLIB ON)
endif()
endif()
# Setup the options
set(SQLITE3MC_BASE_DEFINITIONS
$<$<BOOL:${SQLITE_SHELL_IS_UTF8}>:SQLITE_SHELL_IS_UTF8=1>
CODEC_TYPE=CODEC_TYPE_${CODEC_TYPE}
SQLITE_DQS=${SQLITE_DQS}
SQLITE_MAX_ATTACHED=${SQLITE_MAX_ATTACHED}
$<$<BOOL:${SQLITE_USER_AUTHENTICATION}>:SQLITE_USER_AUTHENTICATION=1>
$<$<BOOL:${SQLITE_ENABLE_DEBUG}>:SQLITE_ENABLE_DEBUG=1>
SQLITE_THREADSAFE=${SQLITE_THREADSAFE}
$<$<BOOL:${SQLITE_SOUNDEX}>:SQLITE_SOUNDEX=1>
$<$<BOOL:${SQLITE_ENABLE_COLUMN_METADATA}>:SQLITE_ENABLE_COLUMN_METADATA=1>
$<$<BOOL:${SQLITE_SECURE_DELETE}>:SQLITE_SECURE_DELETE=1>
$<$<BOOL:${SQLITE_ENABLE_FTS3}>:SQLITE_ENABLE_FTS3=1>
$<$<BOOL:${SQLITE_ENABLE_FTS3_PARENTHESIS}>:SQLITE_ENABLE_FTS3_PARENTHESIS=1>
$<$<BOOL:${SQLITE_ENABLE_FTS4}>:SQLITE_ENABLE_FTS4=1>
$<$<BOOL:${SQLITE_ENABLE_FTS5}>:SQLITE_ENABLE_FTS5=1>
$<$<BOOL:${SQLITE_ENABLE_JSON1}>:SQLITE_ENABLE_JSON1=1>
$<$<BOOL:${SQLITE_ENABLE_RTREE}>:SQLITE_ENABLE_RTREE=1>
$<$<BOOL:${SQLITE_ENABLE_GEOPOLY}>:SQLITE_ENABLE_GEOPOLY=1>
$<$<BOOL:${SQLITE_ENABLE_EXTFUNC}>:SQLITE_ENABLE_EXTFUNC=1>
$<$<BOOL:${SQLITE_ENABLE_CARRAY}>:SQLITE_ENABLE_CARRAY=1>
$<$<BOOL:${SQLITE_ENABLE_UUID}>:SQLITE_ENABLE_UUID=1>
SQLITE_TEMP_STORE=2
$<$<BOOL:${SQLITE_USE_URI}>:SQLITE_USE_URI=1>
$<$<BOOL:${SQLITE_USER_AUTHENTICATION}>:SQLITE_USER_AUTHENTICATION=1>
$<$<BOOL:${SQLITE_ENABLE_PREUPDATE_HOOK}>:SQLITE_ENABLE_PREUPDATE_HOOK=1>
$<$<BOOL:${SQLITE_ENABLE_SESSION}>:SQLITE_ENABLE_SESSION=1>
$<$<BOOL:${SQLITE3MC_USE_MINIZ}>:SQLITE3MC_USE_MINIZ=1>
$<$<BOOL:${SQLITE3MC_OMIT_AES_HARDWARE_SUPPORT}>:SQLITE3MC_OMIT_AES_HARDWARE_SUPPORT=1>
# $<$<BOOL:${SQLITE_USE_TCL}>:SQLITE_USE_TCL=1>
)
set(SQLITE3MC_LIBONLY_DEFINITIONS
$<$<BOOL:${SQLITE_ENABLE_FILEIO}>:SQLITE_ENABLE_FILEIO=1>
$<$<BOOL:${SQLITE_ENABLE_REGEXP}>:SQLITE_ENABLE_REGEXP=1>
$<$<BOOL:${SQLITE_ENABLE_SERIES}>:SQLITE_ENABLE_SERIES=1>
$<$<BOOL:${SQLITE_ENABLE_SHA3}>:SQLITE_ENABLE_SHA3=1>
)
set(SQLITE3MC_ZLIB_DEFINITIONS
)
set(SQLITE3MC_SHELL_DEFINITIONS
$<$<BOOL:${SQLITE_SHELL_IS_UTF8}>:SQLITE_SHELL_IS_UTF8=1>
$<$<BOOL:${SQLITE_ENABLE_EXPLAIN_COMMENTS}>:SQLITE_ENABLE_EXPLAIN_COMMENTS=1>
$<$<BOOL:${SQLITE_ENABLE_DBPAGE_VTAB}>:SQLITE_ENABLE_DBPAGE_VTAB=1>
$<$<BOOL:${SQLITE_ENABLE_DBSTAT_VTAB}>:SQLITE_ENABLE_DBSTAT_VTAB=1>
$<$<BOOL:${SQLITE_ENABLE_STMTVTAB}>:SQLITE_ENABLE_STMTVTAB=1>
$<$<BOOL:${SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION}>:SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION=1>
)
if(SQLITE3MC_USE_SQLEET_LEGACY)
set(SQLITE3MC_BASE_DEFINITIONS
${SQLITE3MC_BASE_DEFINITIONS}
SQLITE3MC_USE_SQLEET_LEGACY=1
)
endif()
if(SQLITE3MC_USE_SQLCIPHER_LEGACY)
if(NOT DEFINED SQLCIPHER_VERSION_DEFAULT)
set(SQLCIPHER_VERSION_DEFAULT "4")
endif()
set(SQLITE3MC_BASE_DEFINITIONS
${SQLITE3MC_BASE_DEFINITIONS}
SQLITE3MC_USE_SQLCIPHER_LEGACY=1
SQLCIPHER_VERSION_DEFAULT=${SQLCIPHER_VERSION_DEFAULT}
)
endif()
if(SQLITE3MC_SECURE_MEMORY)
set(SQLITE3MC_BASE_DEFINITIONS
${SQLITE3MC_BASE_DEFINITIONS}
SQLITE3MC_SECURE_MEMORY=1
)
endif()
if(SQLITE3MC_USE_MINIZ OR _SQLITE3MC_REQUIRE_ZLIB)
if(_SQLITE3MC_REQUIRE_ZLIB)
# Use ZLIB_ROOT to specify the location to look
find_package(ZLIB)
if(NOT ZLIB_FOUND)
message( FATAL_ERROR "One of the flags specified requires zlib. Zlib is not found. Try specifying the ZLIB_ROOT environment variable.")
endif()
endif()
if(SQLITE3MC_USE_MINIZ OR ZLIB_FOUND)
set(SQLITE3MC_BASE_DEFINITIONS
${SQLITE3MC_BASE_DEFINITIONS}
$<$<BOOL:${SQLITE_ENABLE_COMPRESS}>:SQLITE_ENABLE_COMPRESS=1>
)
set(SQLITE3MC_ZLIB_DEFINITIONS
${SQLITE3MC_ZLIB_DEFINITIONS}
$<$<BOOL:${SQLITE_ENABLE_SQLAR}>:SQLITE_ENABLE_SQLAR=1>
$<$<BOOL:${SQLITE_ENABLE_ZIPFILE}>:SQLITE_ENABLE_ZIPFILE=1>
)
set(SQLITE3MC_SHELL_DEFINITIONS
${SQLITE3MC_SHELL_DEFINITIONS}
SQLITE_HAVE_ZLIB=1
)
endif()
endif()
if(SQLITE3MC_WITH_ICU)
find_package(ICU REQUIRED COMPONENTS data i18n io uc)
if(ICU_FOUND)
set(SQLITE3MC_ICU_DEFINITIONS
SQLITE_ENABLE_ICU=1
)
else()
message( FATAL_ERROR "ICU not found.")
endif()
endif()
# Only generate Debug and Release configuration types.
set(CMAKE_CONFIGURATION_TYPES Debug Release)
set(SQLITE3MC_PUBLIC_HEADERS
src/sqlite3.h
src/sqlite3ext.h
src/sqlite3mc.h
src/sqlite3mc_version.h
src/sqlite3mc_vfs.h
src/sqlite3userauth.h
)
set(SQLITE3MC_BASE_SRCS
src/sqlite3mc.c
src/cipher_common.h
src/cipher_config.h
src/fastpbkdf2.h
src/mystdint.h
src/rijndael.h
src/sha1.h
src/sha2.h
src/test_windirent.h
${SQLITE3MC_PUBLIC_HEADERS}
)
set(SQLITE3MC_DLLRES_SRCS
src/sqlite3mc.rc
)
set(SQLITE3MC_SHELL_SRCS
src/shell.c
src/sqlite3mc.c
src/sqlite3mc_shell.rc
)
set(SQLITE3MC_INCLUDEDIRS
src
)
set(SQLITE3MC_LINK_LIBRARIES )
set(SQLITE3MC_DLL_DEFINITIONS )
set(SQLITE3MC_SHELL_SYSTEM_LINKS )
if(MSVC)
set(SQLITE3MC_DLL_DEFINITIONS
_USRDLL
)
endif()
if (CMAKE_SYSTEM_NAME STREQUAL "Linux"
OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.2 -maes")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2 -maes")
set(SQLITE3MC_LINK_LIBRARIES
pthread
dl
m
)
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
list(APPEND SQLITE3MC_LINK_LIBRARIES "-framework Security")
endif()
set(SHARED_LIB_EXPORT_DEFINITION "__attribute__((visibility(\"default\")))")
else()
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.2 -maes")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2 -maes")
endif()
set(SHARED_LIB_EXPORT_DEFINITION "__declspec(dllexport)")
endif()
set(_LIB_DIFINITIONS
_LIB
)
set(_DEFAULT_DEFINITIONS
_CRT_SECURE_NO_WARNINGS
_CRT_SECURE_NO_DEPRECATE
_CRT_NONSTDC_NO_WARNINGS
_CRT_NONSTDC_NO_DEPRECATE
_UNICODE
UNICODE
)
set(SQLITE3MC_SHELL_TARGET "sqlite3mc_shell")
if(SQLITE3MC_STATIC)
set(SQLITE3MC_LINK "STATIC")
set(SQLITE3MC_TARGET "sqlite3mc_static")
else()
set(SQLITE3MC_LINK "SHARED")
set(SQLITE3MC_TARGET "sqlite3mc")
list(APPEND SQLITE3MC_BASE_SRCS ${SQLITE3MC_DLLRES_SRCS})
endif()
# Lib Project
add_library(${SQLITE3MC_TARGET} ${SQLITE3MC_LINK}
${SQLITE3MC_BASE_SRCS}
)
target_include_directories(${SQLITE3MC_TARGET} PRIVATE
${SQLITE3MC_INCLUDEDIRS}
)
target_compile_definitions(${SQLITE3MC_TARGET} PRIVATE
${_LIB_DIFINITIONS}
${_DEFAULT_DEFINITIONS}
${SQLITE3MC_BASE_DEFINITIONS}
${SQLITE3MC_LIBONLY_DEFINITIONS}
${SQLITE3MC_ZLIB_DEFINITIONS}
)
target_link_libraries(${SQLITE3MC_TARGET} PRIVATE
${SQLITE3MC_LINK_LIBRARIES}
)
if(NOT SQLITE3MC_STATIC)
target_compile_definitions(${SQLITE3MC_TARGET} PRIVATE
SQLITE_API=${SHARED_LIB_EXPORT_DEFINITION}
)
endif()
if(ZLIB_FOUND)
target_include_directories(${SQLITE3MC_TARGET} PRIVATE
${ZLIB_INCLUDE_DIRS}
)
target_link_libraries(${SQLITE3MC_TARGET} PRIVATE
${ZLIB_LIBRARIES}
)
message(${ZLIB_LIBRARIES})
endif()
if(SQLITE3MC_WITH_ICU)
target_compile_definitions(${SQLITE3MC_TARGET} PRIVATE
${SQLITE3MC_ICU_DEFINITIONS}
)
target_include_directories(${SQLITE3MC_TARGET} PRIVATE
${ICU_INCLUDE_DIRS}
)
target_link_libraries(${SQLITE3MC_TARGET} PRIVATE
${ICU_LIBRARIES}
)
message("Will build ${SQLITE3MC_TARGET} with ICU")
endif()
if(SQLITE3MC_STATIC_RUNTIME_LINK)
message("Will build ${SQLITE3MC_TARGET} with static runtime link")
_Enable_MT(${SQLITE3MC_TARGET})
endif()
message("Will build ${SQLITE3MC_TARGET} as ${SQLITE3MC_LINK}")
set_target_properties(${SQLITE3MC_TARGET} PROPERTIES PUBLIC_HEADER "${SQLITE3MC_PUBLIC_HEADERS}")
INSTALL(TARGETS ${SQLITE3MC_TARGET}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
PUBLIC_HEADER DESTINATION include/${CMAKE_PROJECT_NAME}
RUNTIME DESTINATION bin
)
# Shell Executable project
if(SQLITE3MC_BUILD_SHELL)
add_executable(${SQLITE3MC_SHELL_TARGET}
${SQLITE3MC_SHELL_SRCS}
)
target_include_directories(${SQLITE3MC_SHELL_TARGET} PRIVATE
${SQLITE3MC_INCLUDEDIRS}
)
target_compile_definitions(${SQLITE3MC_SHELL_TARGET} PRIVATE
${_DEFAULT_DEFINITIONS}
${SQLITE3MC_BASE_DEFINITIONS}
${SQLITE3MC_SHELL_DEFINITIONS}
)
target_link_libraries(${SQLITE3MC_SHELL_TARGET} PRIVATE
${SQLITE3MC_SHELL_SYSTEM_LINKS}
${SQLITE3MC_LINK_LIBRARIES}
)
if(ZLIB_FOUND)
target_include_directories(${SQLITE3MC_SHELL_TARGET} PRIVATE
${ZLIB_INCLUDE_DIRS}
)
target_link_libraries(${SQLITE3MC_SHELL_TARGET} PRIVATE
${ZLIB_LIBRARIES}
)
endif()
if(SQLITE3MC_WITH_ICU)
target_compile_definitions(${SQLITE3MC_SHELL_TARGET} PRIVATE
${SQLITE3MC_ICU_DEFINITIONS}
)
target_include_directories(${SQLITE3MC_SHELL_TARGET} PRIVATE
${ICU_INCLUDE_DIRS}
)
target_link_libraries(${SQLITE3MC_SHELL_TARGET} PRIVATE
${ICU_LIBRARIES}
)
message("Will build ${SQLITE3MC_SHELL_TARGET} with ICU")
endif()
if(SQLITE3MC_RUNTIME_LINK)
message("Will build ${SQLITE3MC_SHELL_TARGET} with static runtime")
_Enable_MT(${SQLIT3MC_SHELL_TARGET})
endif()
message("Will build ${SQLITE3MC_SHELL_TARGET}")
INSTALL(TARGETS ${SQLITE3MC_SHELL_TARGET}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
PUBLIC_HEADER DESTINATION include/${CMAKE_PROJECT_NAME}
RUNTIME DESTINATION bin
)
endif()