File tree Expand file tree Collapse file tree 4 files changed +33
-6
lines changed Expand file tree Collapse file tree 4 files changed +33
-6
lines changed Original file line number Diff line number Diff line change @@ -52,17 +52,17 @@ jobs:
5252 - runs-on : ubuntu-20.04
5353 python : ' 3.8'
5454 args : >
55- -DPYBIND11_FINDPYTHON=ON
55+ -DPYBIND11_FINDPYTHON=OFF
5656 -DCMAKE_CXX_FLAGS="-D_=1"
5757 exercise_D_ : 1
5858 - runs-on : ubuntu-20.04
5959 python : ' pypy-3.8'
6060 args : >
61- -DPYBIND11_FINDPYTHON=ON
61+ -DPYBIND11_FINDPYTHON=OFF
6262 - runs-on : windows-2019
6363 python : ' 3.8'
6464 args : >
65- -DPYBIND11_FINDPYTHON=ON
65+ -DPYBIND11_FINDPYTHON=OFF
6666 # Inject a couple Windows 2019 runs
6767 - runs-on : windows-2019
6868 python : ' 3.9'
Original file line number Diff line number Diff line change @@ -81,7 +81,7 @@ if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
8181else ()
8282 set (PYBIND11_MASTER_PROJECT OFF )
8383 set (pybind11_system SYSTEM )
84- set (_pybind11_findpython_default OFF )
84+ set (_pybind11_findpython_default COMPAT )
8585endif ()
8686
8787# Options
@@ -114,7 +114,9 @@ cmake_dependent_option(
114114 "Install pybind11 headers in Python include directory instead of default installation prefix"
115115 OFF "PYBIND11_INSTALL" OFF )
116116
117- option (PYBIND11_FINDPYTHON "Force new FindPython" ${_pybind11_findpython_default} )
117+ set (PYBIND11_FINDPYTHON
118+ ${_pybind11_findpython_default}
119+ CACHE STRING "Force new FindPython - NEW, OLD, COMPAT" )
118120
119121# Allow PYTHON_EXECUTABLE if in FINDPYTHON mode and building pybind11's tests
120122# (makes transition easier while we support both modes).
Original file line number Diff line number Diff line change @@ -192,7 +192,25 @@ elseif(
192192 ))
193193
194194 # New mode
195- include ("${CMAKE_CURRENT_LIST_DIR} /pybind11NewTools.cmake" )
195+ if (Python_FOUND OR Python3_FOUND)
196+ include ("${CMAKE_CURRENT_LIST_DIR} /pybind11NewTools.cmake" )
197+ else ()
198+ include ("${CMAKE_CURRENT_LIST_DIR} /pybind11NewTools.cmake" )
199+
200+ message (
201+ "Using compatibility mode for Python, set PYBIND11_FINDPYTHON to NEW/OLD to silence this message"
202+ )
203+ set (PYTHON_EXECUTABLE "${Python_EXECUTABLE} " )
204+ set (PYTHON_INCLUDE_DIR "${Python_INCLUDE_DIR} " )
205+ set (Python_INCLUDE_DIRS "${Python_INCLUDE_DIRS} " )
206+ set (PYTHON_LIBRARY "${Python_LIRARY} " )
207+ set (PYTHON_LIBRARIES "${Python_LIRARIES} " )
208+ set (PYTHON_VERSION "${Python_VERSION} " )
209+ set (PYTHON_VERSION_STRING "${Python_VERSION_STRING} " )
210+ set (PYTHON_VERSION_MAJOR "${Python_VERSION_MAJOR} " )
211+ set (PYTHON_VERSION_MINOR "${Python_VERSION_MINOR} " )
212+ set (PYTHON_VERSION_PATCH "${Python_VERSION_PATCH} " )
213+ endif ()
196214
197215else ()
198216
Original file line number Diff line number Diff line change @@ -67,6 +67,13 @@ from 3.12+ forward (3.15+ _highly_ recommended). If you set the minimum or
6767maximum version of CMake to 3.27+, then FindPython is the default (since
6868FindPythonInterp/FindPythonLibs has been removed via policy `CMP0148`).
6969
70+ Starting in pybind11 3.0, the new mode is the default, but we provide backward
71+ compatible names (`PYTHON_*` vs. the new `Python_* names). Set the mode
72+ explicitly to avoid the compatibility defines. You can specify this mode
73+ explicitly by setting `PYBIND11_FINDPYTHON` to `COMPAT`, but if you are changing
74+ your CMakeLists anyway, please just use the `ON` mode. A future release may
75+ default to `ON`.
76+
7077New FindPython mode
7178^^^^^^^^^^^^^^^^^^^
7279
You can’t perform that action at this time.
0 commit comments