agentleFS
LuisaGroupLuisaGroup/LuisaCompute/.agents/skills/cmake/SKILL.md

cmake

Skill1.1k starsChanged 35 days agoApache-2.0View on GitHub

CMake build options, custom functions, and backend patterns for LuisaCompute.

1 other project uses a version of this.

Trending

Quiet since July.thin dataabout the whole repository

Dec 2025: 0 mentionsJan 2026: 0 mentionsFeb 2026: 0 mentionsMar 2026: 0 mentionsApr 2026: 0 mentionsMay 2026: 0 mentionsJun 2026: 0 mentionsJul 2026: 1 mentionAug 2026: 0 mentionsSep 2026: 0 mentionsOct 2026: 0 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the LuisaGroup/LuisaCompute repository that our weekly crawl found: only 5 in all, so this is a hint, not a trend. There is no adoption data for this file yet.

Most recently taken up by

The file

Files
SKILL.md

CMake Build Guide

Requirements: CMake 3.26+, Ninja (recommended), C++20 compiler (MSVC/Clang/GCC).

Quick Start

cmake -S . -B build -G Ninja -D CMAKE_BUILD_TYPE=Release
cmake --build build
cmake --install build --prefix dist

Platform specifics:

Linux:

export CC=clang-20 CXX=clang++-20
cmake -S . -B build -G Ninja -D CMAKE_BUILD_TYPE=Release

macOS:

export PATH="$PATH:/opt/homebrew/opt/llvm/bin"
export CC=/opt/homebrew/opt/llvm/bin/clang
export CXX=/opt/homebrew/opt/llvm/bin/clang++
export SDKROOT=$(xcrun --show-sdk-path)
cmake -S . -B build -G Ninja -D CMAKE_BUILD_TYPE=Release

Windows: Requires VS Developer Command Prompt. Or use Python bootstrap:

import bootstrap
bootstrap.prepare_msvc_environment()

scripts/agent_windows_cmake.py

One-shot configure + build + verify on Windows using the repository defaults.

# Full pipeline: configure → build → verify
python scripts/agent_windows_cmake.py

# Individual steps
python scripts/agent_windows_cmake.py --config          # configure only
python scripts/agent_windows_cmake.py --build           # build only
python scripts/agent_windows_cmake.py --verify          # check key .lib/.dll outputs
python scripts/agent_windows_cmake.py --clean           # clear CMake cache

# Options
python scripts/agent_windows_cmake.py --type Debug      # Debug build
python scripts/agent_windows_cmake.py -j 8              # limit parallel jobs
python scripts/agent_windows_cmake.py --clean --config  # clean re-configure

Auto-finds cmake and ninja (PATH → .deps/ → pip). Auto-prepares MSVC environment via vswhere. Verifies: SPIRV-Tools-opt.lib, SPIRV-Tools.lib, luisa-ast.dll, luisa-core.dll.

Build Options

OptionDefaultDescription
CMAKE_BUILD_TYPE-Release / Debug / RelWithDebInfo / MinSizeRel (single-config generators default to Release, scripts/setup_output_dirs.cmake:16-18)
LUISA_COMPUTE_ENABLE_PACKAGE_DISTRIBUTIONOFFRelocatable CPack distribution build; also turns developer-feature defaults OFF (CMakeLists.txt:45-58)
LUISA_COMPUTE_ENABLE_DSLONC++ DSL
LUISA_COMPUTE_ENABLE_CUDAONCUDA backend
LUISA_COMPUTE_ENABLE_METALONMetal backend (macOS only)
LUISA_COMPUTE_ENABLE_METAL4OFFIndependent Metal4 XIR→LLVM→AIR backend; requires LLVM 22 and Apple Metal 4 tools
LUISA_COMPUTE_ENABLE_DXONDirectX backend (Windows only)
LUISA_COMPUTE_ENABLE_VULKANONVulkan backend
LUISA_COMPUTE_ENABLE_HIPOFFHIP backend (work in progress)
LUISA_COMPUTE_ENABLE_FALLBACKON (OFF in package-distribution builds)Native C++ fallback backend (requires LLVM + Embree, src/backends/fallback/CMakeLists.txt:11-30)
LUISA_COMPUTE_ENABLE_GUIONGUI support (GLFW/ImGui)
LUISA_COMPUTE_ENABLE_CUDA_EXT_LCUBOFFCUDA extension: LCUB
LUISA_COMPUTE_ENABLE_CLANG_CXXOFFClangTooling-based C++ shading language
LUISA_COMPUTE_ENABLE_SIMDOFFExperimental SIMD CPU backend (src/backends/simd/)
LUISA_COMPUTE_ENABLE_REMOTEOFFExperimental C++ remote backend (src/backends/remote/)
LUISA_COMPUTE_ENABLE_TILE_TIRX_BRIDGEOFFNative C++ TileIR to TVM TIRx bridge
LUISA_COMPUTE_ENABLE_VK_XIR_SPIRVONNative XIR-to-SPIR-V codegen path for Vulkan
LUISA_COMPUTE_ENABLE_VK_AST_LLVM_SPIRVOFFExperimental AST→LLVM SPIR-V path; requires LLVM's native SPIRV target
LUISA_COMPUTE_VULKAN_ENABLE_DXC_COMPATIBILITYONLegacy Vulkan HLSL-to-SPIR-V compatibility through DXC
LUISA_COMPUTE_BUILD_TESTSON in master projectBuild tests, examples and tutorials
LUISA_COMPUTE_BUILD_IOS_EXAMPLESOFFBuild the 19 opt-in UIKit example bundles (18 luisa_compute_add_ios_rendering_example apps plus example_ios_path_tracing, examples/ios/CMakeLists.txt:25,109-161); requires an iPhoneOS toolchain and Metal4
LUISA_COMPUTE_BUILD_IOS_TESTSOFFBuild the independent iOS device-conformance bundle (or its host-AOT oracle on macOS)
LUISA_COMPUTE_BUILD_IOS_BENCHMARKSOFFBuild the opt-in iOS Metal backend comparison application
LUISA_COMPUTE_ENABLE_SAFE_MODEOFFRuntime safe mode
LUISA_COMPUTE_ENABLE_UNITY_BUILDOFFUnity build
LUISA_COMPUTE_ENABLE_SANITIZERSOFFAddress/UB sanitizers
LUISA_COMPUTE_ENABLE_LTOOFFLink-time optimization (release builds only)
LUISA_COMPUTE_ENABLE_SCCACHEON (non-MSVC)Use sccache compiler launcher
LUISA_COMPUTE_ENABLE_DX_CUDA_INTEROP / LUISA_COMPUTE_ENABLE_VK_CUDA_INTEROPON (developer builds)CUDA interop in the DX / Vulkan backends when CUDAToolkit is available
LUISA_COMPUTE_CHECK_BACKEND_DEPENDENCIESONAuto-disable backends with missing dependencies
LUISA_COMPUTE_ENABLE_WAYLANDOFF (Linux)Wayland support in GUI/Vulkan swapchains
LUISA_COMPUTE_USE_SYSTEM_LIBSOFFPrefer system libraries; also enables per-lib USE_SYSTEM_* overrides
LUISA_COMPUTE_DOWNLOAD_OIDNOFFDownload OpenImageDenoise
LUISA_COMPUTE_DOWNLOAD_NVCOMPOFF (if CUDA)Download nvCOMP for CUDA decompression

LUISA_COMPUTE_USE_SYSTEM_* options exist for STL, GLFW, LMDB, REPROC, SPDLOG, XXHASH, YYJSON, MAGIC_ENUM, and MARL (CMakeLists.txt:180-188; STL defaults to ON, the rest follow LUISA_COMPUTE_USE_SYSTEM_LIBS).

LUISA_COMPUTE_ENABLE_SCCACHE and LUISA_COMPUTE_ENABLE_LTO are declared in scripts/setup_compilation.cmake:60,76 (not the root file); LTO only sets CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE / _RELWITHDEBINFO / _MINSIZEREL.

