Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
629 lines (598 loc) · 29 KB
/
Copy pathCMakeLists.txt
File metadata and controls
629 lines (598 loc) · 29 KB
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
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
cmake_minimum_required(VERSION 3.20)
project(OpenADS
VERSION 1.09.73
LANGUAGES C CXX
DESCRIPTION "Open-source ADS-compatible engine"
)
# Resolve the public version string the binary reports through
# `--version`. Prefer `git describe --tags` so a build straight off
# tag v1.0.0-rc13 reports "1.0.0-rc13", a build off main (between
# tags) reports "1.0.0-rc13-7-g<sha>[-dirty]", and a tarball without
# a .git tree falls back to ${PROJECT_VERSION} from project() above.
# The previous hard-coded "1.0.0-rc1" string drifted six releases
# behind reality and surprised users running rc12.
# A pipeline that knows the release tag passes it explicitly: the tag
# is the source of truth for a release build's stamp, not the local
# clone's git state (shallow/container checkouts may not resolve
# `git describe` - the glibc231 container leg shipped a plain
# "1.09.68" banner for exactly that reason).
if(OPENADS_VERSION_FORCE)
set(OPENADS_VERSION_STR "${OPENADS_VERSION_FORCE}")
else()
set(OPENADS_VERSION_STR "${PROJECT_VERSION}")
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags --always --dirty
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE _git_describe
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
RESULT_VARIABLE _git_rc)
if(_git_rc EQUAL 0 AND NOT _git_describe STREQUAL "")
# Strip a leading "v" so tags v1.0.0-rc13 surface as 1.0.0-rc13.
string(REGEX REPLACE "^v" "" OPENADS_VERSION_STR "${_git_describe}")
string(REGEX REPLACE "-dirty$" "" OPENADS_VERSION_STR "${OPENADS_VERSION_STR}")
endif()
endif()
endif()
message(STATUS "OpenADS version: ${OPENADS_VERSION_STR}")
# Deliver the version through a generated header instead of a global
# compile definition: a new commit used to change the command line of
# EVERY translation unit (add_compile_definitions), forcing a full
# 340-TU rebuild on the next build. configure_file() is
# copy-if-different, so the header's timestamp only moves when the
# version string really changes and only its ~7 consumers recompile.
configure_file(
"${CMAKE_SOURCE_DIR}/cmake/openads_version.h.in"
"${CMAKE_BINARY_DIR}/generated/openads_version.h"
@ONLY)
include_directories("${CMAKE_BINARY_DIR}/generated")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# openads_core is a STATIC library that gets linked into both an
# executable (openads_serverd, tests) and a SHARED library
# (openads_ace -> ace64.dll / libace64.so). On Linux / macOS the
# shared-library link path requires every translation unit pulled
# in to be position-independent, otherwise we hit
# `R_X86_64_TPOFF32 ... can not be used when making a shared
# object; recompile with -fPIC`. Force PIC globally ÔÇö Windows
# silently ignores the flag, so this is a no-op there.
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Release CACHE STRING "" FORCE)
endif()
option(OPENADS_BUILD_TESTS "Build OpenADS unit tests" ON)
option(OPENADS_WARNINGS_AS_ERRORS "Treat warnings as errors" ON)
# M12.12 ÔÇö real TLS transport via vendored mbedtls (Apache-2.0).
# Off by default so existing builds don't pull a network dependency
# at configure time. When ON, FetchContent downloads mbedtls 3.6 LTS
# at configure time and links it into openads_core; AdsConnect60
# with a `tls://` URI then opens a TlsTransport instead of returning
# AE_FUNCTION_NOT_AVAILABLE.
option(OPENADS_WITH_TLS "Enable TLS transport (vendors mbedtls 3.6 LTS via FetchContent)" OFF)
# studio.web ÔÇö embedded HTTP web console inside openads_serverd.
# When ON, serverd gains a `--http-port N` flag that exposes a
# single-page admin UI + REST API on top of the running engine,
# so the database can be administered from any browser on the LAN
# without installing a desktop client. Vendors cpp-httplib (MIT)
# and nlohmann/json (MIT) at configure time via FetchContent.
option(OPENADS_WITH_HTTP "Enable embedded HTTP web console (Studio) in openads_serverd / ace64.dll" ON)
# OpenADS Plus ÔÇö optional SQLite-backed table driver (static amalgamation).
# On by default; set OFF for dev builds that skip the FetchContent download.
option(OPENADS_WITH_SQLITE "Enable the SQLite-backed table driver (vendors the SQLite amalgamation via FetchContent)" ON)
# Optional PostgreSQL table driver (libpq). OFF by default.
option(OPENADS_WITH_POSTGRESQL "Enable PostgreSQL-backed table driver (libpq)" OFF)
# Optional MariaDB/MySQL table driver (libmariadb). OFF by default.
option(OPENADS_WITH_MARIADB "Enable MariaDB-backed table driver (libmariadb)" OFF)
# Optional generic ODBC table driver (system ODBC driver manager). OFF by default.
option(OPENADS_WITH_ODBC "Enable ODBC-backed table driver (system ODBC driver manager)" OFF)
# Build the OpenADS ODBC *driver* (provider) DLL so external ODBC clients
# (pyodbc, PDO_ODBC, Power BI, Excel, ...) can connect TO OpenADS. Windows only.
option(OPENADS_BUILD_ODBC_DRIVER "Build the OpenADS ODBC driver DLL (Windows)" OFF)
# Native MS SQL Server / TDS 7.4 backend. Requires OPENADS_WITH_TLS=ON
# (uses mbedtls for the TLS layer that SQL Server mandates on port 1433
# since MSSQL 2022 / Azure SQL). No external library is downloaded beyond
# mbedtls which OPENADS_WITH_TLS already fetches. OFF by default.
option(OPENADS_WITH_MSSQL "Enable native MS SQL Server / TDS backend" OFF)
# Opt-in: build the SQLite backend from the SQLite3 Multiple Ciphers
# amalgamation (SQLCipher-compatible encryption at rest, self-contained ÔÇö no
# external OpenSSL) instead of plain SQLite. Vendored under
# third_party/sqlcipher/ (not committed ÔÇö see .gitignore).
option(OPENADS_WITH_SQLCIPHER "Build the SQL backend with SQLCipher-compatible encryption (SQLite3 Multiple Ciphers)" OFF)
if(OPENADS_WITH_SQLCIPHER)
set(OPENADS_WITH_SQLITE ON CACHE BOOL "" FORCE)
endif()
# Optional native Firebird table driver (libfbclient; embedded .fdb in-process
# or TCP server). OFF by default. Requires the Firebird client SDK
# (fbclient + ibase.h) discoverable via FIREBIRD_ROOT.
option(OPENADS_WITH_FIREBIRD "Enable the native Firebird-backed table driver (libfbclient)" OFF)
# hbnetio Bridge - VFS adapter, distributed lock manager, RPC bridge
# Bridges harbour hbnetio virtual file system and RPC capabilities
# with OpenADS network transport layer.
option(OPENADS_WITH_HBNETIO_BRIDGE "Build the hbnetio VFS/RPC bridge for OpenADS" OFF)
# Server-side Harbour UDFs: embed hbvm and load a developer .hrb
# module whose functions become available to index expressions
# (LetoDB letoudf.hrb pattern — canonical upstream is Kresin's
# LetoDB, see docs/server-udf-hrb-design.md). OFF by default:
# needs a Harbour SDK (headers + hbvm/hbrtl libs). Core stays free
# of Harbour symbols by design (provider interface in
# engine/hrb_udf.*); the Harbour backend links into openads_serverd
# and unit tests only.
option(OPENADS_WITH_HARBOUR_UDF "Embed hbvm and load a developer .hrb module for server-side index-expression UDFs" OFF)
set(HARBOUR_INCLUDE_DIR "" CACHE PATH "Harbour include dir (hbvm.h) for HRB UDF support")
set(HARBOUR_LIB_DIR "" CACHE PATH "Harbour library dir for HRB UDF support")
set(OPENADS_HARBOUR_LIBS "hbvmmt;hbrtl;hbmacro;hbpcre;hblang;hbcpage;hbzlib;hbrdd;rddfpt;rddntx;hbsix;hbcommon" CACHE STRING "Harbour libraries to link (in order) for HRB UDF support")
if(OPENADS_WITH_HARBOUR_UDF)
if(NOT HARBOUR_INCLUDE_DIR)
find_path(HARBOUR_INCLUDE_DIR NAMES hbvm.h
HINTS $ENV{HB_ROOT}/include C:/harbour-git/include C:/harbour/include
PATH_SUFFIXES harbour)
endif()
if(NOT HARBOUR_INCLUDE_DIR)
message(FATAL_ERROR "OPENADS_WITH_HARBOUR_UDF=ON but hbvm.h not found (set HARBOUR_INCLUDE_DIR)")
endif()
set(HARBOUR_LIBRARIES "")
foreach(_hb ${OPENADS_HARBOUR_LIBS})
# NOTE: the if() below must name the variable INDIRECTLY
# (if(NOT ${_hb_var})); testing the expanded path value
# instead is always true in CMake and would FATAL every time.
set(_hb_var "HARBOUR_LIB_${_hb}")
find_library(${_hb_var} NAMES ${_hb}
HINTS ${HARBOUR_LIB_DIR} $ENV{HB_ROOT}/lib
PATH_SUFFIXES linux/gcc)
if(NOT ${_hb_var})
message(FATAL_ERROR "OPENADS_WITH_HARBOUR_UDF=ON but Harbour lib '${_hb}' not found (set HARBOUR_LIB_DIR)")
endif()
list(APPEND HARBOUR_LIBRARIES ${${_hb_var}})
endforeach()
if(WIN32)
# hbrtl's GT system references the platform default GT driver
# (see Harbour rtl/gtsys.c HB_GT_REQUEST: WIN on Windows, TRM
# on Unix) — link exactly that one.
set(_hb_gt gtwin)
else()
set(_hb_gt gttrm)
endif()
find_library(HARBOUR_LIB_gt NAMES ${_hb_gt}
HINTS ${HARBOUR_LIB_DIR} $ENV{HB_ROOT}/lib
PATH_SUFFIXES linux/gcc)
if(NOT HARBOUR_LIB_gt)
message(FATAL_ERROR "OPENADS_WITH_HARBOUR_UDF=ON but Harbour GT driver '${_hb_gt}' not found (set HARBOUR_LIB_DIR)")
endif()
list(APPEND HARBOUR_LIBRARIES ${HARBOUR_LIB_gt})
# Harbour archives reference each other in cycles (hbrtl<->hbvm,
# GT back-refs) while GNU ld resolves single-pass — group them so
# every static reference settles. (MSVC iterates archives itself;
# Apple ld accepts no groups.) Deliberately NOT whole-archive:
# runtime-resolved Harbour names are covered explicitly instead
# (our own init table publishes HB_HRB*, see hrb_harbour.cpp;
# UDF names self-register from the loaded .hrb), keeping the
# binary and its static-init surface minimal.
set(HARBOUR_LINK_LIBRARIES "")
if(NOT MSVC AND NOT APPLE)
list(APPEND HARBOUR_LINK_LIBRARIES "-Wl,--start-group")
endif()
list(APPEND HARBOUR_LINK_LIBRARIES ${HARBOUR_LIBRARIES})
if(NOT MSVC AND NOT APPLE)
list(APPEND HARBOUR_LINK_LIBRARIES "-Wl,--end-group")
endif()
if(WIN32)
list(APPEND HARBOUR_LINK_LIBRARIES winmm iphlpapi)
else()
# gttrm rides on ncurses (libncurses pulls libtinfo).
list(APPEND HARBOUR_LINK_LIBRARIES ncurses)
endif()
message(STATUS "OpenADS: Harbour UDF backend (${HARBOUR_LIBRARIES})")
endif()
# Static ACE library (libopenace32.a / libopenace64.a) for Harbour +
# MinGW: an hbmk2 -comp=mingw[64] app links the whole ACE client+engine
# into its .exe, so no ace32.dll / ace64.dll has to be deployed.
# MinGW-on-Windows only (the MSVC static-lib story is a separate one).
option(OPENADS_BUILD_ACE_STATIC "Build the static ACE library for Harbour/MinGW" ON)
# Pull in mbedtls FIRST so our strict /WX -Werror flags don't bleed
# into the upstream sources (C4200 zero-sized arrays etc). Each
# OpenADS target adds the strict flags target-locally below via
# `apply_openads_warnings(<target>)`.
if(OPENADS_WITH_TLS)
include(FetchContent)
set(ENABLE_TESTING OFF CACHE BOOL "" FORCE)
set(ENABLE_PROGRAMS OFF CACHE BOOL "" FORCE)
set(MBEDTLS_FATAL_WARNINGS OFF CACHE BOOL "" FORCE)
# Force a STATIC mbedtls so the OpenADS DLL / server binary
# has no runtime dependency on a system OpenSSL. Reported by
# downstream users: a release ZIP without those system DLLs
# fails to launch on a clean Windows / macOS box. Static
# linking sidesteps that whole class of "missing libssl/
# libcrypto" deployment errors.
set(USE_STATIC_MBEDTLS_LIBRARY ON CACHE BOOL "" FORCE)
set(USE_SHARED_MBEDTLS_LIBRARY OFF CACHE BOOL "" FORCE)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
# Don't let the vendored, statically-linked mbedtls add its own install()
# rules / programs to our package (CPack would otherwise ship mbedtls
# headers + .cmake config). We only link it in.
set(ENABLE_PROGRAMS OFF CACHE BOOL "" FORCE)
set(ENABLE_TESTING OFF CACHE BOOL "" FORCE)
set(MBEDTLS_INSTALL OFF CACHE BOOL "" FORCE)
FetchContent_Declare(
mbedtls
GIT_REPOSITORY https://github.com/Mbed-TLS/mbedtls.git
GIT_TAG v3.6.2
GIT_SHALLOW TRUE
GIT_SUBMODULES framework
GIT_SUBMODULES_RECURSE TRUE
)
FetchContent_MakeAvailable(mbedtls)
message(STATUS "OpenADS: TLS enabled via vendored mbedtls 3.6.2 (statically linked)")
endif()
if(OPENADS_WITH_HTTP)
include(FetchContent)
# cpp-httplib auto-detects OpenSSL / zlib / brotli on the host
# and pulls them in as link libraries on its INTERFACE target.
# That collides with the OpenADS no-runtime-DLL deployment
# promise (the shipped DLL must not depend on libssl /
# libcrypto). Force-disable the auto-link so Linux/macOS
# builds match the Windows side: plain HTTP only, no system
# OpenSSL pulled into ace64.dll / libace64.so.
set(HTTPLIB_USE_OPENSSL_IF_AVAILABLE OFF CACHE BOOL "" FORCE)
set(HTTPLIB_USE_ZLIB_IF_AVAILABLE OFF CACHE BOOL "" FORCE)
set(HTTPLIB_USE_BROTLI_IF_AVAILABLE OFF CACHE BOOL "" FORCE)
set(HTTPLIB_REQUIRE_OPENSSL OFF CACHE BOOL "" FORCE)
# Vendored statically into ace64.dll / serverd ÔÇö don't let httplib or
# nlohmann/json export their headers and *Config.cmake into our package.
set(HTTPLIB_INSTALL OFF CACHE BOOL "" FORCE)
set(JSON_Install OFF CACHE BOOL "" FORCE)
FetchContent_Declare(
cpp_httplib
URL https://github.com/yhirose/cpp-httplib/archive/refs/tags/v0.18.5.tar.gz
URL_HASH SHA256=731190e97acd63edce57cc3dacd496f57e7743bfc7933da7137cb3e93ec6c9a0
)
FetchContent_Declare(
nlohmann_json
URL https://github.com/nlohmann/json/archive/refs/tags/v3.11.3.tar.gz
URL_HASH SHA256=0d8ef5af7f9794e3263480193c491549b2ba6cc74bb018906202ada498a79406
)
set(JSON_BuildTests OFF CACHE INTERNAL "")
FetchContent_MakeAvailable(cpp_httplib nlohmann_json)
message(STATUS "OpenADS: HTTP web console enabled (cpp-httplib + nlohmann/json)")
endif()
# Server-side ZIP/UNZIP (backup/restore archiving under --data):
# zlib + classic minizip (ZipCrypto-compatible, what xBase zip tools
# read). Unconditional — small, needed on every leg. Vendored under
# third_party/zlib/ when present (offline builds); else fetched.
# Upstream C, so warnings are off for these TUs (same treatment as
# the SQLite amalgamation below).
set(_openads_zlib_dir "${CMAKE_SOURCE_DIR}/third_party/zlib")
# zlib 1.3.1 registers example/example64 ctest tests (test/example.c).
# CI builds only --target dbf_cdx_bench openads_unit_tests, so those
# binaries are never built and ctest reports "Not Run" -> exit 8/1 on
# every leg (v1.09.60 CI red, release green because it builds all).
# We never ship the examples: keep them out of the tree entirely.
set(ZLIB_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
if(NOT EXISTS "${_openads_zlib_dir}/zlib.h")
include(FetchContent)
FetchContent_Declare(
zlib_src
URL https://github.com/madler/zlib/releases/download/v1.3.1/zlib-1.3.1.tar.gz
URL_HASH SHA256=9a93b2b7dfdac77ceba5a558a580e74667dd6fede4585b91eefb60f03b72df23
)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
set(SKIP_INSTALL_ALL ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(zlib_src)
set(_openads_zlib_dir "${zlib_src_SOURCE_DIR}")
set(_openads_zlib_bin "${zlib_src_BINARY_DIR}")
set(_openads_zlib_target zlibstatic)
else()
# Offline layout: build the vendored tree into a fixed binary dir
# (zconf.h is generated there by zlib's own CMake).
set(_openads_zlib_bin "${CMAKE_BINARY_DIR}/_deps/zlib-build")
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
set(SKIP_INSTALL_ALL ON CACHE BOOL "" FORCE)
add_subdirectory("${_openads_zlib_dir}" "${_openads_zlib_bin}")
set(_openads_zlib_target zlibstatic)
endif()
add_library(openads_minizip STATIC
"${CMAKE_SOURCE_DIR}/third_party/minizip/zip.c"
"${CMAKE_SOURCE_DIR}/third_party/minizip/unzip.c"
"${CMAKE_SOURCE_DIR}/third_party/minizip/ioapi.c")
target_include_directories(openads_minizip SYSTEM PUBLIC
"${CMAKE_SOURCE_DIR}/third_party/minizip"
"${_openads_zlib_dir}"
"${_openads_zlib_bin}")
if(MSVC)
target_compile_options(openads_minizip PRIVATE /w)
else()
target_compile_options(openads_minizip PRIVATE -w)
endif()
target_link_libraries(openads_minizip PUBLIC ${_openads_zlib_target})
message(STATUS "OpenADS: server-side ZIP support (zlib + minizip)")
if(OPENADS_WITH_SQLITE)
if(OPENADS_WITH_SQLCIPHER)
# SQLite3 Multiple Ciphers amalgamation ÔÇö SQLCipher-compatible AES at
# rest, self-contained. Vendored under third_party/sqlcipher/.
set(_openads_sqlite_src "${CMAKE_SOURCE_DIR}/third_party/sqlcipher/sqlite3mc_amalgamation.c")
set(_openads_sqlite_inc "${CMAKE_SOURCE_DIR}/third_party/sqlcipher")
if(NOT EXISTS "${_openads_sqlite_src}")
message(FATAL_ERROR
"OPENADS_WITH_SQLCIPHER=ON needs the SQLite3 Multiple Ciphers "
"amalgamation at third_party/sqlcipher/sqlite3mc_amalgamation.c")
endif()
message(STATUS "OpenADS: SQL backend with SQLCipher-compatible encryption (SQLite3 Multiple Ciphers)")
else()
# Use a locally vendored amalgamation under third_party/sqlite/ when
# present (offline / air-gapped builds); otherwise fetch it. The
# amalgamation is not committed ÔÇö see .gitignore.
set(_openads_sqlite_src "${CMAKE_SOURCE_DIR}/third_party/sqlite/sqlite3.c")
set(_openads_sqlite_inc "${CMAKE_SOURCE_DIR}/third_party/sqlite")
if(NOT EXISTS "${_openads_sqlite_src}")
include(FetchContent)
FetchContent_Declare(
sqlite_amalgamation
URL https://www.sqlite.org/2024/sqlite-amalgamation-3460100.zip
URL_HASH SHA256=77823cb110929c2bcb0f5d48e4833b5c59a8a6e40cdea3936b99e199dbbe5784
)
FetchContent_MakeAvailable(sqlite_amalgamation)
set(_openads_sqlite_src "${sqlite_amalgamation_SOURCE_DIR}/sqlite3.c")
set(_openads_sqlite_inc "${sqlite_amalgamation_SOURCE_DIR}")
endif()
endif()
add_library(openads_sqlite3 STATIC "${_openads_sqlite_src}")
target_include_directories(openads_sqlite3 SYSTEM PUBLIC "${_openads_sqlite_inc}")
target_compile_definitions(openads_sqlite3 PRIVATE
SQLITE_THREADSAFE=1
SQLITE_DEFAULT_MEMSTATUS=0)
if(MSVC)
target_compile_options(openads_sqlite3 PRIVATE /wd4267 /wd4244)
else()
target_compile_options(openads_sqlite3 PRIVATE -Wno-conversion)
endif()
message(STATUS "OpenADS: SQLite-backed table driver enabled")
endif()
if(OPENADS_WITH_POSTGRESQL)
set(_openads_pg_linked FALSE)
set(OPENADS_LIBPQ_INCLUDE "" CACHE PATH "Directory containing libpq-fe.h")
set(OPENADS_LIBPQ_LIBRARY "" CACHE FILEPATH "libpq import library (.lib/.a)")
if(OPENADS_LIBPQ_INCLUDE AND OPENADS_LIBPQ_LIBRARY)
set(_openads_pg_inc "${OPENADS_LIBPQ_INCLUDE}")
set(_openads_pg_lib "${OPENADS_LIBPQ_LIBRARY}")
endif()
if(NOT _openads_pg_lib)
if(DEFINED ENV{OPENADS_LIBPQ_LIBRARY})
set(_openads_pg_lib "$ENV{OPENADS_LIBPQ_LIBRARY}")
endif()
if(DEFINED ENV{OPENADS_LIBPQ_INCLUDE})
set(_openads_pg_inc "$ENV{OPENADS_LIBPQ_INCLUDE}")
endif()
endif()
if(NOT _openads_pg_lib OR NOT _openads_pg_inc)
if(DEFINED ENV{OPENADS_TOOLCHAIN_ROOT})
set(_openads_toolchain_root "$ENV{OPENADS_TOOLCHAIN_ROOT}")
elseif(DEFINED OPENADS_TOOLCHAIN_ROOT)
set(_openads_toolchain_root "${OPENADS_TOOLCHAIN_ROOT}")
endif()
if(_openads_toolchain_root)
if(NOT _openads_pg_inc)
find_path(_openads_pg_inc libpq-fe.h
PATHS "${_openads_toolchain_root}/pgsql/include"
NO_DEFAULT_PATH)
endif()
if(NOT _openads_pg_lib)
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
find_library(_openads_pg_lib NAMES libpq pq
PATHS "${_openads_toolchain_root}/libpq/x86"
"${_openads_toolchain_root}/libpq/x86/lib"
NO_DEFAULT_PATH)
else()
find_library(_openads_pg_lib NAMES pq libpq
PATHS "${_openads_toolchain_root}/pgsql/lib"
NO_DEFAULT_PATH)
endif()
endif()
endif()
endif()
if(_openads_pg_inc AND _openads_pg_lib)
add_library(openads_libpq INTERFACE)
target_include_directories(openads_libpq INTERFACE "${_openads_pg_inc}")
target_link_libraries(openads_libpq INTERFACE "${_openads_pg_lib}")
set(_openads_pg_linked TRUE)
message(STATUS "OpenADS: PostgreSQL backend (libpq: ${_openads_pg_lib})")
endif()
if(NOT _openads_pg_linked)
find_package(PostgreSQL REQUIRED)
add_library(openads_libpq INTERFACE)
target_include_directories(openads_libpq INTERFACE "${PostgreSQL_INCLUDE_DIRS}")
target_link_libraries(openads_libpq INTERFACE PostgreSQL::PostgreSQL)
message(STATUS "OpenADS: PostgreSQL backend (libpq via find_package)")
endif()
endif()
if(OPENADS_WITH_MARIADB)
set(_openads_maria_linked FALSE)
set(OPENADS_LIBMARIADB_INCLUDE "" CACHE PATH "Directory containing mysql.h")
set(OPENADS_LIBMARIADB_LIBRARY "" CACHE FILEPATH "libmariadb import library (.lib/.a)")
if(OPENADS_LIBMARIADB_INCLUDE AND OPENADS_LIBMARIADB_LIBRARY)
set(_openads_maria_inc "${OPENADS_LIBMARIADB_INCLUDE}")
set(_openads_maria_lib "${OPENADS_LIBMARIADB_LIBRARY}")
endif()
if(NOT _openads_maria_lib)
if(DEFINED ENV{OPENADS_LIBMARIADB_LIBRARY})
set(_openads_maria_lib "$ENV{OPENADS_LIBMARIADB_LIBRARY}")
endif()
if(DEFINED ENV{OPENADS_LIBMARIADB_INCLUDE})
set(_openads_maria_inc "$ENV{OPENADS_LIBMARIADB_INCLUDE}")
endif()
endif()
if(NOT _openads_maria_lib OR NOT _openads_maria_inc)
if(DEFINED ENV{OPENADS_TOOLCHAIN_ROOT})
set(_openads_toolchain_root "$ENV{OPENADS_TOOLCHAIN_ROOT}")
elseif(DEFINED OPENADS_TOOLCHAIN_ROOT)
set(_openads_toolchain_root "${OPENADS_TOOLCHAIN_ROOT}")
endif()
if(_openads_toolchain_root)
if(NOT _openads_maria_inc)
find_path(_openads_maria_inc mysql.h
PATHS "${_openads_toolchain_root}/mariadb/include"
NO_DEFAULT_PATH)
endif()
if(NOT _openads_maria_lib)
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
find_library(_openads_maria_lib NAMES libmariadb
PATHS "${_openads_toolchain_root}/mariadb/lib"
NO_DEFAULT_PATH)
else()
find_library(_openads_maria_lib NAMES libmariadb64 libmariadb
PATHS "${_openads_toolchain_root}/mariadb/lib"
NO_DEFAULT_PATH)
endif()
endif()
endif()
endif()
if(NOT _openads_maria_inc OR NOT _openads_maria_lib)
find_path(_openads_maria_inc mysql.h
PATH_SUFFIXES mariadb mysql)
find_library(_openads_maria_lib NAMES mariadb libmariadb mariadbclient)
endif()
if(_openads_maria_inc AND _openads_maria_lib)
add_library(openads_libmariadb INTERFACE)
target_include_directories(openads_libmariadb INTERFACE "${_openads_maria_inc}")
target_link_libraries(openads_libmariadb INTERFACE "${_openads_maria_lib}")
set(_openads_maria_linked TRUE)
message(STATUS "OpenADS: MariaDB backend (libmariadb: ${_openads_maria_lib})")
endif()
if(NOT _openads_maria_linked)
message(FATAL_ERROR "OPENADS_WITH_MARIADB=ON but libmariadb was not found")
endif()
endif()
if(MSVC)
# /MP: compile TUs of each project in parallel (one cl.exe per core).
# Without it a full rebuild of the ~340-TU tree runs serially.
add_compile_options(/W4 /permissive- /MP)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
if(OPENADS_WARNINGS_AS_ERRORS)
add_compile_options(/WX)
endif()
elseif(WIN32 AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# MinGW/winlibs: static link toolchain runtime; libpq.dll still loads at runtime.
add_link_options(-static)
else()
add_compile_options(-Wall -Wextra -Wpedantic -Wshadow -Wconversion)
# _CRT_SECURE_NO_WARNINGS: needed when clang-cl targets MSVC CRT on Windows;
# harmless on Linux/macOS where this define has no effect.
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
if(OPENADS_WARNINGS_AS_ERRORS)
add_compile_options(-Werror)
endif()
endif()
add_subdirectory(src)
if(OPENADS_BUILD_ODBC_DRIVER AND WIN32)
add_subdirectory(bindings/odbc)
endif()
add_subdirectory(tools/serverd)
add_subdirectory(tools/adsbackup)
add_subdirectory(tools/bench)
add_subdirectory(tools/stress)
add_subdirectory(tools/mgprobe)
add_subdirectory(tools/import_dd)
add_subdirectory(tools/adi_inspect)
if(OPENADS_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
# ---------------------------------------------------------------------------
# Install rules + CPack ÔÇö produce a structured, reproducible package with the
# same shape the release.yml staging assembles by hand (engine DLL + drop-in
# ACE-named copy, import libs, server/bench CLIs, headers, docs). Purely
# additive: a plain `cmake --build` is unaffected; `cmake --install` /
# `cpack` are opt-in.
# ---------------------------------------------------------------------------
include(GNUInstallDirs)
# Windows packages are traditionally flat (drop ace64.dll next to the .exe),
# matching the existing release zip and QUICKSTART; POSIX follows the GNU
# layout so the systemd/DEB story lands binaries under bin/ and lib/.
if(WIN32)
set(OA_INSTALL_BIN ".")
set(OA_INSTALL_LIB "lib")
set(OA_INSTALL_DOC ".")
else()
set(OA_INSTALL_BIN "${CMAKE_INSTALL_BINDIR}")
set(OA_INSTALL_LIB "${CMAKE_INSTALL_LIBDIR}")
set(OA_INSTALL_DOC "${CMAKE_INSTALL_DOCDIR}")
endif()
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(OA_BITS "64")
set(OA_ARCH "x64")
else()
set(OA_BITS "32")
set(OA_ARCH "x86")
endif()
# Engine shared library (openace64/openace32) + its import lib.
install(TARGETS openads_ace
RUNTIME DESTINATION "${OA_INSTALL_BIN}"
LIBRARY DESTINATION "${OA_INSTALL_BIN}"
ARCHIVE DESTINATION "${OA_INSTALL_LIB}")
# Drop-in-named copy so apps that load OpenADS by the canonical ACE name
# (ace64.dll / libace64.so / libace64.dylib) work without renaming anything.
if(WIN32)
install(FILES "$<TARGET_FILE:openads_ace>"
DESTINATION "${OA_INSTALL_BIN}" RENAME "ace${OA_BITS}.dll")
elseif(APPLE)
install(FILES "$<TARGET_FILE:openads_ace>"
DESTINATION "${OA_INSTALL_BIN}" RENAME "libace${OA_BITS}.dylib")
else()
install(FILES "$<TARGET_FILE:openads_ace>"
DESTINATION "${OA_INSTALL_BIN}" RENAME "libace${OA_BITS}.so")
endif()
# Server + bench + backup CLIs.
install(TARGETS openads_serverd openads_bench adsbackup
RUNTIME DESTINATION "${OA_INSTALL_BIN}")
# Public ACE headers.
install(DIRECTORY "${CMAKE_SOURCE_DIR}/include/"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
# License + docs.
install(FILES "${CMAKE_SOURCE_DIR}/LICENSE"
"${CMAKE_SOURCE_DIR}/NOTICE"
"${CMAKE_SOURCE_DIR}/README.md"
DESTINATION "${OA_INSTALL_DOC}")
# Prebuilt per-compiler import libraries (MSVC / MinGW / Borland), Windows.
if(WIN32 AND EXISTS "${CMAKE_SOURCE_DIR}/dist/import-libs/${OA_ARCH}")
install(DIRECTORY "${CMAKE_SOURCE_DIR}/dist/import-libs/${OA_ARCH}/"
DESTINATION "${OA_INSTALL_LIB}")
endif()
# Service unit templates (handy for unattended deploys).
install(FILES "${CMAKE_SOURCE_DIR}/tools/scripts/systemd/openads-serverd.service"
"${CMAKE_SOURCE_DIR}/tools/scripts/launchd/com.openads.serverd.plist"
DESTINATION "${OA_INSTALL_DOC}/service" OPTIONAL)
# Onboarding files that land with sibling PRs (#88 config template, #90 kit).
# OPTIONAL keeps this PR self-contained against upstream/main ÔÇö they install
# automatically once those merge.
install(FILES "${CMAKE_SOURCE_DIR}/openads.ini.sample"
"${CMAKE_SOURCE_DIR}/QUICKSTART.md"
"${CMAKE_SOURCE_DIR}/openads-studio.sh"
"${CMAKE_SOURCE_DIR}/openads-studio.bat"
DESTINATION "${OA_INSTALL_BIN}" OPTIONAL)
# --- CPack ------------------------------------------------------------------
set(CPACK_PACKAGE_NAME "openads")
set(CPACK_PACKAGE_VENDOR "OpenADS")
set(CPACK_PACKAGE_VERSION "${OPENADS_VERSION_STR}")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PROJECT_DESCRIPTION}")
set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/FiveTechSoft/OpenADS")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE")
set(CPACK_VERBATIM_VARIABLES ON)
if(WIN32)
set(_oa_os "windows")
elseif(APPLE)
set(_oa_os "macos")
else()
set(_oa_os "linux")
endif()
set(CPACK_PACKAGE_FILE_NAME "openads-${OPENADS_VERSION_STR}-${_oa_os}-${OA_ARCH}")
if(WIN32)
set(CPACK_GENERATOR "ZIP")
elseif(APPLE)
set(CPACK_GENERATOR "TGZ")
else()
set(CPACK_GENERATOR "TGZ;DEB")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "OpenADS")
set(CPACK_DEBIAN_PACKAGE_SECTION "database")
endif()
include(CPack)