-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
1303 lines (1103 loc) · 43 KB
/
CMakeLists.txt
File metadata and controls
1303 lines (1103 loc) · 43 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
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
cmake_minimum_required(VERSION 3.20)
# ====================================================================
# Vix.cpp — Umbrella CMake Configuration
# ====================================================================
# Purpose:
# - Build Vix modules (json, utils, core, websocket, orm, cli).
# - Provide a single umbrella target: vix::vix
# - Install/export a CMake package: find_package(Vix CONFIG REQUIRED)
#
# Quick start:
# cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DVIX_BUILD_EXAMPLES=ON
# cmake --build build -j
# ====================================================================
# Policies for newer CMake versions
if (POLICY CMP0126)
cmake_policy(SET CMP0126 NEW)
endif()
if (POLICY CMP0167)
cmake_policy(SET CMP0167 NEW)
endif()
# Resolve umbrella version from git (preferred)
set(_VIX_VERSION_FALLBACK "0.0.0")
find_package(Git QUIET)
set(_VIX_GIT_DESCRIBE "")
if(Git_FOUND)
execute_process(
COMMAND "${GIT_EXECUTABLE}" describe --tags --always --dirty
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE _VIX_GIT_DESCRIBE
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
endif()
# Compute PROJECT_VERSION (must be numeric for CMake packaging)
# If describe returns: v1.20.1-4-gXXXX -> numeric is 1.20.1
set(_VIX_PROJECT_VERSION "${_VIX_VERSION_FALLBACK}")
if(_VIX_GIT_DESCRIBE MATCHES "^v([0-9]+\\.[0-9]+\\.[0-9]+)")
set(_VIX_PROJECT_VERSION "${CMAKE_MATCH_1}")
endif()
project(vix VERSION ${_VIX_PROJECT_VERSION} LANGUAGES CXX)
if (WIN32)
add_compile_definitions(
_WIN32_WINNT=0x0A00
WIN32_LEAN_AND_MEAN
NOMINMAX
)
endif()
# Human-friendly version string (can include -N-gHASH[-dirty])
if(_VIX_GIT_DESCRIBE STREQUAL "")
set(VIX_UMBRELLA_VERSION "v${PROJECT_VERSION}")
else()
set(VIX_UMBRELLA_VERSION "${_VIX_GIT_DESCRIBE}")
endif()
set(VIX_UMBRELLA_VERSION "${VIX_UMBRELLA_VERSION}" CACHE STRING "Umbrella version" FORCE)
set(VIX_UMBRELLA_BUILD ON CACHE BOOL "Building Vix from umbrella" FORCE)
# Make find_package honor *_ROOT hints (e.g. MYSQLCPPCONN_ROOT)
if (POLICY CMP0144)
cmake_policy(SET CMP0144 NEW)
endif()
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
include(FetchContent)
# Resolve to a real target (not an ALIAS) so we can mutate properties safely.
function(vix_resolve_real_target out name)
set(_real "")
if (TARGET "${name}")
get_target_property(_aliased "${name}" ALIASED_TARGET)
if (_aliased)
set(_real "${_aliased}")
else()
set(_real "${name}")
endif()
endif()
set(${out} "${_real}" PARENT_SCOPE)
endfunction()
# RPATH to easily run after installation
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON)
if (APPLE)
set(CMAKE_MACOSX_RPATH ON)
endif()
# ----------------------------------------------------
# Global build settings
# ----------------------------------------------------
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Copy compile_commands.json to repo root (tooling QoL)
# Disabled on Windows because Visual Studio generators do not reliably
# generate compile_commands.json and this must never fail a build.
if (NOT WIN32)
if (CMAKE_EXPORT_COMPILE_COMMANDS)
add_custom_target(copy-compile-commands ALL
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_BINARY_DIR}/compile_commands.json"
"${CMAKE_SOURCE_DIR}/compile_commands.json"
BYPRODUCTS "${CMAKE_SOURCE_DIR}/compile_commands.json"
COMMENT "Copy compile_commands.json to project root"
VERBATIM
)
endif()
else()
message(STATUS "compile_commands.json copy disabled on Windows.")
endif()
# ----------------------------------------------------
# Options
# ----------------------------------------------------
option(VIX_ENABLE_WARNINGS "Enable extra warnings" ON)
option(VIX_ENABLE_LTO "Enable IPO/LTO (Release only)" OFF)
option(VIX_MSVC_STATIC_RUNTIME "Link MSVC runtime statically (/MT)" OFF)
option(VIX_ENABLE_CLANG_TIDY "Enable clang-tidy if available" OFF)
option(VIX_ENABLE_CPPCHECK "Enable cppcheck if available" OFF)
option(VIX_ENABLE_COVERAGE "Enable coverage flags (Debug only)" OFF)
option(VIX_ENABLE_SANITIZERS "Enable ASan+UBSan (GCC/Clang only)" OFF)
option(VIX_BUILD_EXAMPLES "Build umbrella examples in ./examples" ON)
option(VIX_BUILD_TESTS "Build unit tests (GoogleTest)" ON)
option(VIX_ENABLE_ORM "Build Vix ORM module" ON)
option(VIX_ENABLE_WEBSOCKET "Build Vix WebSocket module" ON)
option(VIX_ENABLE_CLI "Build Vix CLI module" ON)
option(VIX_FORCE_FETCH_JSON "Fetch JSON backend if modules/json missing" ON)
option(VIX_BENCH_MODE "Disable heavy security/logging checks for benchmarks" OFF)
option(VIX_ENABLE_MIDDLEWARE "Build Vix middleware module" ON)
option(VIX_ENABLE_HTTP_COMPRESSION "Enable HTTP compression middleware deps (zlib/brotli)" ON)
option(VIX_ENABLE_DB "Build Vix DB module (core anti-ORM)" ON)
option(VIX_DB_USE_MYSQL "Enable MySQL backend in vix_db" ON)
option(VIX_DB_USE_SQLITE "Enable SQLite backend in vix_db" OFF)
option(VIX_DB_USE_POSTGRES "Enable PostgreSQL backend in vix_db" OFF)
option(VIX_DB_USE_REDIS "Enable Redis backend in vix_db" OFF)
option(VIX_ENABLE_P2P "Build Vix P2P module" ON)
option(VIX_ENABLE_P2P_HTTP "Build Vix P2P HTTP adapter module" ON)
option(VIX_ENABLE_CACHE "Build Vix Cache module" ON)
option(VIX_FETCH_DEPS "Allow fetching missing deps from the internet" OFF)
option(VIX_ENABLE_ASYNC "Build Vix Async module" ON)
option(VIX_ENABLE_VALIDATION "Build Vix Validation module" ON)
option(VIX_ENABLE_CRYPTO "Build Vix Crypto module" ON)
option(VIX_ENABLE_WEBRPC "Build Vix WebRPC module" ON)
option(VIX_ENABLE_TIME "Build Vix Time module" ON)
option(VIX_TIME_BUILD_TESTS "Build vix::time tests" OFF)
option(VIX_TIME_BUILD_BENCH "Build vix::time benchmarks" OFF)
# ----------------------------------------------------
# Tooling / Static analysis
# ----------------------------------------------------
if (VIX_ENABLE_CLANG_TIDY)
find_program(CLANG_TIDY_EXE NAMES clang-tidy)
if (CLANG_TIDY_EXE)
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE}")
message(STATUS "clang-tidy enabled: ${CLANG_TIDY_EXE}")
else()
message(WARNING "clang-tidy requested but not found")
endif()
endif()
if (VIX_ENABLE_CPPCHECK)
find_program(CPPCHECK_EXE NAMES cppcheck)
if (CPPCHECK_EXE)
set(CMAKE_CXX_CPPCHECK
${CPPCHECK_EXE}
--enable=warning,style,performance,portability
--std=c++20 --inline-suppr
--suppress=unusedFunction
)
message(STATUS "cppcheck enabled: ${CPPCHECK_EXE}")
else()
message(WARNING "cppcheck requested but not found")
endif()
endif()
# ----------------------------------------------------
# Warnings (opt-in reusable interface target)
# ----------------------------------------------------
if (VIX_ENABLE_WARNINGS)
add_library(vix_warnings INTERFACE)
if (MSVC)
target_compile_options(vix_warnings INTERFACE /W4 /permissive-)
else()
target_compile_options(vix_warnings INTERFACE
-Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion
)
# Silence some false positives on GCC 13+ (fmt/spdlog inlines)
target_compile_options(vix_warnings INTERFACE
$<$<CXX_COMPILER_ID:GNU>:-Wno-array-bounds>
)
endif()
endif()
# ----------------------------------------------------
# Coverage (Debug only)
# ----------------------------------------------------
if (VIX_ENABLE_COVERAGE AND CMAKE_BUILD_TYPE MATCHES "Debug")
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
add_library(vix_coverage INTERFACE)
target_compile_options(vix_coverage INTERFACE --coverage -O0 -g)
target_link_options(vix_coverage INTERFACE --coverage)
message(STATUS "Coverage flags enabled")
else()
message(WARNING "Coverage only supported on GCC/Clang")
endif()
endif()
# ----------------------------------------------------
# Sanitizers (opt-in, GCC/Clang) — as INTERFACE target
# ----------------------------------------------------
set(_VIX_SAN_COMMON "")
set(_VIX_SAN_TYPES "")
if (VIX_ENABLE_SANITIZERS)
if (MSVC)
message(FATAL_ERROR "Sanitizers are not supported on MSVC. Use Clang or GCC.")
endif()
set(_VIX_SAN_COMMON -O1 -g -fno-omit-frame-pointer)
set(_VIX_SAN_TYPES -fsanitize=address,undefined)
add_library(vix_sanitizers INTERFACE)
target_compile_options(vix_sanitizers INTERFACE ${_VIX_SAN_COMMON} ${_VIX_SAN_TYPES})
target_link_options(vix_sanitizers INTERFACE ${_VIX_SAN_TYPES})
message(STATUS "Sanitizers enabled via vix_sanitizers interface target.")
endif()
# ----------------------------------------------------
# LTO (Release only)
# ----------------------------------------------------
if (VIX_ENABLE_LTO AND CMAKE_BUILD_TYPE MATCHES "Release")
include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_ok OUTPUT ipo_err)
if (ipo_ok)
message(STATUS "IPO/LTO enabled")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
else()
message(WARNING "IPO/LTO not supported: ${ipo_err}")
endif()
endif()
# ----------------------------------------------------
# MSVC static runtime (/MT)
# ----------------------------------------------------
if (MSVC AND VIX_MSVC_STATIC_RUNTIME)
foreach(flag_var
CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_C_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_DEBUG
)
if (DEFINED ${flag_var})
string(REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif()
endforeach()
endif()
# ----------------------------------------------------
# Umbrella INTERFACE target (created early)
# ----------------------------------------------------
add_library(vix INTERFACE)
if (WIN32)
target_compile_definitions(vix INTERFACE _WIN32_WINNT=0x0A00 WIN32_LEAN_AND_MEAN NOMINMAX)
endif()
# ----------------------------------------------------
# Third-party: Boost (required by core/websocket headers: Boost.Beast)
# Prefer CONFIG mode (CMake 4+), fallback to module mode if needed.
# ----------------------------------------------------
set(VIX_WITH_BOOST ON)
set(_VIX_BOOST_OK OFF)
# Try CONFIG first (preferred with CMake 4+)
find_package(Boost CONFIG QUIET COMPONENTS system)
if (Boost_FOUND)
set(_VIX_BOOST_OK ON)
message(STATUS "Boost found (CONFIG)")
else()
# Fallback for environments without BoostConfig.cmake
find_package(Boost QUIET COMPONENTS system)
if (Boost_FOUND)
set(_VIX_BOOST_OK ON)
message(STATUS "Boost found (FindBoost fallback)")
endif()
endif()
if (NOT _VIX_BOOST_OK)
message(FATAL_ERROR "Boost is required (core/websocket). Install Boost (headers + system).")
endif()
# Normalize targets
if (TARGET Boost::headers AND NOT TARGET Boost::boost)
add_library(Boost::boost ALIAS Boost::headers)
endif()
add_library(vix_thirdparty_boost INTERFACE)
add_library(vix::thirdparty_boost ALIAS vix_thirdparty_boost)
# Some distros do not provide Boost::system target in module mode, so guard it
if (TARGET Boost::system)
target_link_libraries(vix_thirdparty_boost INTERFACE Boost::boost Boost::system)
else()
# Module mode can expose include dirs + libs variables
if (DEFINED Boost_INCLUDE_DIRS)
target_include_directories(vix_thirdparty_boost SYSTEM INTERFACE ${Boost_INCLUDE_DIRS})
endif()
if (DEFINED Boost_LIBRARIES)
target_link_libraries(vix_thirdparty_boost INTERFACE ${Boost_LIBRARIES})
else()
# At least headers
target_link_libraries(vix_thirdparty_boost INTERFACE Boost::boost)
endif()
endif()
target_link_libraries(vix INTERFACE vix::thirdparty_boost)
# ----------------------------------------------------
# Third-party: Asio (standalone, header-only)
# Exposes: vix::thirdparty_asio
# ----------------------------------------------------
add_library(vix_thirdparty_asio INTERFACE)
add_library(vix::thirdparty_asio ALIAS vix_thirdparty_asio)
target_compile_definitions(vix_thirdparty_asio INTERFACE ASIO_STANDALONE=1)
if (WIN32)
target_compile_definitions(vix_thirdparty_asio INTERFACE
_WIN32_WINNT=0x0A00
WIN32_LEAN_AND_MEAN
NOMINMAX
)
endif()
set(VIX_THIRDPARTY_ASIO_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/asio-src/asio/include")
# Prefer vendored Asio (submodule)
if (EXISTS "${VIX_THIRDPARTY_ASIO_DIR}/asio.hpp")
message(STATUS "Asio: using vendored Asio at ${VIX_THIRDPARTY_ASIO_DIR}")
target_include_directories(vix_thirdparty_asio SYSTEM INTERFACE
$<BUILD_INTERFACE:${VIX_THIRDPARTY_ASIO_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/vix/third_party/asio>
)
else()
message(STATUS "Asio submodule missing, fetching Asio automatically...")
include(FetchContent)
FetchContent_Declare(
asio
GIT_REPOSITORY https://github.com/chriskohlhoff/asio.git
GIT_TAG asio-1-30-2
)
FetchContent_MakeAvailable(asio)
target_include_directories(vix_thirdparty_asio SYSTEM INTERFACE
$<BUILD_INTERFACE:${asio_SOURCE_DIR}/asio/include>
)
endif()
target_link_libraries(vix INTERFACE vix::thirdparty_asio)
add_library(vix::vix ALIAS vix)
# ----------------------------------------------------
# Optional deps: HTTP compression (zlib + brotli)
# Propagate defs/libs to all consumers through vix::vix
# ----------------------------------------------------
if (VIX_ENABLE_HTTP_COMPRESSION)
# ---- zlib (gzip) ----
find_package(ZLIB QUIET)
if (ZLIB_FOUND)
message(STATUS "Compression: zlib found -> gzip enabled")
target_compile_definitions(vix INTERFACE VIX_HAS_ZLIB=1)
if (TARGET ZLIB::ZLIB)
target_link_libraries(vix INTERFACE ZLIB::ZLIB)
else()
add_library(ZLIB::ZLIB INTERFACE IMPORTED)
target_include_directories(ZLIB::ZLIB INTERFACE "${ZLIB_INCLUDE_DIRS}")
target_link_libraries(ZLIB::ZLIB INTERFACE "${ZLIB_LIBRARIES}")
target_link_libraries(vix INTERFACE ZLIB::ZLIB)
endif()
else()
message(STATUS "Compression: zlib not found -> gzip disabled")
endif()
# ---- brotli (br) ----
find_library(BROTLI_ENC NAMES brotlienc)
find_library(BROTLI_COMMON NAMES brotlicommon)
if (BROTLI_ENC AND BROTLI_COMMON)
message(STATUS "Compression: brotli found -> br enabled")
target_compile_definitions(vix INTERFACE VIX_HAS_BROTLI=1)
target_link_libraries(vix INTERFACE ${BROTLI_ENC} ${BROTLI_COMMON})
else()
message(STATUS "Compression: brotli not found -> br disabled")
endif()
endif()
# Attach warnings/coverage to umbrella (propagates to consumers)
if (TARGET vix_warnings)
target_link_libraries(vix INTERFACE vix_warnings)
endif()
if (TARGET vix_coverage)
target_link_libraries(vix INTERFACE vix_coverage)
endif()
# Install include interface root
target_include_directories(vix INTERFACE
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
# ----------------------------------------------------
# Add submodules
# ----------------------------------------------------
set(_VIX_JSON_BACKEND "none")
set(JSON_TARGET "")
# --- JSON ---
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/json/CMakeLists.txt")
message(STATUS "Adding 'modules/json'...")
add_subdirectory(modules/json json_build)
set(_VIX_JSON_BACKEND "submodule")
elseif (VIX_FORCE_FETCH_JSON)
message(WARNING "modules/json missing — fetching nlohmann/json fallback")
FetchContent_Declare(
nlohmann_json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.11.3
)
FetchContent_MakeAvailable(nlohmann_json)
add_library(vix_json INTERFACE)
target_link_libraries(vix_json INTERFACE nlohmann_json::nlohmann_json)
if (NOT TARGET vix::json)
add_library(vix::json ALIAS vix_json)
endif()
set(_VIX_JSON_BACKEND "nlohmann_json")
else()
message(FATAL_ERROR "Missing 'modules/json'. Run: git submodule update --init --recursive")
endif()
# Resolve JSON target name
if (TARGET vix::json)
set(JSON_TARGET vix::json)
elseif (TARGET vix_json)
set(JSON_TARGET vix_json)
else()
message(FATAL_ERROR "JSON backend target not found (expected vix::json or vix_json).")
endif()
# --- WebRPC (optional) ---
set(VIX_HAS_WEBRPC OFF)
if (VIX_ENABLE_WEBRPC AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/webrpc/CMakeLists.txt")
message(STATUS "Adding 'modules/webrpc'...")
add_subdirectory(modules/webrpc webrpc_build)
# Normalise: expose vix::webrpc
if (TARGET vix::webrpc OR TARGET vix_webrpc)
set(VIX_HAS_WEBRPC ON)
if (TARGET vix_webrpc AND NOT TARGET vix::webrpc)
add_library(vix::webrpc ALIAS vix_webrpc)
endif()
else()
message(WARNING "WebRPC module added but no vix::webrpc target was exported.")
endif()
else()
message(STATUS "WebRPC: disabled or not present.")
endif()
# --- Utils ---
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/utils/CMakeLists.txt")
message(STATUS "Adding 'modules/utils'...")
add_subdirectory(modules/utils utils_build)
else()
message(FATAL_ERROR "Missing 'modules/utils'. Run: git submodule update --init --recursive")
endif()
# --- Time (foundation module) ---
set(VIX_HAS_TIME OFF)
if (VIX_ENABLE_TIME AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/time/CMakeLists.txt")
message(STATUS "Adding 'modules/time'...")
set(VIX_TIME_BUILD_TESTS ${VIX_TIME_BUILD_TESTS} CACHE BOOL "" FORCE)
set(VIX_TIME_BUILD_BENCH ${VIX_TIME_BUILD_BENCH} CACHE BOOL "" FORCE)
add_subdirectory(modules/time time_build)
if (TARGET vix::time OR TARGET vix_time)
set(VIX_HAS_TIME ON)
if (TARGET vix_time AND NOT TARGET vix::time)
add_library(vix::time ALIAS vix_time)
endif()
else()
message(WARNING "Time module added but no vix::time target was exported.")
endif()
else()
message(STATUS "Time: disabled or not present.")
endif()
# --- Crypto (optional) ---
set(VIX_HAS_CRYPTO OFF)
if (VIX_ENABLE_CRYPTO AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/crypto/CMakeLists.txt")
message(STATUS "Adding 'modules/crypto'...")
# Important: en umbrella, crypto ne fait pas find_package(OpenSSL),
# il attend que OpenSSL::Crypto existe deja.
find_package(OpenSSL QUIET)
if (OpenSSL_FOUND AND TARGET OpenSSL::Crypto)
message(STATUS "Crypto: OpenSSL found -> provider available")
else()
message(STATUS "Crypto: OpenSSL not found -> provider will be disabled")
endif()
add_subdirectory(modules/crypto crypto_build)
if (TARGET vix::crypto OR TARGET vix_crypto)
set(VIX_HAS_CRYPTO ON)
if (TARGET vix_crypto AND NOT TARGET vix::crypto)
add_library(vix::crypto ALIAS vix_crypto)
endif()
else()
message(WARNING "Crypto module added but no vix::crypto target was exported.")
endif()
else()
message(STATUS "Crypto: disabled or not present.")
endif()
# Resolve real utils target (dereference ALIAS if needed)
set(_VIX_UTILS_REAL "")
vix_resolve_real_target(_VIX_UTILS_REAL vix_utils)
if (NOT _VIX_UTILS_REAL)
vix_resolve_real_target(_VIX_UTILS_REAL vix-utils)
endif()
if (NOT _VIX_UTILS_REAL)
vix_resolve_real_target(_VIX_UTILS_REAL utils)
endif()
# Propagate transitive include dirs from deps (avoid warnings from 3rd-party headers)
if (_VIX_UTILS_REAL AND NOT _VIX_UTILS_REAL STREQUAL "")
if (TARGET spdlog::spdlog)
get_target_property(_spdlog_inc spdlog::spdlog INTERFACE_INCLUDE_DIRECTORIES)
if (_spdlog_inc)
target_include_directories(${_VIX_UTILS_REAL} SYSTEM INTERFACE ${_spdlog_inc})
endif()
endif()
if (TARGET fmt::fmt)
get_target_property(_fmt_inc fmt::fmt INTERFACE_INCLUDE_DIRECTORIES)
if (_fmt_inc)
target_include_directories(${_VIX_UTILS_REAL} SYSTEM INTERFACE ${_fmt_inc})
endif()
endif()
else()
message(WARNING "Could not resolve real utils target (tried: vix_utils, vix-utils, utils).")
endif()
# --- Core ---
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/core/CMakeLists.txt")
message(STATUS "Adding 'modules/core'...")
add_subdirectory(modules/core core_build)
else()
message(FATAL_ERROR "Missing 'modules/core'. Run: git submodule update --init --recursive")
endif()
# --- Conversion (required by Validation) ---
set(VIX_HAS_CONVERSION OFF)
if (TARGET vix::conversion)
set(VIX_HAS_CONVERSION ON)
else()
# If you have it as a module, add it here (umbrella must not fetch)
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/conversion/CMakeLists.txt")
message(STATUS "Adding 'modules/conversion'...")
add_subdirectory(modules/conversion conversion_build)
if (TARGET vix::conversion OR TARGET vix_conversion)
set(VIX_HAS_CONVERSION ON)
if (TARGET vix_conversion AND NOT TARGET vix::conversion)
add_library(vix::conversion ALIAS vix_conversion)
endif()
else()
message(FATAL_ERROR "Conversion module added but no vix::conversion target was exported.")
endif()
else()
message(STATUS "Conversion: not present as module. Expecting it to be provided by core or another module.")
endif()
endif()
# --- Validation (optional) ---
set(VIX_HAS_VALIDATION OFF)
if (VIX_ENABLE_VALIDATION AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/validation/CMakeLists.txt")
if (NOT TARGET vix::conversion)
message(FATAL_ERROR "Validation requires vix::conversion. Ensure conversion is added before validation in the umbrella.")
endif()
message(STATUS "Adding 'modules/validation'...")
add_subdirectory(modules/validation validation_build)
if (TARGET vix::validation OR TARGET vix_validation)
set(VIX_HAS_VALIDATION ON)
if (TARGET vix_validation AND NOT TARGET vix::validation)
add_library(vix::validation ALIAS vix_validation)
endif()
else()
message(WARNING "Validation module added but no vix::validation target was exported.")
endif()
else()
message(STATUS "Validation: disabled or not present.")
endif()
# --- Async (optional) ---
set(VIX_HAS_ASYNC OFF)
if (VIX_ENABLE_ASYNC AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/async/CMakeLists.txt")
message(STATUS "Adding 'modules/async'...")
add_subdirectory(modules/async async_build)
if (TARGET vix::async OR TARGET vix_async)
set(VIX_HAS_ASYNC ON)
if (TARGET vix_async AND NOT TARGET vix::async)
add_library(vix::async ALIAS vix_async)
endif()
else()
message(WARNING "Async module added but no vix::async target was exported.")
endif()
else()
message(STATUS "Async: disabled or not present.")
endif()
# --- Net (required by P2P) ---
set(VIX_HAS_NET OFF)
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/net/CMakeLists.txt")
message(STATUS "Adding 'modules/net'...")
add_subdirectory(modules/net net_build)
if (TARGET vix::net OR TARGET vix_net)
set(VIX_HAS_NET ON)
if (TARGET vix_net AND NOT TARGET vix::net)
add_library(vix::net ALIAS vix_net)
endif()
else()
message(WARNING "Net module added but no vix::net target was exported.")
endif()
else()
message(STATUS "Net: not present (P2P will be disabled or will fetch standalone).")
endif()
# --- Cache (optional, used by P2P) ---
set(VIX_HAS_CACHE OFF)
if (VIX_ENABLE_CACHE AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/cache/CMakeLists.txt")
message(STATUS "Adding 'modules/cache'...")
add_subdirectory(modules/cache cache_build)
if (TARGET vix::cache OR TARGET vix_cache)
set(VIX_HAS_CACHE ON)
if (TARGET vix_cache AND NOT TARGET vix::cache)
add_library(vix::cache ALIAS vix_cache)
endif()
else()
message(WARNING "Cache module added but no vix::cache target was exported.")
endif()
else()
message(STATUS "Cache: disabled or not present.")
endif()
# --- Sync (optional, used by P2P) ---
set(VIX_HAS_SYNC OFF)
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/sync/CMakeLists.txt")
message(STATUS "Adding 'modules/sync'...")
add_subdirectory(modules/sync sync_build)
if (TARGET vix::sync OR TARGET vix_sync)
set(VIX_HAS_SYNC ON)
if (TARGET vix_sync AND NOT TARGET vix::sync)
add_library(vix::sync ALIAS vix_sync)
endif()
endif()
else()
message(STATUS "Sync: not present.")
endif()
# If net is missing, P2P must be disabled in umbrella (no auto-fetch here)
if (VIX_ENABLE_P2P AND NOT VIX_HAS_NET)
message(WARNING "P2P requested but Net module is missing -> disabling P2P in umbrella")
set(VIX_ENABLE_P2P OFF CACHE BOOL "Build Vix P2P module" FORCE)
endif()
# --- P2P (optional) ---
set(VIX_HAS_P2P OFF)
if (VIX_ENABLE_P2P AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/p2p/CMakeLists.txt")
message(STATUS "Adding 'modules/p2p'...")
add_subdirectory(modules/p2p p2p_build)
# Normalise: expose vix::p2p
if (TARGET vix::p2p OR TARGET vix_p2p)
set(VIX_HAS_P2P ON)
if (TARGET vix_p2p AND NOT TARGET vix::p2p)
add_library(vix::p2p ALIAS vix_p2p)
endif()
else()
message(WARNING "P2P module added but no vix::p2p target was exported.")
endif()
else()
message(STATUS "P2P: disabled or not present.")
endif()
# --- P2P HTTP Adapter (optional) ---
set(VIX_HAS_P2P_HTTP OFF)
# Guard: p2p_http requires both core + p2p
if (VIX_ENABLE_P2P_HTTP AND VIX_HAS_P2P AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/p2p_http/CMakeLists.txt")
message(STATUS "Adding 'modules/p2p_http'...")
add_subdirectory(modules/p2p_http p2p_http_build)
if (TARGET vix::p2p_http OR TARGET vix_p2p_http)
set(VIX_HAS_P2P_HTTP ON)
if (TARGET vix_p2p_http AND NOT TARGET vix::p2p_http)
add_library(vix::p2p_http ALIAS vix_p2p_http)
endif()
else()
message(WARNING "p2p_http module added but no vix::p2p_http target was exported.")
endif()
else()
message(STATUS "P2P HTTP: disabled, missing, or P2P not built.")
endif()
# --- Middleware (optional) ---
set(VIX_HAS_MIDDLEWARE OFF)
if (VIX_ENABLE_MIDDLEWARE AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/middleware/CMakeLists.txt")
message(STATUS "Adding 'modules/middleware'...")
add_subdirectory(modules/middleware middleware_build)
# Normalise: expose vix::middleware
if (TARGET vix::middleware OR TARGET vix_middleware)
set(VIX_HAS_MIDDLEWARE ON)
if (TARGET vix_middleware AND NOT TARGET vix::middleware)
add_library(vix::middleware ALIAS vix_middleware)
endif()
else()
message(WARNING "Middleware module added but no vix::middleware target was exported.")
endif()
else()
message(STATUS "Middleware: disabled or not present.")
endif()
# Bench mode (compile-time flags)
if (VIX_BENCH_MODE)
message(STATUS "Bench mode enabled: defining VIX_BENCH_MODE")
# Resolve the real core target (vix::core is an ALIAS in your tree)
set(_VIX_CORE_REAL "")
set(_VIX_CORE_REAL "")
vix_resolve_real_target(_VIX_CORE_REAL vix_core)
if (NOT _VIX_CORE_REAL)
vix_resolve_real_target(_VIX_CORE_REAL vix-core)
endif()
if (NOT _VIX_CORE_REAL)
vix_resolve_real_target(_VIX_CORE_REAL core)
endif()
if (_VIX_CORE_REAL)
target_compile_definitions(${_VIX_CORE_REAL} PUBLIC VIX_BENCH_MODE=1)
else()
message(WARNING "Bench mode requested but could not find real core target (tried: vix_core, vix-core, core).")
endif()
endif()
# --- DB (optional, required by ORM) ---
set(VIX_HAS_DB OFF)
if (VIX_ENABLE_DB AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/db/CMakeLists.txt")
message(STATUS "Adding 'modules/db'...")
add_subdirectory(modules/db db_build)
if (TARGET vix::db OR TARGET vix_db)
if (TARGET vix_db AND NOT TARGET vix::db)
add_library(vix::db ALIAS vix_db)
endif()
set(VIX_HAS_DB ON)
else()
message(WARNING "DB module added but no vix::db target was exported.")
endif()
else()
message(STATUS "DB: disabled or not present.")
endif()
# --- WebSocket (optional) ---
set(VIX_HAS_WEBSOCKET OFF)
if (VIX_ENABLE_WEBSOCKET AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/websocket/CMakeLists.txt")
message(STATUS "Adding 'modules/websocket'...")
set(VIX_WEBSOCKET_WITH_JSON "AUTO" CACHE STRING "Link JSON backend (AUTO|ON|OFF)")
add_subdirectory(modules/websocket websocket_build)
if (TARGET vix::websocket OR TARGET vix_websocket)
set(VIX_HAS_WEBSOCKET ON)
endif()
else()
message(STATUS "WebSocket: disabled or not present.")
endif()
# --- CLI (optional) ---
if (VIX_ENABLE_CLI AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/cli/CMakeLists.txt")
message(STATUS "Adding 'modules/cli'...")
add_subdirectory(modules/cli cli_build)
else()
message(STATUS "CLI: disabled or not present.")
endif()
# --- ORM (optional) ---
set(VIX_HAS_ORM OFF)
if (VIX_ENABLE_ORM AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/orm/CMakeLists.txt")
if (NOT VIX_HAS_DB)
message(FATAL_ERROR "ORM requires DB module. Enable it with -DVIX_ENABLE_DB=ON and ensure modules/db exists.")
endif()
message(STATUS "Adding 'modules/orm'...")
set(VIX_ORM_BUILD_EXAMPLES OFF CACHE BOOL "Build vix_orm examples")
set(VIX_ORM_BUILD_TESTS OFF CACHE BOOL "Build vix_orm tests")
add_subdirectory(modules/orm orm_build)
if (TARGET vix::orm OR TARGET vix_orm)
if (TARGET vix_orm AND NOT TARGET vix::orm)
add_library(vix::orm ALIAS vix_orm)
endif()
set(VIX_HAS_ORM ON)
else()
message(WARNING "ORM module added but no vix::orm target was exported.")
endif()
else()
message(STATUS "ORM: disabled or not present.")
endif()
# ----------------------------------------------------
# Link umbrella to required module targets
# ----------------------------------------------------
target_link_libraries(vix INTERFACE
vix::core
vix::utils
${JSON_TARGET}
)
if (TARGET vix::time)
target_link_libraries(vix INTERFACE vix::time)
endif()
if (TARGET vix::conversion)
target_link_libraries(vix INTERFACE vix::conversion)
endif()
if (TARGET vix::validation)
target_link_libraries(vix INTERFACE vix::validation)
endif()
if (TARGET vix::crypto)
target_link_libraries(vix INTERFACE vix::crypto)
endif()
if (TARGET vix::net)
target_link_libraries(vix INTERFACE vix::net)
endif()
if (TARGET vix::cache)
target_link_libraries(vix INTERFACE vix::cache)
endif()
if (TARGET vix::sync)
target_link_libraries(vix INTERFACE vix::sync)
endif()
if (TARGET vix::async)
target_link_libraries(vix INTERFACE vix::async)
endif()
if (TARGET vix::p2p)
target_link_libraries(vix INTERFACE vix::p2p)
endif()
if (TARGET vix::p2p_http)
target_link_libraries(vix INTERFACE vix::p2p_http)
endif()
if (TARGET vix::db)
target_link_libraries(vix INTERFACE vix::db)
endif()
if (TARGET vix::webrpc)
target_link_libraries(vix INTERFACE vix::webrpc)
endif()
# Link websocket only if it exists
if (TARGET vix::websocket)
target_link_libraries(vix INTERFACE vix::websocket)
elseif (TARGET vix_websocket)
add_library(vix::websocket ALIAS vix_websocket)
target_link_libraries(vix INTERFACE vix::websocket)
endif()
# Link middleware only if it exists
if (TARGET vix::middleware)
target_link_libraries(vix INTERFACE vix::middleware)
target_compile_definitions(vix INTERFACE VIX_HAS_MIDDLEWARE=1)
elseif (TARGET vix_middleware)
add_library(vix::middleware ALIAS vix_middleware)
target_link_libraries(vix INTERFACE vix::middleware)
target_compile_definitions(vix INTERFACE VIX_HAS_MIDDLEWARE=1)
endif()
# Propagate sanitizers to consumers (umbrella)
if (TARGET vix_sanitizers)
target_link_libraries(vix INTERFACE vix_sanitizers)
endif()
# ----------------------------------------------------
# Examples filtering
# ----------------------------------------------------
# Examples that require ORM at all
set(_ORM_EXAMPLES
demo_with_orm
error_handling
batch_insert_tx
users_crud
repository_crud_full
migrate_init
tx_unit_of_work
querybuilder_update
)
# Subset of ORM examples that require MySQL backend
set(_ORM_MYSQL_EXAMPLES
demo_with_orm
error_handling
batch_insert_tx
users_crud
repository_crud_full
migrate_init
tx_unit_of_work
querybuilder_update
)
# ----------------------------------------------------
# Examples (flat: examples/*.cpp and examples/orm/*.cpp)
# ----------------------------------------------------
if (VIX_BUILD_EXAMPLES)
file(GLOB VIX_UMBRELLA_EXAMPLES
CONFIGURE_DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/examples/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/examples/orm/*.cpp")
# 1) If ORM is OFF → remove all ORM examples
if (NOT VIX_HAS_ORM)
foreach(_ex IN LISTS _ORM_EXAMPLES)
list(FILTER VIX_UMBRELLA_EXAMPLES EXCLUDE REGEX ".*/${_ex}\\.cpp$")
list(FILTER VIX_UMBRELLA_EXAMPLES EXCLUDE REGEX ".*\\\\${_ex}\\.cpp$")
endforeach()
message(STATUS "Examples: ORM OFF → filtered ORM examples: ${_ORM_EXAMPLES}")
endif()
# 2) If ORM is ON but MySQL backend is OFF → remove MySQL-based ORM examples
if (VIX_HAS_ORM AND NOT VIX_DB_USE_MYSQL)
foreach(_ex IN LISTS _ORM_MYSQL_EXAMPLES)
list(FILTER VIX_UMBRELLA_EXAMPLES EXCLUDE REGEX ".*/${_ex}\\.cpp$")
list(FILTER VIX_UMBRELLA_EXAMPLES EXCLUDE REGEX ".*\\\\${_ex}\\.cpp$")
endforeach()
message(STATUS "Examples: MySQL OFF → filtered MySQL ORM examples: ${_ORM_MYSQL_EXAMPLES}")
endif()
if (VIX_UMBRELLA_EXAMPLES)
foreach(EXAMPLE_SRC IN LISTS VIX_UMBRELLA_EXAMPLES)
get_filename_component(_raw_name "${EXAMPLE_SRC}" NAME_WE)
if (_raw_name MATCHES "_common$" OR _raw_name MATCHES "_disabled$" OR _raw_name MATCHES "_internal$")
message(STATUS "Skipping helper/internal example: ${_raw_name}")
continue()
endif()