Skip to content

[cmake] Fix LAPACK/SuiteSparse never being built on Linux - #2198

Open
predat wants to merge 5 commits into
developfrom
fix/suitesparse-lapack-build
Open

predat wants to merge 5 commits into
developfrom
fix/suitesparse-lapack-build

Conversation

@predat

@predat predat commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Description

When building the dependencies on Linux, LAPACK/BLAS and SuiteSparse were never built, so Ceres ended up configured with CERES_NO_SUITESPARSE and CERES_NO_LAPACK and the sparse bundle adjustment silently fell back to EIGEN_SPARSE.

Root cause: av_conditional_option(... IF "NOT APPLE" ...) receives the quoted condition as a single list element, so if(${_co_IF}) evaluates an undefined variable literally named NOT APPLE and always takes the ELSE branch. This affects AV_BUILD_LAPACK, AV_BUILD_SUITESPARSE and ALICEVISION_REQUIRE_CERES_WITH_SUITESPARSE. That last one is why the AliceVision build did not fail when Ceres had no SuiteSparse support.

Once these dependencies are actually built, two more issues show up. This PR fixes them too.

Features list

  • av_conditional_option now evaluates a condition given as a single quoted string (e.g. IF "NOT APPLE") by splitting it into separate arguments. Multi-element conditions are left untouched, so quoted values inside them (e.g. IF X STREQUAL "a b") keep their spaces. The call sites are unchanged.
  • LAPACK_CMAKE_FLAGS is now a proper list. It used to be a single string, so Ceres/AliceVision received BLAS_LIBRARIES="<libblas> -DLAPACK_LIBRARIES=<liblapack>". It is joined with spaces only for the CMAKE_OPTIONS variable of SuiteSparse's Makefile.
  • Build SuiteSparse with SUITESPARSE_USE_CUDA=OFF. SuiteSparse 7.x enables CUDA by default for all architectures, which greatly increases build time and size. The ENABLE_CUDA option passed so far does not exist in 7.x. The CUDA code is never reached anyway: CHOLMOD only offloads to the GPU through its 64-bit interface (cholmod_l_*), while Ceres, the only SuiteSparse consumer here, uses the 32-bit one.
  • Pass BLA_VENDOR=Generic to SuiteSparse along with the reference BLAS/LAPACK paths. Since SuiteSparse 7.x (7.14 in [deps] Update dependency versions and reduce CUDA architectures #2199), giving BLAS_LIBRARIES also requires BLA_VENDOR; without it, SuiteSparse__blas_threading.cmake fails on an empty ${BLA_VENDOR}. SuiteSparse 7.3.0, the version on develop, does not need it but accepts it. When no BLAS/LAPACK paths are given, SuiteSparse still detects the system BLAS itself.
  • Download GMP from ftp.gnu.org instead of gmplib.org, which throttles or rejects automated downloads. It is the same archive (same MD5), and MPFR is already downloaded from there.

Implementation remarks

  • Checked with CMake 4.2.3:
    • av_conditional_option on Linux: IF "NOT APPLE" and IF "VAR AND NOT APPLE" now give ON (both gave OFF before); IF NOT APPLE, IF VAR, IF APPLE and IF X STREQUAL "a b" give the same result as before.
    • All existing av_conditional_option calls now evaluate as expected: AV_BUILD_LAPACK, AV_BUILD_SUITESPARSE and ALICEVISION_REQUIRE_CERES_WITH_SUITESPARSE are ON, AV_BUILD_OPENMP stays OFF.
    • Through ExternalProject, Ceres receives BLAS_LIBRARIES and LAPACK_LIBRARIES as two separate variables.
    • SuiteSparse's make receives a single CMAKE_OPTIONS=... argument.
  • The full dependency build including LAPACK, GMP, MPFR and SuiteSparse has not run yet with these changes. It is the first time this part of the dependency build actually runs on Linux.
  • To verify after building the dependencies, CERES_NO_SUITESPARSE and CERES_NO_LAPACK must no longer be defined in include/ceres/internal/config.h.

🤖 Generated with Claude Code

predat added 3 commits October 9, 2026 10:44
A condition passed as a single quoted string, e.g. IF "NOT APPLE",
reached if() as one element and was evaluated as the name of an
undefined variable, so it was always false and the ELSE value was used.

As a result AV_BUILD_LAPACK, AV_BUILD_SUITESPARSE and
ALICEVISION_REQUIRE_CERES_WITH_SUITESPARSE, all declared with
IF "NOT APPLE", were OFF on Linux, and Ceres was silently built without
SuiteSparse nor LAPACK.

Split single-element conditions into separate arguments. Conditions
given as several arguments are left untouched, so quoted values inside
them keep their spaces.
LAPACK_CMAKE_FLAGS was a single string holding both -D options, so
CMake-based consumers (Ceres, AliceVision) received
BLAS_LIBRARIES="<libblas> -DLAPACK_LIBRARIES=<liblapack>". Make it a
proper list, and join it with spaces only for the CMAKE_OPTIONS variable
of SuiteSparse's Makefile.
SuiteSparse 7.x enables CUDA by default (SUITESPARSE_USE_CUDA=ON) and
compiles it for every architecture (SUITESPARSE_CUDA_ARCHITECTURES=all),
which now that SuiteSparse is actually built greatly increases build time
and binary size. The ENABLE_CUDA option passed so far is not a
SuiteSparse 7.x option and had no effect.

The CUDA code is never used: CHOLMOD only offloads to the GPU through
its 64-bit integer interface (cholmod_l_*), while Ceres, the only
consumer of SuiteSparse in AliceVision, uses the 32-bit one.
@predat
predat force-pushed the fix/suitesparse-lapack-build branch from 9a2d293 to 9c976a5 Compare October 9, 2026 08:44
predat added 2 commits October 9, 2026 12:33
gmplib.org throttles or rejects automated downloads; ftp.gnu.org serves the same archive (same MD5) and already hosts MPFR. GMP is only built with SuiteSparse, which this branch makes actually build on Linux.
When BLAS_LIBRARIES is given, SuiteSparse 7.x also requires BLA_VENDOR to know which BLAS it is; without it, SuiteSparse__blas_threading.cmake fails on an empty ${BLA_VENDOR}. Pass BLA_VENDOR=Generic, the value for the reference BLAS, along with the BLAS/LAPACK paths. When they are not given, SuiteSparse still detects the system BLAS and sets BLA_VENDOR itself.
@cbentejac cbentejac added this to the 3.4.0 milestone Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants