cmake_minimum_required(VERSION 3.16)
project(walkenv CXX)
if(APPLE)  # Objective-C++: the viewport recorder's AVFoundation encoder (editor/recorder_mac.mm) and the video decoder (engine/video/video_decoder_mac.mm, in every runner: VideoFrame)
  enable_language(OBJCXX)
  set(CMAKE_OBJCXX_STANDARD 17)
  set(CMAKE_OBJCXX_STANDARD_REQUIRED ON)
endif()

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if(EMSCRIPTEN)
  set(CMAKE_POSITION_INDEPENDENT_CODE OFF)  # one static WebAssembly module: nothing is ever relocated
endif()
if(NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE Release)
endif()

# The karasu pip package (pyproject.toml, scikit-build-core sets this): only the Python module (karasu._core, 3D inside it),
# no editor, runners, plugins or bundled PyTorch; the modules, templates and fonts installed into karasu/.
option(WALKENV_WHEEL "Build only the Python modules, as the karasu pip package" OFF)
if(WALKENV_WHEEL)
  foreach(off WALKENV_EDITOR WALKENV_DOCS_API WALKENV_PYTHON_ML WALKENV_AUDIO WALKENV_CAMERA WALKENV_SPEECH WALKENV_TTS WALKENV_PDFIUM)
    set(${off} OFF CACHE BOOL "" FORCE)
  endforeach()
endif()
# ccache, when it's installed (brew / apt / choco install ccache): a file compiled before with the same
# preprocessed source and flags comes out of the cache instead of clang, so a header edit that's reverted, a
# branch switch or a file another tool touched costs seconds, not a recompile. -DWALKENV_CCACHE=OFF skips it.
# (Not with Visual Studio: msbuild has no compiler launcher.)
option(WALKENV_CCACHE "Compile through ccache when it is installed" ON)
if(WALKENV_CCACHE AND NOT CMAKE_GENERATOR MATCHES "Visual Studio")
  find_program(WALKENV_CCACHE_PROGRAM ccache)
  if(WALKENV_CCACHE_PROGRAM)
    set(CMAKE_C_COMPILER_LAUNCHER "${WALKENV_CCACHE_PROGRAM}")
    set(CMAKE_CXX_COMPILER_LAUNCHER "${WALKENV_CCACHE_PROGRAM}")
    message(STATUS "Karasu Engine: compiling through ccache (${WALKENV_CCACHE_PROGRAM})")
  endif()
endif()

# Static C/C++ runtimes too, so Windows builds need no DLLs (MSVC: /MT; MinGW: -static).
set(CMAKE_POLICY_DEFAULT_CMP0091 NEW)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
# Sources are UTF-8: MSVC otherwise reads them in the system code page and, on e.g. a Japanese (932)
# Windows, a "×" in a string swallows its closing quote. (Not for .rc files: rc.exe has no /utf-8.)
if(MSVC)
  add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/utf-8>)
endif()
# Visual Studio generator: the build's job count becomes msbuild /m, that many *projects* at once, while each
# project still compiles its files one by one (30 minutes for a clean build). /MP compiles a project's files in
# parallel. The two multiply, so /MP is capped by RAM: one job per 4 GB, which with play_editor.bat's 4 projects
# stays within RAM at roughly 1 GB per heavy file. Passed to the audio and camera plugins too (cmake/audio.cmake,
# cmake/camera.cmake).
set(WALKENV_CL_JOBS "")
if(MSVC AND CMAKE_GENERATOR MATCHES "Visual Studio")
  set(WALKENV_MSVC_JOBS 0 CACHE STRING "Files each Visual Studio project compiles at once (/MP); 0 = from CPU cores and RAM")
  set(WALKENV_CL_JOBS ${WALKENV_MSVC_JOBS})
  if(WALKENV_CL_JOBS LESS 1)
    cmake_host_system_information(RESULT cores QUERY NUMBER_OF_LOGICAL_CORES)
    cmake_host_system_information(RESULT ram_mb QUERY TOTAL_PHYSICAL_MEMORY)
    math(EXPR WALKENV_CL_JOBS "(${ram_mb} + 2048) / 4096")
    if(cores LESS WALKENV_CL_JOBS)
      set(WALKENV_CL_JOBS ${cores})
    endif()
    if(WALKENV_CL_JOBS LESS 1)
      set(WALKENV_CL_JOBS 1)
    endif()
  endif()
  add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/MP${WALKENV_CL_JOBS}>)
  message(STATUS "Visual Studio: each project compiles ${WALKENV_CL_JOBS} files at once (/MP; -DWALKENV_MSVC_JOBS=N to change)")
endif()
if(MINGW)
  add_link_options(-static -static-libgcc -static-libstdc++ $<$<CONFIG:Release>:-s>)  # -s: strip symbols
endif()

# Executables straight into build/ for every configuration (Visual Studio would use build/Release/),
# next to build/fonts — so `build/walkenv_editor` works the same on every OS.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
foreach(config Debug Release RelWithDebInfo MinSizeRel)
  string(TOUPPER ${config} CONFIG)
  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${CONFIG} ${CMAKE_BINARY_DIR})
endforeach()

include(cmake/deps.cmake)

