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.27 )` 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.27 )
1419  cmake_policy (VERSION  ${CMAKE_MAJOR_VERSION} .${CMAKE_MINOR_VERSION} )
1520else ()
16-   cmake_policy (VERSION  3.22)
21+   cmake_policy (VERSION  3.27)
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,27 +92,58 @@ 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 )
112+ option (PYBIND11_SIMPLE_GIL_MANAGEMENT
113+        "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 )
94116set (PYBIND11_INTERNALS_VERSION
95117    "" 
96118    CACHE  STRING  "Override the ABI version, may be used to enable the unstable ABI." )
97119
120+ if (PYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION)
121+   add_compile_definitions (PYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION)
122+ endif ()
123+ if (PYBIND11_SIMPLE_GIL_MANAGEMENT)
124+   add_compile_definitions (PYBIND11_SIMPLE_GIL_MANAGEMENT)
125+ endif ()
126+ if (PYBIND11_NUMPY_1_ONLY)
127+   add_compile_definitions (PYBIND11_NUMPY_1_ONLY)
128+ endif ()
129+ 
98130cmake_dependent_option(
99131  USE_PYTHON_INCLUDE_DIR
100132  "Install pybind11 headers in Python include directory instead of default installation prefix" 
101133  OFF  "PYBIND11_INSTALL"  OFF )
102134
103- cmake_dependent_option(PYBIND11_FINDPYTHON "Force new FindPython"  OFF 
135+ cmake_dependent_option(PYBIND11_FINDPYTHON "Force new FindPython"  ${_pybind11_findpython_default} 
104136                       "NOT CMAKE_VERSION VERSION_LESS 3.12"  OFF )
105137
138+ # Allow PYTHON_EXECUTABLE if in FINDPYTHON mode and building pybind11's tests 
139+ # (makes transition easier while we support both modes). 
140+ if (PYBIND11_MASTER_PROJECT
141+    AND  PYBIND11_FINDPYTHON
142+    AND  DEFINED  PYTHON_EXECUTABLE
143+    AND  NOT  DEFINED  Python_EXECUTABLE)
144+   set (Python_EXECUTABLE "${PYTHON_EXECUTABLE} " )
145+ endif ()
146+ 
106147# NB: when adding a header don't forget to also add it to setup.py 
107148set (PYBIND11_HEADERS
108149    include /pybind11/detail/class.h
@@ -120,9 +161,13 @@ set(PYBIND11_HEADERS
120161    include /pybind11/complex.h
121162    include /pybind11/options .h
122163    include /pybind11/eigen.h
164+     include /pybind11/eigen/common.h
165+     include /pybind11/eigen/matrix.h
166+     include /pybind11/eigen/tensor.h
123167    include /pybind11/embed.h
124168    include /pybind11/eval.h
125169    include /pybind11/gil.h
170+     include /pybind11/gil_safe_call_once.h
126171    include /pybind11/iostream.h
127172    include /pybind11/functional.h
128173    include /pybind11/numpy.h
@@ -131,7 +176,9 @@ set(PYBIND11_HEADERS
131176    include /pybind11/pytypes.h
132177    include /pybind11/stl.h
133178    include /pybind11/stl_bind.h
134-     include /pybind11/stl/filesystem.h)
179+     include /pybind11/stl/filesystem.h
180+     include /pybind11/type_caster_pyobject_ptr.h
181+     include /pybind11/typing.h)
135182
136183# Compare with grep and warn if mismatched 
137184if (PYBIND11_MASTER_PROJECT AND  NOT  CMAKE_VERSION  VERSION_LESS  3.12)
@@ -198,6 +245,9 @@ else()
198245endif ()
199246
200247include ("${CMAKE_CURRENT_SOURCE_DIR} /tools/pybind11Common.cmake" )
248+ # https://github.com/jtojnar/cmake-snips/#concatenating-paths-when-building-pkg-config-files 
249+ # TODO: cmake 3.20 adds the cmake_path() function, which obsoletes this snippet 
250+ include ("${CMAKE_CURRENT_SOURCE_DIR} /tools/JoinPaths.cmake" )
201251
202252# Relative directory setting 
203253if (USE_PYTHON_INCLUDE_DIR AND  DEFINED  Python_INCLUDE_DIRS)
@@ -262,6 +312,30 @@ if(PYBIND11_INSTALL)
262312    NAMESPACE "pybind11::" 
263313    DESTINATION  ${PYBIND11_CMAKECONFIG_INSTALL_DIR} )
264314
315+   # pkg-config support 
316+   if (NOT  prefix_for_pc_file)
317+     if (IS_ABSOLUTE  "${CMAKE_INSTALL_DATAROOTDIR} " )
318+       set (prefix_for_pc_file "${CMAKE_INSTALL_PREFIX} " )
319+     else ()
320+       set (pc_datarootdir "${CMAKE_INSTALL_DATAROOTDIR} " )
321+       if (CMAKE_VERSION  VERSION_LESS  3.20)
322+         set (prefix_for_pc_file "\$ {pcfiledir}/.." )
323+         while (pc_datarootdir)
324+           get_filename_component (pc_datarootdir "${pc_datarootdir} "  DIRECTORY )
325+           string (APPEND  prefix_for_pc_file "/.." )
326+         endwhile ()
327+       else ()
328+         cmake_path(RELATIVE_PATH CMAKE_INSTALL_PREFIX  BASE_DIRECTORY CMAKE_INSTALL_DATAROOTDIR
329+                    OUTPUT_VARIABLE  prefix_for_pc_file)
330+       endif ()
331+     endif ()
332+   endif ()
333+   join_paths(includedir_for_pc_file "\$ {prefix}"  "${CMAKE_INSTALL_INCLUDEDIR} " )
334+   configure_file ("${CMAKE_CURRENT_SOURCE_DIR} /tools/pybind11.pc.in" 
335+                  "${CMAKE_CURRENT_BINARY_DIR} /pybind11.pc"  @ONLY)
336+   install (FILES  "${CMAKE_CURRENT_BINARY_DIR} /pybind11.pc" 
337+           DESTINATION  "${CMAKE_INSTALL_DATAROOTDIR} /pkgconfig/" )
338+ 
265339  # Uninstall target 
266340  if (PYBIND11_MASTER_PROJECT)
267341    configure_file ("${CMAKE_CURRENT_SOURCE_DIR} /tools/cmake_uninstall.cmake.in" 
0 commit comments