Skip to content

[doc] install target fails if ocaml_doc not built (missing ocamldoc/html directory) #154411

@Acture

Description

@Acture

Description

When building with -DLLVM_BUILD_DOCS=ON -DLLVM_ENABLE_OCAMLDOC=ON -DLLVM_INSTALL_DOCS=ON, running
cmake --build . --target install
fails with:

CMake Error at docs/cmake_install.cmake:41 (file):
  file INSTALL cannot find
  "$HOME/llvm-project/build/docs/ocamldoc/html/.": No such file
  or directory.
Call Stack (most recent call first):
  cmake_install.cmake:162 (include)

Steps to reproduce

Such error does not provoke with no OCAML.

mkdir build
cd build
cmake -G "Unix Makefiles" -DLLVM_TARGETS_TO_BUILD=AArch64 -DLLVM_DEFAULT_TARGET_TRIPLE=arm64-apple-darwin24.5.0 -DCMAKE_BUILD_TYPE="Release" -DLLVM_USE_LINKER=lld -DCMAKE_INSTALL_PREFIX="$HOME/repos/jeandle-llvm-install" -DLLVM_BUILD_DOCS=ON \
      -DLLVM_ENABLE_OCAMLDOC=ON \
      -DLLVM_INSTALL_DOCS=ON -DLLVM_BUILD_LLVM_DYLIB=On -DLLVM_DYLIB_COMPONENTS=all ../llvm
cmake --build . --target install

Actual Behavior

install unconditionally tries to copy ${CMAKE_CURRENT_BINARY_DIR}/ocamldoc/html/. but that directory may not exist yet (the OCaml doc target has not been built), causing the install step to fail.

Expected Behavior

Either:

  • install should build the OCaml docs before installing them, or
  • the OCaml docs should only be installed if they were generated (i.e., guarded by feature checks / target existence).

Root Cause (CMake logic)

In llvm/docs/CMakeLists.txt the OCaml docs are generated by a custom target, but the install rule copies the output directory unconditionally:

install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/ocamldoc/html/.
        COMPONENT ocamldoc-html
        DESTINATION "${LLVM_INSTALL_OCAMLDOC_HTML_DIR}")

Unlike the Doxygen path (where doxygen-xxx targets are wired into a top-level doxygen target that participates in ALL), the OCaml docs target (ocaml_doc) is not on the build path that runs before install. As a result, cmake --build . --target install may execute before ${CMAKE_CURRENT_BINARY_DIR}/ocamldoc/html/ exists, and the copy fails.

Workarounds

  • Explicitly build the doc target before install:
cmake --build . --target ocaml_doc
cmake --build . --target install
  • Or temporarily create the directory to unblock installation (not recommended):
mkdir -p build/docs/ocamldoc/html
cmake --build . --target install

Environment

  • OS: macOS (arm64-apple-darwin24.5.0)
  • Toolchain: Apple Clang / lld
  • OCaml tooling: ocamlc/ocamldoc/ocamlfind available and detected
  • LLVM version/branch: main
  • Generator: Unix Makefiles

Same as shown in #125437 and #108742.
Fix is proposed in PR #154412.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions