Skip to content

Commit 1f4c829

Browse files
committed
Fix cross-machine build: HDF5 target conflict and Eigen3 detection
1 parent 3f9cf91 commit 1f4c829

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

CMakeLists.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ if(NOT Chrono_DIR)
168168
return()
169169
endif()
170170

171+
# Pre-load HDF5 targets so the shims below are only created when genuinely
172+
# needed (i.e., when HDF5 config-mode doesn't provide hdf5_tools).
173+
# Without this, installers that define all HDF5 targets as a batch
174+
# (e.g., HDF Group installer) error out on the partial pre-definition.
175+
find_package(HDF5 CONFIG QUIET)
176+
171177
# Chrono's export file may reference hdf5::hdf5_tools-{shared,static} which is
172178
# absent from some HDF5 installations (e.g., vcpkg). Provide empty shims so
173179
# ChronoTargets.cmake loads without errors. Must be created BEFORE find_package(Chrono).
@@ -250,9 +256,8 @@ endif()
250256
find_package(OpenMP REQUIRED COMPONENTS CXX)
251257

252258
# -- HDF5 Integration --
253-
# Prefer config-mode (vcpkg, official HDF5 installer). Fall back to CMake's
254-
# built-in FindHDF5 module for system-installed packages (apt, yum, brew, etc.).
255-
find_package(HDF5 CONFIG QUIET)
259+
# Config-mode discovery runs early (before Chrono) to avoid target conflicts
260+
# with the hdf5_tools shims. Fall back to module-mode here if it wasn't found.
256261
if(NOT HDF5_FOUND)
257262
find_package(HDF5 REQUIRED COMPONENTS CXX)
258263
endif()

build.ps1

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ if (-not $hasHDF5) {
154154
# Eigen3: extract include path from Chrono config so FindEigen3.cmake can
155155
# bypass Eigen3ConfigVersion.cmake (Eigen 5.x rejects the "3.3" request).
156156
$eigen3Include = $null
157-
if ($chronoContent -match 'Eigen3_DIR\s+"([^"]+)"') {
157+
if ($chronoContent -match 'Eigen3_DIR\s+"([^"]+)"' -and $Matches[1] -notmatch 'NOTFOUND') {
158158
$eigen3Root = Split-Path (Split-Path $Matches[1])
159159
$candidate = Join-Path $eigen3Root "include/eigen3"
160160
if (Test-Path (Join-Path $candidate "Eigen")) {
@@ -164,6 +164,15 @@ if ($chronoContent -match 'Eigen3_DIR\s+"([^"]+)"') {
164164
Write-Warn "Eigen3 headers not found at $candidate"
165165
}
166166
}
167+
if (-not $eigen3Include -and $chronoContent -match 'EIGEN3_INCLUDE_DIR\s+"([^"]+)"' -and $Matches[1] -notmatch 'NOTFOUND') {
168+
$candidate = $Matches[1]
169+
if (Test-Path (Join-Path $candidate "Eigen")) {
170+
$eigen3Include = $candidate
171+
Write-OK "Eigen3: $eigen3Include (via EIGEN3_INCLUDE_DIR)"
172+
} else {
173+
Write-Warn "Eigen3 headers not found at $candidate"
174+
}
175+
}
167176

168177
# =============================================================================
169178
# Check CMake

0 commit comments

Comments
 (0)