-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
1749 lines (1472 loc) · 60.1 KB
/
Copy pathCMakeLists.txt
File metadata and controls
1749 lines (1472 loc) · 60.1 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()
# Apply sanitizer flags to a real local target only.
function(vix_enable_sanitizers target)
if (NOT VIX_ENABLE_SANITIZERS)
return()
endif()
if (NOT TARGET "${target}")
return()
endif()
get_target_property(_target_type "${target}" TYPE)
if (NOT _target_type)
return()
endif()
# INTERFACE libraries do not compile or link anything themselves.
# Sanitizer flags must not be applied to them.
if (_target_type STREQUAL "INTERFACE_LIBRARY")
message(STATUS "Sanitizers: skipping interface target '${target}'")
return()
endif()
if (MSVC)
message(FATAL_ERROR "Sanitizers are not supported on MSVC. Use Clang or GCC.")
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
target_compile_options(${target} PRIVATE
-O1
-g
-fno-omit-frame-pointer
-fsanitize=address,undefined
)
target_link_options(${target} PRIVATE
-fsanitize=address,undefined
)
endif()
endfunction()
# Resolve the first existing target name among candidates, then apply sanitizers.
function(vix_enable_sanitizers_first)
foreach(_candidate IN LISTS ARGN)
if (TARGET "${_candidate}")
get_target_property(_aliased "${_candidate}" ALIASED_TARGET)
if (_aliased)
vix_enable_sanitizers("${_aliased}")
else()
vix_enable_sanitizers("${_candidate}")
endif()
return()
endif()
endforeach()
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" ${VIX_BUILD_TESTS})
option(VIX_TIME_BUILD_BENCH "Build vix::time benchmarks" OFF)
option(VIX_ENABLE_TESTS_MODULE "Build Vix Tests module" ON)
option(VIX_ENABLE_TEMPLATE "Build Vix Template module" ON)
option(VIX_TEMPLATE_BUILD_TESTS "Build vix::template tests" ${VIX_BUILD_TESTS})
option(VIX_TEMPLATE_BUILD_EXAMPLES "Build vix::template examples" OFF)
option(VIX_TEMPLATE_BUILD_BENCH "Build vix::template benchmarks" OFF)
option(VIX_ENABLE_PROCESS "Build Vix Process module" ON)
option(VIX_ENABLE_THREADPOOL "Build Vix ThreadPool module" ON)
option(VIX_THREADPOOL_BUILD_EXAMPLES "Build vix::threadpool examples" OFF)
option(VIX_THREADPOOL_BUILD_TESTS "Build vix::threadpool tests" ${VIX_BUILD_TESTS})
option(VIX_THREADPOOL_BUILD_BENCHMARKS "Build vix::threadpool benchmarks" OFF)
option(VIX_ENABLE_KV "Build Vix KV module" ON)
option(VIX_KV_BUILD_EXAMPLES "Build vix::kv examples" OFF)
option(VIX_KV_BUILD_TESTS "Build vix::kv tests" ${VIX_BUILD_TESTS})
option(VIX_KV_BUILD_BENCHMARKS "Build vix::kv benchmarks" OFF)
option(VIX_ENABLE_AGENT "Build Vix AI Agent module" ON)
option(VIX_AGENT_BUILD_TESTS "Build vix::ai_agent tests" ${VIX_BUILD_TESTS})
option(VIX_AGENT_BUILD_EXAMPLES "Build vix::ai_agent examples" OFF)
option(VIX_ENABLE_GAME "Build Vix Game module" ON)
option(VIX_GAME_BUILD_TESTS "Build vix::game tests" ${VIX_BUILD_TESTS})
option(VIX_GAME_BUILD_EXAMPLES "Build vix::game examples" OFF)
option(VIX_GAME_ENABLE_SDL "Enable SDL backend for vix::game" OFF)
option(VIX_GAME_ENABLE_SDL_OPENGL "Enable SDL OpenGL renderer backend for vix::game" OFF)
option(VIX_ORM_BUILD_EXAMPLES "Build vix::orm examples" OFF)
option(VIX_ORM_BUILD_TESTS "Build vix::orm tests" ${VIX_BUILD_TESTS})
# ----------------------------------------------------
# Module test defaults
# ----------------------------------------------------
# The root tests/ directory may be empty. In umbrella builds, tests live
# inside modules/*, so VIX_BUILD_TESTS must propagate to module options.
set(VIX_ERROR_BUILD_TESTS ${VIX_BUILD_TESTS} CACHE BOOL "Build vix::error tests")
set(VIX_PATH_BUILD_TESTS ${VIX_BUILD_TESTS} CACHE BOOL "Build vix::path tests")
set(VIX_FS_BUILD_TESTS ${VIX_BUILD_TESTS} CACHE BOOL "Build vix::fs tests")
set(VIX_IO_BUILD_TESTS ${VIX_BUILD_TESTS} CACHE BOOL "Build vix::io tests")
set(VIX_ENV_BUILD_TESTS ${VIX_BUILD_TESTS} CACHE BOOL "Build vix::env tests")
set(VIX_OS_BUILD_TESTS ${VIX_BUILD_TESTS} CACHE BOOL "Build vix::os tests")
set(VIX_LOG_BUILD_TESTS ${VIX_BUILD_TESTS} CACHE BOOL "Build vix::log tests")
set(VIX_UTILS_BUILD_TESTS ${VIX_BUILD_TESTS} CACHE BOOL "Build vix::utils tests")
set(VIX_JSON_BUILD_TESTS ${VIX_BUILD_TESTS} CACHE BOOL "Build vix::json tests")
set(VIX_CORE_BUILD_TESTS ${VIX_BUILD_TESTS} CACHE BOOL "Build vix::core tests")
set(VIX_ASYNC_BUILD_TESTS ${VIX_BUILD_TESTS} CACHE BOOL "Build vix::async tests")
set(VIX_CRYPTO_BUILD_TESTS ${VIX_BUILD_TESTS} CACHE BOOL "Build vix::crypto tests")
set(VIX_CONVERSION_BUILD_TESTS ${VIX_BUILD_TESTS} CACHE BOOL "Build vix::conversion tests")
set(VIX_VALIDATION_BUILD_TESTS ${VIX_BUILD_TESTS} CACHE BOOL "Build vix::validation tests")
set(VIX_WEBRPC_BUILD_TESTS ${VIX_BUILD_TESTS} CACHE BOOL "Build vix::webrpc tests")
set(VIX_NET_BUILD_TESTS ${VIX_BUILD_TESTS} CACHE BOOL "Build vix::net tests")
set(VIX_SYNC_BUILD_TESTS ${VIX_BUILD_TESTS} CACHE BOOL "Build vix::sync tests")
set(VIX_CACHE_BUILD_TESTS ${VIX_BUILD_TESTS} CACHE BOOL "Build vix::cache tests")
set(VIX_P2P_BUILD_TESTS ${VIX_BUILD_TESTS} CACHE BOOL "Build vix::p2p tests")
set(VIX_P2P_HTTP_BUILD_TESTS ${VIX_BUILD_TESTS} CACHE BOOL "Build vix::p2p_http tests")
set(VIX_DB_BUILD_TESTS ${VIX_BUILD_TESTS} CACHE BOOL "Build vix::db tests")
set(VIX_MIDDLEWARE_BUILD_TESTS ${VIX_BUILD_TESTS} CACHE BOOL "Build vix::middleware tests")
set(VIX_CLI_BUILD_TESTS ${VIX_BUILD_TESTS} CACHE BOOL "Build vix::cli tests")
set(VIX_WEBSOCKET_BUILD_TESTS ${VIX_BUILD_TESTS} CACHE BOOL "Build vix::websocket tests")
# Some modules use their own public option names.
set(TEMPLATE_BUILD_TESTS ${VIX_TEMPLATE_BUILD_TESTS} CACHE BOOL "Build template tests")
set(VIX_AI_AGENT_BUILD_TESTS ${VIX_AGENT_BUILD_TESTS} CACHE BOOL "Build vix ai agent tests")
# ----------------------------------------------------
# Testing bootstrap
# ----------------------------------------------------
# Must happen before add_subdirectory(modules/*), otherwise module tests may
# be built but not registered correctly in the umbrella CTest tree.
if (VIX_BUILD_TESTS)
include(CTest)
enable_testing()
find_package(GTest QUIET)
if (NOT GTest_FOUND)
message(STATUS "GTest not found, fetching googletest...")
fetchcontent_declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.14.0
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
fetchcontent_makeavailable(googletest)
endif()
endif()
# ----------------------------------------------------
# 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) — internal flags only
# ----------------------------------------------------
if (VIX_ENABLE_SANITIZERS)
message(STATUS "Sanitizers enabled via internal target flags.")
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: 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_compile_options(vix_thirdparty_asio INTERFACE
$<$<CXX_COMPILER_ID:GNU>:-Wno-null-dereference>
)
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 only for local builds.
# Do not export them through the installed package.
if (TARGET vix_warnings)
target_link_libraries(vix INTERFACE
$<BUILD_INTERFACE:vix_warnings>
)
endif()
if (TARGET vix_coverage)
target_link_libraries(vix INTERFACE
$<BUILD_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 "")
# --- Error ---
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/error/CMakeLists.txt")
message(STATUS "Adding 'modules/error'...")
add_subdirectory(modules/error error_build)
else()
message(FATAL_ERROR "Missing 'modules/error'. Run: git submodule update --init --recursive")
endif()
# --- Path ---
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/path/CMakeLists.txt")
message(STATUS "Adding 'modules/path'...")
add_subdirectory(modules/path path_build)
else()
message(FATAL_ERROR "Missing 'modules/path'. Run: git submodule update --init --recursive")
endif()
# --- FS ---
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/fs/CMakeLists.txt")
message(STATUS "Adding 'modules/fs'...")
add_subdirectory(modules/fs fs_build)
else()
message(FATAL_ERROR "Missing 'modules/fs'. Run: git submodule update --init --recursive")
endif()
# --- IO ---
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/io/CMakeLists.txt")
message(STATUS "Adding 'modules/io'...")
add_subdirectory(modules/io io_build)
else()
message(FATAL_ERROR "Missing 'modules/io'. Run: git submodule update --init --recursive")
endif()
# --- Env ---
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/env/CMakeLists.txt")
message(STATUS "Adding 'modules/env'...")
add_subdirectory(modules/env env_build)
else()
message(FATAL_ERROR "Missing 'modules/env'. Run: git submodule update --init --recursive")
endif()
# --- OS ---
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/os/CMakeLists.txt")
message(STATUS "Adding 'modules/os'...")
add_subdirectory(modules/os os_build)
else()
message(FATAL_ERROR "Missing 'modules/os'. Run: git submodule update --init --recursive")
endif()
# --- 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()
# --- Log ---
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/log/CMakeLists.txt")
message(STATUS "Adding 'modules/log'...")
add_subdirectory(modules/log log_build)
else()
message(FATAL_ERROR "Missing 'modules/log'. Run: git submodule update --init --recursive")
endif()
# --- Tests (optional) ---
set(VIX_HAS_TESTS OFF)
if (VIX_ENABLE_TESTS_MODULE AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/tests/CMakeLists.txt")
message(STATUS "Adding 'modules/tests'...")
add_subdirectory(modules/tests tests_build)
if (TARGET vix::tests OR TARGET vix_tests)
set(VIX_HAS_TESTS ON)
if (TARGET vix_tests AND NOT TARGET vix::tests)
add_library(vix::tests ALIAS vix_tests)
endif()
else()
message(WARNING "Tests module added but no vix::tests target was exported.")
endif()
else()
message(STATUS "Tests module: disabled or not present.")
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()
# --- 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()
# --- Process (optional) ---
set(VIX_HAS_PROCESS OFF)
if (VIX_ENABLE_PROCESS AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/process/CMakeLists.txt")
message(STATUS "Adding 'modules/process'...")
add_subdirectory(modules/process process_build)
if (TARGET vix::process OR TARGET vix_process)
set(VIX_HAS_PROCESS ON)
if (TARGET vix_process AND NOT TARGET vix::process)
add_library(vix::process ALIAS vix_process)
endif()
else()
message(WARNING "Process module added but no vix::process target was exported.")
endif()
else()
message(STATUS "Process: disabled or not present.")
endif()
# --- ThreadPool (optional) ---
set(VIX_HAS_THREADPOOL OFF)
if (VIX_ENABLE_THREADPOOL AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/threadpool/CMakeLists.txt")
message(STATUS "Adding 'modules/threadpool'...")
set(VIX_THREADPOOL_BUILD_EXAMPLES ${VIX_THREADPOOL_BUILD_EXAMPLES} CACHE BOOL "Build vix::threadpool examples" FORCE)
set(VIX_THREADPOOL_BUILD_TESTS ${VIX_THREADPOOL_BUILD_TESTS} CACHE BOOL "Build vix::threadpool tests" FORCE)
set(VIX_THREADPOOL_BUILD_BENCHMARKS ${VIX_THREADPOOL_BUILD_BENCHMARKS} CACHE BOOL "Build vix::threadpool benchmarks" FORCE)
add_subdirectory(modules/threadpool threadpool_build)
if (TARGET vix::threadpool OR TARGET vix_threadpool)
set(VIX_HAS_THREADPOOL ON)
if (TARGET vix_threadpool AND NOT TARGET vix::threadpool)
add_library(vix::threadpool ALIAS vix_threadpool)
endif()
else()
message(WARNING "ThreadPool module added but no vix::threadpool target was exported.")
endif()
else()
message(STATUS "ThreadPool: disabled or not present.")
endif()
# --- KV (optional) ---
set(VIX_HAS_KV OFF)
if (VIX_ENABLE_KV AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/kv/CMakeLists.txt")
message(STATUS "Adding 'modules/kv'...")
set(VIX_KV_BUILD_EXAMPLES ${VIX_KV_BUILD_EXAMPLES} CACHE BOOL "Build vix::kv examples" FORCE)
set(VIX_KV_BUILD_TESTS ${VIX_KV_BUILD_TESTS} CACHE BOOL "Build vix::kv tests" FORCE)
set(VIX_KV_BUILD_BENCHMARKS ${VIX_KV_BUILD_BENCHMARKS} CACHE BOOL "Build vix::kv benchmarks" FORCE)
add_subdirectory(modules/kv kv_build)
if (TARGET vix::kv OR TARGET vix_kv)
set(VIX_HAS_KV ON)
if (TARGET vix_kv AND NOT TARGET vix::kv)
add_library(vix::kv ALIAS vix_kv)
endif()
else()
message(WARNING "KV module added but no vix::kv target was exported.")
endif()
else()
message(STATUS "KV: disabled or not present.")
endif()
# --- Template (optional) ---
set(VIX_HAS_TEMPLATE OFF)
if (VIX_ENABLE_TEMPLATE AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/template/CMakeLists.txt")
message(STATUS "Adding 'modules/template'...")
set(TEMPLATE_BUILD_TESTS ${VIX_TEMPLATE_BUILD_TESTS} CACHE BOOL "" FORCE)
set(TEMPLATE_BUILD_EXAMPLES ${VIX_TEMPLATE_BUILD_EXAMPLES} CACHE BOOL "" FORCE)
set(TEMPLATE_BUILD_BENCHMARKS ${VIX_TEMPLATE_BUILD_BENCH} CACHE BOOL "" FORCE)
set(TEMPLATE_INSTALL OFF CACHE BOOL "" FORCE)
add_subdirectory(modules/template template_build)
if (TARGET vix::template)
set(VIX_HAS_TEMPLATE ON)
elseif (TARGET template)
set(VIX_HAS_TEMPLATE ON)
else()
message(WARNING "Template module added but no template target was exported.")
endif()
else()
message(STATUS "Template: disabled or not present.")
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()
# --- Game (optional) ---
set(VIX_HAS_GAME OFF)
if (VIX_ENABLE_GAME AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/game/CMakeLists.txt")
if (NOT TARGET vix::error)
message(FATAL_ERROR "Game requires vix::error. Ensure error is added before game.")
endif()
if (NOT TARGET vix::time)
message(FATAL_ERROR "Game requires vix::time. Ensure time is added before game.")
endif()
if (NOT TARGET vix::fs)
message(FATAL_ERROR "Game requires vix::fs. Ensure fs is added before game.")
endif()
if (NOT TARGET vix::path)
message(FATAL_ERROR "Game requires vix::path. Ensure path is added before game.")
endif()
if (NOT TARGET vix::json)
message(FATAL_ERROR "Game requires vix::json. Ensure json is added before game.")
endif()
if (NOT TARGET vix::log)
message(FATAL_ERROR "Game requires vix::log. Ensure log is added before game.")
endif()
if (NOT TARGET vix::threadpool)
message(FATAL_ERROR "Game requires vix::threadpool. Ensure threadpool is added before game.")
endif()
if (NOT TARGET vix::async)
message(FATAL_ERROR "Game requires vix::async. Ensure async is added before game.")
endif()
if (VIX_GAME_BUILD_EXAMPLES AND NOT TARGET vix::core)
message(FATAL_ERROR "Game examples require vix::core because they use vix::print.")
endif()
message(STATUS "Adding 'modules/game'...")
set(VIX_GAME_BUILD_TESTS ${VIX_GAME_BUILD_TESTS} CACHE BOOL "Build vix::game tests" FORCE)
set(VIX_GAME_BUILD_EXAMPLES ${VIX_GAME_BUILD_EXAMPLES} CACHE BOOL "Build vix::game examples" FORCE)
set(VIX_GAME_ENABLE_SDL ${VIX_GAME_ENABLE_SDL} CACHE BOOL "Enable SDL backend for vix::game" FORCE)
set(VIX_GAME_ENABLE_SDL_OPENGL ${VIX_GAME_ENABLE_SDL_OPENGL} CACHE BOOL "Enable SDL OpenGL renderer backend for vix::game" FORCE)
add_subdirectory(modules/game game_build)
if (TARGET vix::game OR TARGET vix_game)
set(VIX_HAS_GAME ON)
if (TARGET vix_game AND NOT TARGET vix::game)
add_library(vix::game ALIAS vix_game)
endif()
else()
message(WARNING "Game module added but no vix::game target was exported.")
endif()
else()
message(STATUS "Game: disabled or not present.")
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()
# --- 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()