Skip to content

Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.

67.5 KB
Raw Blame
cmake_minimum_required(VERSION 3.24)
project(SculptForge VERSION 0.11.16 LANGUAGES C CXX)
if(APPLE)
  enable_language(OBJCXX) # src/app/MacAppMenu.mm (here: enabled later, CMake leaves its rule variables unset)
endif()
# "beta.1" while this is a beta of that version (title bar and About: "0.11.0 Beta 1"), "" for a stable release.
# scripts/release.sh sets it; release.yml checks the tag against both (v0.11.0-beta.1).
set(SCULPTFORGE_PRERELEASE "")
include(GNUInstallDirs)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
endif()

option(SCULPTFORGE_BUILD_APP "Build the SculptForge desktop application" ON)
option(SCULPTFORGE_BUILD_PYTHON "Build the Python module (import sculptforge)" OFF)
set(SCULPTFORGE_PACKAGE_SUFFIX "" CACHE STRING "Extra tag in package file names, e.g. vfx2026")
option(SCULPTFORGE_BUILD_TESTS "Build unit tests" ON)
option(SCULPTFORGE_USE_SYSTEM_SDL "Use an installed SDL3 if one is found" ON)
option(SCULPTFORGE_UPDATE_CHECK "The app checks the website for a newer version once a day (OFF for package managers)" ON)
if(SCULPTFORGE_BUILD_TESTS)
  enable_testing()
endif()
# Position-independent code so the core libraries can also go into the Python module.
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

include(cmake/BuildSpeed.cmake)
include(cmake/Dependencies.cmake)

# --- Core library: geometry, sculpting, undo, commands, file IO (no GPU/UI) ---
# A custom studio build (docs/studios.md): the profile is compiled in (core/StudioProfile.h); empty for public builds.
set(SCULPTFORGE_STUDIO_PROFILE "" CACHE FILEPATH "studio.json to bake into a studio build (empty: public build)")
set(SF_STUDIO_JSON "")
if(SCULPTFORGE_STUDIO_PROFILE)
  file(READ ${SCULPTFORGE_STUDIO_PROFILE} SF_STUDIO_JSON)
endif()
file(CONFIGURE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/StudioBuild.cpp CONTENT
  "// Generated by CMake (SCULPTFORGE_STUDIO_PROFILE)\nnamespace sf { const char* builtInStudioProfile() { return R\"sfstudio(${SF_STUDIO_JSON})sfstudio\"; } }\n")
add_library(sculptforge_core STATIC
  src/core/Mesh.cpp
  src/core/BVH.cpp
  src/core/SurfaceCursor.cpp
  src/core/IndexBits.cpp
  src/core/ThreadPool.cpp
  src/core/UploadOrder.cpp
  src/core/Benchmark.cpp
  src/core/HardwareProfile.cpp
  src/core/FrameGovernor.cpp
  src/core/PerfTrace.cpp
  src/core/TierConfig.cpp
  src/core/HardwareTier.cpp
  src/core/MemoryGuard.cpp
  src/core/Sculpt.cpp
  src/core/SculptBatch.cpp
  src/core/Dyntopo.cpp
  src/core/DyntopoCommands.cpp
  src/core/Undo.cpp
  src/core/Timeline.cpp
  src/core/Primitives.cpp
  src/core/Document.cpp
  src/core/Commands.cpp
  src/core/FaceGroups.cpp
  src/core/SelectionSets.cpp
  src/core/ScreenSelect.cpp
  src/core/Parts.cpp
  src/core/Units.cpp
  src/core/Garment.cpp
  src/core/GarmentMesh.cpp
  src/core/GarmentFiles.cpp
  src/core/GarmentCommands.cpp
  src/core/ExtractMirror.cpp
  src/core/MeshTransform.cpp
  src/core/Deform.cpp
  src/core/TransformCommands.cpp
  src/core/Decimate.cpp
  src/core/Script.cpp
  src/core/Macro.cpp
  src/core/Pack.cpp
  src/core/NetworkPolicy.cpp
  src/core/StudioProfile.cpp
  ${CMAKE_CURRENT_BINARY_DIR}/StudioBuild.cpp
  src/core/Json.cpp
  src/core/BrushRecipe.cpp
  src/core/BrushPacks.cpp
  src/core/BrushSets.cpp
  src/core/BrushSettings.cpp
  src/core/AlphaOptions.cpp
  src/core/BrushLibrary.cpp
  src/core/Image.cpp
  src/core/ImageTo3D.cpp
  src/core/Splats.cpp
  src/core/SplatCapture.cpp
  src/core/Sculptable.cpp
  src/core/Voxel.cpp
  src/core/QuickRemesh.cpp
  src/core/EnginePresets.cpp
  src/core/Masking.cpp
  src/core/Cut.cpp
  src/core/CloseHoles.cpp
  src/core/MeshCheck.cpp
  src/core/BrushAlpha.cpp
  src/core/Stencil.cpp
  src/core/Stroke.cpp
  src/core/Precision.cpp
  src/core/PathStroke.cpp
  src/core/Sha256.cpp
  src/core/Ed25519.cpp
  src/core/SelfUpdate.cpp
  src/core/MemberBuilds.cpp
  src/core/Keychain.cpp
  src/core/ManagedPolicy.cpp
  src/core/AuditLog.cpp
  src/core/BrushGallery.cpp
  src/core/VertexPaint.cpp
  src/core/PaintLayer.cpp
  src/core/Texture.cpp
  src/core/TextureCommands.cpp
  src/core/Uv.cpp
  src/core/UvCommands.cpp
  src/core/UvPack.cpp
  src/core/UvUnwrap.cpp
  src/core/TileImage.cpp
  src/core/Wavelet.cpp
  src/core/EnvironmentMath.cpp
  src/core/MeshMaps.cpp
  src/core/LayerStack.cpp
  src/core/MaterialRecipe.cpp
  src/core/TextureChannels.cpp
  src/core/TextureChannelCommands.cpp
  src/core/LayerStackIO.cpp
  src/core/MapExport.cpp
  src/core/Multires.cpp
  src/core/Micro.cpp
  src/core/MicroSculpt.cpp
  src/core/MicroCommands.cpp
  src/core/MicroStore.cpp
  src/core/FocusDetail.cpp
  src/core/FocusBench.cpp
  src/core/MultiresCommands.cpp
  src/core/AutoUv.cpp
  src/core/TextureTransfer.cpp
  src/core/SurfaceQuery.cpp
  src/core/QRemesh.cpp
  src/core/GeneratedRemesh.cpp
  src/core/Backdrop.cpp
  src/core/QRemeshGuides.cpp
  src/core/QRemesh2.cpp
  src/core/QRemesh2Proxy.cpp
  src/core/QRemesh2Field.cpp
  src/core/QRemesh2Param.cpp
  src/core/QuadQuality.cpp
  src/core/ForgeSpheres.cpp src/core/AgentTools.cpp
  src/core/Tube.cpp
  src/core/Projection.cpp
  src/core/RetopoCommands.cpp
  third_party/xatlas/xatlas.cpp
  src/core/Bake.cpp
  src/core/BakeImage.cpp
  src/core/Tangents.cpp
  third_party/mikktspace/mikktspace.c
  src/core/Vdm.cpp
  src/core/Kelvinlet.cpp
  src/core/KeepMasked.cpp
  src/core/ViewCapture.cpp
  third_party/tinyexr/tinyexr_impl.cpp
  src/core/LitSphere.cpp
  src/core/Trash.cpp
  src/core/DiscordPresence.cpp
  src/core/ExitWatchdog.cpp
  src/core/Project.cpp
  src/core/Guide.cpp
  src/core/WhatsNew.cpp
  src/core/UpdateCheck.cpp
  src/core/Tablet.cpp
  src/core/RadialMenu.cpp
  src/core/StrokePopup.cpp
  src/core/SpaceMouse.cpp
  src/core/TouchGesture.cpp
  src/io/ObjIO.cpp
  src/io/FbxIO.cpp
  third_party/ufbx/ufbx.c
  src/io/GltfIO.cpp
  src/io/PlyIO.cpp
  src/io/UsdIO.cpp
  src/io/Zip.cpp
  src/io/BridgeIO.cpp
  src/io/BridgeCommands.cpp
  src/io/BlenderBridge.cpp
  src/io/BlenderCommands.cpp
  src/io/MayaBridge.cpp
  src/io/MayaCommands.cpp
  src/io/StlIO.cpp
  src/io/ArExport.cpp
)
# Facial shapes (core/Face.h): the template head with the 52 ARKit shapes, built from ICT-FaceKit (MIT) by
# tools/face/build_ict_template.py, embedded so the app, the CLI and the tests all have it.
include(cmake/EmbedFile.cmake)
embed_files(${CMAKE_CURRENT_BINARY_DIR}/EmbeddedFace.cpp sf::assets
  faceTemplateData ${CMAKE_CURRENT_SOURCE_DIR}/assets/face/ict-arkit.sfface)
target_sources(sculptforge_core PRIVATE src/core/Face.cpp src/core/FaceCommands.cpp
  ${CMAKE_CURRENT_BINARY_DIR}/EmbeddedFace.cpp)
# Starter meshes (core/StarterMeshes.h): base cages in compressed projects, built by tools/starter/build.sh from
# scratch or from the MakeHuman base mesh (CC0; docs/starter-meshes.md).
embed_files(${CMAKE_CURRENT_BINARY_DIR}/EmbeddedStarterMeshes.cpp sf::assets
  starterHumanHead ${CMAKE_CURRENT_SOURCE_DIR}/assets/starter/human-head.sfproj.z
  starterBust ${CMAKE_CURRENT_SOURCE_DIR}/assets/starter/bust.sfproj.z
  starterFullBody ${CMAKE_CURRENT_SOURCE_DIR}/assets/starter/full-body.sfproj.z
  starterHand ${CMAKE_CURRENT_SOURCE_DIR}/assets/starter/hand.sfproj.z
  starterFoot ${CMAKE_CURRENT_SOURCE_DIR}/assets/starter/foot.sfproj.z
  starterEar ${CMAKE_CURRENT_SOURCE_DIR}/assets/starter/ear.sfproj.z
  starterEye ${CMAKE_CURRENT_SOURCE_DIR}/assets/starter/eye.sfproj.z
  starterStylisedHead ${CMAKE_CURRENT_SOURCE_DIR}/assets/starter/stylised-head.sfproj.z
  starterCreatureHead ${CMAKE_CURRENT_SOURCE_DIR}/assets/starter/creature-head.sfproj.z
  starterTorso ${CMAKE_CURRENT_SOURCE_DIR}/assets/starter/torso.sfproj.z
  starterRoundedBox ${CMAKE_CURRENT_SOURCE_DIR}/assets/starter/rounded-box.sfproj.z
  starterCylinder ${CMAKE_CURRENT_SOURCE_DIR}/assets/starter/cylinder.sfproj.z
  starterCapsule ${CMAKE_CURRENT_SOURCE_DIR}/assets/starter/capsule.sfproj.z
  starterRing ${CMAKE_CURRENT_SOURCE_DIR}/assets/starter/ring.sfproj.z)
target_sources(sculptforge_core PRIVATE src/core/StarterMeshes.cpp ${CMAKE_CURRENT_BINARY_DIR}/EmbeddedStarterMeshes.cpp)
# The PBR viewport's bundled environments (core/EnvironmentMath.h): CC0 HDRIs from Poly Haven, 512 x 256
# (THIRD_PARTY_NOTICES.md).
embed_files(${CMAKE_CURRENT_BINARY_DIR}/EmbeddedHdri.cpp sf::assets
  hdriPhotoStudio ${CMAKE_CURRENT_SOURCE_DIR}/assets/hdri/brown_photostudio_02.hdr
  hdriSmallStudio ${CMAKE_CURRENT_SOURCE_DIR}/assets/hdri/studio_small_09.hdr
  hdriOutdoorSky ${CMAKE_CURRENT_SOURCE_DIR}/assets/hdri/kloofendal_48d_partly_cloudy_puresky.hdr)
target_sources(sculptforge_core PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/EmbeddedHdri.cpp)
# The built-in Material Recipes (core/MaterialRecipe.h): Fill layer stacks as data files.
embed_files(${CMAKE_CURRENT_BINARY_DIR}/EmbeddedRecipes.cpp sf::assets
  recipeWornMetal ${CMAKE_CURRENT_SOURCE_DIR}/assets/materials/worn_metal.sfmaterial
  recipePaintedEdges ${CMAKE_CURRENT_SOURCE_DIR}/assets/materials/painted_edges.sfmaterial
  recipeDirtAndDust ${CMAKE_CURRENT_SOURCE_DIR}/assets/materials/dirt_and_dust.sfmaterial
  recipeRustedIron ${CMAKE_CURRENT_SOURCE_DIR}/assets/materials/rusted_iron.sfmaterial)
target_sources(sculptforge_core PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/EmbeddedRecipes.cpp)
# The built-in insert sets (core/Parts.h builtinInsertSets): Creature bones (#154), original pieces made by
# tools/creature-bones/build.sh, a zlib-compressed multi-object OBJ.
embed_files(${CMAKE_CURRENT_BINARY_DIR}/EmbeddedInsertSets.cpp sf::assets
  insertSetCreatureBones ${CMAKE_CURRENT_SOURCE_DIR}/assets/insert-sets/creature-bones.obj.z)
target_sources(sculptforge_core PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/EmbeddedInsertSets.cpp)
target_include_directories(sculptforge_core PUBLIC src PRIVATE third_party/stb third_party/ufbx third_party/xatlas third_party/mikktspace third_party/tinyexr)
if(WIN32)
  target_link_libraries(sculptforge_core PRIVATE shell32 advapi32) # core/Trash.cpp: the Recycle Bin; core/DiscordPresence.cpp: the pipe server's user
  target_link_libraries(sculptforge_core PRIVATE dxgi) # core/HardwareTier.cpp: the graphics cards (GPU picker)
endif()
# Third-party C code: compile quietly.
if(MSVC)
  set_source_files_properties(third_party/ufbx/ufbx.c third_party/xatlas/xatlas.cpp third_party/mikktspace/mikktspace.c third_party/tinyexr/tinyexr_impl.cpp PROPERTIES COMPILE_OPTIONS "/w")
else()
  set_source_files_properties(third_party/ufbx/ufbx.c third_party/xatlas/xatlas.cpp third_party/mikktspace/mikktspace.c third_party/tinyexr/tinyexr_impl.cpp PROPERTIES COMPILE_OPTIONS "-w")
endif()
find_package(Threads REQUIRED)
target_link_libraries(sculptforge_core PUBLIC glm::glm Threads::Threads)
if(UNIX AND NOT APPLE)
  target_link_libraries(sculptforge_core PRIVATE ${CMAKE_DL_LIBS}) # core/Keychain.cpp: libsecret, loaded at run time
endif()
if(APPLE)
  target_link_libraries(sculptforge_core PRIVATE "-framework Security" "-framework CoreFoundation") # core/Keychain.cpp
endif()
# zstd for Focus Detail tiles (core/FocusDetail.h), when the system has it; without it the tiles use our own codec.
# Not on macOS: Homebrew's zstd is single-architecture and breaks the universal (x86_64 + arm64) build.
find_package(PkgConfig QUIET)
if(PkgConfig_FOUND AND NOT APPLE)
  pkg_check_modules(SF_ZSTD QUIET IMPORTED_TARGET libzstd)
endif()
if(SF_ZSTD_FOUND)
  target_link_libraries(sculptforge_core PRIVATE PkgConfig::SF_ZSTD)
  target_compile_definitions(sculptforge_core PRIVATE SF_HAVE_ZSTD)
endif()
target_compile_definitions(sculptforge_core PUBLIC GLM_FORCE_XYZW_ONLY)
target_compile_definitions(sculptforge_core PRIVATE SCULPTFORGE_VERSION="${PROJECT_VERSION}") # written into projects
if(MSVC)
  target_compile_options(sculptforge_core PRIVATE /W4 /utf-8 /permissive-)
  target_compile_definitions(sculptforge_core PUBLIC NOMINMAX _USE_MATH_DEFINES)
else()
  # -ffp-contract=off: no fused multiply-adds, so a result doesn't depend on the optimisation level (distro
  # packages build at -O2; face_weights' fast path is tested to match a full evaluation exactly).
  target_compile_options(sculptforge_core PRIVATE -Wall -Wextra -Wno-unused-parameter -ffp-contract=off)
endif()
sculptforge_pch(sculptforge_core)
set_source_files_properties(third_party/xatlas/xatlas.cpp third_party/tinyexr/tinyexr_impl.cpp ${CMAKE_CURRENT_BINARY_DIR}/EmbeddedRecipes.cpp
                            PROPERTIES SKIP_PRECOMPILE_HEADERS ON)

# --- Bring-your-own-AI (brush assistant). HTTPS via WinHTTP or libcurl. ---
add_library(sculptforge_ai STATIC src/ai/Http.cpp src/ai/AiPolicy.cpp src/ai/Providers.cpp src/ai/Secrets.cpp src/ai/Oidc.cpp src/ai/BrushAssistant.cpp src/ai/Generator3D.cpp
  src/ai/ImageTo3DService.cpp src/ai/Hyper3D.cpp src/ai/GradioClient.cpp src/ai/ComfyUI.cpp src/ai/AiCommands.cpp src/ai/BrushGalleryClient.cpp src/link/Socket.cpp
  src/link/UnrealLink.cpp src/ai/Process.cpp src/ai/SplatTrainer.cpp)
# Lets a build run from its tree find the bundled ComfyUI workflows (integrations/comfyui/workflows).
target_compile_definitions(sculptforge_ai PRIVATE SF_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
find_package(Threads REQUIRED)
target_link_libraries(sculptforge_ai PUBLIC sculptforge_core Threads::Threads)
if(WIN32)
  target_link_libraries(sculptforge_ai PRIVATE winhttp ws2_32)
else()
  find_package(CURL QUIET)
  if(CURL_FOUND)
    target_link_libraries(sculptforge_ai PRIVATE CURL::libcurl)
    target_compile_definitions(sculptforge_ai PRIVATE SF_HAVE_CURL)
  else()
    message(WARNING "libcurl not found: AI features will report that HTTP is unavailable")
  endif()
endif()
if(MSVC)
  target_compile_options(sculptforge_ai PRIVATE /W4 /utf-8 /permissive-)
else()
  target_compile_options(sculptforge_ai PRIVATE -Wall -Wextra -Wno-unused-parameter)
endif()
sculptforge_pch(sculptforge_ai)

# --- Phone link (src/link/PhoneLink.h, docs/phone-link.md): the capture page server, AR export, live face feed ---
option(SCULPTFORGE_WEBRTC "Live face feed over WebRTC (fetches libdatachannel and Mbed TLS; OFF: capture and AR only)" ON)
include(cmake/EmbedFile.cmake)
embed_files(${CMAKE_CURRENT_BINARY_DIR}/EmbeddedPhone.cpp sf::phone_assets
  capturePage ${CMAKE_CURRENT_SOURCE_DIR}/assets/phone/capture.html
  facePage ${CMAKE_CURRENT_SOURCE_DIR}/website/link/index.html)
add_library(sculptforge_phone STATIC ${CMAKE_CURRENT_BINARY_DIR}/EmbeddedPhone.cpp src/link/HttpServer.cpp
  src/link/PhoneLink.cpp src/link/FaceFeed.cpp src/link/PhoneRtc.cpp src/link/Qr.cpp third_party/qrcodegen/qrcodegen.cpp)
target_include_directories(sculptforge_phone PRIVATE third_party/qrcodegen)
target_link_libraries(sculptforge_phone PUBLIC sculptforge_ai)
if(SCULPTFORGE_WEBRTC)
  include(cmake/WebRTC.cmake)
  target_link_libraries(sculptforge_phone PRIVATE LibDataChannel::LibDataChannelStatic MbedTLS::MbedTLS)
  target_compile_definitions(sculptforge_phone PRIVATE SF_HAVE_WEBRTC=1)
else()
  target_compile_definitions(sculptforge_phone PRIVATE SF_HAVE_WEBRTC=0)
endif()
if(MSVC)
  target_compile_options(sculptforge_phone PRIVATE /W4 /utf-8 /permissive-)
  set_source_files_properties(third_party/qrcodegen/qrcodegen.cpp PROPERTIES COMPILE_OPTIONS "/w")
else()
  target_compile_options(sculptforge_phone PRIVATE -Wall -Wextra -Wno-unused-parameter)
  set_source_files_properties(third_party/qrcodegen/qrcodegen.cpp PROPERTIES COMPILE_OPTIONS "-w")
endif()
sculptforge_pch(sculptforge_phone)
set_source_files_properties(third_party/qrcodegen/qrcodegen.cpp ${CMAKE_CURRENT_BINARY_DIR}/EmbeddedPhone.cpp PROPERTIES SKIP_PRECOMPILE_HEADERS ON)

# --- Headless command-line tool (pipelines, build farms, AI agents) ---
# The MCP server (src/cli/McpServer.cpp) is a library of its own: the tool and the tests link it, nobody compiles it twice.
add_library(sculptforge_mcp STATIC src/cli/McpServer.cpp src/cli/McpTools.cpp src/cli/McpAttach.cpp src/link/AiLink.cpp src/link/AiLinkSession.cpp
  src/link/MayaLink.cpp)
target_compile_definitions(sculptforge_mcp PRIVATE SCULPTFORGE_VERSION="${PROJECT_VERSION}")
target_link_libraries(sculptforge_mcp PUBLIC sculptforge_core sculptforge_ai)
if(WIN32)
  target_link_libraries(sculptforge_mcp PRIVATE advapi32) # live mode's pipe ACL (src/link/AiLink.cpp)
endif()
add_executable(sculptforge-cli src/cli/main.cpp)
target_compile_definitions(sculptforge-cli PRIVATE SCULPTFORGE_VERSION="${PROJECT_VERSION}")
target_link_libraries(sculptforge-cli PRIVATE sculptforge_core sculptforge_ai sculptforge_mcp)

# App code the tests also run (layout, looks, translations, Library, brush previews, camera, clusters): one static
# library both link, so an edit to one of these files compiles once, not once per program.
if(SCULPTFORGE_BUILD_APP OR SCULPTFORGE_BUILD_TESTS)
  add_library(sculptforge_appshared STATIC src/app/AssetLibrary.cpp src/app/BrushPreview.cpp src/app/UiLayout.cpp
    src/app/ShellGeometry.cpp src/app/LookSchemes.cpp src/app/I18n.cpp src/app/I18nSpanish.cpp
    src/app/I18nTraditionalChinese.cpp src/app/I18nSimplifiedChinese.cpp src/app/ConnectAi.cpp src/render/Camera.cpp src/render/Clusters.cpp src/render/Ghost.cpp)
  target_link_libraries(sculptforge_appshared PUBLIC sculptforge_core)
  if(MSVC)
    target_compile_options(sculptforge_appshared PRIVATE /W4 /utf-8 /permissive-)
  else()
    target_compile_options(sculptforge_appshared PRIVATE -Wall -Wextra -Wno-unused-parameter)
  endif()
  sculptforge_pch(sculptforge_appshared)
endif()
# The action registry (key chords, shortcut overrides; needs SDL's key names): the app and its tests.
if(SCULPTFORGE_BUILD_APP)
  add_library(sculptforge_actions STATIC src/app/Actions.cpp src/app/BlenderKeymap.cpp)
  target_link_libraries(sculptforge_actions PUBLIC sculptforge_core SDL3::SDL3)
  if(MSVC)
    target_compile_options(sculptforge_actions PRIVATE /W4 /utf-8 /permissive-)
  else()
    target_compile_options(sculptforge_actions PRIVATE -Wall -Wextra -Wno-unused-parameter)
  endif()
endif()

# --- Desktop application ---
if(SCULPTFORGE_BUILD_APP)
  include(cmake/EmbedFile.cmake)
  embed_files(${CMAKE_CURRENT_BINARY_DIR}/EmbeddedFonts.cpp sf::assets
    fontRegular ${CMAKE_CURRENT_SOURCE_DIR}/assets/fonts/Inter-Regular.ttf
    fontSemiBold ${CMAKE_CURRENT_SOURCE_DIR}/assets/fonts/Inter-SemiBold.ttf
    fontLucide ${CMAKE_CURRENT_SOURCE_DIR}/assets/fonts/lucide.ttf
    fontMono ${CMAKE_CURRENT_SOURCE_DIR}/assets/fonts/JetBrainsMono-Regular.ttf # the looks (Preferences > Interface > Look)
    fontMonoBold ${CMAKE_CURRENT_SOURCE_DIR}/assets/fonts/JetBrainsMono-SemiBold.ttf
    fontCjk ${CMAKE_CURRENT_SOURCE_DIR}/assets/fonts/NotoSansTC-UI.otf # Traditional Chinese (tools/i18n/subset_cjk_font.py)
    fontCjkSc ${CMAKE_CURRENT_SOURCE_DIR}/assets/fonts/NotoSansSC-UI.otf # Simplified Chinese (the same tool)
    appIcon ${CMAKE_CURRENT_SOURCE_DIR}/assets/branding/sculptforge-256.png # the cube app icon: window, title bar (BrandMark.cpp)
    appIconSmall ${CMAKE_CURRENT_SOURCE_DIR}/assets/branding/sculptforge-32.png # its small cut (up to 32 px)
    bustMark ${CMAKE_CURRENT_SOURCE_DIR}/assets/branding/bust/bust-256.png # the illustration: About, What's New, support card
    supporters ${CMAKE_CURRENT_SOURCE_DIR}/docs/supporters.txt # Help > About (never empty: it starts with comments)
    foundingMembers ${CMAKE_CURRENT_SOURCE_DIR}/website/founding.json) # Help > About and the membership card
  include(cmake/EmbedGuide.cmake)
  embed_guide(${CMAKE_CURRENT_BINARY_DIR}/EmbeddedGuide.cpp ${CMAKE_CURRENT_SOURCE_DIR}/docs/guide)
  add_executable(sculptforge
    ${CMAKE_CURRENT_BINARY_DIR}/EmbeddedFonts.cpp
    ${CMAKE_CURRENT_BINARY_DIR}/EmbeddedGuide.cpp
    src/app/main.cpp
    src/app/Bench.cpp
    src/app/Calibration.cpp
    src/app/OptimisticBench.cpp
    src/app/PanelPerformanceProfile.cpp
    src/app/PanelHardwareTier.cpp
    src/app/CrashLog.cpp
    src/app/App.cpp
    src/app/Precision.cpp
    src/app/AsyncStroke.cpp
    src/app/Demo.cpp
    src/app/UiTest.cpp
    src/app/UiServe.cpp
    src/app/Ui.cpp
    src/app/UserGlyphs.cpp
    src/app/Shell.cpp
    src/app/Palettes.cpp
    src/app/Theme.cpp
    src/app/CommandPalette.cpp
    src/app/Console.cpp
    src/app/Config.cpp
    src/app/LibraryBrowser.cpp
    src/app/Thumbnails.cpp
    src/app/Pickers.cpp
    src/app/UserGuide.cpp
    src/app/BrandMark.cpp
    src/app/PanelMasking.cpp
    src/app/PanelCut.cpp
    src/app/PanelView.cpp
    src/app/PanelFaceGroups.cpp
    src/app/PanelSelectionSets.cpp
    src/app/Selection.cpp
    src/app/PanelBrushes.cpp
    src/app/BrushSettingsUi.cpp
    src/app/PanelVdm.cpp
    src/app/PanelKelvinlet.cpp
    src/app/PanelFace.cpp
    src/app/PanelBrushLibrary.cpp
    src/app/PanelBrushGallery.cpp
    src/app/PanelVertexPaint.cpp
    src/app/LineGradient.cpp
    src/app/StencilOverlay.cpp
    src/app/PanelPacks.cpp
    src/app/PanelBrushSets.cpp
    src/app/MemoryConfirm.cpp
    src/app/PanelPaintLayers.cpp
    src/app/PanelTexture.cpp
    src/app/PanelUvEditor.cpp
    src/app/PanelPbr.cpp
    src/app/PanelFill.cpp
    src/app/PanelGeometry.cpp
    src/app/Gizmo.cpp
    src/app/PanelBake.cpp
    src/app/FocusDetailApp.cpp
    src/app/PanelRetopo.cpp
    src/app/PanelForgeSpheres.cpp
    src/app/PanelTube.cpp
    src/app/PanelSplatTrain.cpp
    src/app/PanelSculptable.cpp
    src/app/PanelPerformance.cpp
    src/app/PanelBridge.cpp
    src/app/PanelBlender.cpp
    src/app/PanelMaya.cpp
    src/app/PanelPhone.cpp
    src/app/PanelProject.cpp
    src/app/PanelUpdate.cpp
    src/app/PanelParts.cpp
    src/app/PanelSupport.cpp
    src/app/QuickTour.cpp
    src/app/PanelAi.cpp
    src/app/PanelAiLink.cpp
    src/app/PanelConnectAi.cpp
    src/app/PanelSupportCard.cpp
    src/app/PanelIntegrations.cpp
    src/app/WhatsNewPopup.cpp
    src/app/PanelDeform.cpp
    src/app/PanelExtract.cpp
    src/app/PanelMeshCheck.cpp
    src/app/PanelTimeline.cpp
    src/app/ProofMode.cpp
    src/app/BenchVideo.cpp
    src/app/BenchTake.cpp
    src/app/Tablet.cpp
    src/app/Wintab.cpp
    src/app/SpaceMouse.cpp
    src/app/Touch.cpp
    src/app/Input.cpp
    src/app/RadialMenu.cpp
    src/app/StrokePopup.cpp
    src/render/GL.cpp
    src/render/ScreenStroke.cpp
    src/render/Renderer.cpp
    src/render/UvView.cpp
    src/render/MicroRenderer.cpp
  )
  target_link_libraries(sculptforge PRIVATE sculptforge_core sculptforge_ai sculptforge_phone sculptforge_appshared
                                            sculptforge_mcp sculptforge_actions imgui SDL3::SDL3)
  target_include_directories(sculptforge PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/third_party/lucide)
  target_compile_definitions(sculptforge PRIVATE SCULPTFORGE_VERSION="${PROJECT_VERSION}"
                                                 SCULPTFORGE_PRERELEASE="${SCULPTFORGE_PRERELEASE}"
                                                 SF_UPDATE_CHECK=$<BOOL:${SCULPTFORGE_UPDATE_CHECK}>)
  # The commit a build came from, for proof mode's results and HUD (src/app/ProofMode.cpp, BenchTake.cpp); taken when CMake configures.
  find_package(Git QUIET)
  if(GIT_FOUND AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
    execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
                    OUTPUT_VARIABLE SF_GIT_COMMIT OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
  endif()
  if(SF_GIT_COMMIT)
    set_source_files_properties(src/app/ProofMode.cpp src/app/BenchTake.cpp PROPERTIES COMPILE_DEFINITIONS "SF_GIT_COMMIT=\"${SF_GIT_COMMIT}\"")
  endif()
  # A developer's build says so beside the version (window title, top bar): "0.11.13 dev 1a2b3c4". AUTO = a git
  # checkout built outside CI; release packages build in CI or from a tarball (AUR, brew, Flatpak skip .git).
  set(SCULPTFORGE_DEV_BUILD AUTO CACHE STRING "Show 'dev <commit>' beside the version: AUTO, ON or OFF")
  if(SF_GIT_COMMIT AND (SCULPTFORGE_DEV_BUILD STREQUAL "ON" OR (SCULPTFORGE_DEV_BUILD STREQUAL "AUTO" AND NOT DEFINED ENV{CI})))
    set_property(SOURCE src/app/PanelProject.cpp APPEND PROPERTY COMPILE_DEFINITIONS "SF_DEV_COMMIT=\"${SF_GIT_COMMIT}\"")
  endif()
  if(MSVC)
    target_compile_options(sculptforge PRIVATE /W4 /utf-8 /permissive-)
  else()
    target_compile_options(sculptforge PRIVATE -Wall -Wextra -Wno-unused-parameter)
  endif()
  sculptforge_pch(sculptforge <imgui.h>)
  set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/EmbeddedFonts.cpp ${CMAKE_CURRENT_BINARY_DIR}/EmbeddedGuide.cpp
                              PROPERTIES SKIP_PRECOMPILE_HEADERS ON)
  if(WIN32)
    set_target_properties(sculptforge PROPERTIES WIN32_EXECUTABLE $<CONFIG:Release,MinSizeRel>)
    set(ICON_PATH "${CMAKE_CURRENT_SOURCE_DIR}/assets/branding/sculptforge.ico")
    if(CMAKE_HOST_WIN32)
      string(REPLACE "/" "\\\\" ICON_PATH "${ICON_PATH}")
    endif()
    configure_file(packaging/windows/sculptforge.rc ${CMAKE_CURRENT_BINARY_DIR}/sculptforge.rc @ONLY)
    target_sources(sculptforge PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/sculptforge.rc)
    # Per-monitor DPI v2 from the first instruction (a window moved between 100 % and 150 % monitors stays sharp
    # and SDL reports each monitor's scale); MSVC merges it into the manifest the linker writes. (SDL 3 also asks
    # for it at start-up; the manifest covers what runs before, and other toolchains rely on that.)
    if(MSVC)
      target_sources(sculptforge PRIVATE packaging/windows/sculptforge.manifest)
    endif()
  endif()
  if(APPLE)
    # SculptForge > Preferences... in the app menu (#111): SDL's item, given its action (src/app/MacAppMenu.h).
    target_sources(sculptforge PRIVATE src/app/MacAppMenu.mm)
    set_source_files_properties(src/app/MacAppMenu.mm PROPERTIES SKIP_PRECOMPILE_HEADERS ON)
    target_link_libraries(sculptforge PRIVATE "-framework Cocoa")
    # App icon: assets/branding/sculptforge.icns (tools/brand/make_icons.py: the SF mark on Apple's icon grid).
    set(ICNS ${CMAKE_CURRENT_SOURCE_DIR}/assets/branding/sculptforge.icns)
    target_sources(sculptforge PRIVATE ${ICNS})
    set_source_files_properties(${ICNS} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
    set_target_properties(sculptforge PROPERTIES
      MACOSX_BUNDLE TRUE
      OUTPUT_NAME "SculptForge"
      MACOSX_BUNDLE_BUNDLE_NAME "SculptForge"
      MACOSX_BUNDLE_GUI_IDENTIFIER "org.sculptforge.SculptForge"
      MACOSX_BUNDLE_ICON_FILE "sculptforge.icns"
      MACOSX_BUNDLE_COPYRIGHT "Copyright (C) 2026 The SculptForge contributors. GPL-3.0-or-later."
      MACOSX_BUNDLE_BUNDLE_VERSION "${PROJECT_VERSION}"
      MACOSX_BUNDLE_SHORT_VERSION_STRING "${PROJECT_VERSION}")
    install(TARGETS sculptforge BUNDLE DESTINATION .)
    # The command-line tool travels inside the app bundle.
    install(TARGETS sculptforge-cli RUNTIME DESTINATION SculptForge.app/Contents/MacOS)
  else()
    install(TARGETS sculptforge RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
  endif()
endif()

# --- Install layout and packages ---
if(NOT APPLE)
  install(TARGETS sculptforge-cli RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
if(UNIX AND NOT APPLE)
  install(FILES packaging/linux/org.sculptforge.SculptForge.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
  install(FILES packaging/linux/org.sculptforge.SculptForge.metainfo.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/metainfo)
  foreach(size 16 24 32 48 64 128 256 512) # (tools/brand/make_icons.py; up to 32 px the SF mark's small cut)
    install(FILES assets/branding/sculptforge-${size}.png DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/${size}x${size}/apps
            RENAME org.sculptforge.SculptForge.png)
  endforeach()
endif()
if(APPLE)
  set(SF_DOC_DIR .)
elseif(WIN32)
  set(SF_DOC_DIR doc)
else()
  set(SF_DOC_DIR ${CMAKE_INSTALL_DOCDIR})
endif()
# Windows: the Visual C++ runtime (msvcp140, vcruntime140, vcruntime140_1) goes next to the exe, so the portable zip
# and the installer start on a PC without the Visual C++ Redistributable (#109: nothing happened at all).
if(MSVC)
  set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION ${CMAKE_INSTALL_BINDIR})
  set(CMAKE_INSTALL_UCRT_LIBRARIES OFF) # the Universal CRT is part of Windows 10 and 11
  include(InstallRequiredSystemLibraries)
endif()
install(FILES LICENSE THIRD_PARTY_NOTICES.md README.md CHANGELOG.md DESTINATION ${SF_DOC_DIR})
install(FILES docs/ai-services.md docs/unreal.md docs/generators.md docs/comfyui.md DESTINATION ${SF_DOC_DIR}/docs)
# A studio build: the profile's folder (packs, preferences, logo) where core/StudioProfile.h looks for it.
if(SCULPTFORGE_STUDIO_PROFILE)
  get_filename_component(SF_STUDIO_DIR ${SCULPTFORGE_STUDIO_PROFILE} DIRECTORY)
  if(APPLE)
    install(DIRECTORY ${SF_STUDIO_DIR}/ DESTINATION SculptForge.app/Contents/Resources/studio)
  else()
    install(DIRECTORY ${SF_STUDIO_DIR}/ DESTINATION ${CMAKE_INSTALL_DATADIR}/sculptforge/studio)
  endif()
endif()
# Bundled ComfyUI workflows, where the Generate 3D window looks for them (see src/ai/ComfyUI.cpp).
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/integrations/comfyui/workflows)
  if(APPLE)
    set(SF_COMFY_DIR SculptForge.app/Contents/Resources/comfyui)
  else()
    set(SF_COMFY_DIR ${CMAKE_INSTALL_DATADIR}/sculptforge/comfyui)
  endif()
  install(DIRECTORY integrations/comfyui/workflows DESTINATION ${SF_COMFY_DIR})
endif()

set(CPACK_PACKAGE_NAME "sculptforge")
set(CPACK_PACKAGE_VENDOR "The SculptForge contributors")
set(CPACK_PACKAGE_CONTACT "https://github.com/islandmed/SculptForge/issues")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Free and open-source digital sculpting with game-engine pipelines")
set(CPACK_PACKAGE_HOMEPAGE_URL "https://sculptforge.app/")
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE)
set(CPACK_PACKAGE_INSTALL_DIRECTORY "SculptForge")
set(CPACK_PACKAGE_EXECUTABLES "sculptforge" "SculptForge")
string(TOLOWER "${CMAKE_SYSTEM_NAME}" SF_OS)
set(SF_ARCH ${CMAKE_SYSTEM_PROCESSOR})
if(SF_ARCH MATCHES "^(AMD64|amd64|x86_64)$")
  set(SF_ARCH x86_64)
elseif(SF_ARCH MATCHES "^(arm64|ARM64|aarch64)$")
  set(SF_ARCH arm64)
endif()
if(APPLE AND CMAKE_OSX_ARCHITECTURES MATCHES ";")
  set(SF_ARCH universal)
endif()
set(CPACK_PACKAGE_FILE_NAME "SculptForge-${PROJECT_VERSION}-${SF_OS}-${SF_ARCH}")
if(SCULPTFORGE_PACKAGE_SUFFIX)
  string(APPEND CPACK_PACKAGE_FILE_NAME "-${SCULPTFORGE_PACKAGE_SUFFIX}")
endif()
set(CPACK_STRIP_FILES ON)
# Debian / Ubuntu
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set(CPACK_DEBIAN_PACKAGE_SECTION graphics)
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "The SculptForge contributors <https://github.com/islandmed/SculptForge>")
# Fedora / RHEL
set(CPACK_RPM_FILE_NAME RPM-DEFAULT)
set(CPACK_RPM_PACKAGE_LICENSE "GPL-3.0-or-later")
set(CPACK_RPM_PACKAGE_GROUP "Applications/Multimedia")
set(CPACK_RPM_PACKAGE_URL "https://sculptforge.app/")
set(CPACK_RPM_PACKAGE_AUTOREQ ON)
# Windows installer
set(CPACK_NSIS_DISPLAY_NAME "SculptForge")
set(CPACK_NSIS_PACKAGE_NAME "SculptForge")
set(CPACK_NSIS_MUI_ICON ${CMAKE_CURRENT_SOURCE_DIR}/assets/branding/sculptforge.ico)
set(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\sculptforge.exe")
set(CPACK_NSIS_URL_INFO_ABOUT "https://sculptforge.app/")
set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON)
set(CPACK_NSIS_CREATE_ICONS_EXTRA "CreateShortCut '$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\SculptForge.lnk' '$INSTDIR\\\\bin\\\\sculptforge.exe'")
# macOS disk image
set(CPACK_DMG_VOLUME_NAME "SculptForge")
if(APPLE)
  set(CPACK_PRE_BUILD_SCRIPTS ${CMAKE_CURRENT_SOURCE_DIR}/cmake/MacSign.cmake)
endif()
if(WIN32)
  set(CPACK_GENERATOR "NSIS;ZIP")
elseif(APPLE)
  set(CPACK_GENERATOR "DragNDrop")
else()
  set(CPACK_GENERATOR "DEB;RPM;TGZ")
endif()
include(CPack)

# --- Python module ---
if(SCULPTFORGE_BUILD_PYTHON)
  find_package(Python 3.9 REQUIRED COMPONENTS Interpreter Development.Module)
  sf_fetch_declare(pybind11 DOWNLOAD_EXTRACT_TIMESTAMP TRUE)
  FetchContent_MakeAvailable(pybind11)
  pybind11_add_module(sculptforge_python MODULE src/python/module.cpp)
  set_target_properties(sculptforge_python PROPERTIES OUTPUT_NAME sculptforge)
  target_link_libraries(sculptforge_python PRIVATE sculptforge_core sculptforge_ai)
  target_compile_definitions(sculptforge_python PRIVATE SCULPTFORGE_VERSION="${PROJECT_VERSION}")
  set(SCULPTFORGE_PYTHON_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages"
      CACHE STRING "Where to install the Python module")
  install(TARGETS sculptforge_python LIBRARY DESTINATION ${SCULPTFORGE_PYTHON_INSTALL_DIR})
  if(SCULPTFORGE_BUILD_TESTS)
    add_test(NAME python_api COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=$<TARGET_FILE_DIR:sculptforge_python>
             ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_python.py)
  endif()
endif()

# --- Blender add-on (addons/blender): `cmake --build build --target blender_addon` writes its zips ---
find_package(Python3 COMPONENTS Interpreter QUIET)
if(Python3_Interpreter_FOUND)
  add_custom_target(blender_addon
    COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/addons/blender/build_addon.py --check
            --out ${CMAKE_CURRENT_BINARY_DIR}/blender-addon
    COMMENT "Packaging the Blender add-on (its own version: addons/blender/sculptforge_bridge/blender_manifest.toml)")
endif()

# --- Tests ---
if(SCULPTFORGE_BUILD_TESTS)
  # tests/test_main.cpp plus every tests/test_*.cpp (add a file to add tests; see tests/TestHarness.h).
  file(GLOB SCULPTFORGE_TEST_SOURCES CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_*.cpp)
  add_executable(sculptforge_tests ${SCULPTFORGE_TEST_SOURCES})
  target_include_directories(sculptforge_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tests)
  target_compile_definitions(sculptforge_tests PRIVATE SF_TEST_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/tests/data")
  if(Python3_EXECUTABLE) # the Maya shelf script as a real Live link client (tests/test_maya_live.cpp)
    target_compile_definitions(sculptforge_tests PRIVATE SF_PYTHON_EXE="${Python3_EXECUTABLE}")
  endif()
  target_link_libraries(sculptforge_tests PRIVATE sculptforge_core sculptforge_ai sculptforge_phone sculptforge_mcp sculptforge_appshared)
  sculptforge_pch(sculptforge_tests)
  if(SCULPTFORGE_BUILD_APP) # the action registry (key chords, shortcut overrides) needs SDL's key names
    target_link_libraries(sculptforge_tests PRIVATE sculptforge_actions)
    target_compile_definitions(sculptforge_tests PRIVATE SF_TEST_ACTIONS)
  endif()
  if(MSVC)
    target_compile_options(sculptforge_tests PRIVATE /utf-8)
  endif()
  # The suite as SCULPTFORGE_TEST_SHARDS processes (sculptforge_tests_0of16 ...; `ctest -j` runs them at once, CI does;
  # more shards than cores balance better), each with its own temporary folder so tests in different shards never
  # share a scratch file.
  set(SCULPTFORGE_TEST_SHARDS 16 CACHE STRING "Number of ctest entries the sculptforge_tests suite is split into")
  math(EXPR last_shard "${SCULPTFORGE_TEST_SHARDS} - 1")
  foreach(k RANGE ${last_shard})
    set(shard_tmp ${CMAKE_CURRENT_BINARY_DIR}/test-tmp/shard${k})
    file(MAKE_DIRECTORY ${shard_tmp})
    add_test(NAME sculptforge_tests_${k}of${SCULPTFORGE_TEST_SHARDS}
             COMMAND sculptforge_tests --shard ${k}/${SCULPTFORGE_TEST_SHARDS})
    set_tests_properties(sculptforge_tests_${k}of${SCULPTFORGE_TEST_SHARDS} PROPERTIES COST 1000 # the longest: start first
                         ENVIRONMENT "TMPDIR=${shard_tmp};TMP=${shard_tmp};TEMP=${shard_tmp}")
  endforeach()
  # T3 (docs/testing-flow.md): the TEST(nightly_*) cases, which no shard runs. Label nightly: tools/test/run.py and CI
  # leave it out; the nightly workflow and tools/test/nightly.sh run `ctest -L nightly`.
  add_test(NAME sculptforge_tests_nightly COMMAND sculptforge_tests --nightly)
  set_tests_properties(sculptforge_tests_nightly PROPERTIES LABELS nightly TIMEOUT 3600
                       ENVIRONMENT "TMPDIR=${CMAKE_CURRENT_BINARY_DIR}/test-tmp/nightly;TMP=${CMAKE_CURRENT_BINARY_DIR}/test-tmp/nightly;TEMP=${CMAKE_CURRENT_BINARY_DIR}/test-tmp/nightly")
  file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test-tmp/nightly)
  # A stand-in for Brush, COLMAP and ffmpeg (tests/tools/fake_splat_tools.cpp): splat training is tested without a GPU.
  add_executable(sf_fake_splat_tools tests/tools/fake_splat_tools.cpp)
  target_include_directories(sf_fake_splat_tools PRIVATE third_party/stb)
  target_link_libraries(sf_fake_splat_tools PRIVATE sculptforge_core)
  add_dependencies(sculptforge_tests sf_fake_splat_tools)
  target_compile_definitions(sculptforge_tests PRIVATE SF_FAKE_SPLAT_TOOLS="$<TARGET_FILE:sf_fake_splat_tools>")

  # Tests that launch our programs from Python get a path they can run directly. When cross-compiling
  # (e.g. a Windows build tested under Wine, tools/wintest.sh) that is a script calling the emulator.
  function(sculptforge_runner out target)
    if(CMAKE_CROSSCOMPILING_EMULATOR)
      list(JOIN CMAKE_CROSSCOMPILING_EMULATOR " " emulator)
      file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/run-${target}.sh
           CONTENT "#!/bin/sh\nexec ${emulator} \"$<TARGET_FILE:${target}>\" \"$@\"\n"
           FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
      set(${out} ${CMAKE_CURRENT_BINARY_DIR}/run-${target}.sh PARENT_SCOPE)
    else()
      set(${out} $<TARGET_FILE:${target}> PARENT_SCOPE)
    endif()
  endfunction()

  # The seeded community brush gallery (tools/brush-gallery/repo) must stay valid
  # and its index.json current: every brush is round-tripped through sculptforge-cli.
  find_package(Python3 COMPONENTS Interpreter QUIET)
  if(Python3_Interpreter_FOUND)
    sculptforge_runner(SCULPTFORGE_CLI_RUNNER sculptforge-cli)
    add_test(NAME brush_gallery_index
             COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/brush-gallery/build_index.py
                     ${CMAKE_CURRENT_SOURCE_DIR}/tools/brush-gallery/repo --check --cli ${SCULPTFORGE_CLI_RUNNER})
    # The user guide (docs/guide): every link, anchor and image resolves, only characters the app's font has,
    # and the website pages build.
    # The Blender add-on's exchange code (addons/blender) against sculptforge-cli: a round trip through the
    # bridge is the identity (needs numpy, which Blender bundles).
    execute_process(COMMAND ${Python3_EXECUTABLE} -c "import numpy" RESULT_VARIABLE SCULPTFORGE_NO_NUMPY OUTPUT_QUIET ERROR_QUIET)
    if(SCULPTFORGE_NO_NUMPY EQUAL 0)
      add_test(NAME blender_exchange COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tests/blender/test_exchange.py
                                           --cli ${SCULPTFORGE_CLI_RUNNER})
    endif()
    # The add-on's zips build and its manifest passes the checks Blender's validator makes.
    add_test(NAME blender_addon_package COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/addons/blender/build_addon.py
                                              --check --out ${CMAKE_CURRENT_BINARY_DIR}/blender-addon)
    # The Maya shelf script (integrations/maya, #42) with a mocked maya.cmds, round-tripped through sculptforge-cli.
    add_test(NAME maya_shelf_script COMMAND ${Python3_EXECUTABLE} -I ${CMAKE_CURRENT_SOURCE_DIR}/tests/maya/test_sculptforge_maya.py
                                            --cli ${SCULPTFORGE_CLI_RUNNER})
    # The add-on inside a real Blender, when one is installed (tests/blender/test_in_blender.py).
    find_program(SCULPTFORGE_BLENDER blender)
    if(SCULPTFORGE_BLENDER)
      add_test(NAME blender_addon COMMAND ${SCULPTFORGE_BLENDER} -b --factory-startup -noaudio --python-exit-code 1
                                        --python ${CMAKE_CURRENT_SOURCE_DIR}/tests/blender/test_in_blender.py
                                        -- --cli ${SCULPTFORGE_CLI_RUNNER})
      set_tests_properties(blender_addon PROPERTIES TIMEOUT 300)
    endif()
    # The release smoke test (tests/release_smoke.py, run by release.yml on every package): open, sculpt, save, reopen.
    add_test(NAME release_smoke COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tests/release_smoke.py
                                      --cli ${SCULPTFORGE_CLI_RUNNER} --out ${CMAKE_CURRENT_BINARY_DIR}/release-smoke)
    # Proof mode results: the validator and website list tool (tools/benchmark/submit.py, docs/benchmark.md).
    # Insider daily drops (tools/drops): the generator is deterministic, the gate rejects blank, seamed, torn and
    # duplicate candidates, and every kind makes a pack that passes the install checks.
    add_test(NAME insider_drops COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/drops/drops.py selftest
                                        --cli ${SCULPTFORGE_CLI_RUNNER})
    set_tests_properties(insider_drops PROPERTIES TIMEOUT 300)
    # Member Requests (tools/member-requests): only approved items, "Requested by" in each, no other apps' names,
    # public a month later, and the month's pack passes the install checks.
    add_test(NAME member_requests COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/member-requests/requests.py
                                          selftest --cli ${SCULPTFORGE_CLI_RUNNER})
    # Release notes from note fragments (tools/release/assemble_notes.py, changes/README.md): the assembler, and
    # every fragment on this branch parses.
    add_test(NAME marks COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/check_marks.py
             WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) # docs/legal/trademarks.md
    # No raw string literal in src/ over MSVC's ~16K characters (C2026: only the Windows build would fail).
    add_test(NAME raw_literal_size COMMAND ${Python3_EXECUTABLE} -I ${CMAKE_CURRENT_SOURCE_DIR}/tools/dev/check_literals.py)
    # assets/branding/sculptforge.icns: every slot decodes at its size, 16/32 px as RGB + mask, never PNG (#156).
    add_test(NAME icns COMMAND ${Python3_EXECUTABLE} -I ${CMAKE_CURRENT_SOURCE_DIR}/tools/brand/icns.py)
    add_test(NAME icns_self_test COMMAND ${Python3_EXECUTABLE} -I ${CMAKE_CURRENT_SOURCE_DIR}/tools/brand/icns.py --self-test)
    add_test(NAME macos_api COMMAND ${Python3_EXECUTABLE} -I ${CMAKE_CURRENT_SOURCE_DIR}/tools/dev/check_macos_api.py)
    add_test(NAME macos_api_self_test COMMAND ${Python3_EXECUTABLE} -I ${CMAKE_CURRENT_SOURCE_DIR}/tools/dev/check_macos_api.py --self-test)
    # website/brushes.html #packs matches src/core/BrushPacks.cpp: every brush, its preview and the guide links.
    add_test(NAME website_brush_packs COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/brush-packs/sync_website.py --check)
    # Every interface label has a Spanish, a Traditional and a Simplified Chinese translation (or is a name kept in English,
    # tools/i18n/keep_english.txt): a new label without one fails here, not in a release.
    add_test(NAME i18n_coverage COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/i18n/coverage.py --check)
    # ...and no label reaches ImGui without tr() unless tools/i18n/raw_allow.txt lists it (names that stay English, and
    # the 11-06 backlog, which only shrinks): coverage can't see a label that never goes through tr().
    add_test(NAME i18n_raw_labels COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/i18n/coverage.py --raw-check)
    # The release's SBOM (tools/release/sbom.py, docs/guide/security.md): every fetched archive is a listed component.
    add_test(NAME sbom COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/release/sbom.py --check)
    add_test(NAME marks_self_test COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/check_marks.py --self-test)
    # Our email address stays off everything public (website/, docs/, README*): hello@ is a private support inbox.
    add_test(NAME public_email COMMAND ${Python3_EXECUTABLE} -I ${CMAKE_CURRENT_SOURCE_DIR}/tools/check_public_email.py
             ${CMAKE_CURRENT_SOURCE_DIR})
    add_test(NAME public_email_self_test COMMAND ${Python3_EXECUTABLE} -I ${CMAKE_CURRENT_SOURCE_DIR}/tools/check_public_email.py --self-test)
    # The same marks read off the pixels of every tracked image and video (OCR, cached by file hash), and the deploy's
    # takedown of flagged ones (tools/media_takedown.py). --cached-only reads it as CI does (no OCR there), so a new image
    # without its committed cache entry fails here too, not only in CI (0.11.12 staging).
    add_test(NAME marks_media COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/check_marks_media.py --cached-only
             WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
    # Without .git (the PC's shipped tree) both report "skipped", not "passed"; t0.sh runs marks locally first.
    set_tests_properties(marks marks_media PROPERTIES SKIP_RETURN_CODE 77)
    add_test(NAME marks_media_self_test COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/check_marks_media.py --self-test)
    add_test(NAME media_takedown_self_test COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/media_takedown.py --self-test)
    # The public gallery repository matches tools/brush-gallery/repo (the live compare is in release.sh: network).
    add_test(NAME gallery_published_self_test COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/brush-gallery/check_published.py --self-test)
    # Credited @handles are GitHub accounts (the live check is in release.sh's preflight: network).
    add_test(NAME credits_self_test COMMAND ${Python3_EXECUTABLE} -I ${CMAKE_CURRENT_SOURCE_DIR}/tools/release/check_credits.py --self-test)
    # The Claude Desktop bundle and its MCP registry entry (tools/release/build_mcpb.py, mcp_server_json.py): packed
    # from the built CLI and its server run from the unpacked bundle, as packages.yml does on every OS.
    add_test(NAME mcpb_self_test COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/release/build_mcpb.py --self-test)
    add_test(NAME reply_drafts_self_test COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/release/reply_drafts.py --self-test)
    add_test(NAME mcp_server_json_self_test COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/release/mcp_server_json.py --self-test)
    if(NOT CMAKE_CROSSCOMPILING)
      if(WIN32)
        set(SF_MCPB_PLATFORM win32)
      elseif(APPLE)
        set(SF_MCPB_PLATFORM darwin)
      else()
        set(SF_MCPB_PLATFORM linux)
      endif()
      add_test(NAME mcpb_bundle COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/release/build_mcpb.py
               --cli $<TARGET_FILE:sculptforge-cli> --version auto --platform ${SF_MCPB_PLATFORM}
               --out ${CMAKE_CURRENT_BINARY_DIR}/mcpb-test/SculptForge-test.mcpb)
    endif()
    add_test(NAME release_notes COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/release/assemble_notes.py --self-test)
    add_test(NAME release_notes_fragments COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/release/assemble_notes.py --check)
    # The members' publishing path stays locked down: release.yml's actions pinned to commit SHAs, INSIDERS_REPO_TOKEN only
    # in GitHub Environments, no pull_request_target (tools/release/check_workflows.py; release.sh check runs it too).
    add_test(NAME release_workflows COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/release/check_workflows.py)
    add_test(NAME release_workflows_self_test COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/release/check_workflows.py --self-test)
    # Every asset install/install.sh and install.ps1 download is one release.yml publishes (#159; release.sh checks
    # the real release's asset list too).
    add_test(NAME release_install_assets COMMAND ${Python3_EXECUTABLE} -I ${CMAKE_CURRENT_SOURCE_DIR}/tools/release/check_install_assets.py)
    add_test(NAME release_install_assets_self_test COMMAND ${Python3_EXECUTABLE} -I ${CMAKE_CURRENT_SOURCE_DIR}/tools/release/check_install_assets.py --self-test)
    add_test(NAME release_paperwork COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/release/paperwork_only.py --self-test)
    # Build once, promote: only a maintainer's push run on staging is promotable (staged_run.py), and every package must
    # match its recorded SHA-256 and attestation before publishing (verify_staged.py).
    add_test(NAME release_staged_run COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/release/staged_run.py --self-test)
    add_test(NAME release_verify_staged COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/release/verify_staged.py --self-test)
    # Step bump pins tests/ui/whats_new.sfui to the newest What's New sections (tools/release/pin_whats_new_test.py).
    add_test(NAME release_pin_whats_new COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/release/pin_whats_new_test.py --self-test)
    # scripts/merge-queue.sh refuses a merge or squash that throws away the other side's change (tools/ci/no_revert.py).
    add_test(NAME ci_no_revert COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/ci/no_revert.py --self-test)
    # A branch made from an old tree (a squash with reset --soft onto a moved origin/main) put older main files back (0.11.11).
    add_test(NAME stale_tree COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/ci/no_revert.py --stale origin/main HEAD WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
    # scripts/release.sh's beta (X.Y.Z-beta.N), its promotion to stable, and build once (--stage, then promote), in a
    # sandbox with stand-ins for gh and curl.
    if(UNIX AND NOT APPLE AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
      add_test(NAME release_script_beta COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/tests/release_beta_test.sh)
      set_tests_properties(release_script_beta PROPERTIES TIMEOUT 300)
    endif()
    # The Actions cache pruner keeps the newest cache of each kind (tools/ci/prune_caches.py).
    add_test(NAME ci_prune_caches COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/ci/prune_caches.py --self-test)
    add_test(NAME ci_slowest_tests COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/ci/slowest_tests.py --self-test)
    add_test(NAME test_impact COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/test/impacted.py --self-test)
    add_test(NAME test_run COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/test/run.py --self-test)
    add_test(NAME benchmark_submit COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/benchmark/submit.py selftest)
    # The upstream watch (tools/upstream-watch, .github/workflows/upstream-watch.yml) against recorded API responses.
    add_test(NAME upstream_watch COMMAND ${Python3_EXECUTABLE} -I ${CMAKE_CURRENT_SOURCE_DIR}/tests/upstream/test_upstream_watch.py)
    add_test(NAME guide_site COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/guide/build_site.py --check
                                     --out ${CMAKE_CURRENT_BINARY_DIR}/guide-site)
    # Menu paths in the guide name the SculptForge layout's task menus (Edit > Preferences, not Preferences).
    add_test(NAME guide_menu_paths COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/guide/menu_paths.py --check)
  endif()

  # The phone link's relay (services/link-worker, a Cloudflare Worker) under plain Node, when Node 20+ is installed.
  find_program(SCULPTFORGE_NODE node)
  if(SCULPTFORGE_NODE)
    add_test(NAME link_worker COMMAND ${SCULPTFORGE_NODE} --test test/relay.test.mjs
             WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/services/link-worker)
  endif()

  # UI tests: each tests/ui/*.sfui script drives the real app headless (needs an
  # OpenGL 3.3 context; CI runs them on Linux under Xvfb with Mesa). Label "ui".
  if(SCULPTFORGE_BUILD_APP)
    # Warm UI tests (tools/test/warm_ui.py): the fixture ui_warm starts a pool of `sculptforge --ui-serve` servers
    # (one window and GL context each, made once) and each ui_* script test is a thin client of it, with the same
    # output and exit code as a cold run. SF_UI_COLD=1 when running ctest runs them cold, as does
    # -DSCULPTFORGE_UI_WARM=OFF; a script with a `# cold` line always runs cold. Not yet on Windows (cold there).
    option(SCULPTFORGE_UI_WARM "Run UI test scripts in a pool of warm servers" ON)
    set(SF_UI_WARM_DIR ${CMAKE_CURRENT_BINARY_DIR}/ui-warm)
    if(SCULPTFORGE_UI_WARM AND Python3_Interpreter_FOUND AND NOT WIN32)
      sculptforge_runner(SF_UI_WARM_APP sculptforge)
      set(SF_UI_WARM_PY ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/test/warm_ui.py)
      add_test(NAME ui_warm_start COMMAND ${SF_UI_WARM_PY} start --dir ${SF_UI_WARM_DIR} --app ${SF_UI_WARM_APP})
      add_test(NAME ui_warm_stop COMMAND ${SF_UI_WARM_PY} stop --dir ${SF_UI_WARM_DIR})
      set_tests_properties(ui_warm_start PROPERTIES FIXTURES_SETUP ui_warm LABELS ui TIMEOUT 60)
      set_tests_properties(ui_warm_stop PROPERTIES FIXTURES_CLEANUP ui_warm LABELS ui TIMEOUT 400)
    endif()
    # sculptforge_ui_test(NAME SCRIPT [ARGS...]): ui_NAME runs tests/ui/SCRIPT.sfui, screenshots in ui-shots/NAME.
    function(sculptforge_ui_test name script)
      set(args --ui-test ${CMAKE_CURRENT_SOURCE_DIR}/tests/ui/${script}.sfui ${ARGN}
               --ui-out ${CMAKE_CURRENT_BINARY_DIR}/ui-shots/${name})
      if(TEST ui_warm_start)
        add_test(NAME ui_${name} COMMAND ${SF_UI_WARM_PY} client --dir ${SF_UI_WARM_DIR} --app ${SF_UI_WARM_APP} -- ${args})
        set_tests_properties(ui_${name} PROPERTIES FIXTURES_REQUIRED ui_warm)
      else()
        add_test(NAME ui_${name} COMMAND sculptforge ${args})
      endif()
      set_tests_properties(ui_${name} PROPERTIES LABELS ui TIMEOUT 300)
    endfunction()
    file(GLOB SCULPTFORGE_UI_TESTS CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tests/ui/*.sfui)
    foreach(script ${SCULPTFORGE_UI_TESTS})
      get_filename_component(name ${script} NAME_WE)
      sculptforge_ui_test(${name} ${name})
    endforeach()
    # Heavy-mesh and benchmark scripts (tests/perf/*.sfui, e.g. 33M-triangle precision): nightly only (T3).
    file(GLOB SCULPTFORGE_PERF_TESTS CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tests/perf/*.sfui)
    foreach(script ${SCULPTFORGE_PERF_TESTS})
      get_filename_component(name ${script} NAME_WE)
      add_test(NAME perf_${name} COMMAND sculptforge --ui-test ${script} --ui-out ${CMAKE_CURRENT_BINARY_DIR}/ui-shots/perf_${name})
      set_tests_properties(perf_${name} PROPERTIES LABELS "ui;nightly" TIMEOUT 3600 RUN_SERIAL TRUE)
    endforeach()
    # Splat training (also started by a phone scan) runs the fake Brush / COLMAP / ffmpeg.
    foreach(t ui_splat_train ui_phone_link)
      if(TEST ${t})
        set_tests_properties(${t} PROPERTIES ENVIRONMENT
          "SCULPTFORGE_BRUSH=$<TARGET_FILE:sf_fake_splat_tools>;SCULPTFORGE_COLMAP=$<TARGET_FILE:sf_fake_splat_tools>;SCULPTFORGE_FFMPEG=$<TARGET_FILE:sf_fake_splat_tools>")
      endif()
    endforeach()
    # Label no_d3d12: tests that the Windows PC's WSL GPU path (Mesa's OpenGL on D3D12, ~/Work/.sf/pc.sh) can't run and
    # pc.sh leaves out. ui_micro_levels: its first micro-displacement frame makes D3D12 remove the device (a segfault,
    # and every UI test running beside it loses its GL context); it passes on CI's llvmpipe and on the same PC's native
    # NVIDIA driver (2026-11-03, v0.10.11, 128 frames), so it is the translation layer, not SculptForge.
    if(TEST ui_micro_levels)
      set_tests_properties(ui_micro_levels PROPERTIES LABELS "ui;no_d3d12")
    endif()
    # The hardware profile panel with a real calibration (tests/ui/hardware_profile.sfui).
    if(TEST ui_hardware_profile)
      set_tests_properties(ui_hardware_profile PROPERTIES ENVIRONMENT "SF_HW_PROFILE_IN_TESTS=1")
    endif()
    # Hardware tiers: the first-run card, the tier chip, Turbo, the panel (tests/ui/hardware_tier.sfui).
    # Also at 2880 px wide, so the 200 % top bar has room for the chip and the bolt (the shots show them).
    sculptforge_ui_test(hardware_tier_2880 hardware_tier --size 2880x1620)
    if(TEST ui_hardware_tier)
      set_tests_properties(ui_hardware_tier ui_hardware_tier_2880 PROPERTIES ENVIRONMENT "SF_HW_PROFILE_IN_TESTS=1;SF_NO_CALIBRATION=1;SF_HW_SIMULATE=high")
    endif()
    # The shell layout again on a 1920x1080 window (docs/ui-design.md §2.3).
    # Studio mode: About shows the studio (tests/data/studio; core/StudioProfile.h).
    sculptforge_ui_test(studio_mode studio/studio_mode --studio ${CMAKE_CURRENT_SOURCE_DIR}/tests/data/studio/studio.json)
    sculptforge_ui_test(shell_layout_1080 shell_layout --size 1920x1080)
    sculptforge_ui_test(menu_stable_720 menu_stable --size 1280x720)
    sculptforge_ui_test(title_version_1440 title_version --size 1440x900)
    sculptforge_ui_test(title_version_1024 title_version --size 1024x768)
    sculptforge_ui_test(tablet_view_speed_1440 tablet_view_speed --size 1440x900)
    sculptforge_ui_test(tablet_view_speed_1024 tablet_view_speed --size 1024x768)
    # Tool > Geometry's groups at 1440 and 1024 px (tests/ui/geometry_groups.sfui, 100% and 200% inside;
    # tests/ui/narrow/geometry_groups.sfui at 1024: the drop-down palettes).
    sculptforge_ui_test(geometry_groups_1440 geometry_groups --size 1440x900)
    sculptforge_ui_test(geometry_groups_2880 geometry_groups --size 2880x1800) # its 200% shot: 1440 px of UI
    sculptforge_ui_test(geometry_groups_1024 narrow/geometry_groups --size 1024x768)
    sculptforge_ui_test(timeline_narrow_1024 timeline_narrow --size 1024x768)
    sculptforge_ui_test(extract_labels_1024 extract_labels --size 1024x768)
    sculptforge_ui_test(extract_labels_1440 extract_labels --size 1440x900)
    # The membership moments' card and the top bar's heart at 1440 and 1024 px (tests/ui/support/support_shots.sfui).
    sculptforge_ui_test(support_shots_1440 support/support_shots --size 1440x900)
    # Help > Support (the welcome screen) and the full membership card at 1440 px: the perk lines fit (100 % and 200 %).
    sculptforge_ui_test(support_1440 support --size 1440x900)
    sculptforge_ui_test(support_card_1440 support_card --size 1440x900)
    sculptforge_ui_test(support_shots_1024 support/support_shots --size 1024x768)
    sculptforge_ui_test(help_console_1080 help_console --size 1920x1080)
    # The S / U / I / O slider on a UI scaled 1.5x (Windows at 150%, #9): it must still open under the cursor.
    sculptforge_ui_test(size_popup_scaled size_popup --size 2400x1350)
    # The Parts / Geometry tools (foirgairwolf on Discord) at a laptop's and a small window's width: rows fit.
    sculptforge_ui_test(parts_split_selection_1440 parts_split_selection --size 1440x900)
    sculptforge_ui_test(mesh_check_1440 mesh_check --size 1440x900)
    sculptforge_ui_test(parts_tools_1024 sizes/parts_tools_1024 --size 1024x768) # (palettes are drop-downs there)
    # The stroke popup on a UI scaled 1.5x: it opens under the cursor and its items are where they're drawn.
    sculptforge_ui_test(stroke_popup_scaled stroke_popup --size 2400x1350)
    # Library single click (#142) on a UI scaled 1.5x: tiles still take one click.
    sculptforge_ui_test(library_click_scaled library_click --size 2400x1350)
    # UI scale (#87) at 1600x900, where Automatic in a test is exactly 100 %; label "dpi": release.sh step check runs them before the tag.
    sculptforge_ui_test(ui_scale_900 ui_scale --size 1600x900)
    set_tests_properties(ui_ui_scale_900 PROPERTIES LABELS "ui;dpi" TIMEOUT 300)
    if(TEST ui_ui_scale)
      set_tests_properties(ui_ui_scale PROPERTIES LABELS "ui;dpi")
    endif()
    # The UV Editor toolbar on a 4K screen (scales 1.0, 1.5 and 2.4): wrapped, nothing cut off, each control its own click.
    sculptforge_ui_test(uv_editor_scales_4k uv_editor_scales --size 3840x2160)
    # The Library on a 1280x720 screen (#80): its close button stays on screen.
    sculptforge_ui_test(library_small_screen_720 library_small_screen --size 1280x720)
    # Framing fits the model into the canvas the Library and the Sculpt Timeline leave free; the left shelf fits its
    # column (1080p at 100 / 150 / 200 %; tests/ui/hidpi/: only at that size).
    sculptforge_ui_test(frame_free_area_1080 hidpi/frame_free_area --size 1920x1080)
    # #107: every look's right tray on a 1280x720 screen; #105: a Windows laptop at 150-200 % (2560x1600 at 200 % is
    # 1280x800 logical px), nothing past the window's edges.
    sculptforge_ui_test(right_tray_looks_720 right_tray_looks --size 1280x720)
    sculptforge_ui_test(windows_dpi_2560 windows_dpi --size 2560x1600)
    sculptforge_ui_test(windows_dpi_2160 windows_dpi --size 2160x1350)
    # Part folders (#96) at 200 % on a 3200x1800 screen (tests/ui/hidpi/: scripts only run at their HiDPI size).
    sculptforge_ui_test(part_folders_hidpi hidpi/part_folders --size 3200x1800)
    # Trays and columns never scroll sideways at auto scale on a 1920x1200 screen (dm4nd on Discord).
    sculptforge_ui_test(tray_hscroll_hidpi hidpi/tray_hscroll --size 1920x1200)
    set_tests_properties(ui_right_tray_looks_720 ui_windows_dpi_2560 ui_windows_dpi_2160 PROPERTIES LABELS "ui;dpi" TIMEOUT 300)
    sculptforge_ui_test(user_guide_1080 user_guide --size 1920x1080)
    # The Deform panel for the look review (tests/ui/sizes/: scripts only run at their own sizes).
    sculptforge_ui_test(deform_panel_1440 sizes/deform_panel --size 1440x900)
    sculptforge_ui_test(deform_panel_1024 sizes/deform_panel_1024 --size 1024x768)
    sculptforge_ui_test(deform_panel_1024_200 sizes/deform_panel_1024 --size 2048x1536)
    # Cut with X symmetry and its caps, for the look review at 1440 px, 100 % and 200 % (tests/ui/sizes/cut_symmetry.sfui).
    sculptforge_ui_test(cut_symmetry_1440 sizes/cut_symmetry --size 1440x900)
    sculptforge_ui_test(cut_symmetry_1440_200 sizes/cut_symmetry --size 2880x1800)
    # A crash leaves a note in the log file (#16). Needs no window.
    add_test(NAME crash_log COMMAND ${CMAKE_COMMAND} -DAPP=$<TARGET_FILE:sculptforge>
             -DDIR=${CMAKE_CURRENT_BINARY_DIR}/crash-log-test -P ${CMAKE_CURRENT_SOURCE_DIR}/tests/crash_log.cmake)
    # Idle, the app draws nothing (#14) and uses next to no CPU: --measure-idle fails when it keeps drawing frames or
    # its process CPU is over SF_IDLE_CPU_MAX % of one core (4 s here: a spinning loop's 100 % fails it; the 30 s
    # nightly holds it to 2 %).
    add_test(NAME ui_idle_redraw COMMAND sculptforge --measure-idle 4)
    set_tests_properties(ui_idle_redraw PROPERTIES LABELS ui TIMEOUT 60 ENVIRONMENT "SF_NO_UPDATE_CHECK=1;SF_IDLE_CPU_MAX=10")
    add_test(NAME ui_idle_cpu_30s COMMAND sculptforge --measure-idle 30)
    set_tests_properties(ui_idle_cpu_30s PROPERTIES LABELS "ui;nightly" TIMEOUT 120 RUN_SERIAL TRUE ENVIRONMENT "SF_NO_UPDATE_CHECK=1")
    # sculptforge --calibrate on this machine's GPU: the JSON it prints passes the schema check (it exits 1 if not).
    add_test(NAME ui_calibrate_json COMMAND sculptforge --calibrate-quick --calibrate-no-save)
    set_tests_properties(ui_calibrate_json PROPERTIES LABELS ui TIMEOUT 60)
    # A fast stroke in the interactive loop (dabs queued, placed a few milliseconds a frame): every dab lands on the
    # pointer's circle (#19).
    add_test(NAME ui_stroke_path COMMAND sculptforge --run "new_sphere" --measure-stroke 1.5)
    set_tests_properties(ui_stroke_path PROPERTIES LABELS ui TIMEOUT 60 ENVIRONMENT "SF_NO_UPDATE_CHECK=1")
    # A benchmark take (--benchmark-script, src/app/BenchTake.cpp) on a sphere: played in real time, a CSV row per
    # frame with the strokes' lag, and a video as long as the take (within 5%).
    if(Python3_Interpreter_FOUND)
      add_test(NAME bench_take_sphere COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tests/takes/check_take.py
                                            $<TARGET_FILE:sculptforge> ${CMAKE_CURRENT_SOURCE_DIR}/tests/takes/sphere.sfui
                                            ${CMAKE_CURRENT_BINARY_DIR}/bench-take --min-seconds 5)
      set_tests_properties(bench_take_sphere PROPERTIES LABELS ui TIMEOUT 240 RUN_SERIAL TRUE)
    endif()
    # Background dabs (a heavy mesh's stroke on the solver thread, no preview), forced on a light sphere: replaying
    # the stroke in the frame loop gives the same mesh, bit for bit, and its undo the mesh it started from.
    add_test(NAME ui_stroke_background COMMAND sculptforge --run "new_sphere" --measure-stroke 1.5)
    set_tests_properties(ui_stroke_background PROPERTIES LABELS ui TIMEOUT 60
                         ENVIRONMENT "SF_NO_UPDATE_CHECK=1;SF_MEASURE_VERIFY=1;SF_BACKGROUND_DABS=1")
    # The same with Background Preview (experimental): the preview never changes the mesh and the frame no longer waits
    # for a batch; the stroke still replays bit for bit.
    add_test(NAME ui_stroke_background_preview COMMAND sculptforge --run "new_sphere" --measure-stroke 1.5)
    set_tests_properties(ui_stroke_background_preview PROPERTIES LABELS ui TIMEOUT 60
                         ENVIRONMENT "SF_NO_UPDATE_CHECK=1;SF_MEASURE_VERIFY=1;SF_BACKGROUND_DABS=1;SF_BG_GHOST=1")
    # And with the persistent upload (experimental, SF_PERSISTENT_UPLOAD): staging buffers instead of glBufferSubData.
    add_test(NAME ui_stroke_persistent_upload COMMAND sculptforge --run "new_sphere" --measure-stroke 1.5)
    set_tests_properties(ui_stroke_persistent_upload PROPERTIES LABELS ui TIMEOUT 60
                         ENVIRONMENT "SF_NO_UPDATE_CHECK=1;SF_MEASURE_VERIFY=1;SF_BACKGROUND_DABS=1;SF_BG_GHOST=1;SF_PERSISTENT_UPLOAD=1")
    # Predictive strokes with the brush size changing every frame mid-stroke: each batch of dabs keeps the size it
    # was handed (no data race with the solver thread), replaying the stroke without the thread gives the same
    # mesh, bit for bit, and its undo the mesh it started from.
    add_test(NAME ui_stroke_resize COMMAND sculptforge --run "new_sphere" --measure-stroke 1.5)
    set_tests_properties(ui_stroke_resize PROPERTIES LABELS ui TIMEOUT 60 DISABLED TRUE # predictive strokes: not yet identical in every run
                         ENVIRONMENT "SF_NO_UPDATE_CHECK=1;SF_MEASURE_RESIZE=1;SF_MEASURE_VERIFY=1;SF_PREDICTIVE_STROKE=1")
    # The system clipboard is one per desktop (one X server under CI's xvfb-run), and on X11 every SDL program asks a
    # new clipboard owner what it holds: a program that quits meanwhile makes the owner's answer fail (BadWindow).
    # Scripts that set, read or paste it (or click a Copy / Paste button) run alone under ctest -j.
    foreach(t ${SCULPTFORGE_UI_TESTS} shell_layout_1080 help_console_1080 size_popup_scaled stroke_popup_scaled user_guide_1080 ui_scale_900)
      string(REGEX REPLACE "_1080$|_scaled$|_900$" "" base ${t})
      get_filename_component(base ${base} NAME_WE)
      set(script ${CMAKE_CURRENT_SOURCE_DIR}/tests/ui/${base}.sfui)
      get_filename_component(name ${t} NAME_WE)
      if(EXISTS ${script} AND TEST ui_${name})
        file(READ ${script} body)
        if(body MATCHES "(^|\n)(clipboard|expect_clipboard) |\"[^\"\n]*(Copy|Paste)[^\"\n]*\"|ctrl\\+[cvx]")
          set_tests_properties(ui_${name} PROPERTIES RUN_SERIAL TRUE)
        endif()
      endif()
    endforeach()
    # The longest UI tests start first under ctest -j (COST orders a parallel run; without it they may start last).
    foreach(t ui_make_sculptable ui_texture_transfer ui_bake)
      if(TEST ${t})
        set_tests_properties(${t} PROPERTIES COST 500)
      endif()
    endforeach()
    # Timed measurements run alone when ctest runs tests in parallel (CI: ctest -j): other tests' load must not
    # change what they measure.
    foreach(t ui_idle_redraw ui_calibrate_json ui_stroke_path ui_hardware_profile)
      if(TEST ${t})
        set_tests_properties(${t} PROPERTIES RUN_SERIAL TRUE)
      endif()
    endforeach()
    # The guide's keyboard table must match the app's default shortcuts (tools/guide/update_shortcuts.py).
    if(Python3_Interpreter_FOUND)
      sculptforge_runner(SCULPTFORGE_APP_RUNNER sculptforge)
      add_test(NAME ui_guide_shortcuts COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/guide/update_shortcuts.py
               --app ${SCULPTFORGE_APP_RUNNER} --check)
      set_tests_properties(ui_guide_shortcuts PROPERTIES LABELS ui TIMEOUT 300)
    endif()
  endif()
endif()
# Every ctest entry has a time limit (11-07: a sculptforge_tests shard spun for 4.5 h on the PC, holding it): a hang
# fails as "Timeout" with the test's name. 300 s unless the test sets its own; the shards get 600 s (about 45 s each on
# the PC, so room for sanitizer and debug builds), and the shard's last "[ RUN] name" line names the hung test.
if(SCULPTFORGE_BUILD_TESTS)
  get_directory_property(sf_all_tests TESTS)
  foreach(t ${sf_all_tests})
    get_test_property(${t} TIMEOUT sf_timeout)
    if(NOT sf_timeout)
      if(t MATCHES "^sculptforge_tests_[0-9]+of")
        set_tests_properties(${t} PROPERTIES TIMEOUT 600)
      else()
        set_tests_properties(${t} PROPERTIES TIMEOUT 300)
      endif()
    endif()
  endforeach()
endif()