-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
2362 lines (2193 loc) · 126 KB
/
Copy pathCMakeLists.txt
File metadata and controls
2362 lines (2193 loc) · 126 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.21)
# SYS-W11-10: one authoritative version source (the repo-root VERSION file)
# for MeshCraft/Mc3/Mcb/mc3togltf/mc3tomcb, so the root project, each
# standalone-buildable component, package configs, --version, release
# archive names, and the changelog can never drift out of sync with each
# other. Read before project() since project(VERSION ...) needs the value
# directly, not a variable set afterward.
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" MESHCRAFT_VERSION_STRING LIMIT_COUNT 1)
project(MeshCraft VERSION ${MESHCRAFT_VERSION_STRING} LANGUAGES C CXX)
include(CTest)
include(GNUInstallDirs)
message(STATUS "Project: ${PROJECT_NAME}")
message(STATUS "Platform: ${CMAKE_SYSTEM_NAME}")
message(STATUS "Compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
if (NOT WIN32 AND CMAKE_BINARY_DIR MATCHES "build-windows")
message(WARNING "Building in 'build-windows' directory, but WIN32 is not set. "
"Make sure you used -DCMAKE_TOOLCHAIN_FILE=<toolchain> on a CLEAN build directory.")
endif()
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# AUD-055: opt-in AddressSanitizer + UndefinedBehaviorSanitizer build for the
# first-party targets that parse untrusted input (Mc3's XML parser, Mcb's
# binary reader) or are otherwise part of this project's own surface --
# deliberately NOT applied to CNA/SHARP_RUNTIME/vendored deps (imgui,
# manifold, tinyobjloader, tinygltf, httplib): those are third-party/sibling
# code this project doesn't own (see CLAUDE.md -- no CNA changes without
# owner permission), so instrumenting them is out of scope here. This means
# a bug that only manifests across the instrumented/uninstrumented boundary
# may not be caught -- a real, accepted limitation of a first-party-only
# opt-in build, not full whole-program coverage.
#
# cmake -S . -B build-asan -DMESHCRAFT_SANITIZE=ON
# cmake --build build-asan && ctest --test-dir build-asan
option(MESHCRAFT_SANITIZE
"Build first-party MeshCraft targets (Mc3/Mcb/mc3togltf/mc3tomcb/editor) with ASan+UBSan. Does not instrument CNA/SHARP_RUNTIME/vendored deps."
OFF)
if(MESHCRAFT_SANITIZE)
if(MSVC)
message(WARNING "MESHCRAFT_SANITIZE is not wired up for MSVC; ignoring.")
set(MESHCRAFT_SANITIZE OFF)
else()
set(MESHCRAFT_SANITIZE_COMPILE_OPTIONS -fsanitize=address,undefined -fno-omit-frame-pointer -g)
# The link flag has to be applied at every EXECUTABLE's final link
# step, not just the instrumented static libraries themselves --
# otherwise a test executable that links an instrumented Mc3/Mcb/
# mc3togltf_lib fails with "undefined reference to __asan_*" (the
# object files reference the sanitizer runtime, but nothing tells
# the final link to pull it in). add_link_options() here, before any
# add_subdirectory() below, applies it to every target created
# anywhere in this build -- including CNA/SHARP_RUNTIME/vendored
# deps and the test executables in mc3/mcb/mc3togltf. Those
# dependencies are not compiled WITH sanitizer instrumentation
# (meshcraft_apply_sanitize() below is only called on first-party
# targets), but linking the runtime into every final binary is
# required for any of this to link at all, and is harmless for
# non-instrumented object code.
add_link_options(-fsanitize=address,undefined)
endif()
endif()
# Applies the ASan/UBSan COMPILE-time instrumentation to `tgt` when
# MESHCRAFT_SANITIZE is ON; no-op otherwise. Called from this file and from
# the first-party subdirectories (mc3/mcb/mc3togltf/mc3tomcb) after each of
# their own target definitions -- MESHCRAFT_SANITIZE is a cache variable set
# here at the root, visible in every add_subdirectory() below it. Only
# instruments first-party code (see the option() help text above for why);
# the link-time runtime is wired in globally, above, since it must be.
function(meshcraft_apply_sanitize tgt)
if(MESHCRAFT_SANITIZE AND TARGET ${tgt})
target_compile_options(${tgt} PRIVATE ${MESHCRAFT_SANITIZE_COMPILE_OPTIONS})
endif()
endfunction()
# -----------------------------------------------------------------------------
# Graphics backend selection
# -----------------------------------------------------------------------------
#
# This variable selects the CNA engine backend. MeshCraft's ImGui renderer
# consumes ImDrawData through CNA graphics APIs, so it does not require an
# native graphics context or a renderer backend tied to one API.
#
# Override with:
# cmake -S . -B build -DMESH_CRAFT_GRAPHICS_BACKEND=EASYGL
# cmake -S . -B build-vulkan -DMESH_CRAFT_GRAPHICS_BACKEND=VULKAN
# cmake -S . -B build-webgpu -DMESH_CRAFT_GRAPHICS_BACKEND=WEBGPU
#
# Accepted (CNA engine): SDL_RENDERER, EASYGL, BGFX, VULKAN, WEBGPU.
# Editor compatibility is determined by CNA's selected backend capabilities.
# -----------------------------------------------------------------------------
set(MESH_CRAFT_GRAPHICS_BACKEND "EASYGL" CACHE STRING
"CNA engine backend used by the MeshCraft editor GUI.")
set_property(CACHE MESH_CRAFT_GRAPHICS_BACKEND PROPERTY STRINGS
SDL_RENDERER EASYGL BGFX VULKAN WEBGPU)
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/MeshCraftGraphicsBackend.cmake")
meshcraft_select_graphics_backend(
"${MESH_CRAFT_GRAPHICS_BACKEND}" "${ANDROID}" "${EMSCRIPTEN}"
MESH_CRAFT_GRAPHICS_BACKEND_UPPER)
if(EMSCRIPTEN)
# -sWASM_LEGACY_EXCEPTIONS=0 must match CNA, which sets it in its own root CMakeLists: it
# selects the standardized try_table exception ABI over Emscripten's still-default legacy
# `try`. Without it, MeshCraft's own objects and its third-party subtrees (lua54, imgui,
# manifold, tinygltf) are built on the legacy ABI while everything under CNA_dep uses the
# standardized one, and the browser refuses the linked module outright:
# "module uses a mix of legacy and new exception handling instructions".
add_compile_options(-fwasm-exceptions -sWASM_LEGACY_EXCEPTIONS=0)
add_link_options(-fwasm-exceptions -sWASM_LEGACY_EXCEPTIONS=0)
endif()
if(NOT MESH_CRAFT_GRAPHICS_BACKEND_UPPER MATCHES "^(SDL_RENDERER|EASYGL|BGFX|VULKAN|WEBGPU)$")
message(FATAL_ERROR
"Unsupported MESH_CRAFT_GRAPHICS_BACKEND='${MESH_CRAFT_GRAPHICS_BACKEND}'. "
"Use SDL_RENDERER, EASYGL, BGFX, VULKAN, or WEBGPU.")
endif()
message(STATUS "MeshCraft graphics backend (CNA engine): ${MESH_CRAFT_GRAPHICS_BACKEND_UPPER}")
# CNA no longer has a CNA_GRAPHICS_BACKEND string or CNA_BACKEND_<NAME> options:
# graphics implementations were modularized into modules/renderers/<family>,
# selected by the single CNA_GRAPHICS_RENDERER identity in CNA's own
# cmake/RendererSelection.cmake, and the library targets were renamed from
# cna_backend_graphics_<family> to cna_renderer_<family>. Setting the old
# variables was silently ignored, so CNA always built its platform default
# renderer while this file still tried to link the vanished
# cna_backend_graphics_* target.
#
# MeshCraft keeps its own five-value MESH_CRAFT_GRAPHICS_BACKEND vocabulary
# (it is what GraphicsBackendCheck and MESH_CRAFT_GRAPHICS_BACKEND_STR speak)
# and maps it here, in one place, onto both the CNA identity to select and the
# CNA target to link.
if(MESH_CRAFT_GRAPHICS_BACKEND_UPPER STREQUAL "SDL_RENDERER")
set(_cna_renderer_identity "SDL_RENDERER")
set(_cna_backend_target cna_renderer_sdl_renderer)
elseif(MESH_CRAFT_GRAPHICS_BACKEND_UPPER STREQUAL "EASYGL")
# EasyGL is an internal implementation family in CNA now, not a public
# identity: it is reached through one of five GL-profile names. WEBGL2 is
# the Emscripten one; OPENGLES3 is CNA's own Linux default for the same
# family, which is the profile MeshCraft has been building all along.
if(EMSCRIPTEN)
set(_cna_renderer_identity "WEBGL2")
else()
set(_cna_renderer_identity "OPENGLES3")
endif()
set(_cna_backend_target cna_renderer_easygl)
elseif(MESH_CRAFT_GRAPHICS_BACKEND_UPPER STREQUAL "BGFX")
set(_cna_renderer_identity "BGFX")
set(_cna_backend_target cna_renderer_bgfx)
elseif(MESH_CRAFT_GRAPHICS_BACKEND_UPPER STREQUAL "VULKAN")
set(_cna_renderer_identity "VULKAN")
set(_cna_backend_target cna_renderer_vulkan)
elseif(MESH_CRAFT_GRAPHICS_BACKEND_UPPER STREQUAL "WEBGPU")
set(_cna_renderer_identity "WEBGPU")
set(_cna_backend_target cna_renderer_webgpu)
endif()
set(CNA_GRAPHICS_RENDERER "${_cna_renderer_identity}" CACHE STRING "" FORCE)
message(STATUS
"MeshCraft: CNA graphics renderer identity: ${_cna_renderer_identity} "
"(target ${_cna_backend_target})")
# -----------------------------------------------------------------------------
# Dependencies
# -----------------------------------------------------------------------------
set(MESH_CRAFT_BUILD_TESTING "${BUILD_TESTING}" CACHE BOOL "Build MeshCraft tests")
set(BUILD_TESTING OFF CACHE BOOL "" FORCE)
set(BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(CNA_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(CNA_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(EASY_GL_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(EASY_GL_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(EASYGL_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(EASYGL_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
# MeshCraft is a single-user desktop editor with no multiplayer/Xbox-Live-
# style networking — it never links CNA_GamerServices or CNA_Net (confirmed:
# neither appears in this file's target_link_libraries calls). CNA_ENABLE_NET
# defaults to ON in ../cna/CMakeLists.txt, unconditionally pulling both into
# the default `ninja`/`all` target even though nothing here needs them.
# Disabling it removes an unused, un-built-by-MeshCraft component from the
# default build graph — not a CNA source change, just not opting into an
# optional CNA feature this project doesn't use.
set(CNA_ENABLE_NET OFF CACHE BOOL "" FORCE)
# -----------------------------------------------------------------------------
# AUD-057: sibling-repo revision check (informational, configure-time)
#
# ../cna and ../sharp-runtime are separate git repositories consumed by
# relative path (not a submodule or pinned dependency) -- whatever happens to
# be checked out there is what gets built. That is non-reproducible and,
# per README.md, has previously broken a from-scratch rebuild without
# warning. A hard version PIN with a FATAL_ERROR on mismatch is deliberately
# NOT used here: CNA is developed by a separate process (see CLAUDE.md --
# "No CNA changes without owner permission. A separate Claude Code instance
# handles CNA.") and legitimately moves ahead of whatever revision this
# project last verified against; failing configure on every such move would
# block that work. Instead this prints a non-fatal heads-up so a drifted
# sibling revision is the first, not the last, suspect when something breaks.
# Update the two *_VERIFIED_SHA values below after re-running `ctest` against
# a newer sibling checkout and confirming it still passes.
# -----------------------------------------------------------------------------
set(MESHCRAFT_CNA_VERIFIED_SHA "d0c21ee613ebd8f8b0055f7868103dd5c5c30fc7")
set(MESHCRAFT_SHARP_RUNTIME_VERIFIED_SHA "5cdaafb2bace46dce5393da21dad9ff9f8ad3c58")
function(meshcraft_check_sibling_revision name path expected_sha)
if(EXISTS "${path}/.git")
execute_process(
COMMAND git -C "${path}" rev-parse HEAD
OUTPUT_VARIABLE _actual_sha
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE _git_rc
ERROR_QUIET
)
if(_git_rc EQUAL 0 AND NOT _actual_sha STREQUAL expected_sha)
message(WARNING
"AUD-057: ${name} at '${path}' is checked out at ${_actual_sha}, "
"not the revision (${expected_sha}) MeshCraft's own test "
"suite was last verified against. Not necessarily broken -- "
"${name} is developed independently -- but if the build or "
"tests fail, this drift is a likely first suspect. Re-verify "
"with `ctest` and update MESHCRAFT_${name}_VERIFIED_SHA in "
"CMakeLists.txt once confirmed working.")
endif()
endif()
endfunction()
meshcraft_check_sibling_revision(CNA "${CMAKE_CURRENT_SOURCE_DIR}/../cna" "${MESHCRAFT_CNA_VERIFIED_SHA}")
meshcraft_check_sibling_revision(SHARP_RUNTIME "${CMAKE_CURRENT_SOURCE_DIR}/../sharp-runtime" "${MESHCRAFT_SHARP_RUNTIME_VERIFIED_SHA}")
# SYS-W14-15: enables CNA::Devices::FileDialog (native open/save dialogs) for
# the editor's texture/mesh path fields. CNA_DEVICES is an existing CNA-side
# CMake option (off by default, "device/sensor extensions beyond XNA 4.0");
# forcing it on here is a mesh-craft-side consumer choice, not a CNA edit.
set(CNA_DEVICES ON CACHE BOOL "" FORCE)
# CNA — XNA-like runtime (window, input, audio, graphics)
add_subdirectory(../cna CNA_dep)
# -----------------------------------------------------------------------------
# The slice of CNA and sharp-runtime MeshCraft actually consumes
# -----------------------------------------------------------------------------
#
# `CNA` is an umbrella INTERFACE target meaning "the whole framework": runtime,
# devices, devices-ext, graphics-ext, cnaext, storage, content, media, audio,
# input, graphics core, core, math, platform and the selected renderer. This
# editor includes headers from six of those modules and no others:
#
# Microsoft/Xna/Framework/{Game,GameTime}.hpp -> cna_runtime
# Microsoft/Xna/Framework/Graphics/* -> cna_graphics_core
# Microsoft/Xna/Framework/Input/* -> cna_input
# Microsoft/Xna/Framework/Audio/* -> cna_audio
# Microsoft/Xna/Framework/{Color,Matrix,Vector3,...}.hpp -> cna_math
# CNA/Devices/FileDialog.hpp -> cna_devices_ext
#
# All six are named explicitly rather than leaning on the PUBLIC edges between
# them, so a later change to CNA's internal wiring cannot quietly pull a module
# out from under MeshCraft. Relative to the umbrella this drops cna_devices,
# cna_graphics_ext, cna_cnaext and cna_storage -- MeshCraft includes no header
# from any of them. cna_core/cna_platform/cna_content/cna_media still arrive as
# PUBLIC dependencies of the six above; those are CNA's own internal edges, not
# a MeshCraft dependency to declare.
set(MESHCRAFT_CNA_MODULES
cna_runtime
cna_graphics_core
cna_input
cna_audio
cna_math
cna_devices_ext)
# sharp-runtime is consumed the same way. CNA already narrows it from the
# default `All` selection to its own ten-component closure and rebuilds a
# compatibility SHARP_RUNTIME umbrella over that closure, so nothing here has to
# fight the `All` build. MeshCraft's own sources reach sharp-runtime for
# System/Object.hpp alone, so they name that one component and let everything
# else arrive through the CNA modules that declare it. The else branch mirrors
# CNA's own shape detection for a pre-modularization (monolithic) checkout,
# where the per-component targets do not exist at all.
if(TARGET SharpRuntime::Core.Base)
set(MESHCRAFT_SHARP_RUNTIME_TARGETS SharpRuntime::Core.Base)
else()
set(MESHCRAFT_SHARP_RUNTIME_TARGETS SHARP_RUNTIME)
endif()
set(BUILD_TESTING "${MESH_CRAFT_BUILD_TESTING}" CACHE BOOL "" FORCE)
# Mc3 — MC3 format library (pure C++, no graphics dependency)
add_subdirectory(mc3)
# Mcb — MCB binary format library
add_subdirectory(mcb)
# mc3tomcb — CLI converter between MC3 XML and MCB binary
add_subdirectory(mc3tomcb)
# ImGui — immediate-mode UI (SDL3 input platform backend; rendering is CNA).
include(FetchContent)
FetchContent_Declare(imgui
GIT_REPOSITORY https://github.com/ocornut/imgui.git
GIT_TAG v1.91.6
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(imgui)
add_library(imgui STATIC
${imgui_SOURCE_DIR}/imgui.cpp
${imgui_SOURCE_DIR}/imgui_draw.cpp
${imgui_SOURCE_DIR}/imgui_tables.cpp
${imgui_SOURCE_DIR}/imgui_widgets.cpp
${imgui_SOURCE_DIR}/backends/imgui_impl_sdl3.cpp
)
target_include_directories(imgui PUBLIC
${imgui_SOURCE_DIR}
${imgui_SOURCE_DIR}/backends
)
# SDL3 headers: use prebuilt path from CNA's SDL3_DIR cache variable
# SDL3_DIR is .../lib/cmake/SDL3, so include dir is 3 levels up + /include
if(DEFINED SDL3_DIR)
get_filename_component(_sdl3_inc "${SDL3_DIR}/../../../include" ABSOLUTE)
target_include_directories(imgui PUBLIC "${_sdl3_inc}")
elseif(TARGET SDL3::SDL3)
target_link_libraries(imgui PUBLIC SDL3::SDL3)
endif()
# Manifold — CSG boolean mesh evaluation. Pinned at v3.0.0 (STAB-0222); no
# minimum-version requirement beyond this exact pin has been established —
# MeshCraft's CsgEvaluator.cpp only uses the stable, long-standing
# Manifold/MeshGL boolean-op API (+, -, ^, Transform), so any 3.x release
# is expected to work, but only v3.0.0 is actually built/tested here.
#
# All the FORCE-disabled options below are non-essential features this
# project doesn't use, kept off to minimize build complexity/time rather
# than because of a discovered technical blocker (no historical
# investigation found a specific reason to enable any of them):
# MANIFOLD_EXPORT/TEST/FUZZ: Manifold's own export CLI, test suite, and
# fuzzers -- not needed since MeshCraft only links the library.
# MANIFOLD_PAR (STAB-0232): Manifold's internal (TBB/PSTL) parallelism
# for its own mesh-processing algorithms. Left off; not yet profiled
# against this project's typical scene sizes to see whether it would
# help — a real perf investigation, not done, would need before/after
# timing on a large CSG-heavy scene (see STAB-0233's perf test).
# MANIFOLD_CROSS_SECTION (STAB-0235): Manifold's 2D cross-section/
# polygon-boolean module (its `CrossSection` class) — unrelated to
# MC3's own `Mc3CrossSection` (extrude cross-sections, a completely
# separate, pre-existing MeshCraft feature). Left off since nothing in
# mc3togltf calls into Manifold's CrossSection API.
set(MANIFOLD_PAR OFF CACHE BOOL "" FORCE)
set(MANIFOLD_EXPORT OFF CACHE BOOL "" FORCE)
set(MANIFOLD_TEST OFF CACHE BOOL "" FORCE)
set(MANIFOLD_FUZZ OFF CACHE BOOL "" FORCE)
set(MANIFOLD_CROSS_SECTION OFF CACHE BOOL "" FORCE)
FetchContent_Declare(manifold
GIT_REPOSITORY https://github.com/elalish/manifold.git
GIT_TAG v3.0.0
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(manifold)
# tinyobjloader — OBJ mesh loading for viewport preview
set(TINYOBJLOADER_BUILD_TEST_LOADER OFF CACHE BOOL "" FORCE)
FetchContent_Declare(tinyobjloader
GIT_REPOSITORY https://github.com/tinyobjloader/tinyobjloader.git
GIT_TAG v2.0.0rc13
GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(tinyobjloader)
# Lua 5.4 + sol2 — SYS-W14-18 (2026-07-20): Mc3Object::scriptId/doc.scripts
# ("lua") round-tripped/were editable but nothing ever executed a script.
# Mirrors the sibling ../mesh-world repo's own already-working, sandboxed
# setup exactly (library choice, versions, sandbox discipline) rather than
# inventing a different one -- see its Mc3ScriptRunner.cpp/LuaRuntime.cpp.
# mesh-world deliberately kept its Lua/sol2 dependency OUT of the shared
# mc3/ library (also consumed by CNA/mc3togltf/mc3tomcb) to avoid forcing
# it on every mc3/ consumer; that constraint doesn't apply here since this
# is the MeshCraft EDITOR target specifically (which already vendors much
# heavier dependencies like Manifold/ImGui), so it's added directly to it,
# not to mc3/. Pure portable C/C++, unconditional like ImGui/Manifold
# above -- not gated behind NOT EMSCRIPTEN/NOT ANDROID like SQLite3/
# cpp-httplib below (those gate on external system libraries; Lua is
# self-contained and commonly compiled to WASM/Android already).
FetchContent_Declare(lua
GIT_REPOSITORY https://github.com/lua/lua.git
GIT_TAG v5.4.7
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(lua)
file(GLOB LUA_SOURCES "${lua_SOURCE_DIR}/*.c")
# Exclude interpreter/compiler mains (lua.c/luac.c both define main()),
# matching mesh-world's own exclusion list. ALSO exclude onelua.c and
# ltests.c -- mesh-world fetched the lua.org release TARBALL, which
# doesn't include either; this fetches the git mirror instead (matching
# this repo's own GIT_REPOSITORY/GIT_TAG FetchContent convention), whose
# checkout does include them. onelua.c #includes every other .c file
# verbatim into one translation unit (its own header comment: "Lua core,
# libraries, and interpreter in a single file") -- compiling it ALONGSIDE
# the individual .c files below would duplicate-define every Lua symbol,
# a link-time failure once something actually pulls both object files in
# (confirmed: onelua.c.o built "successfully" as an object file on its
# own, since a static library's ar step doesn't detect the conflict --
# only linking a consumer that references these symbols would). ltests.c
# is Lua's own internal test/diagnostics module, not needed for embedding.
list(FILTER LUA_SOURCES EXCLUDE REGEX ".*/lua\\.c$")
list(FILTER LUA_SOURCES EXCLUDE REGEX ".*/luac\\.c$")
list(FILTER LUA_SOURCES EXCLUDE REGEX ".*/onelua\\.c$")
list(FILTER LUA_SOURCES EXCLUDE REGEX ".*/ltests\\.c$")
add_library(lua54 STATIC ${LUA_SOURCES})
target_include_directories(lua54 PUBLIC "${lua_SOURCE_DIR}")
if(NOT MSVC)
target_compile_options(lua54 PRIVATE -w)
else()
target_compile_options(lua54 PRIVATE /w)
endif()
# v3.3.0 and v3.3.1 do not compile with a current clang: optional<T&>::emplace calls a
# this->construct() that specialization does not have, and since optional<T&> is a full
# specialization the lookup is not deferred, so newer clang reports it even though nothing
# instantiates it. v3.5.0 replaced that body with a placement-new that returns properly.
# Found when the Emscripten build (emsdk 5.0.7) stopped on LuaScriptRunner.cpp.
FetchContent_Declare(sol2
GIT_REPOSITORY https://github.com/ThePhD/sol2.git
GIT_TAG v3.5.0
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(sol2)
# sol2's own CMakeLists.txt creates the sol2::sol2 INTERFACE target.
# mc3togltf — MC3 to glTF/GLB export tool (uses Mc3 + tinyobjloader already fetched above)
add_subdirectory(mc3togltf)
# SYS-W11-05: build only the two standalone tools and their format libraries
# before creating the relocatable release archive. CPack's default `package`
# target depends on the entire editor graph, which would make a CLI release
# depend on unrelated CNA backends and tooling. This target deliberately
# uses the normal install rules but keeps its build dependency narrow.
add_custom_target(meshcraft_cli_release
COMMAND "${CMAKE_COMMAND}"
"-DMC_RELEASE_BUILD_DIR=${CMAKE_BINARY_DIR}"
"-DMC_RELEASE_VERSION=${PROJECT_VERSION}"
"-DMC_RELEASE_SYSTEM=${CMAKE_SYSTEM_NAME}"
"-DMC_RELEASE_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}"
-P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/CreateCliRelease.cmake"
DEPENDS mc3tomcb mc3togltf
COMMENT "Creating the relocatable MeshCraft CLI release archive")
if(BUILD_TESTING)
# SYS-W11-09: this test's entire purpose is proving a PLAIN external
# consumer (no special compiler/linker flags) can use the installed
# Mc3/Mcb libraries via find_package(). That is structurally
# incompatible with MESHCRAFT_SANITIZE=ON: the installed .a files are
# instrumented, so their object code references __asan_*/__ubsan_*
# symbols a plain, non-instrumented consumer executable never links
# against, and the link fails -- not a real product bug, just an
# unrepresentative test for this configuration. Skipped only in that
# configuration; still registered and required in every other one.
if(NOT MESHCRAFT_SANITIZE)
add_test(
NAME package_consumer_smoke
COMMAND "${CMAKE_COMMAND}"
"-DMC_PACKAGE_BUILD_DIR=${CMAKE_BINARY_DIR}"
"-DMC_PACKAGE_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}/test/cmake/package_consumer"
-P "${CMAKE_CURRENT_SOURCE_DIR}/test/cmake/package_consumer_smoke.cmake")
set_tests_properties(package_consumer_smoke PROPERTIES
TIMEOUT 60
LABELS "package")
endif()
# SYS-W11-06: fixed binary hashes produced from a checked-in scene are a
# compact cross-platform contract for both standalone CLI tools. The
# Windows artifact job below runs the same source-backed fixture before
# publishing its executables.
find_program(MESHCRAFT_PYTHON3 NAMES python3 python)
if(MESHCRAFT_PYTHON3)
add_test(
NAME cli_cross_platform_fixture
COMMAND "${MESHCRAFT_PYTHON3}"
"${CMAKE_CURRENT_SOURCE_DIR}/test/cross_platform_cli_fixture_test.py"
"$<TARGET_FILE:mc3tomcb>"
"$<TARGET_FILE:mc3togltf>"
"${CMAKE_CURRENT_SOURCE_DIR}/test/house.mc3.xml"
"${CMAKE_BINARY_DIR}/cli-cross-platform-fixture")
set_tests_properties(cli_cross_platform_fixture PROPERTIES
TIMEOUT 30
LABELS "export;portability")
# SYS-W11-08: proves the .tar.gz release archive itself -- not just
# the in-tree build products cli_cross_platform_fixture above
# exercises -- is a self-contained artifact: builds it fresh,
# extracts it into a path with a space and a non-ASCII character
# outside the build tree, and runs both CLI tools with a PATH that
# contains no build-tree directory at all.
add_test(
NAME clean_room_cli_release_smoke
COMMAND "${CMAKE_COMMAND}"
"-DMC_RELEASE_BUILD_DIR=${CMAKE_BINARY_DIR}"
"-DMC_RELEASE_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}"
"-DMC_RELEASE_VERSION=${PROJECT_VERSION}"
"-DMC_RELEASE_SYSTEM=${CMAKE_SYSTEM_NAME}"
"-DMC_RELEASE_PYTHON3=${MESHCRAFT_PYTHON3}"
-P "${CMAKE_CURRENT_SOURCE_DIR}/test/cmake/clean_room_cli_release_smoke.cmake")
set_tests_properties(clean_room_cli_release_smoke PROPERTIES
TIMEOUT 120
LABELS "package;portability")
endif()
endif()
# SQLite3 — model registry persistence (desktop builds only). Optional,
# not REQUIRED: ModelRegistry.cpp's MESHCRAFT_HAS_SQLITE3 guard already
# provides safe no-op stubs for its absence (STAB-0008/0366/0552/0563),
# so a REQUIRED find_package() here would contradict that and needlessly
# block any environment/toolchain without a SQLite3 dev package for its
# target (e.g. a fresh MinGW cross-compile sysroot) — same pattern as the
# OpenSSL check right below.
if(NOT EMSCRIPTEN AND NOT ANDROID)
find_package(SQLite3)
if(SQLite3_FOUND)
message(STATUS "SQLite3 found: ${SQLite3_VERSION}")
else()
message(STATUS "SQLite3 not found — ModelRegistry will be disabled at runtime")
endif()
endif()
# mc3togltf is linked against this shared third-party library in the
# default desktop build. Ship its runtime files in the same release
# component so the CLI archive is usable outside the build tree.
# tinyobjloader is deliberately NOT listed here: mc3togltf_lib only ever uses
# it as a single-header library (see mc3togltf/CMakeLists.txt's
# TINYOBJLOADER_IMPLEMENTATION note) and no longer links its separately
# compiled target, so there is no runtime tinyobjloader artifact to ship.
foreach(MESHCRAFT_CLI_RUNTIME_TARGET IN ITEMS manifold)
if(TARGET ${MESHCRAFT_CLI_RUNTIME_TARGET})
install(TARGETS ${MESHCRAFT_CLI_RUNTIME_TARGET}
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT release
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT release
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT release)
endif()
endforeach()
# cpp-httplib + OpenSSL — AI Assistant (desktop builds only)
if(NOT EMSCRIPTEN AND NOT ANDROID)
set(HTTPLIB_USE_BROTLI_IF_AVAILABLE OFF CACHE BOOL "" FORCE)
# MeshCraft packages its own CLI and format-library surface. Do not let
# this FetchContent-only editor dependency add an unrelated install tree
# or invoke CPack with its defaults.
set(HTTPLIB_INSTALL OFF CACHE BOOL "" FORCE)
FetchContent_Declare(httplib
GIT_REPOSITORY https://github.com/yhirose/cpp-httplib.git
GIT_TAG v0.18.3
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(httplib)
find_package(OpenSSL)
if(OpenSSL_FOUND)
message(STATUS "OpenSSL found: ${OPENSSL_VERSION} — AI HTTPS enabled")
else()
message(STATUS "OpenSSL not found — AI Assistant will be disabled at runtime")
endif()
endif()
# LibXml2 — XSD validation of AI-generated XML (STAB-0391, desktop builds only)
if(NOT EMSCRIPTEN AND NOT ANDROID)
find_package(LibXml2)
if(LIBXML2_FOUND)
message(STATUS "LibXml2 found: ${LIBXML2_VERSION_STRING} — AI response XSD validation enabled")
else()
message(STATUS "LibXml2 not found — AI response XSD validation disabled (falls back to structural parse only)")
endif()
endif()
# Embed mc3.xsd content into a generated header so runtime XSD validation
# never depends on the working directory or install layout.
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/mc3/mc3.xsd" MC3_XSD_CONTENT)
set(MESHCRAFT_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/generated")
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Mc3XsdEmbed.hpp.in"
"${MESHCRAFT_GENERATED_INCLUDE_DIR}/MeshCraft/Mc3XsdEmbed.hpp"
@ONLY
)
# -----------------------------------------------------------------------------
# Sources
# -----------------------------------------------------------------------------
file(GLOB_RECURSE SOURCES
"src/MeshCraft/*.cpp"
"src/MeshCraft/Editor/*.cpp"
"src/MeshCraft/Editor/Tools/*.cpp"
"src/MeshCraft/Renderer/*.cpp"
"src/MeshCraft/Scene/*.cpp"
"src/MeshCraft/Ui/*.cpp"
)
# -----------------------------------------------------------------------------
# Executable
# -----------------------------------------------------------------------------
if(ANDROID)
set(_target main)
add_library(${_target} SHARED ${SOURCES})
else()
set(_target MeshCraft)
add_executable(${_target} ${SOURCES})
endif()
if(EMSCRIPTEN)
set_target_properties(${_target} PROPERTIES SUFFIX ".html")
endif()
target_include_directories(${_target}
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
${tinyobjloader_SOURCE_DIR}
)
target_compile_definitions(${_target} PRIVATE MESHCRAFT_VERSION="${PROJECT_VERSION}")
# AUD-054: -Wall -Wextra was previously enabled on only 2 of the first-party
# targets (Mc3, mc3togltf_lib) -- the editor itself (32 files / 18.5k LOC,
# the largest first-party surface) compiled with no warning flags at all.
# PRIVATE so this only applies to MeshCraft's own translation units, not
# anything consuming this target.
target_compile_options(${_target} PRIVATE -Wall -Wextra)
meshcraft_apply_sanitize(${_target})
# AUD-039b: the configure-time warning above (Gate C truthfulness) does not
# stop a non-functional editor binary from being built and run -- it only
# prints a message a headless/CI configure or a GUI CMake frontend can easily
# miss. Wrapping this whole target in a CMake conditional to skip building it
# entirely under non-EASYGL backends would require restructuring several
# hundred lines of existing, stabilized target configuration (sources, link
# libraries, tests all reference ${_target}) for high regression risk. A
# runtime check is the surgical alternative that still satisfies Gate C
# ("unsupported and rejected clearly"): embed the selected backend name, and
# main() (src/MeshCraft/main.cpp) refuses to proceed under a backend the
# editor cannot render on, before any window or graphics-device initialization -- an
# unsupported configuration is REJECTED at startup with a clear message and a
# non-zero exit code, not silently launched as a broken window. The CLI tools
# (mc3togltf/mc3tomcb) do not link this target and are unaffected.
target_compile_definitions(${_target} PRIVATE
MESH_CRAFT_GRAPHICS_BACKEND_STR="${MESH_CRAFT_GRAPHICS_BACKEND_UPPER}")
# Enable SQLite3-backed ModelRegistry on desktop builds
if(SQLite3_FOUND)
target_compile_definitions(${_target} PRIVATE MESHCRAFT_HAS_SQLITE3)
target_include_directories(${_target} PRIVATE ${SQLite3_INCLUDE_DIRS})
endif()
# Enable AI Assistant when cpp-httplib + OpenSSL are available
if(httplib_POPULATED AND OpenSSL_FOUND)
target_compile_definitions(${_target} PRIVATE MESHCRAFT_HAS_AI)
target_link_libraries(${_target} PRIVATE httplib::httplib)
endif()
# Enable AI-response XSD validation when LibXml2 is available (STAB-0391)
target_include_directories(${_target} PRIVATE ${MESHCRAFT_GENERATED_INCLUDE_DIR})
if(LIBXML2_FOUND)
target_compile_definitions(${_target} PRIVATE MESHCRAFT_HAS_LIBXML2)
target_include_directories(${_target} PRIVATE ${LIBXML2_INCLUDE_DIR})
target_link_libraries(${_target} PRIVATE ${LIBXML2_LIBRARIES})
endif()
# -----------------------------------------------------------------------------
# Link
# -----------------------------------------------------------------------------
#
# ${MESHCRAFT_CNA_MODULES} provides: windowing/game loop, input, audio,
# graphics (XNA-style API) and the file dialog -- the six CNA modules this
# editor includes headers from, named and justified where the variable is set.
# ${MESHCRAFT_SHARP_RUNTIME_TARGETS} provides System/Object.hpp; every other
# sharp-runtime component MeshCraft ends up using arrives through the CNA
# module that declares it.
# Mc3 provides: MC3 format data structures (pure C++).
#
# The CNA modules and the graphics renderer may have circular symbol references
# on Linux, so wrap them in a linker group (GNU ld / Clang ld on non-Windows).
# -----------------------------------------------------------------------------
# ${_cna_backend_target} is resolved once, next to the CNA_GRAPHICS_RENDERER
# identity it has to agree with, near the top of this file. It used to be
# mapped a second time here, which is how the two drifted apart when CNA
# renamed its renderer targets: the identity mapping was updated and this copy
# was not.
if(EMSCRIPTEN)
# SDL3 imported targets are directory-scoped; re-declare them in this scope.
find_package(SDL3 REQUIRED CONFIG)
target_link_libraries(${_target} PRIVATE
${MESHCRAFT_CNA_MODULES} ${_cna_backend_target} ${MESHCRAFT_SHARP_RUNTIME_TARGETS}
Mc3 Mcb mc3togltf_lib imgui SDL3::SDL3-static
lua54 sol2::sol2)
target_link_options(${_target} PRIVATE
-sALLOW_MEMORY_GROWTH=1
-sSTACK_SIZE=1048576
-sINITIAL_MEMORY=134217728
-sFORCE_FILESYSTEM=1
"-sEXPORTED_RUNTIME_METHODS=['FS','ccall','cwrap']"
"-sMIN_WEBGL_VERSION=2"
"-sMAX_WEBGL_VERSION=2"
-lidbfs.js
"SHELL:--pre-js ${CMAKE_CURRENT_SOURCE_DIR}/cmake/web/pre.js"
"SHELL:--preload-file ${CMAKE_CURRENT_SOURCE_DIR}/test@/test"
)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" AND NOT WIN32 AND NOT ANDROID)
target_link_libraries(${_target} PRIVATE
-Wl,--start-group ${MESHCRAFT_CNA_MODULES} ${_cna_backend_target} -Wl,--end-group
${MESHCRAFT_SHARP_RUNTIME_TARGETS}
Mc3
Mcb
mc3togltf_lib
imgui
manifold
lua54
sol2::sol2)
if(SQLite3_FOUND)
target_link_libraries(${_target} PRIVATE ${SQLite3_LIBRARIES})
endif()
else()
target_link_libraries(${_target} PRIVATE
${MESHCRAFT_CNA_MODULES} ${_cna_backend_target} ${MESHCRAFT_SHARP_RUNTIME_TARGETS}
Mc3 Mcb mc3togltf_lib imgui manifold lua54 sol2::sol2)
if(SQLite3_FOUND)
target_link_libraries(${_target} PRIVATE ${SQLite3_LIBRARIES})
endif()
endif()
# -----------------------------------------------------------------------------
# Windows / MinGW runtime
# -----------------------------------------------------------------------------
if(WIN32)
cna_copy_sdl_runtime(${_target})
# cna_copy_sdl_runtime() (cna/cmake/ThirdPartySDL.cmake) only copies DLLs
# for SDL3::SDL3/SDL3_image::SDL3_image/SDL3_mixer::SDL3_mixer if those
# targets are visible in the calling scope — but they're IMPORTED targets
# created by find_package(SDL3 CONFIG) while processing CNA's own
# add_subdirectory(), so they're invisible here in MeshCraft's parent
# scope (confirmed via --trace-expand: all three if(TARGET ...) checks
# evaluate false, so no copy commands are ever added — STAB-0566). Copy
# them directly via the CACHE variable CNA sets for its prebuilt SDL
# install root, which *is* visible everywhere.
foreach(_sdl_dll IN ITEMS SDL3.dll SDL3_image.dll SDL3_mixer.dll)
set(_sdl_dll_path "${CNA_SDL_PREBUILT_ROOT}/install/bin/${_sdl_dll}")
if(EXISTS "${_sdl_dll_path}")
add_custom_command(TARGET ${_target} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${_sdl_dll_path}" "$<TARGET_FILE_DIR:${_target}>"
COMMENT "Copying ${_sdl_dll} next to ${_target}"
VERBATIM)
endif()
endforeach()
endif()
if(MINGW)
target_link_options(${_target} PRIVATE -static-libgcc -static-libstdc++)
cna_copy_mingw_runtime(${_target})
endif()
# -----------------------------------------------------------------------------
# Tests
# -----------------------------------------------------------------------------
if(MESH_CRAFT_BUILD_TESTING AND UNIX AND NOT ANDROID AND NOT EMSCRIPTEN)
# Pure unit test: ActiveTool enum <-> name mapping. Header-only, no CNA/GL
# deps, so it always builds. Regression guard for the Measure-tool
# out-of-bounds title read (activeToolName exhaustive switch).
add_executable(active_tool_test
${CMAKE_CURRENT_SOURCE_DIR}/test/active_tool_test.cpp)
target_include_directories(active_tool_test PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include)
target_compile_features(active_tool_test PRIVATE cxx_std_23)
meshcraft_apply_sanitize(active_tool_test)
add_test(NAME active_tool COMMAND active_tool_test)
set_tests_properties(active_tool PROPERTIES TIMEOUT 15 LABELS "unit")
# SYS-W14-14: the shared coordinate conversion must remain CNA-free so
# render, picking and the Normalize-to-Y-up command share one exact axis
# mapping. This fixture covers transform inversion, picking-ray inversion
# and normalization's scene-level camera/light handling.
add_executable(coordinate_system_test
${CMAKE_CURRENT_SOURCE_DIR}/test/coordinate_system_test.cpp)
target_include_directories(coordinate_system_test PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/mc3/include)
target_link_libraries(coordinate_system_test PRIVATE Mc3)
target_compile_features(coordinate_system_test PRIVATE cxx_std_23)
meshcraft_apply_sanitize(coordinate_system_test)
add_test(NAME coordinate_system COMMAND coordinate_system_test)
set_tests_properties(coordinate_system PROPERTIES TIMEOUT 15 LABELS "unit")
# SYS-W5-06: document-level degrees/radians and all six Euler orders are
# interpreted by one CNA-free helper shared with mc3togltf. The test also
# locks the degrees/XYZ normalization math used by the explicit command.
add_executable(rotation_convention_algorithms_test
${CMAKE_CURRENT_SOURCE_DIR}/test/rotation_convention_algorithms_test.cpp)
target_include_directories(rotation_convention_algorithms_test PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include)
target_compile_features(rotation_convention_algorithms_test PRIVATE cxx_std_23)
meshcraft_apply_sanitize(rotation_convention_algorithms_test)
target_compile_options(rotation_convention_algorithms_test PRIVATE -Wall -Wextra)
add_test(NAME rotation_convention_algorithms COMMAND rotation_convention_algorithms_test)
set_tests_properties(rotation_convention_algorithms PROPERTIES TIMEOUT 15 LABELS "unit")
# SYS-W3-01: Editor::KeybindingManager, extracted from
# MeshCraftApplication (H9). No test existed for this subsystem before
# the extraction. Needs real Microsoft::Xna::Framework::Input::Keys/
# KeyboardState (CNA), so unlike active_tool_test/object_type_name_test
# above it links CNA + SHARP_RUNTIME (SDL3 comes in transitively via CNA
# on this native, non-Emscripten path -- see the "Link" section below for
# why SDL3 isn't named explicitly here) -- but not Mc3/Mcb/
# mc3togltf_lib/imgui, which this subsystem has no dependency on.
add_executable(keybinding_manager_test
${CMAKE_CURRENT_SOURCE_DIR}/test/keybinding_manager_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/MeshCraft/Editor/KeybindingManager.cpp)
target_include_directories(keybinding_manager_test PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(keybinding_manager_test PRIVATE
${MESHCRAFT_CNA_MODULES} ${_cna_backend_target} ${MESHCRAFT_SHARP_RUNTIME_TARGETS})
target_compile_features(keybinding_manager_test PRIVATE cxx_std_23)
meshcraft_apply_sanitize(keybinding_manager_test)
add_test(NAME keybinding_manager COMMAND keybinding_manager_test)
set_tests_properties(keybinding_manager PROPERTIES TIMEOUT 15 LABELS "unit")
# SYS-W3-01 Phase 2 (narrow): Editor::Preferences, extracted from
# MeshCraftApplication (H7). No test existed for this subsystem before
# the extraction. Needs only ImGui's core (no CNA/window/GL context),
# matching undo_gesture_frame_test's minimal-dependency pattern above.
add_executable(preferences_test
${CMAKE_CURRENT_SOURCE_DIR}/test/preferences_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/MeshCraft/Editor/Preferences.cpp)
target_include_directories(preferences_test PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(preferences_test PRIVATE imgui)
target_compile_features(preferences_test PRIVATE cxx_std_23)
meshcraft_apply_sanitize(preferences_test)
add_test(NAME preferences COMMAND preferences_test)
set_tests_properties(preferences PROPERTIES TIMEOUT 15 LABELS "unit")
# SYS-W5-04: Editor::ObjectIndex, a lazily-rebuilt id/name -> object
# cache over Mc3Document.objects extracted out of
# MeshCraftApplication::flatFindById()/flatFindByName(). CNA-free (only
# depends on Mc3Object/Mc3Document, which are header-only for this
# class's purposes -- no factory methods are called), so unlike
# keybinding_manager_test above this needs neither CNA nor Mc3 linked.
add_executable(object_index_test
${CMAKE_CURRENT_SOURCE_DIR}/test/object_index_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/MeshCraft/Editor/ObjectIndex.cpp)
target_include_directories(object_index_test PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/mc3/include)
target_compile_features(object_index_test PRIVATE cxx_std_23)
meshcraft_apply_sanitize(object_index_test)
add_test(NAME object_index COMMAND object_index_test)
set_tests_properties(object_index PROPERTIES TIMEOUT 15 LABELS "unit")
# F9 (2026-07-20 audit): registerTextureFromPathAlg() (EditorAlgorithms.hpp),
# backing MeshCraftApplication::registerTextureFromPath(). CNA-free --
# EditorAlgorithms.hpp only needs Mc3Document/Mc3Object (header-only),
# matching object_index_test above.
add_executable(texture_from_path_test
${CMAKE_CURRENT_SOURCE_DIR}/test/texture_from_path_test.cpp)
target_include_directories(texture_from_path_test PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/mc3/include)
target_compile_features(texture_from_path_test PRIVATE cxx_std_23)
meshcraft_apply_sanitize(texture_from_path_test)
add_test(NAME texture_from_path COMMAND texture_from_path_test)
set_tests_properties(texture_from_path PROPERTIES TIMEOUT 15 LABELS "unit")
# SYS-W14-38: clip ranges, rate/reverse/loop boundary behavior, and
# malformed programmatic values are CNA-free deterministic math.
add_executable(animation_preview_algorithms_test
${CMAKE_CURRENT_SOURCE_DIR}/test/animation_preview_algorithms_test.cpp)
target_include_directories(animation_preview_algorithms_test PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/mc3/include)
target_compile_features(animation_preview_algorithms_test PRIVATE cxx_std_23)
meshcraft_apply_sanitize(animation_preview_algorithms_test)
add_test(NAME animation_preview_algorithms COMMAND animation_preview_algorithms_test)
set_tests_properties(animation_preview_algorithms PROPERTIES TIMEOUT 15 LABELS "unit")
add_executable(animation_clip_format_test
${CMAKE_CURRENT_SOURCE_DIR}/test/animation_clip_format_test.cpp)
target_include_directories(animation_clip_format_test PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/mc3/include
${CMAKE_CURRENT_SOURCE_DIR}/mcb/include)
target_link_libraries(animation_clip_format_test PRIVATE Mc3 Mcb)
target_compile_features(animation_clip_format_test PRIVATE cxx_std_23)
meshcraft_apply_sanitize(animation_clip_format_test)
add_test(NAME animation_clip_format COMMAND animation_clip_format_test)
set_tests_properties(animation_clip_format PROPERTIES TIMEOUT 15 LABELS "format")
# F10 (2026-07-20 audit): clear*ReferencesAlg()/removeTriggerStepsReferencingAlg()
# (EditorAlgorithms.hpp), backing the Tex/Defs/Mat/Scripts/Sounds/Music/
# Embeds Delete buttons' reference-integrity cleanup. CNA-free, matching
# object_index_test/texture_from_path_test above.
add_executable(delete_reference_integrity_test
${CMAKE_CURRENT_SOURCE_DIR}/test/delete_reference_integrity_test.cpp)
target_include_directories(delete_reference_integrity_test PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/mc3/include)
target_compile_features(delete_reference_integrity_test PRIVATE cxx_std_23)
meshcraft_apply_sanitize(delete_reference_integrity_test)
add_test(NAME delete_reference_integrity COMMAND delete_reference_integrity_test)
set_tests_properties(delete_reference_integrity PROPERTIES TIMEOUT 15 LABELS "unit")
# F19 (2026-07-20 audit): runObjExport()'s intermediate .glb temp path
# used to be derived from `this`'s pointer value (deterministic --
# collision risk across concurrent instances) and was only cleaned up
# on the success path (leaked on exportDocument()/LoadBinaryFromFile()
# throwing). Mirrors the fixed control-flow shape with real
# uniqueTempPath()/std::filesystem calls -- CNA-free, header-only
# (MeshCraft/TempFile.hpp), matching object_index_test's precedent.
add_executable(obj_export_temp_cleanup_test
${CMAKE_CURRENT_SOURCE_DIR}/test/obj_export_temp_cleanup_test.cpp)
target_include_directories(obj_export_temp_cleanup_test PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include)
target_compile_features(obj_export_temp_cleanup_test PRIVATE cxx_std_23)
meshcraft_apply_sanitize(obj_export_temp_cleanup_test)
add_test(NAME obj_export_temp_cleanup COMMAND obj_export_temp_cleanup_test)
set_tests_properties(obj_export_temp_cleanup PROPERTIES TIMEOUT 15 LABELS "unit")
# SYS-W3-01 Phase 3: Editor::MacroRecorder, extracted from
# MeshCraftApplication (H12). No test existed for this subsystem before
# the extraction. CNA-free -- executeStep()'s cross-domain calls
# (addPrimitive/deleteSelected/document_/selection_/etc.) are resolved
# through a Context of std::function callbacks (a PropertiesContext-
# style DI struct) rather than linking MeshCraftApplication itself, so
# this only needs Mc3Object.hpp's ObjectType enum (header-only) plus
# EditorAlgorithms.hpp's save/load helpers -- neither needs Mc3/CNA
# linked, matching object_index_test above.
add_executable(macro_recorder_test
${CMAKE_CURRENT_SOURCE_DIR}/test/macro_recorder_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/MeshCraft/Editor/MacroRecorder.cpp)
target_include_directories(macro_recorder_test PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/mc3/include)
target_compile_features(macro_recorder_test PRIVATE cxx_std_23)
meshcraft_apply_sanitize(macro_recorder_test)
add_test(NAME macro_recorder COMMAND macro_recorder_test)
set_tests_properties(macro_recorder PROPERTIES TIMEOUT 15 LABELS "unit")
# SYS-W3-01 Phase 4: Editor::UndoManager, extracted from
# MeshCraftApplication (the undo/redo stack mechanism, SYS-W9-03's
# selection-restore stacks included). No test existed for this
# subsystem before the extraction (undo_gesture_frame_test.cpp covers
# the same invariants against hand-rolled stand-ins, since
# MeshCraftApplication's real pushUndo()/performUndo()/performRedo()
# aren't headlessly callable -- this exercises the real class
# directly). CNA-free -- unlike MacroRecorder, this needs no callback
# Context at all: every side effect beyond stack bookkeeping
# (deepCopyDoc(), objectIndex_ invalidation, selection restore) stays
# the caller's responsibility, so this only needs Mc3Document.hpp
# (header-only), matching object_index_test above.
add_executable(undo_manager_test
${CMAKE_CURRENT_SOURCE_DIR}/test/undo_manager_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/MeshCraft/Editor/UndoManager.cpp)
target_include_directories(undo_manager_test PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/mc3/include)
target_compile_features(undo_manager_test PRIVATE cxx_std_23)
meshcraft_apply_sanitize(undo_manager_test)
add_test(NAME undo_manager COMMAND undo_manager_test)
set_tests_properties(undo_manager PROPERTIES TIMEOUT 15 LABELS "unit")
# SYS-W9-04: a separately-budgeted review/checkpoint timeline must keep
# the exact UndoManager contract untouched. CNA-free: it owns MC3 value
# snapshots only, so eviction, restore and object-level diff behavior can
# be tested without an editor window.
add_executable(scene_history_test
${CMAKE_CURRENT_SOURCE_DIR}/test/scene_history_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/MeshCraft/Editor/SceneHistory.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/MeshCraft/Editor/UndoManager.cpp)
target_include_directories(scene_history_test PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/mc3/include)
target_link_libraries(scene_history_test PRIVATE Mc3)
target_compile_features(scene_history_test PRIVATE cxx_std_23)
meshcraft_apply_sanitize(scene_history_test)
add_test(NAME scene_history COMMAND scene_history_test)
set_tests_properties(scene_history PROPERTIES TIMEOUT 15 LABELS "unit")
# F7 (2026-07-20 audit): Model Registry Insert's undo ordering.
# drawRegistryPanel()'s Insert handler (MeshCraftApplication_UiRegistry.cpp)
# is not headlessly callable (full ImGui panel tied into the
# application), so this exercises the real Editor::UndoManager against a
# hand-rolled stand-in matching the handler's exact fixed control-flow
# shape (pushUndo() before insertIntoScene(), popUndoWithoutApplying()
# on failure). CNA-free, same dependency footprint as undo_manager_test.