Skip to content

[CMake] Don't override find_package() for builtins#22604

Open
guitargeek wants to merge 2 commits into
root-project:masterfrom
guitargeek:issue-8633
Open

[CMake] Don't override find_package() for builtins#22604
guitargeek wants to merge 2 commits into
root-project:masterfrom
guitargeek:issue-8633

Conversation

@guitargeek

Copy link
Copy Markdown
Contributor

Targeted changes to make the find_package override unnecessary (more detail in inline comments and commit messages).

Closes #8633.

🤖 Done with the help of Claude Code (Claude Opus 4.8)

builtins/zstd defined the imported ZSTD::ZSTD target but never tied it to
the BUILTIN_ZSTD ExternalProject that actually produces libzstd.a. As a
result a parallel or targeted build (e.g. building only the Core target)
could try to link the archive before it exists. Add the dependency edge,
consistent with what builtins/zlib already does for BUILTIN_ZLIB.

🤖 Done with the help of [Claude Code](https://claude.com/claude-code) (Claude Opus 4.8)
@guitargeek guitargeek self-assigned this Jun 14, 2026
@guitargeek guitargeek requested a review from bellenot as a code owner June 14, 2026 13:38
@guitargeek guitargeek added in:Build System clean build Ask CI to do non-incremental build on PR labels Jun 14, 2026
@guitargeek guitargeek changed the title [CMake] Don't override find_package() for builtins [CMake] Don't override find_package() for builtins Jun 14, 2026
@github-actions

github-actions Bot commented Jun 14, 2026

Copy link
Copy Markdown

Test Results

    21 files      21 suites   3d 6h 2m 46s ⏱️
 3 860 tests  3 847 ✅   0 💤 13 ❌
72 771 runs  72 612 ✅ 146 💤 13 ❌

For more details on these failures, see this check.

Results for commit 448ffc3.

♻️ This comment has been updated with latest results.

Comment on lines +83 to +84
set(ZLIB_INCLUDE_DIR ${ZLIB_INCLUDE_DIR} CACHE PATH "Path to the builtin zlib headers" FORCE)
set(ZLIB_LIBRARY ${ROOT_ZLIB_LIBRARY} CACHE FILEPATH "Path to the builtin zlib library" FORCE)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
set(ZLIB_INCLUDE_DIR ${ZLIB_INCLUDE_DIR} CACHE PATH "Path to the builtin zlib headers" FORCE)
set(ZLIB_LIBRARY ${ROOT_ZLIB_LIBRARY} CACHE FILEPATH "Path to the builtin zlib library" FORCE)
set(ZLIB_INCLUDE_DIR ${ZLIB_INCLUDE_DIR} PARENT_SCOPE)
set(ZLIB_LIBRARY ${ROOT_ZLIB_LIBRARY} PARENT_SCOPE)

for consistency with above?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I'll try! As long as FindPNG (which does find_package(ZLIB) internally) picks up the builtin ZLIB we're good. We just need to set the right variables so find_package(ZLIB) knows ZLIB is already there, and it will not look for it again and find the system ZLIB.

@ferdymercury ferdymercury left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, just a minor nitpick

ROOT redefined the global find_package() command to no-op for its
builtins, so that sub-projects added later (notably the bundled LLVM)
and transitive find modules (e.g. FindPNG -> find_package(ZLIB)) would
reuse ROOT's builtin imported targets instead of re-discovering a system
copy. This relied on undocumented CMake behaviour and recursed
infinitely under tools that override find_package() themselves, such as
vcpkg (root-project#8633).

The override only ever did real work for ZLIB and zstd: every other name
in ROOT_BUILTINS was unnecessary (no find_package() consumer
downstream). Both are now handled directly, so the override and the
ROOT_BUILTINS list can be removed:

  * ZLIB (used by core/zip's find_package(ZLIB REQUIRED) and the
    transitive FindPNG -> find_package(ZLIB) of the asimage build):
    builtins/zlib pre-seeds the singular cache variables ZLIB_LIBRARY
    and ZLIB_INCLUDE_DIR that FindZLIB.cmake checks, so find_package()
    short-circuits to the builtin and keeps the ZLIB::ZLIB target. This
    also avoids the "FORCE specified without CACHE" error from
    select_library_configurations() that a real FindPNG -> FindZLIB
    chain would otherwise hit.

  * zstd (used only by the bundled LLVM): interpreter/CMakeLists.txt sets
    LLVM_ENABLE_ZSTD=OFF (and LLVM_ENABLE_ZLIB=OFF) for builtin builds,
    so LLVM never searches for the system copy. We can't point LLVM at
    the builtins instead, as it probes them with a configure-time
    compile/link check that the not-yet-built ExternalProject can't pass
    anyway.

This makes ROOT compatible with vcpkg and other dependency providers
without changing behaviour: in builtin builds LLVM is still built without
zlib/zstd, and a system build is unaffected since find_package() is no
longer shadowed.

Closes root-project#8633.

🤖 Done with the help of [Claude Code](https://claude.com/claude-code) (Claude Opus 4.8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clean build Ask CI to do non-incremental build on PR in:Build System

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Don't replace CMake's find_package

2 participants