# Branding: window icon and menu bar / hub banners next to the executables; Windows .exe icon resource.
configure_file(branding/icon-256.png ${CMAKE_BINARY_DIR}/branding/icon-256.png COPYONLY)
configure_file(branding/app-icon-256.png ${CMAKE_BINARY_DIR}/branding/app-icon-256.png COPYONLY)
configure_file(branding/banner-64.png ${CMAKE_BINARY_DIR}/branding/banner-64.png COPYONLY)
configure_file(branding/banner-160.png ${CMAKE_BINARY_DIR}/branding/banner-160.png COPYONLY)
if(WIN32)
  enable_language(RC)
  set(WALKENV_ICO ${CMAKE_CURRENT_SOURCE_DIR}/branding/KarasuEngine.ico)
  # The manifest (branding/karasu.manifest): the process's code page is UTF-8, so the engine's UTF-8 paths work in
  # std::filesystem, fopen and sherpa-onnx. MSVC's linker writes a manifest and merges a .manifest source into it; MinGW
  # writes none, so icon.rc carries it (RT_MANIFEST, id 1). (An MSYS2 GCC that links its own default-manifest.o would
  # then have two; the cross-build here has none.)
  set(WALKENV_MANIFEST ${CMAKE_CURRENT_SOURCE_DIR}/branding/karasu.manifest)
  set(WALKENV_RC_MANIFEST "")
  if(NOT MSVC)
    set(WALKENV_RC_MANIFEST "1 24 \"${WALKENV_MANIFEST}\"")
  endif()
  configure_file(branding/icon.rc.in ${CMAKE_BINARY_DIR}/icon.rc @ONLY)
  set(WALKENV_ICON_RC ${CMAKE_BINARY_DIR}/icon.rc)  # (the icon and the manifest: every executable lists it)
  if(MSVC)
    list(APPEND WALKENV_ICON_RC ${WALKENV_MANIFEST})
  endif()
endif()

# Luau (vendored in third_party/luau, MIT licence)
add_subdirectory(third_party/luau)

# --- Engine: the shared core + one library per dimension (engine/dimension.h). Object libraries,
# so static registrations (REGISTER_GAME, DimensionModule::Registrar, method registrars) are never
# dropped. Each executable links the core and exactly the dimensions it needs: walkenv_run(_py) is
# 2D only, walkenv_run3d(_py) 3D only; the editor and the tools have both.
option(WALKENV_3D "Build 3D support (walkenv_run3d, 3D in the editor)" ON)
file(GLOB ENGINE_SRC CONFIGURE_DEPENDS engine/*.cpp engine/forms/*.cpp engine/luau/*.cpp engine/stats/*.cpp engine/llm/*.cpp engine/ui/*.cpp engine/audio/*.cpp engine/camera/*.cpp engine/speech/*.cpp engine/video/*.cpp)  # (audio/plugin/, camera/plugin/, speech/plugin/: cmake/audio.cmake, cmake/camera.cmake, cmake/speech.cmake)  # (python_rt/: cmake/python.cmake)
list(REMOVE_ITEM ENGINE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/engine/main.cpp ${CMAKE_CURRENT_SOURCE_DIR}/engine/launch.cpp ${CMAKE_CURRENT_SOURCE_DIR}/engine/tools_main.cpp)
# Summarize findings (engine/stats/stats_findings): the editor and the tools only, not the game runners.
set(FINDINGS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/engine/stats/stats_findings.cpp)
list(REMOVE_ITEM ENGINE_SRC ${FINDINGS_SRC})
set(BENCHMARK_TEST_SRC ${CMAKE_CURRENT_SOURCE_DIR}/engine/stats/stats_benchmark_test.cpp)  # (walkenv_tools --benchmark-selftest)
list(REMOVE_ITEM ENGINE_SRC ${BENCHMARK_TEST_SRC})
set(SPEECH_TEST_SRC ${CMAKE_CURRENT_SOURCE_DIR}/engine/speech/speech_selftest.cpp)  # (walkenv_tools --speech-selftest)
list(REMOVE_ITEM ENGINE_SRC ${SPEECH_TEST_SRC})
set(FORMS_TEST_SRC ${CMAKE_CURRENT_SOURCE_DIR}/engine/forms/form_selftest.cpp)  # (walkenv_tools --forms-selftest)
list(REMOVE_ITEM ENGINE_SRC ${FORMS_TEST_SRC})
set(VIDEO_TEST_SRC ${CMAKE_CURRENT_SOURCE_DIR}/engine/video/video_selftest.cpp)  # (walkenv_tools --video-selftest)
list(REMOVE_ITEM ENGINE_SRC ${VIDEO_TEST_SRC})
# Newer PyTorch / numpy versions (engine/ml_install.h): the editor and the tools only, not the game runners
set(ML_INSTALL_SRC ${CMAKE_CURRENT_SOURCE_DIR}/engine/ml_install.cpp)
set(ML_INSTALL_TEST_SRC ${CMAKE_CURRENT_SOURCE_DIR}/engine/ml_install_selftest.cpp)  # (walkenv_tools --ml-selftest)
list(REMOVE_ITEM ENGINE_SRC ${ML_INSTALL_SRC} ${ML_INSTALL_TEST_SRC})
file(GLOB GAME_SRC CONFIGURE_DEPENDS games/*/*.cpp)  # native C++ games (2D)

# The engine's version: env/VERSION.txt (one line, set by /karasu-release) -> generated/karasu_version.h, read by
# engine/version.cpp alone (karasu::version()). The editor shows it in the status bar and Engine Settings > Info.
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/VERSION.txt KARASU_VERSION LIMIT_COUNT 1)
string(STRIP "${KARASU_VERSION}" KARASU_VERSION)
if(NOT KARASU_VERSION MATCHES "^[0-9]+\\.[0-9]+\\.[0-9]+$")
  message(FATAL_ERROR "env/VERSION.txt must hold one version like 0.2.0, found: '${KARASU_VERSION}'")
endif()
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS VERSION.txt)
configure_file(cmake/karasu_version.h.in ${CMAKE_CURRENT_BINARY_DIR}/generated/karasu_version.h @ONLY)
set_source_files_properties(engine/version.cpp PROPERTIES INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}/generated)
# The PyTorch / numpy versions the editor offers (engine/ml_install.cpp; cmake/python.cmake bundles its "bundled" ones)
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/ml_versions.json ML_MANIFEST)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ml_versions.json)
configure_file(cmake/karasu_ml_versions.h.in ${CMAKE_CURRENT_BINARY_DIR}/generated/karasu_ml_versions.h @ONLY)
set_source_files_properties(engine/ml_install.cpp PROPERTIES INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}/generated)
add_library(walkenv_core OBJECT ${ENGINE_SRC})
include(cmake/tts.cmake)  # text to speech: sherpa-onnx's prebuilt libraries beside the executables (engine/speech/tts_plugin.cpp loads them)
if(WALKENV_TTS_INCLUDE)
  target_include_directories(walkenv_core PRIVATE ${WALKENV_TTS_INCLUDE})
  target_compile_definitions(walkenv_core PRIVATE WALKENV_TTS=1)
endif()
target_include_directories(walkenv_core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/engine)
target_link_libraries(walkenv_core PUBLIC walkenv_sdl nlohmann_json::nlohmann_json luau)
if(MSVC)  # windows.h's min / max macros break std::min / std::max. Only MSVC shows it: the MinGW cross-build never fails
  target_compile_definitions(walkenv_core PUBLIC NOMINMAX)
endif()
# Game UI fonts (engine/ui/ui_font.cpp): next to the executable (build/fonts, packaged apps, exported
# games), else straight from the source tree (a runner built without the editor).
target_compile_definitions(walkenv_core PRIVATE WALKENV_SOURCE_FONTS="${CMAKE_CURRENT_SOURCE_DIR}/third_party/fonts")
# VideoFrame (engine/video/): the system's own video decoder, so the engine ships no codecs. macOS: AVFoundation, linked
# (about 2 ms more per process start, measured). Windows: Media Foundation, whose DLLs are loaded at the first video
# (Windows N editions lack them): only its GUIDs (mfuuid, a static library) are linked. Elsewhere none (video_decoder_none.cpp).
if(APPLE AND NOT EMSCRIPTEN)
  target_sources(walkenv_core PRIVATE engine/video/video_decoder_mac.mm)
  set_source_files_properties(engine/video/video_decoder_mac.mm PROPERTIES COMPILE_OPTIONS "-fobjc-arc")
  target_link_libraries(walkenv_core PUBLIC "-framework AVFoundation" "-framework CoreMedia" "-framework CoreVideo" "-framework Foundation")
elseif(WIN32)
  target_link_libraries(walkenv_core PUBLIC mfuuid ole32)
endif()

