Skip to content

refactor(cmake): reorganize dependency management into per-library files#2091

Open
predat wants to merge 6 commits intodevelopfrom
dev/refactor-build-dependencies
Open

refactor(cmake): reorganize dependency management into per-library files#2091
predat wants to merge 6 commits intodevelopfrom
dev/refactor-build-dependencies

Conversation

@predat
Copy link
Contributor

@predat predat commented Mar 19, 2026

Description

This PR reorganizes the entire dependency management system of AliceVision's
CMake superbuild to improve maintainability, readability, and long-term
scalability.

Changes

CMake / Build system

  • DependenciesVersions.cmake (new): single source of truth for all dependency
    versions, download URLs and hashes.
  • src/cmake/deps/ (new directory): each third-party library now has its
    own dedicated .cmake file (alembic, boost, ceres, cuda, eigen, opencv,
    openexr, openimageio, onnxruntime, suitesparse, tbb, …).
  • Helpers.cmake: new macros to avoid code duplication across dependency
    files.
  • Ensured all built libraries are installed consistently under the lib/ folder.
  • Fixed pkgconfig install paths for Eigen and OpenMesh.

Dependencies

  • Updated library versions to match internal studio usage.

Motivation

The previous Dependencies.cmake was a single large file mixing versions,
URLs, hashes and build logic for all dependencies, making it hard to review,
update or extend. The new per-library structure makes each dependency
self-contained and independently versionable.

- Introduce DependenciesVersions.cmake to centralize all versions, URLs and
  hashes
- Split monolithic Dependencies.cmake into individual files under
  src/cmake/deps/
- Add helper macros in Helpers.cmake to reduce boilerplate
- Ensure all libraries install into the 'lib' folder
- Fix pkgconfig paths for Eigen and OpenMesh
@predat predat force-pushed the dev/refactor-build-dependencies branch from 6170417 to 20920d4 Compare March 20, 2026 08:53
Sylvain Maziere added 5 commits March 20, 2026 12:19
The dependency Docker image build was broken: `cmake -P` was called on
`external/src/tiff-stamp/download-tiff.cmake` which never existed
because
`tiff` is a git-based dep. This error was a symptom of a deeper
inconsistency in `av_add_cmake_dep` where `SOURCE_DIR` was set outside
the ExternalProject `PREFIX`, causing CMake to derive `STAMP_DIR` and
`TMP_DIR` to paths it could not locate.

This PR fixes the root cause and modernizes the surrounding
infrastructure.

`SOURCE_DIR` was set to `${CMAKE_CURRENT_BINARY_DIR}/<name>` which is
outside `PREFIX` (`BUILD_DIR/external`). CMake derives `STAMP_DIR` and
`TMP_DIR` from `PREFIX`, so step scripts (`download-*.cmake`,
`gitclone-*.cmake`) were written to paths CMake could not find at
configure time.

All ExternalProject directories are now explicitly set under
`BUILD_DIR`:
- `SOURCE_DIR` → `${BUILD_DIR}/src/<name>`
- `BINARY_DIR` → `${BUILD_DIR}/<name>_build`
- `STAMP_DIR`  → `${BUILD_DIR}/src/<name>-stamp`
- `TMP_DIR`    → `${BUILD_DIR}/src/<name>-tmp`

`GIT_SHALLOW TRUE` added for git-based deps: faster clones, less
network.
Internal `_D_RESOLVED_*` variables are `unset()` after use to avoid
macro scope leakage.

- Replace 15 hardcoded `cmake -P` calls with a loop over URL-based deps
  only. Git-based deps (`tiff`, `ceres`, ...) generate
`gitclone-*.cmake`
  not `download-*.cmake` — calling `cmake -P` on them was the visible
  symptom of the stamp dir bug.
- Remove cmake tarball download: the image now uses the official CMake
  binary installer, no source build needed.
- Replace `test && ...` with `if/fi` for the `ColorChartDetectionModel`
  clone — clearer intent, avoids the silent failure on `rm README.md`.
- Quote all variables and paths consistently.

- Add `# syntax=docker/dockerfile:1.4` to enable BuildKit features.
- Add `--mount=type=cache` on `dnf` and `pip` `RUN` steps: RPMs and
  Python wheels survive layer invalidation, significantly speeding up
  iterative rebuilds.
- Replace cmake source build (`bootstrap + make -j16`, ~15 min) with the
  official binary installer: `cmake-${CMAKE_VERSION}-linux-x86_64.sh`.
  `CMAKE_VERSION` is now an `ARG` (default `3.31.11`), overridable with
  `--build-arg CMAKE_VERSION=x.y.z`.
- Re-declare `ARG CMAKE_VERSION` after `FROM` (Docker ARG scoping rule).
- Merge configure + build + cleanup into a single `RUN`: the ~10 GB of
  build artefacts in `AV_BUILD` are removed in the same layer and never
  committed to the final image.
- Merge 4× `COPY` + 4× `RUN echo` into 4× `COPY` + 1× `RUN` block for
  env var exports.
- Replace `update-alternatives --force` (unsupported on Rocky 9
  `alternatives` 1.20) with `rm -f` before `alternatives --install`.
- Replace backtick substitution `` ` `` with `$(...)` throughout.
- Sort `dnf` package list alphabetically, one package per line.
- Order `COPY` instructions from least to most frequently changed to
  maximize Docker layer cache reuse.
- Enable `DOCKER_BUILDKIT=1` in `build-rocky.sh`.

- Verified full `docker/build-rocky.sh` run on Rocky Linux 9 /
  CUDA 12.1.1 / GCC 12.4
- All URL-based deps pre-fetched successfully via `docker/fetch.sh`
- Git-based deps (tiff, ceres, lemon, ...) cloned correctly at build
  time
…IES_PARALLEL=0

Docker build contexts have limited parallelism headroom; building deps
sequentially avoids OOM kills and I/O contention on the builder host.
cmake --build is updated accordingly (--parallel 1).
…oring

- Add # syntax=docker/dockerfile:1.4 and BuildKit cache mounts on
  apt (/var/cache/apt + /var/lib/apt) and pip (/root/.cache/pip)
- Merge all apt-get install + PPA setup into a single RUN layer
- Merge 4x COPY+RUN echo into 4x COPY + 1x RUN block for env vars
- Merge configure + build + cleanup into a single RUN to avoid
  committing ~10 GB of build artefacts into intermediate layers
- Sort package list alphabetically, one package per line
- Order COPY from least to most frequently changed for cache reuse
- Replace backtick substitution with $(...) throughout
- Re-declare ARG CUDA_VERSION/UBUNTU_VERSION after FROM
- Add build example and section comments
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