Skip to content

Commit aa388b7

Browse files
committed
fix: propagate HDF5_DIR from Chrono config
The early find_package(HDF5 CONFIG QUIET) before find_package(Chrono) was writing HDF5_DIR-NOTFOUND into the CMake cache. Chrono's config then failed to overwrite it, so the later REQUIRED find also failed. Fix: extract HDF5_DIR from chrono-config.cmake in build.ps1 and pass it on the cmake command line (same pattern as Eigen3). Also fix the detection regex to match CHRONO_HDF5_AVAILABLE set to 1 (not just ON/TRUE).
1 parent f66ed12 commit aa388b7

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,16 @@ find_package(Chrono
188188
CONFIG REQUIRED
189189
COMPONENTS Parsers)
190190

191+
# If the early HDF5 find failed but Chrono has now set HDF5_DIR, retry.
192+
# The early find may have cached HDF5_DIR-NOTFOUND, blocking Chrono's
193+
# non-FORCE cache set. Clear it and retry with the Chrono-provided path.
194+
if(NOT HDF5_FOUND AND DEFINED CACHE{HDF5_DIR})
195+
if("${HDF5_DIR}" MATCHES "NOTFOUND")
196+
unset(HDF5_DIR CACHE)
197+
find_package(HDF5 CONFIG QUIET)
198+
endif()
199+
endif()
200+
191201
message(STATUS "----\n")
192202

193203
message(STATUS "Chrono targets: ${CHRONO_TARGETS}")

build.ps1

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ $chronoContent = Get-Content $chronoConfig -Raw
140140
# Auto-detect available modules
141141
$hasIrrlicht = $chronoContent -match 'Chrono_IRRLICHT_AVAILABLE\s+ON'
142142
$hasVSG = $chronoContent -match 'Chrono_VSG_AVAILABLE\s+ON'
143-
$hasHDF5 = $chronoContent -match 'CHRONO_HDF5_AVAILABLE\s+TRUE'
143+
$hasHDF5 = $chronoContent -match 'CHRONO_HDF5_AVAILABLE\s+(ON|TRUE|1)'
144144

145145
# Enable features by default if Chrono has them (unless user disabled)
146146
$useIrrlicht = $hasIrrlicht -and (-not $NoIrrlicht)
@@ -151,7 +151,7 @@ Write-Detail "VSG: $(if($hasVSG){if($useVSG){'ON'}else{'OFF (disabled)'}}else{'n
151151
Write-Detail "HDF5: $(if($hasHDF5){'available'}else{'not available'})"
152152

153153
if (-not $hasHDF5) {
154-
Write-Warn "Chrono built without HDF5 - build may fail"
154+
Write-Warn "Chrono built without HDF5 - HydroChrono requires HDF5 for .h5 data loading"
155155
}
156156

157157
# Eigen3: extract include path from Chrono config so FindEigen3.cmake can
@@ -177,6 +177,19 @@ if (-not $eigen3Include -and $chronoContent -match 'EIGEN3_INCLUDE_DIR\s+"([^"]+
177177
}
178178
}
179179

180+
# HDF5: extract HDF5_DIR from Chrono config so CMake can find the vcpkg
181+
# (or other non-system) HDF5 installation before the early pre-load step.
182+
$hdf5Dir = $null
183+
if ($chronoContent -match 'HDF5_DIR\s+"([^"]+)"' -and $Matches[1] -notmatch 'NOTFOUND') {
184+
$candidate = $Matches[1]
185+
if (Test-Path (Join-Path $candidate "hdf5-config.cmake")) {
186+
$hdf5Dir = $candidate
187+
Write-OK "HDF5: $hdf5Dir"
188+
} else {
189+
Write-Warn "HDF5 config not found at $candidate"
190+
}
191+
}
192+
180193
# =============================================================================
181194
# Check CMake
182195
# =============================================================================
@@ -238,6 +251,11 @@ if ($eigen3Include) {
238251
$cmakeArgs += "-DEIGEN3_INCLUDE_DIR=`"$($eigen3Include -replace '\\','/')`""
239252
}
240253

254+
# Add HDF5 config path if extracted from Chrono config
255+
if ($hdf5Dir) {
256+
$cmakeArgs += "-DHDF5_DIR=`"$($hdf5Dir -replace '\\','/')`""
257+
}
258+
241259
# Add Python if specified
242260
if ($PythonRoot -and (Test-Path $PythonRoot)) {
243261
$cmakeArgs += "-DPython3_ROOT_DIR=`"$($PythonRoot -replace '\\','/')`""

0 commit comments

Comments
 (0)