55# All rights reserved. Use of this source code is governed by a
66# BSD-style license that can be found in the LICENSE file.
77
8- cmake_minimum_required (VERSION 3.4 )
8+ # Propagate this policy (FindPythonInterp removal) so it can be detected later
9+ if (NOT CMAKE_VERSION VERSION_LESS "3.27" )
10+ cmake_policy (GET CMP0148 _pybind11_cmp0148 )
11+ endif ()
12+
13+ cmake_minimum_required (VERSION 3.5 )
914
10- # The `cmake_minimum_required(VERSION 3.4 ...3.22 )` syntax does not work with
15+ # The `cmake_minimum_required(VERSION 3.5 ...3.29 )` syntax does not work with
1116# some versions of VS that have a patched CMake 3.11. This forces us to emulate
1217# the behavior using the following workaround:
13- if (${CMAKE_VERSION} VERSION_LESS 3.22 )
18+ if (${CMAKE_VERSION} VERSION_LESS 3.29 )
1419 cmake_policy (VERSION ${CMAKE_MAJOR_VERSION} .${CMAKE_MINOR_VERSION} )
1520else ()
16- cmake_policy (VERSION 3.22 )
21+ cmake_policy (VERSION 3.29 )
22+ endif ()
23+
24+ if (_pybind11_cmp0148)
25+ cmake_policy (SET CMP0148 ${_pybind11_cmp0148} )
26+ unset (_pybind11_cmp0148)
1727endif ()
1828
1929# Avoid infinite recursion if tests include this as a subdirectory
@@ -82,42 +92,71 @@ if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
8292 set (pybind11_system "" )
8393
8494 set_property (GLOBAL PROPERTY USE_FOLDERS ON )
95+ if (CMAKE_VERSION VERSION_LESS "3.18" )
96+ set (_pybind11_findpython_default OFF )
97+ else ()
98+ set (_pybind11_findpython_default ON )
99+ endif ()
85100else ()
86101 set (PYBIND11_MASTER_PROJECT OFF )
87102 set (pybind11_system SYSTEM)
103+ set (_pybind11_findpython_default OFF )
88104endif ()
89105
90106# Options
91107option (PYBIND11_INSTALL "Install pybind11 header files?" ${PYBIND11_MASTER_PROJECT} )
92108option (PYBIND11_TEST "Build pybind11 test suite?" ${PYBIND11_MASTER_PROJECT} )
93109option (PYBIND11_NOPYTHON "Disable search for Python" OFF )
110+ option (PYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION
111+ "To enforce that a handle_type_name<> specialization exists" OFF )
94112option (PYBIND11_SIMPLE_GIL_MANAGEMENT
95113 "Use simpler GIL management logic that does not support disassociation" OFF )
114+ option (PYBIND11_NUMPY_1_ONLY
115+ "Disable NumPy 2 support to avoid changes to previous pybind11 versions." OFF )
96116set (PYBIND11_INTERNALS_VERSION
97117 ""
98118 CACHE STRING "Override the ABI version, may be used to enable the unstable ABI." )
119+ option (PYBIND11_USE_CROSSCOMPILING "Respect CMAKE_CROSSCOMPILING" OFF )
99120
121+ if (PYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION)
122+ add_compile_definitions (PYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION )
123+ endif ()
100124if (PYBIND11_SIMPLE_GIL_MANAGEMENT)
101125 add_compile_definitions (PYBIND11_SIMPLE_GIL_MANAGEMENT )
102126endif ()
127+ if (PYBIND11_NUMPY_1_ONLY)
128+ add_compile_definitions (PYBIND11_NUMPY_1_ONLY )
129+ endif ()
103130
104131cmake_dependent_option (
105132 USE_PYTHON_INCLUDE_DIR
106133 "Install pybind11 headers in Python include directory instead of default installation prefix"
107134 OFF "PYBIND11_INSTALL" OFF )
108135
109- cmake_dependent_option (PYBIND11_FINDPYTHON "Force new FindPython" OFF
136+ cmake_dependent_option (PYBIND11_FINDPYTHON "Force new FindPython" ${_pybind11_findpython_default}
110137 "NOT CMAKE_VERSION VERSION_LESS 3.12" OFF )
111138
139+ # Allow PYTHON_EXECUTABLE if in FINDPYTHON mode and building pybind11's tests
140+ # (makes transition easier while we support both modes).
141+ if (PYBIND11_MASTER_PROJECT
142+ AND PYBIND11_FINDPYTHON
143+ AND DEFINED PYTHON_EXECUTABLE
144+ AND NOT DEFINED Python_EXECUTABLE)
145+ set (Python_EXECUTABLE "${PYTHON_EXECUTABLE} " )
146+ endif ()
147+
112148# NB: when adding a header don't forget to also add it to setup.py
113149set (PYBIND11_HEADERS
114150 include/pybind11/detail/class.h
115151 include/pybind11/detail/common.h
152+ include/pybind11/detail/cpp_conduit.h
116153 include/pybind11/detail/descr.h
117154 include/pybind11/detail/init.h
118155 include/pybind11/detail/internals.h
119156 include/pybind11/detail/type_caster_base.h
120157 include/pybind11/detail/typeid.h
158+ include/pybind11/detail/value_and_holder.h
159+ include/pybind11/detail/exception_translation.h
121160 include/pybind11/attr.h
122161 include/pybind11/buffer_info.h
123162 include/pybind11/cast.h
@@ -126,11 +165,13 @@ set(PYBIND11_HEADERS
126165 include/pybind11/complex.h
127166 include/pybind11/options.h
128167 include/pybind11/eigen.h
168+ include/pybind11/eigen/common.h
129169 include/pybind11/eigen/matrix.h
130170 include/pybind11/eigen/tensor.h
131171 include/pybind11/embed.h
132172 include/pybind11/eval.h
133173 include/pybind11/gil.h
174+ include/pybind11/gil_safe_call_once.h
134175 include/pybind11/iostream.h
135176 include/pybind11/functional.h
136177 include/pybind11/numpy.h
@@ -139,7 +180,9 @@ set(PYBIND11_HEADERS
139180 include/pybind11/pytypes.h
140181 include/pybind11/stl.h
141182 include/pybind11/stl_bind.h
142- include/pybind11/stl/filesystem.h)
183+ include/pybind11/stl/filesystem.h
184+ include/pybind11/type_caster_pyobject_ptr.h
185+ include/pybind11/typing.h)
143186
144187# Compare with grep and warn if mismatched
145188if (PYBIND11_MASTER_PROJECT AND NOT CMAKE_VERSION VERSION_LESS 3.12)
@@ -260,6 +303,7 @@ if(PYBIND11_INSTALL)
260303 tools/pybind11Common.cmake
261304 tools/pybind11Tools.cmake
262305 tools/pybind11NewTools.cmake
306+ tools/pybind11GuessPythonExtSuffix.cmake
263307 DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR} )
264308
265309 if (NOT PYBIND11_EXPORT_NAME)
@@ -275,7 +319,21 @@ if(PYBIND11_INSTALL)
275319
276320 # pkg-config support
277321 if (NOT prefix_for_pc_file)
278- set (prefix_for_pc_file "${CMAKE_INSTALL_PREFIX} " )
322+ if (IS_ABSOLUTE "${CMAKE_INSTALL_DATAROOTDIR} " )
323+ set (prefix_for_pc_file "${CMAKE_INSTALL_PREFIX} " )
324+ else ()
325+ set (pc_datarootdir "${CMAKE_INSTALL_DATAROOTDIR} " )
326+ if (CMAKE_VERSION VERSION_LESS 3.20)
327+ set (prefix_for_pc_file "\$ {pcfiledir}/.." )
328+ while (pc_datarootdir)
329+ get_filename_component (pc_datarootdir "${pc_datarootdir} " DIRECTORY )
330+ string (APPEND prefix_for_pc_file "/.." )
331+ endwhile ()
332+ else ()
333+ cmake_path (RELATIVE_PATH CMAKE_INSTALL_PREFIX BASE_DIRECTORY CMAKE_INSTALL_DATAROOTDIR
334+ OUTPUT_VARIABLE prefix_for_pc_file )
335+ endif ()
336+ endif ()
279337 endif ()
280338 join_paths (includedir_for_pc_file "\$ {prefix}" "${CMAKE_INSTALL_INCLUDEDIR} " )
281339 configure_file ("${CMAKE_CURRENT_SOURCE_DIR} /tools/pybind11.pc.in"
0 commit comments