Skip to content

cmake: don't gate FetchContent_Populate(rocm-cmake) on the source dir already being absent - #5

Open
pvelesko wants to merge 1 commit into
mainfrom
fix-fetchcontent-populate-guard
Open

cmake: don't gate FetchContent_Populate(rocm-cmake) on the source dir already being absent#5
pvelesko wants to merge 1 commit into
mainfrom
fix-fetchcontent-populate-guard

Conversation

@pvelesko

@pvelesko pvelesko commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

rocm-cmake_SOURCE_DIR is a plain variable, only set when FetchContent_Populate actually runs; it does not persist between separate cmake invocations. The if(NOT EXISTS ...) guard added in d340aa2 wraps the whole Declare/GetProperties/Populate block, so reconfiguring a build tree where rocm-cmake was already fetched skips Populate, leaves the variable empty, and find_package(ROCM ... HINTS "${rocm-cmake_SOURCE_DIR}") fails with "ROCMConfig.cmake ... not found" even though the file is on disk.

Hit this in chipStar CI (PR #1442, build-and-test-libraries) once a build dir got reconfigured after an interrupted prior run left _deps/rocm-cmake-src populated but never reached find_package to cache ROCM_DIR.

FetchContent_Populate is already idempotent across configures (stamp-file gated), which is why it's safe to call unconditionally; removing the redundant outer guard restores that. Keeps FetchContent_Populate rather than FetchContent_MakeAvailable, matching d340aa2's reason for that choice (keeps rocm-cmake's own tests out of this project's CTest).

Verified in isolation with a minimal FetchContent+find_package repro using the same structure: fails on a second configure with the old guard when the first configure only got as far as populating (simulating an interrupted run), succeeds with it removed.

… already being absent

rocm-cmake_SOURCE_DIR is a plain CMake variable, set only when
FetchContent_Populate actually runs. It does not persist between separate
`cmake` invocations the way a cache entry does. The `if(NOT EXISTS
"${FETCHCONTENT_BASE_DIR}/rocm-cmake-src")` guard added in d340aa2 wrapped
the whole Declare/GetProperties/Populate block, so on any configure of a
build tree where rocm-cmake had already been fetched by an earlier
invocation, that guard evaluated false, Populate never ran, and
rocm-cmake_SOURCE_DIR came back empty -- causing find_package(ROCM ...
HINTS "${rocm-cmake_SOURCE_DIR}") to fail with "ROCMConfig.cmake ... The
file was not found", even though it was sitting on disk right where the
earlier fetch had put it.

This was invisible as long as every build started from a wiped build
directory, but hits immediately once anything reconfigures an existing
tree -- in practice, a build interrupted (job cancelled, runner restarted)
after the fetch but before find_package ever ran and cached ROCM_DIR:
the next configure of that same tree has _deps/rocm-cmake-src on disk and
no cached ROCM_DIR to short-circuit past the bug.

FetchContent_Populate is already idempotent across configures on its own
(it consults a stamp file under the subbuild dir and skips the network
fetch when it is already there), which is the whole reason it is safe to
call unconditionally every configure; the outer guard here was redundant
with that and broke the one thing Populate is relied on to still do even
on a no-op call: setting rocm-cmake_SOURCE_DIR for the current process.
Keeping FetchContent_Populate (not switching to FetchContent_MakeAvailable)
per d340aa2, which chose it specifically to keep rocm-cmake's own test
suite out of this project's CTest.

Verified in isolation: a minimal FetchContent+find_package pair using this
exact structure fails on a second configure of a tree whose first
configure only ran the FetchContent half (simulating an interrupted first
run) with the old guard, and succeeds with it removed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant