From 5815dcbccbbb1a4e9ab6394616c22995695b57e6 Mon Sep 17 00:00:00 2001 From: Paulius Velesko Date: Fri, 7 Aug 2026 15:38:27 +0300 Subject: [PATCH] cmake: don't gate FetchContent_Populate(rocm-cmake) on the source dir 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. --- cmake/Dependencies.cmake | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index 5a5106922..20a045519 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -180,17 +180,28 @@ if(NOT DEPENDENCIES_FORCE_DOWNLOAD) set(CMAKE_FIND_DEBUG_MODE FALSE) endif() if(NOT ROCM_FOUND) - if(NOT EXISTS "${FETCHCONTENT_BASE_DIR}/rocm-cmake-src") - message(STATUS "ROCm CMake not found. Fetching...") - set(rocm_cmake_tag "master" CACHE STRING "rocm-cmake tag to download") - FetchContent_Declare( - rocm-cmake - URL https://github.com/RadeonOpenCompute/rocm-cmake/archive/${rocm_cmake_tag}.tar.gz - ) - FetchContent_GetProperties(rocm-cmake) - if(NOT rocm-cmake_POPULATED) - FetchContent_Populate(rocm-cmake) - endif() + message(STATUS "ROCm CMake not found. Fetching...") + set(rocm_cmake_tag "master" CACHE STRING "rocm-cmake tag to download") + FetchContent_Declare( + rocm-cmake + URL https://github.com/RadeonOpenCompute/rocm-cmake/archive/${rocm_cmake_tag}.tar.gz + ) + # FetchContent_Populate is idempotent on its own: it skips the network + # fetch once _deps/rocm-cmake-subbuild's stamp file shows it already ran, + # but it still sets rocm-cmake_SOURCE_DIR for this process every time, + # since that is a plain variable, not a cache entry, and does not survive + # between separate `cmake` invocations. Do not re-add the + # `if(NOT EXISTS "${FETCHCONTENT_BASE_DIR}/rocm-cmake-src")` guard this + # used to have: it gated the whole block, including + # FetchContent_Populate, on the source dir already being absent, so on a + # configure of a build tree where rocm-cmake had already been fetched by + # an earlier run, rocm-cmake_SOURCE_DIR came back empty here and + # find_package below failed with "ROCMConfig.cmake ... not found" even + # though the file was sitting on disk exactly where FetchContent had left + # it. + FetchContent_GetProperties(rocm-cmake) + if(NOT rocm-cmake_POPULATED) + FetchContent_Populate(rocm-cmake) endif() find_package(ROCM CONFIG REQUIRED NO_DEFAULT_PATH HINTS "${rocm-cmake_SOURCE_DIR}") else()