Skip to content

Commit dbda0b1

Browse files
committed
fix(cmake): correct Eigen source dir and Catch2 deprecation error
FetchContent lowercases the declared name, so the populated source directory is eigen3_SOURCE_DIR. EIGEN3_INCLUDE_DIR was set from the empty eigen_SOURCE_DIR, and the Eigen tests could not find Eigen/Core. Catch2 2.13.10 asks for compatibility with CMake < 3.10. CMake 4 makes this a deprecation warning, which -Werror=dev turns into an error and stops the configure step. CMAKE_WARN_DEPRECATED cannot suppress it because CMP0218 ignores that variable, so raise the policy floor for the subproject instead. Also set CATCH_VERSION, which all the Catch status messages report. Assisted-by: ClaudeCode:claude-opus-5
1 parent 0e95794 commit dbda0b1

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

tests/CMakeLists.txt

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -310,15 +310,14 @@ if(PYBIND11_EIGEN_TESTS AND PYBIND11_TEST_FILES_EIGEN_I GREATER -1)
310310
GIT_TAG "${PYBIND11_EIGEN_VERSION_HASH}"
311311
${_opts})
312312
FetchContent_MakeAvailable(Eigen3)
313-
if(NOT CMAKE_VERSION VERSION_LESS 3.18)
314-
set(EIGEN3_INCLUDE_DIR "${eigen_SOURCE_DIR}")
315-
endif()
316-
317-
set(EIGEN3_INCLUDE_DIR ${eigen_SOURCE_DIR})
318313
set(EIGEN3_FOUND TRUE)
319-
# When getting locally, the version is not visible from a superprojet,
320-
# so just force it.
321-
set(EIGEN3_VERSION "${PYBIND11_EIGEN_VERSION_STRING}")
314+
if(eigen3_SOURCE_DIR)
315+
# Fetched, not found: no config file supplies the target or the version
316+
set(EIGEN3_INCLUDE_DIR "${eigen3_SOURCE_DIR}")
317+
set(EIGEN3_VERSION "${PYBIND11_EIGEN_VERSION_STRING}")
318+
else()
319+
set(EIGEN3_VERSION "${Eigen3_VERSION}")
320+
endif()
322321

323322
else()
324323
find_package(Eigen3 3.2.7 QUIET CONFIG)
@@ -395,15 +394,23 @@ if(PYBIND11_CATCH_TESTS)
395394
GIT_REPOSITORY "${PYBIND11_CATCH_REPO}"
396395
GIT_TAG "${PYBIND11_CATCH_VERSION_HASH}"
397396
${_opts})
397+
# Catch2 2.x asks for compatibility with CMake < 3.10. That is deprecated and
398+
# becomes fatal under -Werror=dev, so raise the floor for the subproject.
399+
# CMake 3.31+ honors this; earlier versions do not give the warning.
400+
set(CMAKE_POLICY_VERSION_MINIMUM 3.10)
398401
FetchContent_MakeAvailable(Catch2)
399-
# Fetchcontent-ed branch does not set CATCH_VERSION
402+
unset(CMAKE_POLICY_VERSION_MINIMUM)
403+
# Fetchcontent-ed branch does not set the version
400404
if(NOT Catch2_VERSION)
401-
set(Catch2_VERSION ${PYBIND11_CATCH_VERSION_STRING})
405+
string(REGEX REPLACE "^v" "" Catch2_VERSION "${PYBIND11_CATCH_VERSION_STRING}")
402406
endif()
403407
else()
404408
find_package(Catch2 2.13.10 REQUIRED)
405409
endif()
406410

411+
# The test subdirectories report this too
412+
set(CATCH_VERSION "${Catch2_VERSION}")
413+
407414
message(STATUS "Building interpreter tests using Catch v${CATCH_VERSION}")
408415
endif()
409416

0 commit comments

Comments
 (0)