build: support Eigen 5 (#6036)
* build: support Eigen 5
fix #6034
* build: probe Eigen 3 and 5 separately in CMake config mode
Avoid relying on package-specific handling of a bounded version range when discovering Eigen through Eigen3Config.cmake.
Made-with: Cursor
* [skip ci] build: clarify Eigen 5 module fallback comment
Explain that the MODULE-mode fallback only exists for older Eigen 3 setups so the remaining fallback path does not look like an unresolved Eigen 5 issue.
Made-with: Cursor
* [skip ci] docs: add Eigen 5 entry to v3.0.4 changelog
Document the Eigen 5 CMake package detection fix in the 3.0.4 release notes before merging the PR.
Made-with: Cursor
---------
Co-authored-by: Eisuke Kawashima <e-kwsm@users.noreply.github.com>
Co-authored-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com>
diff --git a/docs/changelog.md b/docs/changelog.md
index d752f1f..9c624ef 100644
--- a/docs/changelog.md
+++ b/docs/changelog.md
@@ -33,6 +33,9 @@
Bug fixes:
+- Fixed test builds with installed Eigen 5 by improving `Eigen3` CMake package detection.
+ [#6036](https://github.com/pybind/pybind11/pull/6036)
+
- Fixed move semantics of `scoped_ostream_redirect` to preserve buffered output and avoid crashes when moved redirects restore stream buffers.
[#6033](https://github.com/pybind/pybind11/pull/6033)
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index d5d597c..fc08a90 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -300,10 +300,17 @@
else()
find_package(Eigen3 3.2.7 QUIET CONFIG)
+ if(NOT Eigen3_FOUND)
+ find_package(Eigen3 5 QUIET CONFIG)
+ endif()
+ set(EIGEN3_FOUND ${Eigen3_FOUND})
+ set(EIGEN3_VERSION ${Eigen3_VERSION})
if(NOT EIGEN3_FOUND)
# Couldn't load via target, so fall back to allowing module mode finding, which will pick up
# tools/FindEigen3.cmake
+ # This MODULE-mode fallback is for older Eigen 3 setups; Eigen 5 is expected to be found
+ # via the CONFIG-mode probes above.
find_package(Eigen3 3.2.7 QUIET)
endif()
endif()