The two Vulkan SPIR-V codegen options are mutually exclusive: CMakeLists.txt:160-164 and src/backends/CMakeLists.txt:3-8 raise a FATAL_ERROR if both are ON. The LLVM path also builds/links the common luisa-compute-spirv support library (STATIC, src/backends/common/spirv/CMakeLists.txt:18) because the Vulkan backend still uses its disassembler/validation utilities and its target-feature reconciliation (reconcile_spirv_target_features, src/backends/common/spirv/spirv_codegen/optimizer.cpp:657) in that configuration (src/backends/vk/CMakeLists.txt:143-148).

Minimal build (no GPU/fallback backends):

cmake -S . -B build -G Ninja -D CMAKE_BUILD_TYPE=Release \
  -D LUISA_COMPUTE_ENABLE_CUDA=OFF \
  -D LUISA_COMPUTE_ENABLE_VULKAN=OFF \
  -D LUISA_COMPUTE_ENABLE_FALLBACK=OFF
cmake --build build

CI jobs are defined in .github/workflows/build-cmake.yml: all three platforms configure with -G Ninja -D LUISA_COMPUTE_ENABLE_PACKAGE_DISTRIBUTION=<ON|OFF> -D CMAKE_BUILD_TYPE=<Release|Debug>, and the macOS job additionally passes -D LUISA_COMPUTE_ENABLE_VULKAN=OFF -D LUISA_COMPUTE_ENABLE_UNITY_BUILD=OFF. Release jobs then run cmake --build build --target luisa-compute-package-e2e (cmake/LuisaComputeCPack.cmake:78).

Target Naming

PrefixExamplePurpose
luisa-compute-<module>luisa-compute-coreInternal library
luisa-compute-backend-<name>luisa-compute-backend-cudaBackend plugin (output: luisa-backend-<name>)
luisa-compute-ext-<name>luisa-compute-ext-btreeThird-party ext
luisa::computeAliasInterface target for all core modules

Module Hierarchy

luisa-compute-include (INTERFACE, header-only)
  → luisa-compute-ext (INTERFACE, third-party deps)
    → luisa-compute-core
      → luisa-compute-ast
        → luisa-compute-xir
      → luisa-compute-runtime (links ast; PRIVATE luisa-compute-vstl)
        → luisa-compute-dsl, luisa-compute-gui (gui links runtime + dsl)
luisa-compute-backends (INTERFACE aggregator: each luisa_compute_add_backend target links ast/runtime/gui/dsl and registers itself via add_dependencies)

These libraries follow BUILD_SHARED_LIBS: ordinary desktop builds force it ON, while iOS forces it OFF so the signed app contains static core/runtime/XIR and backend slices.

The umbrella target is compute, aliased as luisa::compute (src/CMakeLists.txt:55-75); it links luisa-compute-core, -tile, -ast, -xir, -dsl, -osl, -runtime, -gui, -backends, -coro, -clangcxx, plus luisa-compute-cuda-ext-lcub when LUISA_COMPUTE_ENABLE_CUDA_EXT_LCUB is ON. luisa-compute-vstl is an OBJECT helper (src/vstl/CMakeLists.txt:11) linked PRIVATE by luisa-compute-runtime (src/runtime/CMakeLists.txt:44-46), not by compute.

Custom CMake Functions

luisa_compute_add_backend(name [SOURCES <srcs...>] [SUPPORT_DIR dir] [BUILTIN_DIR dir])

File: src/backends/CMakeLists.txt:11. Creates a backend MODULE target named luisa-compute-backend-<name> on desktop platforms and a STATIC target on iOS (CMAKE_SYSTEM_NAME STREQUAL "iOS"). It links luisa-compute-ast, luisa-compute-runtime, luisa-compute-gui, and (when LUISA_COMPUTE_ENABLE_DSL is ON) luisa-compute-dsl. Desktop output is named luisa-backend-<name> (OUTPUT_NAME, EXPORT_NAME backend_<name>) and runtime artifacts are installed to bin/. If SUPPORT_DIR is given, its contents are copied next to the runtime outputs ($<TARGET_FILE_DIR:luisa-compute-core>) and installed to bin/. A BUILTIN_DIR keyword is parsed but currently unused by the function body.

