-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
executable file
·748 lines (667 loc) · 30.8 KB
/
Copy pathCMakeLists.txt
File metadata and controls
executable file
·748 lines (667 loc) · 30.8 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
#############################################################
#
# On Windows, define the following environnemental variables before running:
#
# - OGRE_HOME (C:\OgreSDK)
# - CMAKE_PREFIX_PATH (to Qt <version>\<compiler>\lib\cmake folder)
#
##############################################################
# Versions
##############################################################
cmake_minimum_required(VERSION 3.24.0)
cmake_policy(SET CMP0005 NEW)
cmake_policy(SET CMP0048 NEW) # manages project version
project(QtMeshEditor VERSION 3.35.0 LANGUAGES C CXX)
message(STATUS "Building QtMeshEditor version ${PROJECT_VERSION}")
set(QTMESHEDITOR_VERSION_STRING "\"${PROJECT_VERSION}\"")
if(WIN32 OR APPLE)
set(PLUGIN_DIR "../")
endif()
add_definitions( -DQTMESHEDITOR_VERSION=${QTMESHEDITOR_VERSION_STRING} )
# Public QtMesh Cloud web URL (used by CLI promo + any future link-outs).
# Override with -DQTMESH_CLOUD_WEB_URL=https://... for self-hosted instances.
set(QTMESH_CLOUD_WEB_URL "https://qtmesh.dev" CACHE STRING
"QtMesh Cloud web UI base URL (no trailing slash)")
# Normalize: strip a single trailing slash so callers can paste a copied URL
# without breaking string concatenation downstream.
string(REGEX REPLACE "/+$" "" QTMESH_CLOUD_WEB_URL "${QTMESH_CLOUD_WEB_URL}")
add_definitions(-DQTMESH_CLOUD_WEB_URL="${QTMESH_CLOUD_WEB_URL}")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
##############################################################
# Configuring CMake
##############################################################
if(WIN32)
cmake_policy(SET CMP0020 NEW) # to avoid cmake warning
endif()
enable_language(CXX)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# Building directories
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "debug")
MESSAGE("DEBUG COMPILATION")
# NOTE: do NOT use ADD_DEFINITIONS("-DDEBUG") here — it's directory-scoped
# and leaks into the FetchContent'd llama.cpp/mtmd subdir, where
# mtmd-audio.cpp uses DEBUG as an ordinary identifier and fails to compile.
# Apply -DDEBUG to OUR targets only, via this marker + target_compile_
# definitions on the app/test targets (see src/CMakeLists.txt).
set(QTMESH_DEFINE_DEBUG ON)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib-debug)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib-debug)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/debug)
set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/debug)
set(BUILD_INCLUDE_DIR ${CMAKE_BINARY_DIR}/include_d)
else()
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: None (CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE)
ADD_DEFINITIONS(-DQT_NO_DEBUG -DQT_NO_DEBUG_OUTPUT -DQT_NO_WARNING_OUTPUT)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/bin)
set(BUILD_INCLUDE_DIR ${CMAKE_BINARY_DIR}/include)
endif()
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
##############################################################
# Searching Qt dependencies
##############################################################
# On newer macOS (11+), AGL framework is deprecated and has no actual library.
# Create a stub AGL.framework for linking purposes
if(APPLE)
set(AGL_STUB_DIR "${CMAKE_BINARY_DIR}/AGL_stub")
set(AGL_FW_DIR "${AGL_STUB_DIR}/AGL.framework")
set(AGL_FW_LIB "${AGL_FW_DIR}/Versions/A/AGL")
if(NOT EXISTS "${AGL_FW_LIB}")
file(MAKE_DIRECTORY "${AGL_FW_DIR}/Versions/A")
file(WRITE "${AGL_STUB_DIR}/agl_stub.c" "void __agl_stub_placeholder(void) {}")
# Build for arm64 since that's what modern macOS uses
execute_process(
COMMAND clang -arch arm64 -dynamiclib
-o "${AGL_FW_LIB}"
"${AGL_STUB_DIR}/agl_stub.c"
-install_name "/System/Library/Frameworks/AGL.framework/Versions/A/AGL"
-current_version 1.0.0 -compatibility_version 1.0.0
WORKING_DIRECTORY "${AGL_STUB_DIR}"
)
# Create symlinks
execute_process(COMMAND ln -sf A "${AGL_FW_DIR}/Versions/Current")
execute_process(COMMAND ln -sf Versions/Current/AGL "${AGL_FW_DIR}/AGL")
endif()
# Add our stub framework directory to the framework search path
link_directories("${AGL_STUB_DIR}")
set(CMAKE_FRAMEWORK_PATH "${AGL_STUB_DIR}" ${CMAKE_FRAMEWORK_PATH})
endif()
#Find Qt Packages
find_package(QT NAMES Qt6)
find_package(Qt6 REQUIRED COMPONENTS Core Widgets Gui QuickWidgets Quick Qml QmlModels QmlMeta Test Network QuickControls2)
message("Found Qt (${QT_VERSION_MAJOR})")
SET (QTLIBLIST
Qt${QT_VERSION_MAJOR}Gui
Qt${QT_VERSION_MAJOR}Core
Qt${QT_VERSION_MAJOR}Widgets
Qt${QT_VERSION_MAJOR}QuickWidgets
Qt${QT_VERSION_MAJOR}Quick
Qt${QT_VERSION_MAJOR}Qml
Qt${QT_VERSION_MAJOR}QmlModels
Qt${QT_VERSION_MAJOR}QmlWorkerScript
Qt${QT_VERSION_MAJOR}Network
Qt${QT_VERSION_MAJOR}OpenGL
Qt${QT_VERSION_MAJOR}QmlMeta
Qt${QT_VERSION_MAJOR}QuickControls2
Qt${QT_VERSION_MAJOR}QuickTemplates2
)
FOREACH(qtlib ${QTLIBLIST})
include_directories(${${qtlib}_INCLUDE_DIRS})
ENDFOREACH(qtlib)
#set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/;${CMAKE_MODULE_PATH}")
##############################################################
# googletest
##############################################################
option(BUILD_TESTS "Build the unity tests" OFF)
if(BUILD_TESTS)
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/f8d7d77c06936315286eb55f8de22cd23c188571.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
# Include Google Test headers
include_directories(
${gtest_SOURCE_DIR}/include
${gtest_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/src
)
enable_testing()
# Add the test
add_test(NAME UnitTests COMMAND UnitTests)
include(GoogleTest)
endif()
##############################################################
# llama.cpp for local LLM inference
##############################################################
option(ENABLE_LOCAL_LLM "Enable local LLM inference with llama.cpp" ON)
if(ENABLE_LOCAL_LLM)
include(FetchContent)
# Configure llama.cpp build options
set(LLAMA_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(LLAMA_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(LLAMA_BUILD_SERVER OFF CACHE BOOL "" FORCE)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
# The `mtmd` multimodal library (tools/mtmd) powers image captioning
# (SmolVLM, #764). It only builds under LLAMA_BUILD_TOOLS + LLAMA_BUILD_COMMON
# — but enabling all llama tools also builds CLI executables
# (cvector-generator, export-lora, llama-*-cli) that FAIL TO LINK on
# Windows-MinGW, where GGML_CPU is off (undefined ggml_backend_cpu_init /
# ggml_get_f32_nd). We don't ship those tools. So enable them only where
# they link: NOT on MinGW. The captioner (QTMESH_HAVE_MTMD) degrades
# gracefully when absent, and Windows-MinGW has ONNX off anyway, so the
# image-to-3D texture path there already falls back.
if(WIN32 AND MINGW)
set(LLAMA_BUILD_COMMON OFF CACHE BOOL "" FORCE)
set(LLAMA_BUILD_TOOLS OFF CACHE BOOL "" FORCE)
set(QTMESH_HAVE_MTMD OFF)
else()
set(LLAMA_BUILD_COMMON ON CACHE BOOL "" FORCE)
set(LLAMA_BUILD_TOOLS ON CACHE BOOL "" FORCE)
set(QTMESH_HAVE_MTMD ON)
endif()
# Enable Metal on macOS for GPU acceleration
if(APPLE)
set(GGML_METAL ON CACHE BOOL "" FORCE)
set(GGML_METAL_EMBED_LIBRARY ON CACHE BOOL "" FORCE)
message(STATUS "Enabling Metal acceleration for llama.cpp on macOS")
endif()
# Enable CUDA on systems with NVIDIA GPUs
if(CMAKE_CUDA_COMPILER OR DEFINED ENV{CUDA_PATH})
set(GGML_CUDA ON CACHE BOOL "" FORCE)
message(STATUS "Enabling CUDA acceleration for llama.cpp")
endif()
# Disable native optimizations for cross-platform compatibility
set(GGML_NATIVE OFF CACHE BOOL "" FORCE)
# Enable CUDA for NVIDIA GPUs (much faster and avoids CPU compatibility issues)
find_package(CUDAToolkit QUIET)
if(CUDAToolkit_FOUND)
set(GGML_CUDA ON CACHE BOOL "" FORCE)
message(STATUS "CUDA found - enabling GPU acceleration for llama.cpp")
endif()
# For CPU fallback: disable AVX2/FMA for older CPUs (pre-Haswell compatibility)
set(GGML_AVX2 OFF CACHE BOOL "" FORCE)
set(GGML_FMA OFF CACHE BOOL "" FORCE)
set(GGML_BMI2 OFF CACHE BOOL "" FORCE)
# On Windows with MinGW, disable CPU backend to avoid SDK compatibility issues
if(WIN32 AND MINGW)
set(GGML_CPU OFF CACHE BOOL "" FORCE)
message(STATUS "Disabling CPU backend on MinGW due to SDK compatibility")
endif()
FetchContent_Declare(
llama_cpp
GIT_REPOSITORY https://github.com/ggml-org/llama.cpp.git
GIT_TAG b9267
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(llama_cpp)
# Include llama.cpp headers (+ mtmd multimodal for image captioning where
# available — not on Windows-MinGW, see QTMESH_HAVE_MTMD above).
include_directories(
${llama_cpp_SOURCE_DIR}/include
${llama_cpp_SOURCE_DIR}/ggml/include
)
if(QTMESH_HAVE_MTMD)
include_directories(
${llama_cpp_SOURCE_DIR}/tools/mtmd
${llama_cpp_SOURCE_DIR}/common
)
add_definitions(-DENABLE_MTMD)
message(STATUS "mtmd multimodal (image captioning) enabled")
endif()
add_definitions(-DENABLE_LOCAL_LLM)
message(STATUS "Local LLM support enabled with llama.cpp")
endif()
##############################################################
# stable-diffusion.cpp for AI texture generation
##############################################################
option(ENABLE_STABLE_DIFFUSION "Enable AI texture generation with stable-diffusion.cpp" OFF)
if(ENABLE_STABLE_DIFFUSION)
include(FetchContent)
# Configure stable-diffusion.cpp build options
set(SD_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(SD_BUILD_SERVER OFF CACHE BOOL "" FORCE)
# Enable Metal on macOS for GPU acceleration
if(APPLE)
set(SD_METAL ON CACHE BOOL "" FORCE)
message(STATUS "Enabling Metal acceleration for stable-diffusion.cpp on macOS")
endif()
# Enable CUDA on systems with NVIDIA GPUs
find_package(CUDAToolkit QUIET)
if(CUDAToolkit_FOUND)
set(SD_CUDA ON CACHE BOOL "" FORCE)
message(STATUS "CUDA found - enabling GPU acceleration for stable-diffusion.cpp")
endif()
FetchContent_Declare(
stable_diffusion_cpp
GIT_REPOSITORY https://github.com/leejet/stable-diffusion.cpp.git
GIT_TAG 545fac4
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(stable_diffusion_cpp)
# Include stable-diffusion.cpp headers
include_directories(
${stable_diffusion_cpp_SOURCE_DIR}
)
add_definitions(-DENABLE_STABLE_DIFFUSION)
message(STATUS "AI texture generation enabled with stable-diffusion.cpp")
endif()
##############################################################
# ONNX Runtime — AI PBR map synthesis (#404)
##############################################################
option(ENABLE_ONNX "Enable AI PBR map synthesis via ONNX Runtime" OFF)
if(ENABLE_ONNX)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/OnnxRuntime.cmake)
add_definitions(-DENABLE_ONNX)
if(QTMESH_ONNX_GPU)
add_definitions(-DQTMESH_ONNX_GPU_BUILD)
message(STATUS "ONNX Runtime GPU package enabled (CUDA EP on Linux x64 when cuDNN 9 is installed)")
endif()
message(STATUS "AI PBR map synthesis enabled with ONNX Runtime")
endif()
##############################################################
# Alembic — mesh / vertex animation import (#519, Anim Slice B)
##############################################################
# Vendored (BSD) reader for baked per-vertex caches (cloth / sims / fluids /
# Houdini + Blender exports). Default OFF: the Alembic + Imath build is
# non-trivial across the three target platforms. VertexAnimationManager + Ogre
# VAT_POSE playback work WITHOUT Alembic; this flag adds the .abc reader
# (cmake/Alembic.cmake, FetchContent). The C++ #ifdef ENABLE_ALEMBIC guards the
# reader so a build without it still compiles and skips .abc with a clear message.
option(ENABLE_ALEMBIC "Enable Alembic (.abc) vertex-animation import" OFF)
if(ENABLE_ALEMBIC)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Alembic.cmake)
add_definitions(-DENABLE_ALEMBIC)
message(STATUS "Alembic vertex-animation import enabled")
else()
message(STATUS "Alembic vertex-animation import disabled (VAT_POSE playback still available)")
endif()
##############################################################
# Draco — glTF mesh compression on export (#506)
##############################################################
# Assimp's glTF2 EXPORTER has no Draco support (ASSIMP_BUILD_DRACO=ON only wires
# the Draco DECODER into the importer), so `qtmesh convert -o out.glb --compress
# draco` is served by the standalone MeshDracoEncoder module which links Draco's
# encoder directly and rewrites the finished glTF. Default OFF: Draco has to be
# present (built via Assimp's -DASSIMP_BUILD_DRACO=ON, or a standalone build via
# -DDRACO_ROOT). The C++ #ifdef ENABLE_DRACO guards every Draco call so a build
# without it still compiles and reports a clear "rebuild with -DENABLE_DRACO".
option(ENABLE_DRACO "Enable Draco mesh compression on glTF/glb export (#506)" OFF)
if(ENABLE_DRACO)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Draco.cmake)
if(QTMESH_DRACO_FOUND)
add_definitions(-DENABLE_DRACO)
message(STATUS "Draco glTF mesh compression enabled")
else()
message(WARNING "ENABLE_DRACO requested but Draco not found — disabling")
set(ENABLE_DRACO OFF)
endif()
else()
message(STATUS "Draco glTF mesh compression disabled")
endif()
##############################################################
# Performance capture — video/webcam mocap (epic #869)
##############################################################
# Slice B (#871): brings in Qt Multimedia (camera + video decode) and the
# src/Mocap/ frame-source layer. Default OFF: Qt Multimedia is a new runtime
# dependency (FFmpeg backend) that packaging has to carry per platform. The
# ONNX predictors (Slices C/E) additionally require ENABLE_ONNX; requiring it
# here keeps a single "mocap build" configuration instead of a half-working
# one. Non-mocap builds print "rebuild with -DENABLE_MOCAP" on every surface.
option(ENABLE_MOCAP "Enable performance capture (video/webcam mocap)" OFF)
if(ENABLE_MOCAP)
if(NOT ENABLE_ONNX)
message(FATAL_ERROR "ENABLE_MOCAP requires ENABLE_ONNX (the face/pose "
"predictors run on ONNX Runtime). Configure with "
"-DENABLE_ONNX=ON -DENABLE_MOCAP=ON.")
endif()
find_package(Qt6 REQUIRED COMPONENTS Multimedia)
add_definitions(-DENABLE_MOCAP)
message(STATUS "Performance capture enabled (Qt Multimedia ${Qt6Multimedia_VERSION})")
else()
message(STATUS "Performance capture disabled (rebuild with -DENABLE_MOCAP=ON -DENABLE_ONNX=ON)")
endif()
##############################################################
# PS1 runtime geometry extraction (experimental)
##############################################################
option(ENABLE_PS1_RIP "Enable experimental PS1 runtime geometry extraction" OFF)
if(ENABLE_PS1_RIP)
add_definitions(-DENABLE_PS1_RIP)
message(STATUS "PS1 runtime geometry extraction enabled (experimental)")
find_package(Qt6 COMPONENTS Gamepad QUIET)
if(TARGET Qt6::Gamepad)
set(QTMESH_HAVE_QT_GAMEPAD ON CACHE INTERNAL "")
message(STATUS "Qt6 Gamepad found — PS1 controller support enabled")
else()
message(STATUS "Qt6 Gamepad not found — PS1 keyboard/mouse only")
endif()
add_subdirectory(plugins/ps1core_libretro)
add_subdirectory(plugins/ps1core_stub)
endif()
##############################################################
# Area lights (Slice I #491 — multi-point approximation)
##############################################################
option(ENABLE_AREA_LIGHTS "Enable area-light gizmo + multi-point approximation" ON)
if(ENABLE_AREA_LIGHTS)
add_definitions(-DENABLE_AREA_LIGHTS)
message(STATUS "Area lights enabled (multi-point approximation)")
endif()
##############################################################
# In-app auto-updater (portable Windows/macOS/Linux tarballs)
##############################################################
option(ENABLE_AUTO_UPDATER "Enable in-app auto-updater UI and download path" ON)
if(ENABLE_AUTO_UPDATER)
add_definitions(-DENABLE_AUTO_UPDATER)
message(STATUS "In-app auto-updater enabled")
endif()
##############################################################
# meshoptimizer — LOD generation, vertex-cache / overdraw /
# fetch optimization, vertex remap dedupe. MIT, header-light,
# ~200 KB. First consumer is `qtmesh lod --algo meshopt`
# (issue #398 under the AI-Assist epic #397). Always built —
# small enough that no opt-out flag is justified.
##############################################################
include(FetchContent)
FetchContent_Declare(
meshoptimizer
GIT_REPOSITORY https://github.com/zeux/meshoptimizer.git
GIT_TAG v0.21
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(meshoptimizer)
message(STATUS "meshoptimizer enabled (LOD, vertex cache, dedupe)")
##############################################################
# xatlas — automatic UV unwrapping. MIT, single .h + .cpp,
# used by Blender and Godot. Consumer: `qtmesh uv --unwrap`
# (issue #400 under the AI-Assist epic #397).
##############################################################
FetchContent_Declare(
xatlas
GIT_REPOSITORY https://github.com/jpcy/xatlas.git
GIT_TAG f700c7790aaa030e794b52ba7791a05c085faf0c # latest master as of 2025-05; no tagged release upstream
GIT_SHALLOW FALSE
)
FetchContent_MakeAvailable(xatlas)
# xatlas ships with no CMake config — wrap its `source/xatlas/xatlas.{h,cpp}` ourselves.
if(NOT TARGET xatlas)
add_library(xatlas STATIC ${xatlas_SOURCE_DIR}/source/xatlas/xatlas.cpp)
target_include_directories(xatlas PUBLIC ${xatlas_SOURCE_DIR}/source/xatlas)
set_target_properties(xatlas PROPERTIES POSITION_INDEPENDENT_CODE ON)
# Build xatlas SINGLE-THREADED (XA_MULTITHREADED=0). Its internal
# std::thread TaskScheduler livelocks on large/organic image-to-3D meshes —
# ComputeCharts spins forever in cthread_yield/swtch_pri, freezing the app
# with an untextured mesh (verified via process sampling, #764). Unwrap is a
# one-off; single-threaded is slower but deadlock-free and correct.
target_compile_definitions(xatlas PRIVATE XA_MULTITHREADED=0)
endif()
message(STATUS "xatlas enabled (auto UV unwrap)")
##############################################################
# stb — Radiance .hdr decode for HDR environment maps (#467).
##############################################################
FetchContent_Declare(
stb
GIT_REPOSITORY https://github.com/nothings/stb.git
# Re-pinned 2026-08: the previous pin 31c1ad3745… stopped fetching in CI
# ("fatal: unable to read tree" on every platform). NB stb has no upstream
# tags/releases, so we must pin a commit SHA — and GIT_SHALLOW does NOT
# support fetching an arbitrary SHA (only branches/tags), so it's OFF here: a
# full clone can always resolve the pinned commit even after master advances.
GIT_TAG 2c980bb59875b0d32144a71867fbdebb2f77cd20
GIT_SHALLOW FALSE
)
FetchContent_MakeAvailable(stb)
##############################################################
# tinyexr — OpenEXR decode for HDR environment maps (#467).
##############################################################
option(ENABLE_OPENEXR "Enable OpenEXR (.exr) HDR environment loading via tinyexr" ON)
if(ENABLE_OPENEXR)
FetchContent_Declare(
tinyexr
GIT_REPOSITORY https://github.com/syoyo/tinyexr.git
GIT_TAG v1.0.12
GIT_SHALLOW TRUE
)
# Header-only use — do NOT MakeAvailable: upstream CMake builds test
# targets that fail macOS cross-compile (-Wpoison-system-directories).
FetchContent_GetProperties(tinyexr)
if(NOT tinyexr_POPULATED)
FetchContent_Populate(tinyexr)
endif()
if(NOT TARGET tinyexr_miniz)
add_library(tinyexr_miniz STATIC ${tinyexr_SOURCE_DIR}/deps/miniz/miniz.c)
target_include_directories(tinyexr_miniz PUBLIC
${tinyexr_SOURCE_DIR}/deps/miniz
${tinyexr_SOURCE_DIR})
set_target_properties(tinyexr_miniz PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()
add_definitions(-DENABLE_OPENEXR)
message(STATUS "OpenEXR HDR loading enabled (tinyexr)")
else()
message(STATUS "OpenEXR HDR loading disabled")
endif()
##############################################################
# libsodium — minisign signature verify (auto-updater spike #440)
##############################################################
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Libsodium.cmake)
##############################################################
# Sentry crash reporting and analytics
##############################################################
option(ENABLE_SENTRY "Enable Sentry crash reporting and analytics" ON)
if(ENABLE_SENTRY)
include(FetchContent)
set(SENTRY_BACKEND "inproc" CACHE STRING "" FORCE)
set(SENTRY_BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
set(SENTRY_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(SENTRY_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(SENTRY_INTEGRATION_QT ON CACHE BOOL "" FORCE)
FetchContent_Declare(sentry
GIT_REPOSITORY https://github.com/getsentry/sentry-native.git
GIT_TAG 0.7.17
GIT_SHALLOW TRUE
GIT_SUBMODULES_RECURSE FALSE)
FetchContent_MakeAvailable(sentry)
include_directories(${sentry_SOURCE_DIR}/include)
add_definitions(-DENABLE_SENTRY)
endif()
##############################################################
# Find Ogre
##############################################################
find_package(OGRE REQUIRED)
# On Linux, use the OGRE-detected plugin directory instead of a hardcoded path
if(UNIX AND NOT APPLE AND NOT PLUGIN_DIR)
if(OGRE_PLUGIN_DIR)
set(PLUGIN_DIR "${OGRE_PLUGIN_DIR}")
else()
set(PLUGIN_DIR "/usr/local/lib/OGRE/")
endif()
endif()
message("OGRE_INCLUDE_DIRS: ")
message(${OGRE_INCLUDE_DIRS})
include_directories(${OGRE_INCLUDE_DIRS} "${OGRE_INCLUDE_DIRS}/Plugins/Assimp")
##############################################################
# Find ZLIB
##############################################################
OPTION(FIX_NEED_ZLIB "Switch on if your configuration requires zlib" OFF)
if(FIX_NEED_ZLIB)
find_package(ZLIB REQUIRED)
set(OGRE_LIBRARIES ${OGRE_LIBRARIES} ${ZLIB_LIBRARIES})
endif()
##############################################################
# Find Assimp
##############################################################
find_package(assimp REQUIRED)
if (assimp_FOUND)
message("Assimp Found")
set(ASSIMP_LIBRARY "assimp")
add_library(${ASSIMP_LIBRARY} SHARED IMPORTED)
set_target_properties(${ASSIMP_LIBRARY} PROPERTIES IMPORTED_LOCATION "${ASSIMP_LIBRARY_DIRS}/libassimp.so")
include_directories(${ASSIMP_INCLUDE_DIRS})
endif(assimp_FOUND)
##############################################################
# Adding ReadMe file
##############################################################
add_custom_target(readMeFile SOURCES README.md)
##############################################################
# Processing Subdirs
##############################################################
ADD_SUBDIRECTORY(ui_files)
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(media)
ADD_SUBDIRECTORY(profiles)
ADD_SUBDIRECTORY(cfg)
if(BUILD_TESTS)
ADD_SUBDIRECTORY(tests)
endif()
##############################################################
# Install Qt dependencies
##############################################################
IF(WIN32)
MESSAGE(STATUS "Installing Qt DLLs for Windows...")
MESSAGE(STATUS "QT_DIR: ${QT_DIR}")
FOREACH(qtlib ${QTLIBLIST})
MESSAGE(STATUS "Installing ${qtlib}.dll from ${QT_DIR}/../../../bin/")
INSTALL(FILES ${QT_DIR}/../../../bin/${qtlib}.dll DESTINATION ${CMAKE_INSTALL_PREFIX})
ENDFOREACH(qtlib)
SET (QTPLATFORMSLIST
qminimal
qoffscreen
qwindows)
FOREACH(platform ${QTPLATFORMSLIST})
MESSAGE(STATUS "Installing platform plugin ${platform}.dll")
INSTALL(FILES ${QT_DIR}/../../../plugins/platforms/${platform}.dll DESTINATION ${CMAKE_INSTALL_PREFIX}/platforms/)
ENDFOREACH(platform)
# Qt 6: HTTPS requires TLS backend plugins (otherwise QNetworkAccessManager: "TLS initialization failed")
if(IS_DIRECTORY "${QT_DIR}/../../../plugins/tls")
install(DIRECTORY "${QT_DIR}/../../../plugins/tls/" DESTINATION "${CMAKE_INSTALL_PREFIX}/tls")
endif()
ELSEIF(APPLE)
# FOREACH(qtlib ${QTLIBLIST})
# INSTALL(FILES ${QT_DIR}/../../lib${qtlib}.${QT_VERSION_MAJOR}.dylib DESTINATION ${CMAKE_INSTALL_PREFIX})
# ENDFOREACH(qtlib)
ELSEIF(UNIX)
SET (QTLIBLIST ${QTLIBLIST}
Qt${QT_VERSION_MAJOR}XcbQpa
Qt${QT_VERSION_MAJOR}EglFSDeviceIntegration
Qt${QT_VERSION_MAJOR}DBus
Qt${QT_VERSION_MAJOR}WaylandClient
Qt${QT_VERSION_MAJOR}OpenGL)
FOREACH(qtlib ${QTLIBLIST})
INSTALL(FILES ${QT_DIR}/../../lib${qtlib}.so.${QT_VERSION} DESTINATION ${CMAKE_INSTALL_PREFIX}/)
INSTALL(FILES ${QT_DIR}/../../lib${qtlib}.so.${QT_VERSION_MAJOR} DESTINATION ${CMAKE_INSTALL_PREFIX}/)
INSTALL(FILES ${QT_DIR}/../../lib${qtlib}.so DESTINATION ${CMAKE_INSTALL_PREFIX}/)
# INSTALL(FILES ${QT_DIR}/../../lib${qtlib}.so.${QT_VERSION} DESTINATION /usr/local/lib)
# INSTALL(FILES ${QT_DIR}/../../lib${qtlib}.so.${QT_VERSION_MAJOR} DESTINATION /usr/local/lib)
# INSTALL(FILES ${QT_DIR}/../../lib${qtlib}.so DESTINATION /usr/local/lib)
ENDFOREACH(qtlib)
SET (QTPLATFORMSLIST
qminimal
qxcb
qeglfs
qwayland-generic)
FOREACH(platform ${QTPLATFORMSLIST})
INSTALL(FILES ${QT_DIR}/../../../plugins/platforms/lib${platform}.so DESTINATION ${CMAKE_INSTALL_PREFIX}/platforms/)
ENDFOREACH(platform)
# Qt 6: HTTPS requires TLS backend plugins (otherwise QNetworkAccessManager: "TLS initialization failed")
if(IS_DIRECTORY "${QT_DIR}/../../../plugins/tls")
install(DIRECTORY "${QT_DIR}/../../../plugins/tls/" DESTINATION "${CMAKE_INSTALL_PREFIX}/tls")
endif()
# Install Qt QML modules required for Material Editor
# When Qt libraries are bundled, Qt can't find system QML modules automatically
get_filename_component(QT_BASE_DIR "${QT_DIR}/../../.." ABSOLUTE)
set(QT_QML_DIR "")
foreach(_qml_candidate
"${QT_BASE_DIR}/qml"
"${QT_BASE_DIR}/lib/qt6/qml"
"${QT_BASE_DIR}/lib/x86_64-linux-gnu/qt6/qml"
"${QT_BASE_DIR}/share/qt6/qml")
if(EXISTS "${_qml_candidate}/QtQuick")
set(QT_QML_DIR "${_qml_candidate}")
break()
endif()
endforeach()
if(QT_QML_DIR)
message(STATUS "Found Qt QML modules at: ${QT_QML_DIR}")
set(QML_MODULES_TO_INSTALL
QtQuick
QtQuick/Controls
QtQuick/Controls/Basic
QtQuick/Layouts
QtQuick/Templates
QtQuick/Dialogs
QtQml
QtQml/Models
QtQml/WorkerScript)
foreach(module ${QML_MODULES_TO_INSTALL})
if(EXISTS "${QT_QML_DIR}/${module}")
# Get the parent directory of the module for correct installation structure
get_filename_component(_module_parent "${module}" DIRECTORY)
install(DIRECTORY "${QT_QML_DIR}/${module}"
DESTINATION "${CMAKE_INSTALL_PREFIX}/qml/${_module_parent}"
COMPONENT Runtime)
endif()
endforeach()
else()
message(WARNING "Could not find Qt QML modules directory - QML features may not work in installed version")
endif()
ENDIF()
# This is a test for deploying using qt script, still needs more investigation.
#if(NOT APPLE)
# # Generate the deployment script for the target QtMeshEditor.
# qt_generate_deploy_app_script(
# TARGET QtMeshEditor
# FILENAME_VARIABLE deploy_script
# NO_UNSUPPORTED_PLATFORM_ERROR
# )
# # Call the deployment script on "cmake --install".
# install(SCRIPT ${deploy_script})
#endif()
##############################################################
# DEB package
##############################################################
if(LINUX)
configure_file (
"${CMAKE_CURRENT_SOURCE_DIR}/DEBIAN-control.in"
"${CMAKE_INSTALL_PREFIX}/DEBIAN-control"
@ONLY)
endif()
##############################################################
# CPACK
##############################################################
# Destination paths below are relative to ${CMAKE_INSTALL_PREFIX}
install(TARGETS ${APP_NAME}
BUNDLE DESTINATION . COMPONENT Runtime
RUNTIME DESTINATION bin COMPONENT Runtime
)
set(CPACK_PACKAGE_NAME "QtMeshEditor")
set(CPACK_PACKAGE_VENDOR "Fernando")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A graphical editor for Ogre3D mesh, material and skeleton")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
if(APPLE)
# Note Mac specific extension .app
set(APPS "\${CMAKE_INSTALL_PREFIX}/${CMAKE_PROJECT_NAME}.app")
# Directories to look for dependencies
set(DIRS ${CMAKE_INSTALL_PREFIX})
set(CPACK_GENERATOR "DragNDrop")
elseif(UNIX)
set(CPACK_GENERATOR "DEB")
# For now, only linux is using CPACK
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Fernando Tonon <tonon.fernando@hotmail.com>")
set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME})
set(CPACK_VERBATIM_VARIABLES ON)
# set(CPACK_PACKAGING_INSTALL_PREFIX "/opt/QtMeshEditor")
set(CPACK_DEBIAN_PACKAGE_DEPENDS libicui18n.so.56 libicuuc.so.56 libicudata.so.56)
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
elseif(WIN32)
# Define NSIS installation types
set(CPACK_ALL_INSTALL_TYPES Full Developer)
endif()
# Must be after the last CPACK macros
include(CPack)