Skip to content

Commit fb6b5c2

Browse files
jeongseok-metameta-codesync[bot]
authored andcommitted
Add system mdspan CMake option (#1403)
Summary: - Add a `MOMENTUM_USE_SYSTEM_MDSPAN` CMake option, defaulting to `OFF`. - Use `find_package(mdspan CONFIG REQUIRED)` when that option is enabled. - Preserve the existing `FetchContent` mdspan path by default for source builds. ## Motivation Package-manager builds should be able to use the mdspan package supplied by the environment instead of downloading it with CMake `FetchContent`. This keeps conda-forge and similar builds offline-friendly, reproducible, and aligned with their declared dependency graph, while leaving the default source-build path convenient for users who do not already have mdspan installed. This is needed by the conda-forge packaging flow today: `conda-forge/momentum-feedstock` currently carries a downstream patch to replace the mdspan `FetchContent` block with `find_package(mdspan CONFIG REQUIRED)`: - conda-forge PR: conda-forge/momentum-feedstock#292 - downstream patch permalink: https://github.com/conda-forge/momentum-feedstock/blob/8abdac65ab4781261eb856bdcb3b2e66e2b09964/recipe/patches/0003-Use-packaged-mdspan.patch - recipe dependency permalink: https://github.com/conda-forge/momentum-feedstock/blob/8abdac65ab4781261eb856bdcb3b2e66e2b09964/recipe/recipe.yaml - conda-forge mdspan feedstock: https://github.com/conda-forge/mdspan-feedstock With this option upstream, conda-forge can eventually drop that downstream patch after a Momentum release and pass `-DMOMENTUM_USE_SYSTEM_MDSPAN=ON` instead. Pull Request resolved: #1403 Test Plan: - `git diff --check origin/main..HEAD` - `pixi run -e py312 cmake -S . -B build/pr-mdspan-off-clean ... -DMOMENTUM_USE_SYSTEM_MDSPAN=OFF` - `CMAKE_PREFIX_PATH=<conda-forge mdspan prefix> pixi run -e py312 cmake -S . -B build/pr-mdspan-on-clean ... -DMOMENTUM_USE_SYSTEM_MDSPAN=ON` - `pixi run -e py312 cmake --build build/pr-mdspan-on-clean --target rasterizer -j4` Reviewed By: jeongseok-meta Differential Revision: D105652029 fbshipit-source-id: 23d58194b903b164d841e788c25e0a698f5b2739
1 parent 2366d7c commit fb6b5c2

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

CMakeLists.txt

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ mt_option(MOMENTUM_ENABLE_PROFILING "Enable building with profiling annotations"
8888
mt_option(MOMENTUM_ENABLE_SIMD "Enable building with SIMD instructions" ON)
8989
mt_option(MOMENTUM_INSTALL_EXAMPLES "Install examples" OFF)
9090
mt_option(MOMENTUM_USE_SYSTEM_GOOGLETEST "Use GoogleTest installed in system" OFF)
91+
mt_option(MOMENTUM_USE_SYSTEM_MDSPAN "Use mdspan installed in system" OFF)
9192
mt_option(MOMENTUM_USE_SYSTEM_PYBIND11 "Use pybind11 installed in system" OFF)
9293
mt_option(MOMENTUM_USE_SYSTEM_RERUN_CPP_SDK "Use Rerun C++ SDK installed in system" OFF)
9394
mt_option(MOMENTUM_USE_SYSTEM_TRACY "Use Tracy installed in system" OFF)
@@ -132,17 +133,21 @@ find_package(re2 MODULE REQUIRED)
132133
find_package(spdlog CONFIG REQUIRED)
133134
find_package(urdfdom CONFIG REQUIRED)
134135

135-
# Use standalone mdspan (header-only) instead of full Kokkos.
136-
# Full Kokkos with CUDA sets CMAKE_CXX_COMPILER to nvcc_wrapper globally,
137-
# which breaks pybind11 compilation. We only need mdspan headers.
138-
include(FetchContent)
139-
FetchContent_Declare(mdspan
140-
URL https://github.com/kokkos/mdspan/archive/refs/heads/stable.tar.gz
141-
)
142-
set(MDSPAN_ENABLE_TESTS OFF CACHE BOOL "" FORCE)
143-
set(MDSPAN_ENABLE_BENCHMARKS OFF CACHE BOOL "" FORCE)
144-
set(MDSPAN_ENABLE_EXAMPLES OFF CACHE BOOL "" FORCE)
145-
FetchContent_MakeAvailable(mdspan)
136+
if(MOMENTUM_USE_SYSTEM_MDSPAN)
137+
find_package(mdspan CONFIG REQUIRED)
138+
else()
139+
# Use standalone mdspan (header-only) instead of full Kokkos.
140+
# Full Kokkos with CUDA sets CMAKE_CXX_COMPILER to nvcc_wrapper globally,
141+
# which breaks pybind11 compilation. We only need mdspan headers.
142+
include(FetchContent)
143+
FetchContent_Declare(mdspan
144+
URL https://github.com/kokkos/mdspan/archive/refs/heads/stable.tar.gz
145+
)
146+
set(MDSPAN_ENABLE_TESTS OFF CACHE BOOL "" FORCE)
147+
set(MDSPAN_ENABLE_BENCHMARKS OFF CACHE BOOL "" FORCE)
148+
set(MDSPAN_ENABLE_EXAMPLES OFF CACHE BOOL "" FORCE)
149+
FetchContent_MakeAvailable(mdspan)
150+
endif()
146151

147152
if(MOMENTUM_BUILD_RERUN)
148153
if(MOMENTUM_USE_SYSTEM_RERUN_CPP_SDK)

0 commit comments

Comments
 (0)