From f8dfadfeaeb46df3eec17bd76b7abdf42a79108c Mon Sep 17 00:00:00 2001 From: Beyley Cardellio Date: Sun, 23 Aug 2026 16:23:46 -0700 Subject: [PATCH] cmake,external: Add xrt-external-bigceres target This depends on a system install of Ceres which contains the EIGENSPARSE feature, which is used downstream for solving large bundle adjustment problems. Signed-off-by: Beyley Cardellio Part-of: --- CMakeLists.txt | 5 ++++- src/external/CMakeLists.txt | 11 ++++++----- src/external/bigceres/CMakeLists.txt | 9 +++++++++ src/external/tinyceres/CMakeLists.txt | 8 ++++++++ src/xrt/auxiliary/math/CMakeLists.txt | 4 +++- src/xrt/auxiliary/math/m_quatexpmap_bigceres.hpp | 14 ++++++++++++++ ...p_ceres.hpp => m_quatexpmap_ceres_internal.hpp} | 5 ++--- src/xrt/auxiliary/math/m_quatexpmap_tinyceres.hpp | 14 ++++++++++++++ src/xrt/include/xrt/xrt_config_have.h.cmake_in | 1 + tests/tests_quatexpmap.cpp | 6 +++--- 10 files changed, 64 insertions(+), 13 deletions(-) create mode 100644 src/external/bigceres/CMakeLists.txt create mode 100644 src/external/tinyceres/CMakeLists.txt create mode 100644 src/xrt/auxiliary/math/m_quatexpmap_bigceres.hpp rename src/xrt/auxiliary/math/{m_quatexpmap_ceres.hpp => m_quatexpmap_ceres_internal.hpp} (71%) create mode 100644 src/xrt/auxiliary/math/m_quatexpmap_tinyceres.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 5015b31da..5bc230c0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -132,6 +132,7 @@ find_package(cJSON MODULE) find_package(LeapV2 MODULE) find_package(LeapSDK 5 CONFIG) find_package(ONNXRuntime MODULE) +find_package(Ceres COMPONENTS EigenSparse NO_MODULE) if(NOT WIN32) find_package(EGL MODULE) find_package(Percetto MODULE) @@ -253,10 +254,11 @@ option_with_deps(XRT_HAVE_XLIB "Enable xlib support" DEPENDS X11_FOUND) option_with_deps(XRT_HAVE_XRANDR "Enable xlib-xrandr support" DEPENDS XRANDR_FOUND) # System deps to use (sorted) -option_with_deps(XRT_HAVE_OPENCV "Enable OpenCV backend" DEPENDS OpenCV_FOUND) +option_with_deps(XRT_HAVE_BIGCERES "Enable full non-vendored Ceres support for non-linear optimization" DEPENDS CERES_FOUND) option_with_deps(XRT_HAVE_DBUS "Enable dbus support (for BLE support)" DEPENDS DBUS_FOUND) option_with_deps(XRT_HAVE_LIBBSD "Enable libbsd support" DEPENDS LIBBSD_FOUND) option_with_deps(XRT_HAVE_LIBUDEV "Enable libudev (used for device probing on Linux)" DEPENDS UDEV_FOUND) +option_with_deps(XRT_HAVE_OPENCV "Enable OpenCV backend" DEPENDS OpenCV_FOUND) option_with_deps(XRT_HAVE_PERCETTO "Enable percetto support" DEPENDS PERCETTO_FOUND) option_with_deps(XRT_HAVE_SYSTEMD "Enable systemd support" DEPENDS Systemd_FOUND) @@ -610,6 +612,7 @@ endif() message(STATUS "#####----- Config -----#####") message(STATUS "# GIT_DESC: ${GIT_DESC}") message(STATUS "#") +message(STATUS "# BIGCERES: ${XRT_HAVE_BIGCERES}") message(STATUS "# BLUETOOTH: ${XRT_HAVE_BLUETOOTH}") message(STATUS "# D3D11: ${XRT_HAVE_D3D11}") message(STATUS "# D3D12: ${XRT_HAVE_D3D12}") diff --git a/src/external/CMakeLists.txt b/src/external/CMakeLists.txt index 40fb5b8f8..f43b38faa 100644 --- a/src/external/CMakeLists.txt +++ b/src/external/CMakeLists.txt @@ -148,11 +148,12 @@ if(XRT_HAVE_OPENGL) add_subdirectory(imgui) endif() -# tinyceres -add_library(xrt-external-tinyceres INTERFACE) -target_include_directories( - xrt-external-tinyceres SYSTEM INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/tinyceres/include - ) +# Ceres, from the system if we have it +if(XRT_HAVE_BIGCERES) + add_subdirectory(bigceres) +endif() + +add_subdirectory(tinyceres) # Tracy if(XRT_HAVE_TRACY) diff --git a/src/external/bigceres/CMakeLists.txt b/src/external/bigceres/CMakeLists.txt new file mode 100644 index 000000000..dbfebe093 --- /dev/null +++ b/src/external/bigceres/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright 2026, Beyley Cardellio +# SPDX-License-Identifier: BSL-1.0 + +# Set our ceres target to the found system ceres +set(XRT_CERES_TARGET Ceres::ceres) + +# Create a wrapper library to carry our ceres target. +add_library(xrt-external-bigceres INTERFACE) +target_link_libraries(xrt-external-bigceres INTERFACE ${XRT_CERES_TARGET}) diff --git a/src/external/tinyceres/CMakeLists.txt b/src/external/tinyceres/CMakeLists.txt new file mode 100644 index 000000000..c73d676a6 --- /dev/null +++ b/src/external/tinyceres/CMakeLists.txt @@ -0,0 +1,8 @@ +# Copyright 2020-2025, Collabora, Ltd. +# SPDX-License-Identifier: BSL-1.0 + +# The header-only part of Ceres: TinySolver, Jet and what they need. +add_library(xrt-external-tinyceres INTERFACE) +target_include_directories( + xrt-external-tinyceres SYSTEM INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include + ) diff --git a/src/xrt/auxiliary/math/CMakeLists.txt b/src/xrt/auxiliary/math/CMakeLists.txt index 8d4da222d..30d5b8e92 100644 --- a/src/xrt/auxiliary/math/CMakeLists.txt +++ b/src/xrt/auxiliary/math/CMakeLists.txt @@ -37,7 +37,9 @@ add_library( m_predict.h m_quatexpmap.cpp m_quatexpmap.hpp - m_quatexpmap_ceres.hpp + m_quatexpmap_bigceres.hpp + m_quatexpmap_ceres_internal.hpp + m_quatexpmap_tinyceres.hpp m_rational.hpp m_relation_history.cpp m_relation_history.h diff --git a/src/xrt/auxiliary/math/m_quatexpmap_bigceres.hpp b/src/xrt/auxiliary/math/m_quatexpmap_bigceres.hpp new file mode 100644 index 000000000..48e8cd7ff --- /dev/null +++ b/src/xrt/auxiliary/math/m_quatexpmap_bigceres.hpp @@ -0,0 +1,14 @@ +// Copyright 2026, Beyley Cardellio +// SPDX-License-Identifier: Apache-2.0 +/*! + * @file + * @brief Helpers for quatexpmap math for bigceres usage. + * @author Beyley Cardellio + * @ingroup aux_math + */ +// IWYU pragma: no_include "src/Core/MatrixBase.h" + +#pragma once + +#include "ceres/jet.h" +#include "m_quatexpmap_ceres_internal.hpp" diff --git a/src/xrt/auxiliary/math/m_quatexpmap_ceres.hpp b/src/xrt/auxiliary/math/m_quatexpmap_ceres_internal.hpp similarity index 71% rename from src/xrt/auxiliary/math/m_quatexpmap_ceres.hpp rename to src/xrt/auxiliary/math/m_quatexpmap_ceres_internal.hpp index 45b964305..d609bbace 100644 --- a/src/xrt/auxiliary/math/m_quatexpmap_ceres.hpp +++ b/src/xrt/auxiliary/math/m_quatexpmap_ceres_internal.hpp @@ -2,7 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 /*! * @file - * @brief Helpers for quatexpmap math for ceres usage. + * @brief Helpers for quatexpmap math for ceres usage. Internal header to be included by one of the wrappers which + * provide the correct Ceres types depending on what the including module is using. * @author Beyley Cardellio * @ingroup aux_math */ @@ -10,8 +11,6 @@ #pragma once -#include "tinyceres/jet.hpp" - #include "m_quatexpmap.hpp" diff --git a/src/xrt/auxiliary/math/m_quatexpmap_tinyceres.hpp b/src/xrt/auxiliary/math/m_quatexpmap_tinyceres.hpp new file mode 100644 index 000000000..cfeb40c51 --- /dev/null +++ b/src/xrt/auxiliary/math/m_quatexpmap_tinyceres.hpp @@ -0,0 +1,14 @@ +// Copyright 2026, Beyley Cardellio +// SPDX-License-Identifier: Apache-2.0 +/*! + * @file + * @brief Helpers for quatexpmap math for tinyceres usage. + * @author Beyley Cardellio + * @ingroup aux_math + */ +// IWYU pragma: no_include "src/Core/MatrixBase.h" + +#pragma once + +#include "tinyceres/jet.hpp" +#include "m_quatexpmap_ceres_internal.hpp" diff --git a/src/xrt/include/xrt/xrt_config_have.h.cmake_in b/src/xrt/include/xrt/xrt_config_have.h.cmake_in index b266b1a82..bed0af0d9 100644 --- a/src/xrt/include/xrt/xrt_config_have.h.cmake_in +++ b/src/xrt/include/xrt/xrt_config_have.h.cmake_in @@ -11,6 +11,7 @@ /* keep sorted */ +#cmakedefine XRT_HAVE_BIGCERES #cmakedefine XRT_HAVE_BLUETOOTH #cmakedefine XRT_HAVE_D3D11 #cmakedefine XRT_HAVE_D3D12 diff --git a/tests/tests_quatexpmap.cpp b/tests/tests_quatexpmap.cpp index c0df3c7d8..ec9b8a7cf 100644 --- a/tests/tests_quatexpmap.cpp +++ b/tests/tests_quatexpmap.cpp @@ -11,11 +11,11 @@ #include "math/m_api.h" #include "math/m_vec3.h" -#include "math/m_quatexpmap.hpp" -#include "math/m_quatexpmap_ceres.hpp" - #include "tinyceres/jet.hpp" +#include "math/m_quatexpmap.hpp" +#include "math/m_quatexpmap_tinyceres.hpp" + #include using std::vector; -- 2.51.2