file(GLOB ENGINE_2D_SRC CONFIGURE_DEPENDS engine/2d/*.cpp)
list(FILTER ENGINE_2D_SRC EXCLUDE REGEX "/py_[^/]*\\.cpp$")  # Python bindings: walkenv_pyrt2d (cmake/python.cmake)
add_library(walkenv_2d OBJECT ${ENGINE_2D_SRC} ${GAME_SRC})
target_include_directories(walkenv_2d PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/engine/2d)
target_link_libraries(walkenv_2d PUBLIC walkenv_core tinyxml2::tinyxml2 box2d::box2d)

if(EMSCRIPTEN)  # the browser build (cmake/emscripten.cmake) is the 2D Luau runner and nothing else
  include(cmake/web.cmake)
  return()
endif()

if(WALKENV_3D)
  include(cmake/deps3d.cmake)
  file(GLOB ENGINE_3D_SRC CONFIGURE_DEPENDS engine/3d/*.cpp)
  list(FILTER ENGINE_3D_SRC EXCLUDE REGEX "/py_[^/]*\\.cpp$")
  add_library(walkenv_3d OBJECT ${ENGINE_3D_SRC})
  target_include_directories(walkenv_3d PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/engine/3d)
  target_link_libraries(walkenv_3d PUBLIC walkenv_core walkenv_deps3d)
endif()

# LLM requests (engine/llm/) over HTTPS with the OS's own client: WinHTTP on Windows, libcurl elsewhere
# (part of macOS; libcurl-dev on Linux). Without one, LLM requests fail with a clear error.
if(WIN32)
  target_link_libraries(walkenv_core PUBLIC winhttp)
else()
  find_package(CURL)
  if(CURL_FOUND)
    target_link_libraries(walkenv_core PUBLIC CURL::libcurl)
    target_compile_definitions(walkenv_core PRIVATE WALKENV_HAS_CURL)
  endif()
endif()

include(cmake/python.cmake)
include(cmake/luau_torch.cmake)
include(cmake/audio.cmake)
include(cmake/camera.cmake)
include(cmake/video.cmake)  # Linux: VideoFrame through FFmpeg (the system's, else a bundled one)
include(cmake/speech.cmake)
include(cmake/pdfium.cmake)  # the Library's PDF reader (editor only)

# Dear ImGui: the editor's UI, and the forms a game shows in a desktop window (engine/forms/ui/: the runners draw them with it).
if(NOT TARGET imgui)
  add_subdirectory(third_party/imgui)
endif()
add_library(walkenv_forms_ui OBJECT engine/forms/ui/form_imgui.cpp)  # (the runners link it with imgui_runtime, the editor with its imgui)
target_link_libraries(walkenv_forms_ui PUBLIC walkenv_core)
target_include_directories(walkenv_forms_ui PRIVATE third_party/imgui third_party/imgui/backends)
target_compile_definitions(walkenv_forms_ui PRIVATE IMGUI_USE_WCHAR32)

if(NOT WALKENV_WHEEL)  # (the pip package: none of the executables below)
# --- Standalone runners (window, keyboard). walkenv_run: 2D, Luau only, no Python inside;
# walkenv_run_py: + embedded Python. walkenv_run3d / walkenv_run3d_py: the same for 3D projects.
# The editor's Build picks the one the game needs (dimension::runnerName).
function(walkenv_add_runner name dims python)
  add_executable(${name} WIN32 engine/main.cpp engine/launch.cpp ${WALKENV_ICON_RC})  # WIN32: no console window
  target_link_libraries(${name} PRIVATE walkenv_core walkenv_forms_ui imgui_runtime)
  foreach(d ${dims})
    target_link_libraries(${name} PRIVATE walkenv_${d})
  endforeach()
  if(python)
    walkenv_use_python(${name} "${dims}")
  endif()
  if(CMAKE_BUILD_TYPE STREQUAL "Release")  # 2D stays free of 3D code (and the other way round), sizes stay put
    add_custom_command(TARGET ${name} POST_BUILD
      COMMAND ${CMAKE_COMMAND} -DRUNNER=$<TARGET_FILE:${name}> -DDIMENSION=${dims} -DSYSTEM=${CMAKE_SYSTEM_NAME} -DSIZES=${CMAKE_CURRENT_SOURCE_DIR}/cmake/runner_sizes.cmake
              -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/check_runner.cmake VERBATIM)
  endif()
endfunction()
walkenv_add_runner(walkenv_run 2d OFF)
if(WALKENV_PYTHON_SCRIPTS)
  walkenv_add_runner(walkenv_run_py 2d ON)
endif()
if(WALKENV_3D)
  walkenv_add_runner(walkenv_run3d 3d OFF)
  if(WALKENV_PYTHON_SCRIPTS)
    walkenv_add_runner(walkenv_run3d_py 3d ON)
  endif()
endif()

# The study host (WEB_PLAN.md, engine/host/): serves a Web export to participants' browsers and stores what their runs write.
# Its own library with no engine in it, used by the editor's Study window and by walkenv_host, which goes beside a Web export.
add_library(walkenv_host_lib STATIC engine/host/study_host.cpp engine/host/study_setup.cpp engine/host/web_export.cpp)
target_include_directories(walkenv_host_lib PUBLIC engine/host PRIVATE third_party/httplib)
target_link_libraries(walkenv_host_lib PUBLIC nlohmann_json::nlohmann_json)
find_package(Threads REQUIRED)
target_link_libraries(walkenv_host_lib PUBLIC Threads::Threads)
if(WIN32)
  target_link_libraries(walkenv_host_lib PUBLIC ws2_32)
endif()
# Its window (engine/host/host_window.cpp, a double-click opens it) draws the editor's own Study widgets (editor/study_panel.cpp)
# in the editor's theme, with the runners' ImGui. A console program still: it hosts from a terminal too, and hides the console
# Windows opens for a double-click.
add_executable(walkenv_host engine/host/host_main.cpp engine/host/study_host_test.cpp engine/host/host_window.cpp
               editor/study_panel.cpp editor/theme_colors.cpp editor/theme_presets.cpp editor/qr.cpp editor/child_process.cpp ${WALKENV_ICON_RC})
target_include_directories(walkenv_host PRIVATE third_party/httplib ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/editor)
target_link_libraries(walkenv_host PRIVATE walkenv_host_lib walkenv_core imgui_runtime)  # (the core: llm::chat, for a study that lets the game call LLMs)

# Build tools (console): API reference and editor types for every dimension.
#   walkenv_tools --dump-api api.json · --luau-types 2d|3d out.d.luau · --python-stub 2d|3d out.pyi
add_executable(walkenv_tools engine/tools_main.cpp editor/component_fields.cpp editor/runs_estimate.cpp editor/runs_estimate_test.cpp editor/runs_resume_test.cpp editor/runs_repeat_test.cpp editor/runs_torch_compiler_test.cpp editor/runs_hold_test.cpp editor/runs_steps.cpp editor/child_process.cpp ${FINDINGS_SRC} ${BENCHMARK_TEST_SRC} ${SPEECH_TEST_SRC} ${FORMS_TEST_SRC} ${VIDEO_TEST_SRC} ${ML_INSTALL_SRC} ${ML_INSTALL_TEST_SRC} ${WALKENV_ICON_RC})  # (component_fields: --fields; runs_estimate: --estimate-selftest; runs_resume_test, child_process: --resume-selftest; runs_repeat_test: --repeat-selftest; runs_torch_compiler_test: --torch-compiler-selftest; runs_hold_test, runs_steps: --llm-hold-selftest)
target_include_directories(walkenv_tools PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_definitions(walkenv_tools PRIVATE WALKENV_SPEECH_TESTDATA="${CMAKE_CURRENT_SOURCE_DIR}/engine/speech/testdata")  # --speech-selftest's clip
target_compile_definitions(walkenv_tools PRIVATE WALKENV_VIDEO_TESTDATA="${CMAKE_CURRENT_SOURCE_DIR}/engine/video/testdata")  # --video-selftest's video
if(TARGET walkenv_torch)  # the Luau types of torch come from the plugin: a new plugin re-runs the types step below
  add_dependencies(walkenv_tools walkenv_torch)
  set_target_properties(walkenv_tools PROPERTIES LINK_DEPENDS $<TARGET_FILE:walkenv_torch>)
  # The torch Luau types, saved next to the plugin: the editor reads them instead of loading libtorch (luau_torch.cpp)
  add_custom_command(TARGET walkenv_tools POST_BUILD COMMAND $<TARGET_FILE:walkenv_tools> --torch-types VERBATIM)
endif()
target_link_libraries(walkenv_tools PRIVATE walkenv_core walkenv_2d)
if(WALKENV_3D)
  target_link_libraries(walkenv_tools PRIVATE walkenv_3d)
endif()
# Docs and editor types stay in sync with the engine: after every build of the tools, dump the API and
# update docs-site/public/api.json when it changed (a running ./docs rebuilds + reloads).
option(WALKENV_DOCS_API "Refresh docs-site/public/api.json and env/types after each build" ON)
if(WALKENV_DOCS_API AND NOT CMAKE_CROSSCOMPILING AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/docs-site)
  add_custom_command(TARGET walkenv_tools POST_BUILD
    COMMAND $<TARGET_FILE:walkenv_tools> --check-shared
    COMMAND $<TARGET_FILE:walkenv_tools> --dump-api ${CMAKE_BINARY_DIR}/api.json
    COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_BINARY_DIR}/api.json ${CMAKE_CURRENT_SOURCE_DIR}/docs-site/public/api.json
    # WORKING_DIRECTORY: without one, the Visual Studio generator runs the tools by bare file name, which cmd.exe
    # can't find when NoDefaultCurrentDirectoryInExePath is set; with one it uses the full path.
    WORKING_DIRECTORY $<TARGET_FILE_DIR:walkenv_tools>
    COMMENT "Updating the docs API (docs-site/public/api.json)" VERBATIM)
  # Then the docs site itself (docs-site/dist), when the API or a guide is newer than its last build: what the editor's
  # File › Open docs serves and the packaged editor carries, so they never lag the engine (open pages reload by themselves).
  # docs-site/scripts/build-if-stale.mjs: skipped while ./docs runs (it rebuilds by itself) or without Node.js / the site's
  # packages; a site that fails to build keeps its last version and the build says why, without failing.
  find_program(WALKENV_NODE node)
  if(WALKENV_NODE)
    add_custom_target(docs_site ALL
      COMMAND ${WALKENV_NODE} scripts/build-if-stale.mjs
      WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/docs-site VERBATIM)
    add_dependencies(docs_site walkenv_tools)  # (after api.json is refreshed)
  else()
    message(STATUS "Karasu Engine: no Node.js, so builds don't refresh the docs site (docs-site/dist)")
  endif()
  # The editor types (types/2d, types/3d: VS Code autocomplete), each time the tools or a runner change:
  # checked against what scripts can really reach, and validated before they replace the old ones
  # (cmake/editor_types.cmake). The VS Code extension notices the new files and reloads them.
  set(type_stamps)
  set(dims 2d)
  if(WALKENV_3D)
    list(APPEND dims 3d)
  endif()
  foreach(d ${dims})
    set(runner walkenv_run)
    if(d STREQUAL "3d")
      set(runner walkenv_run3d)
    endif()
    if(WALKENV_PYTHON_SCRIPTS)
      set(runner ${runner}_py)  # (lists the Python globals too)
    endif()
    add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/types_${d}.stamp
      COMMAND ${CMAKE_COMMAND} -DTOOLS=$<TARGET_FILE:walkenv_tools> -DRUNNER=$<TARGET_FILE:${runner}> -DDIM=${d}
              -DTEMPLATE=${CMAKE_CURRENT_SOURCE_DIR}/templates/${d}/empty -DOUT=${CMAKE_BINARY_DIR}
              -DTYPES=${CMAKE_CURRENT_SOURCE_DIR}/types/${d} -DSTAMP=${CMAKE_BINARY_DIR}/types_${d}.stamp
              -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/editor_types.cmake
      DEPENDS walkenv_tools ${runner} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/editor_types.cmake
      COMMENT "Updating the editor types (types/${d})" VERBATIM)
    list(APPEND type_stamps ${CMAKE_BINARY_DIR}/types_${d}.stamp)
  endforeach()
  add_custom_target(editor_types ALL DEPENDS ${type_stamps})
endif()
endif()  # NOT WALKENV_WHEEL

# --- Python module ----------------------------------------------------------
# Built when Python + pybind11 are found (pip install pybind11); skipped otherwise.
option(WALKENV_PYTHON "Build the Python module" ON)
if(WALKENV_PYTHON)
  find_package(Python 3.9 COMPONENTS Interpreter Development.Module)
  if(Python_FOUND)
    execute_process(COMMAND ${Python_EXECUTABLE} -m pybind11 --cmakedir
                    OUTPUT_VARIABLE pybind11_DIR OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
    find_package(pybind11 CONFIG QUIET)
    if(NOT pybind11_FOUND AND pybind11_SOURCE_DIR)  # no pip pybind11: the copy the Python runtime fetched
      add_subdirectory(${pybind11_SOURCE_DIR} ${CMAKE_BINARY_DIR}/pybind11-module EXCLUDE_FROM_ALL)
      set(pybind11_FOUND TRUE)
    endif()
  endif()
  if(pybind11_FOUND)
    # walkenv.stats / walkenv3d.stats: python/walkenv_stats.py, embedded (it's also usable as a plain file)
    file(READ ${CMAKE_CURRENT_SOURCE_DIR}/python/walkenv_stats.py WALKENV_STATS_PY)
    string(LENGTH "${WALKENV_STATS_PY}" stats_len)
    set(stats_chunks "")
    foreach(at RANGE 0 ${stats_len} 8000)  # pieces under MSVC's string literal limit
      string(SUBSTRING "${WALKENV_STATS_PY}" ${at} 8000 piece)
      string(APPEND stats_chunks "R\"PYSRC(${piece})PYSRC\"\n")
    endforeach()
    file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/generated/walkenv_stats_py.h
         "#pragma once\n// Generated from python/walkenv_stats.py (CMakeLists.txt): the walkenv.stats module's source.\n"
         "static const char* kWalkenvStatsPy =\n${stats_chunks};\n")
    set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS python/walkenv_stats.py)
    # walkenv.library / walkenv3d.library: python/walkenv_library.py, embedded the same way (a project's Library, read-only)
    file(READ ${CMAKE_CURRENT_SOURCE_DIR}/python/walkenv_library.py WALKENV_LIBRARY_PY)
    string(LENGTH "${WALKENV_LIBRARY_PY}" library_len)
    set(library_chunks "")
    foreach(at RANGE 0 ${library_len} 8000)
      string(SUBSTRING "${WALKENV_LIBRARY_PY}" ${at} 8000 piece)
      string(APPEND library_chunks "R\"PYSRC(${piece})PYSRC\"\n")
    endforeach()
    file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/generated/walkenv_library_py.h
         "#pragma once\n// Generated from python/walkenv_library.py (CMakeLists.txt): the walkenv.library module's source.\n"
         "static const char* kWalkenvLibraryPy =\n${library_chunks};\n")
    set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS python/walkenv_library.py)
    pybind11_add_module(walkenv python/env.cpp python/vec_env.cpp python/bindings.cpp)
    target_include_directories(walkenv PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/generated)
    target_link_libraries(walkenv PRIVATE walkenv_core walkenv_2d)
    # Python game scripts in walkenv.VecEnv / Env: the script runtime (engine/python_rt + the 2D bindings), built again
    # against the importing Python, whose interpreter runs them (WALKENV_PYTHON_HOSTED: py_install.h installHosted).
    if(WALKENV_PYTHON_SCRIPTS AND PYRT_SRC)
      file(GLOB pyrt_hosted_2d CONFIGURE_DEPENDS engine/2d/py_*.cpp)
      add_library(walkenv_pyrt_hosted OBJECT ${PYRT_SRC} ${pyrt_hosted_2d})
      target_include_directories(walkenv_pyrt_hosted PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/generated)
      target_link_libraries(walkenv_pyrt_hosted PUBLIC pybind11::module walkenv_core walkenv_2d)
      target_compile_definitions(walkenv_pyrt_hosted PUBLIC WALKENV_HAS_PYTHON=1 WALKENV_PYTHON_HOSTED=1
                                 PRIVATE WALKENV_PYTHON_HOME="${WALKENV_PYTHON_HOME}")
      set_target_properties(walkenv_pyrt_hosted PROPERTIES CXX_VISIBILITY_PRESET hidden)
      target_link_libraries(walkenv PRIVATE walkenv_pyrt_hosted)
    endif()
    if(WALKENV_3D)  # 3D projects: walkenv3d (rgb, depth, segmentation)
      pybind11_add_module(walkenv3d python/env3d.cpp)
      target_include_directories(walkenv3d PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/generated)
      target_link_libraries(walkenv3d PRIVATE walkenv_core walkenv_3d)
    endif()
    if(WALKENV_WHEEL)  # the pip package: karasu/_core*.so beside python/karasu/*.py (pyproject.toml). Component karasu: the
      # dependencies' own install rules (Box2D, Jolt, Recast, tinyxml2 headers and .a files) stay out of the wheel
      set_target_properties(walkenv PROPERTIES OUTPUT_NAME _core)
      target_compile_definitions(walkenv PRIVATE WALKENV_PY_MODULE=_core WALKENV_PY_FULLNAME="karasu._core")
      install(TARGETS walkenv LIBRARY DESTINATION karasu COMPONENT karasu RUNTIME DESTINATION karasu COMPONENT karasu)
      if(WALKENV_3D)  # 3D inside the same module (karasu._core._3d: one copy of SDL; python/env3d.cpp)
        target_sources(walkenv PRIVATE python/env3d.cpp)
        target_link_libraries(walkenv PRIVATE walkenv_3d)
        target_compile_definitions(walkenv PRIVATE WALKENV_PY3D_SUBMODULE=1)
        set_target_properties(walkenv3d PROPERTIES EXCLUDE_FROM_ALL ON)
      endif()
      install(DIRECTORY templates/ DESTINATION karasu/templates COMPONENT karasu)  # (karasu new)
      install(DIRECTORY third_party/fonts/ DESTINATION karasu/fonts COMPONENT karasu FILES_MATCHING PATTERN "*.ttf" PATTERN "*.otf" PATTERN "LICENSE-*")
    endif()
  else()
    message(STATUS "walkenv: Python module skipped (Python or pybind11 not found)")
  endif()
endif()

# --- Editor (Dear ImGui) ------------------------------------------------------
option(WALKENV_EDITOR "Build the editor" ON)
if(WALKENV_EDITOR)
  if(NOT TARGET imgui)
    add_subdirectory(third_party/imgui)
  endif()
  add_subdirectory(third_party/implot)
  file(GLOB EDITOR_SRC CONFIGURE_DEPENDS editor/*.cpp editor/mcp/*.cpp)  # mcp/: the MCP server (editor/mcp/mcp.h)
  list(REMOVE_ITEM EDITOR_SRC ${CMAKE_CURRENT_SOURCE_DIR}/editor/runs_estimate_test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/editor/runs_resume_test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/editor/runs_repeat_test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/editor/runs_torch_compiler_test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/editor/runs_hold_test.cpp)  # (walkenv_tools --estimate-selftest, --resume-selftest, --repeat-selftest, --llm-hold-selftest)
  # What's new: this version's announcement (changelog/releases/vX.Y.Z/WHATSNEW.md, written by /karasu-release), compiled
  # into the editor, which shows it the first time this version opens (editor/whats_new.cpp). None: an empty string.
  set(KARASU_WHATSNEW_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../changelog/releases/v${KARASU_VERSION}/WHATSNEW.md)
  set(KARASU_WHATSNEW "")
  if(EXISTS ${KARASU_WHATSNEW_FILE})
    file(READ ${KARASU_WHATSNEW_FILE} KARASU_WHATSNEW)
    string(STRIP "${KARASU_WHATSNEW}" KARASU_WHATSNEW)
    set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${KARASU_WHATSNEW_FILE})
  endif()
  configure_file(cmake/karasu_whatsnew.h.in ${CMAKE_CURRENT_BINARY_DIR}/generated/karasu_whatsnew.h @ONLY)
  set_source_files_properties(editor/whats_new.cpp PROPERTIES INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}/generated)
  add_executable(walkenv_editor WIN32 ${EDITOR_SRC} ${FINDINGS_SRC} ${ML_INSTALL_SRC} ${WALKENV_ICON_RC})
  target_link_libraries(walkenv_editor PRIVATE walkenv_core walkenv_2d imgui implot walkenv_host_lib walkenv_forms_ui)
  add_dependencies(walkenv_editor walkenv_host)  # (the packaged editor carries it: Web exports copy it beside the game)
  # Updates (editor/updates.h): karasu_updater swaps a downloaded release in after the editor quits (engine/updater/). A
  # release build (CI: -DWALKENV_RELEASE_BUILD=ON) compares itself with GitHub's latest release; any other build follows its
  # git checkout and rebuilds through watch_build.py, with this build folder and this cmake.
  option(WALKENV_RELEASE_BUILD "The editor is a published release: it updates from GitHub's releases (CI sets it)" OFF)
  add_executable(karasu_updater WIN32 engine/updater/updater_main.cpp)
  if(WIN32)
    target_link_libraries(karasu_updater PRIVATE shell32)  # CommandLineToArgvW
  endif()
  add_dependencies(walkenv_editor karasu_updater)
  target_compile_definitions(walkenv_editor PRIVATE WALKENV_BINARY_DIR="${CMAKE_BINARY_DIR}" WALKENV_CMAKE_COMMAND="${CMAKE_COMMAND}"
                             $<$<BOOL:${WALKENV_RELEASE_BUILD}>:WALKENV_RELEASE_BUILD=1>)
  if(TARGET docs_site)
    add_dependencies(walkenv_editor docs_site)  # (packaging copies docs-site/dist: after it is rebuilt, never during)
  endif()
  include(cmake/skills.cmake)  # the agent skills: embedded (skills/general) and synced to .claude / .agents
  target_include_directories(walkenv_editor PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/generated)
  # miniz (MIT, third_party/miniz): reading and writing the Stats window's .stats.zip packages (editor only)
  enable_language(C)
  target_sources(walkenv_editor PRIVATE third_party/miniz/miniz.c)
  target_include_directories(walkenv_editor PRIVATE third_party/miniz)
  target_compile_definitions(walkenv_editor PRIVATE MINIZ_NO_ZLIB_COMPATIBLE_NAMES)
  set_source_files_properties(third_party/miniz/miniz.c PROPERTIES COMPILE_OPTIONS "-w")
  # libbzip2 1.0.8 (BSD-style, third_party/bzip2): unpacking text-to-speech voices (.tar.bz2) without a system tar, which
  # Windows 10 can't do (editor/tar_bz2.cpp). BZ_NO_STDIO: only the stream functions, no FILE* ones.
  set(BZIP2_SRC blocksort huffman crctable randtable compress decompress bzlib)
  list(TRANSFORM BZIP2_SRC PREPEND third_party/bzip2/)
  list(TRANSFORM BZIP2_SRC APPEND .c)
  target_sources(walkenv_editor PRIVATE ${BZIP2_SRC})
  target_include_directories(walkenv_editor PRIVATE third_party/bzip2)
  target_compile_definitions(walkenv_editor PRIVATE BZ_NO_STDIO)
  set_source_files_properties(${BZIP2_SRC} PROPERTIES COMPILE_OPTIONS "-w")
  if(WALKENV_3D)
    target_link_libraries(walkenv_editor PRIVATE walkenv_3d)
    add_dependencies(walkenv_editor walkenv_run3d)
    # ImGuizmo (MIT, third_party/imguizmo): the 3D viewport's move / rotate / scale handles
    target_sources(walkenv_editor PRIVATE third_party/imguizmo/ImGuizmo.cpp)
    target_include_directories(walkenv_editor PRIVATE third_party/imguizmo)
    set_source_files_properties(third_party/imguizmo/ImGuizmo.cpp PROPERTIES COMPILE_OPTIONS "-w")
    target_compile_definitions(walkenv_editor PRIVATE WALKENV_HAS_3D=1)
  endif()
  target_include_directories(walkenv_editor PRIVATE editor third_party/httplib)  # cpp-httplib (MIT), header-only
  if(WIN32)
    target_link_libraries(walkenv_editor PRIVATE ws2_32 shell32 psapi shlwapi advapi32)  # the MCP server's sockets; the IDE icons; run processes' memory; default apps; the registry (Info: specs)
    target_link_libraries(walkenv_editor PRIVATE mfplat mfreadwrite mfuuid ole32)  # the viewport recorder's encoder: Media Foundation (editor/recorder_win.cpp)
  elseif(APPLE)
    # The viewport recorder's encoder: AVFoundation, in Objective-C++ (editor/recorder_mac.mm). The editor only: no runner links it.
    # (The core's video decoder links the same frameworks: engine/video/video_decoder_mac.mm.)
    target_sources(walkenv_editor PRIVATE editor/recorder_mac.mm)
    set_source_files_properties(editor/recorder_mac.mm PROPERTIES COMPILE_OPTIONS "-fobjc-arc")
    target_link_libraries(walkenv_editor PRIVATE "-framework AVFoundation" "-framework CoreMedia" "-framework CoreVideo" "-framework Foundation")
    target_link_libraries(walkenv_editor PRIVATE "-framework CoreServices" "-framework IOKit")  # the default app for scripts (editor/default_app.cpp); the GPU name (engine_info.cpp)
  endif()
  target_compile_definitions(walkenv_editor PRIVATE WALKENV_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
  # The VS Code extension (vscode-extension/ → build/karasu.vsix); the editor installs it
  # into VS Code when you open a script, so autocomplete is always there (editor/vscode.cpp).
  file(READ vscode-extension/package.json vscode_pkg)
  string(JSON vscode_ext_version GET "${vscode_pkg}" version)
  target_compile_definitions(walkenv_editor PRIVATE WALKENV_VSCODE_EXT_VERSION="${vscode_ext_version}")
  set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS vscode-extension/package.json)
  add_custom_command(TARGET walkenv_editor POST_BUILD
    COMMAND ${CMAKE_COMMAND} -DSRC=${CMAKE_CURRENT_SOURCE_DIR}/vscode-extension -DTYPES=${CMAKE_CURRENT_SOURCE_DIR}/types
            -DOUT=${CMAKE_BINARY_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/package_vscode.cmake
    COMMENT "Packaging the VS Code extension (karasu.vsix)" VERBATIM)
  add_dependencies(walkenv_editor walkenv_run)  # Build (game export) copies the runner
  if(TARGET editor_types)
    add_dependencies(walkenv_editor editor_types)  # karasu.vsix carries env/types
  endif()
  foreach(plugin walkenv_audio_plugin walkenv_camera_plugin walkenv_speech_plugin walkenv_video)  # Play with audio / webcams / speech / video (Linux); exports copy them
    if(TARGET ${plugin})
      add_dependencies(walkenv_editor ${plugin})
    endif()
  endforeach()
  if(WALKENV_PYTHON_SCRIPTS)
    if(WALKENV_3D)
      walkenv_use_python(walkenv_editor "2d;3d")
      add_dependencies(walkenv_editor walkenv_run3d_py)
    else()
      walkenv_use_python(walkenv_editor "2d")
    endif()
    add_dependencies(walkenv_editor walkenv_run_py)
  endif()
  walkenv_use_pdfium(walkenv_editor)  # PDFium: the Library's PDF reader (after walkenv_use_python: both add rpaths)
  file(GLOB EDITOR_FONTS third_party/fonts/*.ttf third_party/fonts/*.otf third_party/fonts/LICENSE-*)  # (+ licences: builds carry them)
  foreach(font ${EDITOR_FONTS})
    get_filename_component(name ${font} NAME)
    configure_file(${font} ${CMAKE_BINARY_DIR}/fonts/${name} COPYONLY)
  endforeach()

  # Double-clickable editor, refreshed after every build (cmake/package_editor.cmake).
  # Default: the repository root (one level above env/). -DWALKENV_EDITOR_APP_DIR="" turns it off.
  get_filename_component(repo_root "${CMAKE_CURRENT_SOURCE_DIR}/.." ABSOLUTE)
  set(WALKENV_EDITOR_APP_DIR "${repo_root}" CACHE PATH "Where to put walkenv Editor(.app); empty = don't package")
  # macOS: sealing the .app (codesign over its 870 MB of Python) takes 15 s on an idle machine and minutes beside
  # a build, every time the editor links. A local development build doesn't need it: the executables carry the
  # linker's ad-hoc signature and the app opens. Keep it for builds that get zipped and downloaded (CI: without a
  # seal, Gatekeeper calls a downloaded app damaged) — -DWALKENV_SEAL_APP=ON, the default.
  option(WALKENV_SEAL_APP "macOS: codesign the packaged editor .app after each build (slow; needed only for a downloadable app)" ON)
  if(WALKENV_EDITOR_APP_DIR)
    set(torch_plugin_arg "")
    if(TARGET walkenv_torch)  # PyTorch for Luau rides along (cmake/luau_torch.cmake)
      add_dependencies(walkenv_editor walkenv_torch)
      set(torch_plugin_arg "-DTORCH_PLUGIN=$<TARGET_FILE:walkenv_torch>")
    endif()
    set(audio_plugin_arg "")
    if(TARGET walkenv_audio_plugin)  # audio rides along (cmake/audio.cmake)
      add_dependencies(walkenv_editor walkenv_audio_plugin)
      set(audio_plugin_arg "-DAUDIO_PLUGIN=${WALKENV_AUDIO_PLUGIN}")
    endif()
    if(TARGET walkenv_camera_plugin)
      list(APPEND audio_plugin_arg "-DCAMERA_PLUGIN=${WALKENV_CAMERA_PLUGIN}")
    endif()
    if(TARGET walkenv_speech_plugin)
      list(APPEND audio_plugin_arg "-DSPEECH_PLUGIN=${WALKENV_SPEECH_PLUGIN}")
    endif()
    if(TARGET walkenv_video)  # Linux: build/video/ (the FFmpeg video plugins and the bundled FFmpeg, cmake/video.cmake)
      list(APPEND audio_plugin_arg "-DVIDEO_DIR=${WALKENV_VIDEO_DIR}")
    endif()
    if(WALKENV_TTS_LIBS)  # text to speech: sherpa-onnx's libraries, all in build/: their names, comma-separated. (Not a ";"
      # list, which would split the argument, nor "|": with Ninja on Windows the command runs inside cmd.exe /C "…", where
      # the argument's own quotes end the outer ones and a "|" becomes a pipe.)
      set(tts_names "")
      foreach(lib ${WALKENV_TTS_LIBS})
        get_filename_component(name "${lib}" NAME)
        list(APPEND tts_names "${name}")
      endforeach()
      string(REPLACE ";" "," tts_names "${tts_names}")
      list(APPEND audio_plugin_arg -DTTS_DIR=${CMAKE_BINARY_DIR} -DTTS_LIBS=${tts_names})
    endif()
    if(TARGET walkenv_pdfium)  # the PDF reader's shared library (cmake/pdfium.cmake)
      list(APPEND audio_plugin_arg "-DPDFIUM_LIBRARY=${WALKENV_PDFIUM_LIBRARY}")
    endif()
    add_custom_command(TARGET walkenv_editor POST_BUILD
      COMMAND ${CMAKE_COMMAND} -DEDITOR=$<TARGET_FILE:walkenv_editor> -DRUNNER=$<TARGET_FILE:walkenv_run>
              -DFONTS=${CMAKE_BINARY_DIR}/fonts -DOUT=${WALKENV_EDITOR_APP_DIR} -DMAC_APP=${APPLE}
              "-DRUNNER_PY=$<$<BOOL:${WALKENV_PYTHON_SCRIPTS}>:$<TARGET_FILE:walkenv_run_py>>"
              -DPYHOME=${CMAKE_BINARY_DIR}/python -DBRANDING=${CMAKE_CURRENT_SOURCE_DIR}/branding
              -DVSIX=${CMAKE_BINARY_DIR}/karasu.vsix -DDOCS=${CMAKE_CURRENT_SOURCE_DIR}/docs-site/dist -DSEAL=${WALKENV_SEAL_APP}
              -DTEMPLATES=${CMAKE_CURRENT_SOURCE_DIR}/templates
              -DHOST=$<TARGET_FILE:walkenv_host> -DUPDATER=$<TARGET_FILE:karasu_updater> -DWEB=${CMAKE_CURRENT_SOURCE_DIR}/build-web
              "-DRUNNER3D=$<$<BOOL:${WALKENV_3D}>:$<TARGET_FILE:walkenv_run3d>>"
              "-DRUNNER3D_PY=$<$<AND:$<BOOL:${WALKENV_3D}>,$<BOOL:${WALKENV_PYTHON_SCRIPTS}>>:$<TARGET_FILE:walkenv_run3d_py>>"
              ${torch_plugin_arg} ${audio_plugin_arg}
              -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/package_editor.cmake
      VERBATIM)
  endif()
endif()