luisa_compute_add_backend(cuda SOURCES ${LUISA_COMPUTE_CUDA_SOURCES})          # src/backends/cuda/CMakeLists.txt:53
luisa_compute_add_backend(dx SOURCES ${LC_BACKEND_DX_SOURCES} SUPPORT_DIR ${LUISA_COMPUTE_DX_SDK_DIR})

luisa_compute_install(target [SOURCES <srcs...>])

File: src/CMakeLists.txt:14. Installs luisa-compute-<target> into the LuisaComputeTargets export with LIBRARY/ARCHIVE → ${CMAKE_INSTALL_LIBDIR} and RUNTIME → ${CMAKE_INSTALL_BINDIR}. The SOURCES keyword is accepted by the call sites but ignored by the function.

luisa_compute_install(core SOURCES ${LUISA_COMPUTE_CORE_SOURCES})

luisa_compute_add_executable(name [sources...])

File: src/CMakeLists.txt:77. Wraps add_executable(${name} ${ARGN}) (extra arguments are the sources) and links luisa::compute PRIVATE.

luisa_compute_add_executable(test_basic_traits unit/core/test_basic_traits.cpp)

luisa_compute_add_test(name source [LABELS ...] [ARGS ...])

File: src/tests/CMakeLists.txt:19. Builds one standalone executable per source (via luisa_compute_add_executable) and adds ./ and ./common to its include paths. With LABELS, registers a CTest entry; ARGS becomes the test's argv, used to pin a backend for a GPU integration test (e.g. ARGS metal4, ARGS simd). Without LABELS, it just builds the binary and any device test is invoked manually with a backend argument.

luisa_compute_add_test(test_basic_traits unit/core/test_basic_traits.cpp LABELS "unit;unit_core")
luisa_compute_add_test(test_vk_cuda_kernel_launch integration/runtime/test_vk_cuda_kernel_launch.cpp)  # no CTest
luisa_compute_add_test(test_tile_xir_runtime_gpu_dx unit/tile/bridge/test_xir_runtime_gpu.cpp LABELS "integration;integration_tile_xir;integration_dx" ARGS dx)

luisa_compute_add_example(name [sources...] [MIRROR_AS_TEST])

File: examples/CMakeLists.txt:1. Builds the <name> executable (call sites pass names already prefixed with example_) and, when MIRROR_AS_TEST is set, additionally builds a mirror executable whose name is <name> with the leading example_ replaced by test_ (only if that target does not already exist), recording it in the LUISA_TEST_MIRROR target property. Reserved for auto-checkable examples (reference-image comparison, deterministic sims, headless compute). GUI/interop demos must omit the flag.

luisa_compute_add_example(example_path_tracing rendering/path_tracing.cpp MIRROR_AS_TEST)
luisa_compute_add_example(example_swapchain_qt gui/swapchain_qt.cpp)  # no mirror

luisa_example_pair_link(name <link-args>)

File: examples/CMakeLists.txt:16. Companion to luisa_compute_add_example. Calls target_link_libraries on <name> and, if its LUISA_TEST_MIRROR property is set, on that mirror too. Use whenever an example needs extra libs.

luisa_compute_add_example(example_cuda_lcub extension/cuda_lcub.cpp)
luisa_example_pair_link(example_cuda_lcub PRIVATE CUDA::cudart CUDA::cuda_driver)

Backend Plugin Build

Desktop backends are built as MODULE runtime-loadable libraries:

luisa_compute_add_backend(cuda SOURCES ${LUISA_COMPUTE_CUDA_SOURCES})

Key: output renamed to luisa-backend-<name>, installed to bin/. Device-lib embedding is done by each backend's own CMakeLists.txt through the luisa_embed_device_lib host tool (utils/CMakeLists.txt:2; e.g. src/backends/cuda/CMakeLists.txt:6-11) — luisa_compute_add_backend itself does not embed anything.

On iOS, the same helper emits a static backend. A signed Metal4 AIR device app also requires static arm64 iPhoneOS LLVM 22 archives; an arm64 macOS LLVM build is not platform-compatible. Prefer the checked scripts so local and CI options remain identical:

scripts/build_ios_llvm.sh \
  --host-llvm-prefix "$(brew --prefix llvm@22)"
scripts/build_ios_metal4.sh \
  --llvm-dir cmake-build-llvm22-ios/lib/cmake/llvm \
  --team <team-id> --mode all

# CI/link closure only; these bundles are not installable.
scripts/build_ios_metal4.sh \
  --llvm-dir cmake-build-llvm22-ios/lib/cmake/llvm \
  --mode all --unsigned
scripts/audit_ios_bundles.sh \
  --bin-dir cmake-build-ios-metal4-device-air-xcode/bin/Release

build_ios_llvm.sh downloads the official LLVM 22.1.8 source when needed and uses CMake/Ninja with arm64-apple-ios<deployment> host/default triples. The application script uses CMake's Xcode generator only because provisioning and automatic signing are Xcode workflows. --mode examples, tests, or all maps to luisa-ios-rendering-examples, luisa-ios-device-tests, or both.

Metal4 user shaders and fixed runtime builtins are LLVM/AIR. BC6H/BC7 fixed support sources are compiled to target-specific metallibs by xcrun metal and metallib at build time; the runtime embeds and loads only their binary bytes.

Third-Party Extension Pattern

Each src/ext/<lib>/ (pattern from src/ext/CMakeLists.txt:283-310):

if (LUISA_COMPUTE_USE_SYSTEM_<LIB>)
    find_package(<LIB> REQUIRED)
    target_link_libraries(luisa-compute-ext INTERFACE <target>)
    target_compile_definitions(luisa-compute-ext INTERFACE LUISA_USE_SYSTEM_<LIB>=1)
else()
    add_subdirectory(<lib>)
    target_link_libraries(luisa-compute-ext INTERFACE <target>)
    luisa_compute_install_extension(<target> INCLUDE <lib>/include/<LIB>)
endif()

luisa_compute_install_extension(target [INCLUDE dir] [INCLUDES dirs...] [HEADER_FILES files...] [HEADER_DESTINATION dir]) is defined in src/ext/CMakeLists.txt:243 and installs the target plus its headers to ${CMAKE_INSTALL_INCLUDEDIR}/luisa/ext.

Output & RPATH

${CMAKE_BINARY_DIR}/bin  → Runtime + library outputs (DLLs/.so/.dylib, executables)
${CMAKE_BINARY_DIR}/lib  → Archive outputs (static libs, import libs, PDBs)

Per scripts/setup_output_dirs.cmake:1-14; multi-config generators (e.g. Xcode, VS) write bin/<config> and lib/<config> instead.

Install layout: headers → ${CMAKE_INSTALL_INCLUDEDIR}/luisa (CMakeLists.txt:323-326), libraries → ${CMAKE_INSTALL_LIBDIR} and runtime binaries → ${CMAKE_INSTALL_BINDIR} (luisa_compute_install, src/CMakeLists.txt:14-20), CMake package files (LuisaComputeConfig.cmake, LuisaComputeTargets.cmake) → LUISA_COMPUTE_INSTALL_CMAKEDIR, which defaults to ${CMAKE_INSTALL_LIBDIR}/cmake/LuisaCompute (CMakeLists.txt:267-270, 367-381). RPATH is set from CMakeLists.txt:244-249.

  • macOS: @loader_path, @loader_path/../bin, @loader_path/../lib
  • Linux: $ORIGIN, $ORIGIN/../bin, $ORIGIN/../lib

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.