Skip to content

Commit 1b880df

Browse files
committed
ci: download EIGEN
1 parent 9521bc5 commit 1b880df

File tree

3 files changed

+41
-13
lines changed

3 files changed

+41
-13
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ jobs:
8080
cmake -S . -B build
8181
-DPYBIND11_WERROR=ON
8282
-DDOWNLOAD_CATCH=ON
83+
-DDOWNLOAD_EIGEN=ON
8384
-DCMAKE_CXX_STANDARD=11
8485
-DPYTHON_EXECUTABLE=$(python -c "import sys; print(sys.executable)")
8586
@@ -101,6 +102,7 @@ jobs:
101102
cmake -S . -B build17
102103
-DPYBIND17_WERROR=ON
103104
-DDOWNLOAD_CATCH=ON
105+
-DDOWNLOAD_EIGEN=ON
104106
-DCMAKE_CXX_STANDARD=17
105107
-DPYTHON_EXECUTABLE=$(python -c "import sys; print(sys.executable)")
106108
@@ -138,7 +140,7 @@ jobs:
138140
- uses: actions/checkout@v2
139141

140142
- name: Add wget and python3
141-
run: apt-get update && apt-get install -y python3-dev python3-numpy python3-pytest
143+
run: apt-get update && apt-get install -y python3-dev python3-numpy python3-pytest libeigen3-dev
142144

143145
- name: Configure
144146
shell: bash

tests/CMakeLists.txt

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ set(PYBIND11_CROSS_MODULE_GIL_TESTS
9797
test_gil_scoped.py
9898
)
9999

100+
option(DOWNLOAD_EIGEN "Download EIGEN (requires CMake 3.11+)" OFF)
101+
100102
# Check if Eigen is available; if not, remove from PYBIND11_TEST_FILES (but
101103
# keep it in PYBIND11_PYTEST_FILES, so that we get the "eigen is not installed"
102104
# skip message).
@@ -105,18 +107,42 @@ if(PYBIND11_TEST_FILES_EIGEN_I GREATER -1)
105107
# Try loading via newer Eigen's Eigen3Config first (bypassing tools/FindEigen3.cmake).
106108
# Eigen 3.3.1+ exports a cmake 3.0+ target for handling dependency requirements, but also
107109
# produces a fatal error if loaded from a pre-3.0 cmake.
108-
if (NOT CMAKE_VERSION VERSION_LESS 3.0)
109-
find_package(Eigen3 3.2.7 QUIET CONFIG)
110-
if (EIGEN3_FOUND)
111-
if (EIGEN3_VERSION_STRING AND NOT EIGEN3_VERSION_STRING VERSION_LESS 3.3.1)
112-
set(PYBIND11_EIGEN_VIA_TARGET 1)
110+
if(DOWNLOAD_EIGEN)
111+
if(CMAKE_VERSION VERSION_LESS 3.11)
112+
message(FATAL_ERROR "CMake 3.11+ required when using DOWNLOAD_EIGEN")
113+
endif()
114+
115+
set(EIGEN3_VERSION_STRING "3.3.7")
116+
117+
include(FetchContent)
118+
FetchContent_Declare(
119+
eigen
120+
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
121+
GIT_TAG ${EIGEN3_VERSION_STRING}
122+
)
123+
124+
FetchContent_GetProperties(eigen)
125+
if(NOT eigen_POPULATED)
126+
message(STATUS "Downloading Eigen")
127+
FetchContent_Populate(eigen)
128+
endif()
129+
130+
set(EIGEN3_INCLUDE_DIR ${eigen_SOURCE_DIR})
131+
set(EIGEN3_FOUND TRUE)
132+
else()
133+
if (NOT CMAKE_VERSION VERSION_LESS 3.0)
134+
find_package(Eigen3 3.2.7 QUIET CONFIG)
135+
if (EIGEN3_FOUND)
136+
if (EIGEN3_VERSION_STRING AND NOT EIGEN3_VERSION_STRING VERSION_LESS 3.3.1)
137+
set(PYBIND11_EIGEN_VIA_TARGET TRUE)
138+
endif()
113139
endif()
114140
endif()
115-
endif()
116-
if (NOT EIGEN3_FOUND)
117-
# Couldn't load via target, so fall back to allowing module mode finding, which will pick up
118-
# tools/FindEigen3.cmake
119-
find_package(Eigen3 3.2.7 QUIET)
141+
if (NOT EIGEN3_FOUND)
142+
# Couldn't load via target, so fall back to allowing module mode finding, which will pick up
143+
# tools/FindEigen3.cmake
144+
find_package(Eigen3 3.2.7 QUIET)
145+
endif()
120146
endif()
121147

122148
if(EIGEN3_FOUND)
@@ -129,7 +155,7 @@ if(PYBIND11_TEST_FILES_EIGEN_I GREATER -1)
129155
message(STATUS "Building tests with Eigen v${EIGEN3_VERSION}")
130156
else()
131157
list(REMOVE_AT PYBIND11_TEST_FILES ${PYBIND11_TEST_FILES_EIGEN_I})
132-
message(STATUS "Building tests WITHOUT Eigen")
158+
message(STATUS "Building tests WITHOUT Eigen, use -DDOWNLOAD_EIGEN on CMake 3.11+ to download")
133159
endif()
134160
endif()
135161

tests/test_embed/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if(CATCH_FOUND)
99
message(STATUS "Building interpreter tests using Catch v${CATCH_VERSION}")
1010
else()
1111
message(STATUS "Catch not detected. Interpreter tests will be skipped. Install Catch headers"
12-
" manually or use `cmake -DDOWNLOAD_CATCH=1` to fetch them automatically.")
12+
" manually or use `cmake -DDOWNLOAD_CATCH=ON` to fetch them automatically.")
1313
return()
1414
endif()
1515

0 commit comments

Comments
 (0)