Skip to content

Commit 054ddc1

Browse files
author
Dominic Price
committed
Update pybind to latest version
1 parent 9e98183 commit 054ddc1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3367
-1515
lines changed

libs/pybind11/CMakeLists.txt

Lines changed: 227 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -5,153 +5,262 @@
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 2.8.12)
8+
cmake_minimum_required(VERSION 3.4)
99

10-
if (POLICY CMP0048)
11-
# cmake warns if loaded from a min-3.0-required parent dir, so silence the warning:
12-
cmake_policy(SET CMP0048 NEW)
10+
# The `cmake_minimum_required(VERSION 3.4...3.18)` syntax does not work with
11+
# some versions of VS that have a patched CMake 3.11. This forces us to emulate
12+
# the behavior using the following workaround:
13+
if(${CMAKE_VERSION} VERSION_LESS 3.18)
14+
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
15+
else()
16+
cmake_policy(VERSION 3.18)
1317
endif()
1418

15-
# CMake versions < 3.4.0 do not support try_compile/pthread checks without C as active language.
16-
if(CMAKE_VERSION VERSION_LESS 3.4.0)
17-
project(pybind11)
18-
else()
19-
project(pybind11 CXX)
19+
# Extract project version from source
20+
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/include/pybind11/detail/common.h"
21+
pybind11_version_defines REGEX "#define PYBIND11_VERSION_(MAJOR|MINOR|PATCH) ")
22+
23+
foreach(ver ${pybind11_version_defines})
24+
if(ver MATCHES [[#define PYBIND11_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$]])
25+
set(PYBIND11_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}")
26+
endif()
27+
endforeach()
28+
29+
if(PYBIND11_VERSION_PATCH MATCHES [[\.([a-zA-Z0-9]+)$]])
30+
set(pybind11_VERSION_TYPE "${CMAKE_MATCH_1}")
31+
endif()
32+
string(REGEX MATCH "^[0-9]+" PYBIND11_VERSION_PATCH "${PYBIND11_VERSION_PATCH}")
33+
34+
project(
35+
pybind11
36+
LANGUAGES CXX
37+
VERSION "${PYBIND11_VERSION_MAJOR}.${PYBIND11_VERSION_MINOR}.${PYBIND11_VERSION_PATCH}")
38+
39+
# Standard includes
40+
include(GNUInstallDirs)
41+
include(CMakePackageConfigHelpers)
42+
include(CMakeDependentOption)
43+
44+
if(NOT pybind11_FIND_QUIETLY)
45+
message(STATUS "pybind11 v${pybind11_VERSION} ${pybind11_VERSION_TYPE}")
2046
endif()
2147

2248
# Check if pybind11 is being used directly or via add_subdirectory
23-
set(PYBIND11_MASTER_PROJECT OFF)
24-
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
49+
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
50+
### Warn if not an out-of-source builds
51+
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
52+
set(lines
53+
"You are building in-place. If that is not what you intended to "
54+
"do, you can clean the source directory with:\n"
55+
"rm -r CMakeCache.txt CMakeFiles/ cmake_uninstall.cmake pybind11Config.cmake "
56+
"pybind11ConfigVersion.cmake tests/CMakeFiles/\n")
57+
message(AUTHOR_WARNING ${lines})
58+
endif()
59+
2560
set(PYBIND11_MASTER_PROJECT ON)
61+
62+
if(OSX AND CMAKE_VERSION VERSION_LESS 3.7)
63+
# Bug in macOS CMake < 3.7 is unable to download catch
64+
message(WARNING "CMAKE 3.7+ needed on macOS to download catch, and newer HIGHLY recommended")
65+
elseif(WINDOWS AND CMAKE_VERSION VERSION_LESS 3.8)
66+
# Only tested with 3.8+ in CI.
67+
message(WARNING "CMAKE 3.8+ tested on Windows, previous versions untested")
68+
endif()
69+
70+
message(STATUS "CMake ${CMAKE_VERSION}")
71+
72+
if(CMAKE_CXX_STANDARD)
73+
set(CMAKE_CXX_EXTENSIONS OFF)
74+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
75+
endif()
76+
else()
77+
set(PYBIND11_MASTER_PROJECT OFF)
78+
set(pybind11_system SYSTEM)
2679
endif()
2780

81+
# Options
2882
option(PYBIND11_INSTALL "Install pybind11 header files?" ${PYBIND11_MASTER_PROJECT})
29-
option(PYBIND11_TEST "Build pybind11 test suite?" ${PYBIND11_MASTER_PROJECT})
83+
option(PYBIND11_TEST "Build pybind11 test suite?" ${PYBIND11_MASTER_PROJECT})
84+
option(PYBIND11_NOPYTHON "Disable search for Python" OFF)
3085

31-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/tools")
86+
cmake_dependent_option(
87+
USE_PYTHON_INCLUDE_DIR
88+
"Install pybind11 headers in Python include directory instead of default installation prefix"
89+
OFF "PYBIND11_INSTALL" OFF)
3290

33-
include(pybind11Tools)
34-
35-
# Cache variables so pybind11_add_module can be used in parent projects
36-
set(PYBIND11_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/include" CACHE INTERNAL "")
37-
set(PYTHON_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS} CACHE INTERNAL "")
38-
set(PYTHON_LIBRARIES ${PYTHON_LIBRARIES} CACHE INTERNAL "")
39-
set(PYTHON_MODULE_PREFIX ${PYTHON_MODULE_PREFIX} CACHE INTERNAL "")
40-
set(PYTHON_MODULE_EXTENSION ${PYTHON_MODULE_EXTENSION} CACHE INTERNAL "")
41-
set(PYTHON_VERSION_MAJOR ${PYTHON_VERSION_MAJOR} CACHE INTERNAL "")
42-
set(PYTHON_VERSION_MINOR ${PYTHON_VERSION_MINOR} CACHE INTERNAL "")
91+
cmake_dependent_option(PYBIND11_FINDPYTHON "Force new FindPython" OFF
92+
"NOT CMAKE_VERSION VERSION_LESS 3.12" OFF)
4393

4494
# NB: when adding a header don't forget to also add it to setup.py
4595
set(PYBIND11_HEADERS
46-
include/pybind11/detail/class.h
47-
include/pybind11/detail/common.h
48-
include/pybind11/detail/descr.h
49-
include/pybind11/detail/init.h
50-
include/pybind11/detail/internals.h
51-
include/pybind11/detail/typeid.h
52-
include/pybind11/attr.h
53-
include/pybind11/buffer_info.h
54-
include/pybind11/cast.h
55-
include/pybind11/chrono.h
56-
include/pybind11/common.h
57-
include/pybind11/complex.h
58-
include/pybind11/options.h
59-
include/pybind11/eigen.h
60-
include/pybind11/embed.h
61-
include/pybind11/eval.h
62-
include/pybind11/functional.h
63-
include/pybind11/numpy.h
64-
include/pybind11/operators.h
65-
include/pybind11/pybind11.h
66-
include/pybind11/pytypes.h
67-
include/pybind11/stl.h
68-
include/pybind11/stl_bind.h
69-
)
70-
string(REPLACE "include/" "${CMAKE_CURRENT_SOURCE_DIR}/include/"
71-
PYBIND11_HEADERS "${PYBIND11_HEADERS}")
72-
73-
if (PYBIND11_TEST)
74-
add_subdirectory(tests)
96+
include/pybind11/detail/class.h
97+
include/pybind11/detail/common.h
98+
include/pybind11/detail/descr.h
99+
include/pybind11/detail/init.h
100+
include/pybind11/detail/internals.h
101+
include/pybind11/detail/typeid.h
102+
include/pybind11/attr.h
103+
include/pybind11/buffer_info.h
104+
include/pybind11/cast.h
105+
include/pybind11/chrono.h
106+
include/pybind11/common.h
107+
include/pybind11/complex.h
108+
include/pybind11/options.h
109+
include/pybind11/eigen.h
110+
include/pybind11/embed.h
111+
include/pybind11/eval.h
112+
include/pybind11/iostream.h
113+
include/pybind11/functional.h
114+
include/pybind11/numpy.h
115+
include/pybind11/operators.h
116+
include/pybind11/pybind11.h
117+
include/pybind11/pytypes.h
118+
include/pybind11/stl.h
119+
include/pybind11/stl_bind.h)
120+
121+
# Compare with grep and warn if mismatched
122+
if(PYBIND11_MASTER_PROJECT AND NOT CMAKE_VERSION VERSION_LESS 3.12)
123+
file(
124+
GLOB_RECURSE _pybind11_header_check
125+
LIST_DIRECTORIES false
126+
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
127+
CONFIGURE_DEPENDS "include/pybind11/*.h")
128+
set(_pybind11_here_only ${PYBIND11_HEADERS})
129+
set(_pybind11_disk_only ${_pybind11_header_check})
130+
list(REMOVE_ITEM _pybind11_here_only ${_pybind11_header_check})
131+
list(REMOVE_ITEM _pybind11_disk_only ${PYBIND11_HEADERS})
132+
if(_pybind11_here_only)
133+
message(AUTHOR_WARNING "PYBIND11_HEADERS has extra files:" ${_pybind11_here_only})
134+
endif()
135+
if(_pybind11_disk_only)
136+
message(AUTHOR_WARNING "PYBIND11_HEADERS is missing files:" ${_pybind11_disk_only})
137+
endif()
75138
endif()
76139

77-
include(GNUInstallDirs)
78-
include(CMakePackageConfigHelpers)
140+
# CMake 3.12 added list(TRANSFORM <list> PREPEND
141+
# But we can't use it yet
142+
string(REPLACE "include/" "${CMAKE_CURRENT_SOURCE_DIR}/include/" PYBIND11_HEADERS
143+
"${PYBIND11_HEADERS}")
79144

80-
# extract project version from source
81-
file(STRINGS "${PYBIND11_INCLUDE_DIR}/pybind11/detail/common.h" pybind11_version_defines
82-
REGEX "#define PYBIND11_VERSION_(MAJOR|MINOR|PATCH) ")
83-
foreach(ver ${pybind11_version_defines})
84-
if (ver MATCHES "#define PYBIND11_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$")
85-
set(PYBIND11_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "")
86-
endif()
87-
endforeach()
88-
set(${PROJECT_NAME}_VERSION ${PYBIND11_VERSION_MAJOR}.${PYBIND11_VERSION_MINOR}.${PYBIND11_VERSION_PATCH})
89-
message(STATUS "pybind11 v${${PROJECT_NAME}_VERSION}")
145+
# Cache variables so pybind11_add_module can be used in parent projects
146+
set(PYBIND11_INCLUDE_DIR
147+
"${CMAKE_CURRENT_LIST_DIR}/include"
148+
CACHE INTERNAL "")
149+
150+
# Note: when creating targets, you cannot use if statements at configure time -
151+
# you need generator expressions, because those will be placed in the target file.
152+
# You can also place ifs *in* the Config.in, but not here.
153+
154+
# This section builds targets, but does *not* touch Python
90155

91-
option (USE_PYTHON_INCLUDE_DIR "Install pybind11 headers in Python include directory instead of default installation prefix" OFF)
92-
if (USE_PYTHON_INCLUDE_DIR)
93-
file(RELATIVE_PATH CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX} ${PYTHON_INCLUDE_DIRS})
156+
# Build the headers-only target (no Python included):
157+
# (long name used here to keep this from clashing in subdirectory mode)
158+
add_library(pybind11_headers INTERFACE)
159+
add_library(pybind11::pybind11_headers ALIAS pybind11_headers) # to match exported target
160+
add_library(pybind11::headers ALIAS pybind11_headers) # easier to use/remember
161+
162+
include("${CMAKE_CURRENT_SOURCE_DIR}/tools/pybind11Common.cmake")
163+
164+
# Relative directory setting
165+
if(USE_PYTHON_INCLUDE_DIR AND DEFINED Python_INCLUDE_DIRS)
166+
file(RELATIVE_PATH CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX} ${Python_INCLUDE_DIRS})
167+
elseif(USE_PYTHON_INCLUDE_DIR AND DEFINED PYTHON_INCLUDE_DIR)
168+
file(RELATIVE_PATH CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX} ${PYTHON_INCLUDE_DIRS})
94169
endif()
95170

96-
if(NOT (CMAKE_VERSION VERSION_LESS 3.0)) # CMake >= 3.0
97-
# Build an interface library target:
98-
add_library(pybind11 INTERFACE)
99-
add_library(pybind11::pybind11 ALIAS pybind11) # to match exported target
100-
target_include_directories(pybind11 INTERFACE $<BUILD_INTERFACE:${PYBIND11_INCLUDE_DIR}>
101-
$<BUILD_INTERFACE:${PYTHON_INCLUDE_DIRS}>
171+
# Fill in headers target
172+
target_include_directories(
173+
pybind11_headers ${pybind11_system} INTERFACE $<BUILD_INTERFACE:${PYBIND11_INCLUDE_DIR}>
102174
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
103-
target_compile_options(pybind11 INTERFACE $<BUILD_INTERFACE:${PYBIND11_CPP_STANDARD}>)
104175

105-
add_library(module INTERFACE)
106-
add_library(pybind11::module ALIAS module)
107-
if(NOT MSVC)
108-
target_compile_options(module INTERFACE -fvisibility=hidden)
176+
target_compile_features(pybind11_headers INTERFACE cxx_inheriting_constructors cxx_user_literals
177+
cxx_right_angle_brackets)
178+
179+
if(PYBIND11_INSTALL)
180+
install(DIRECTORY ${PYBIND11_INCLUDE_DIR}/pybind11 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
181+
set(PYBIND11_CMAKECONFIG_INSTALL_DIR
182+
"${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}"
183+
CACHE STRING "install path for pybind11Config.cmake")
184+
185+
configure_package_config_file(
186+
tools/${PROJECT_NAME}Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
187+
INSTALL_DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR})
188+
189+
if(CMAKE_VERSION VERSION_LESS 3.14)
190+
# Remove CMAKE_SIZEOF_VOID_P from ConfigVersion.cmake since the library does
191+
# not depend on architecture specific settings or libraries.
192+
set(_PYBIND11_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
193+
unset(CMAKE_SIZEOF_VOID_P)
194+
195+
write_basic_package_version_file(
196+
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
197+
VERSION ${PROJECT_VERSION}
198+
COMPATIBILITY AnyNewerVersion)
199+
200+
set(CMAKE_SIZEOF_VOID_P ${_PYBIND11_CMAKE_SIZEOF_VOID_P})
201+
else()
202+
# CMake 3.14+ natively supports header-only libraries
203+
write_basic_package_version_file(
204+
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
205+
VERSION ${PROJECT_VERSION}
206+
COMPATIBILITY AnyNewerVersion ARCH_INDEPENDENT)
109207
endif()
110-
target_link_libraries(module INTERFACE pybind11::pybind11)
111-
if(WIN32 OR CYGWIN)
112-
target_link_libraries(module INTERFACE $<BUILD_INTERFACE:${PYTHON_LIBRARIES}>)
113-
elseif(APPLE)
114-
target_link_libraries(module INTERFACE "-undefined dynamic_lookup")
208+
209+
install(
210+
FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
211+
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
212+
tools/FindPythonLibsNew.cmake
213+
tools/pybind11Common.cmake
214+
tools/pybind11Tools.cmake
215+
tools/pybind11NewTools.cmake
216+
DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR})
217+
218+
if(NOT PYBIND11_EXPORT_NAME)
219+
set(PYBIND11_EXPORT_NAME "${PROJECT_NAME}Targets")
115220
endif()
116221

117-
add_library(embed INTERFACE)
118-
add_library(pybind11::embed ALIAS embed)
119-
target_link_libraries(embed INTERFACE pybind11::pybind11 $<BUILD_INTERFACE:${PYTHON_LIBRARIES}>)
222+
install(TARGETS pybind11_headers EXPORT "${PYBIND11_EXPORT_NAME}")
223+
224+
install(
225+
EXPORT "${PYBIND11_EXPORT_NAME}"
226+
NAMESPACE "pybind11::"
227+
DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR})
228+
229+
# Uninstall target
230+
if(PYBIND11_MASTER_PROJECT)
231+
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake_uninstall.cmake.in"
232+
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY)
233+
234+
add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P
235+
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
236+
endif()
120237
endif()
121238

122-
if (PYBIND11_INSTALL)
123-
install(DIRECTORY ${PYBIND11_INCLUDE_DIR}/pybind11 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
124-
# GNUInstallDirs "DATADIR" wrong here; CMake search path wants "share".
125-
set(PYBIND11_CMAKECONFIG_INSTALL_DIR "share/cmake/${PROJECT_NAME}" CACHE STRING "install path for pybind11Config.cmake")
126-
127-
configure_package_config_file(tools/${PROJECT_NAME}Config.cmake.in
128-
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
129-
INSTALL_DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR})
130-
# Remove CMAKE_SIZEOF_VOID_P from ConfigVersion.cmake since the library does
131-
# not depend on architecture specific settings or libraries.
132-
set(_PYBIND11_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
133-
unset(CMAKE_SIZEOF_VOID_P)
134-
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
135-
VERSION ${${PROJECT_NAME}_VERSION}
136-
COMPATIBILITY AnyNewerVersion)
137-
set(CMAKE_SIZEOF_VOID_P ${_PYBIND11_CMAKE_SIZEOF_VOID_P})
138-
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
139-
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
140-
tools/FindPythonLibsNew.cmake
141-
tools/pybind11Tools.cmake
142-
DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR})
143-
144-
if(NOT (CMAKE_VERSION VERSION_LESS 3.0))
145-
if(NOT PYBIND11_EXPORT_NAME)
146-
set(PYBIND11_EXPORT_NAME "${PROJECT_NAME}Targets")
239+
# BUILD_TESTING takes priority, but only if this is the master project
240+
if(PYBIND11_MASTER_PROJECT AND DEFINED BUILD_TESTING)
241+
if(BUILD_TESTING)
242+
if(_pybind11_nopython)
243+
message(FATAL_ERROR "Cannot activate tests in NOPYTHON mode")
244+
else()
245+
add_subdirectory(tests)
147246
endif()
148-
149-
install(TARGETS pybind11 module embed
150-
EXPORT "${PYBIND11_EXPORT_NAME}")
151-
if(PYBIND11_MASTER_PROJECT)
152-
install(EXPORT "${PYBIND11_EXPORT_NAME}"
153-
NAMESPACE "${PROJECT_NAME}::"
154-
DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR})
247+
endif()
248+
else()
249+
if(PYBIND11_TEST)
250+
if(_pybind11_nopython)
251+
message(FATAL_ERROR "Cannot activate tests in NOPYTHON mode")
252+
else()
253+
add_subdirectory(tests)
155254
endif()
156255
endif()
157256
endif()
257+
258+
# Better symmetry with find_package(pybind11 CONFIG) mode.
259+
if(NOT PYBIND11_MASTER_PROJECT)
260+
set(pybind11_FOUND
261+
TRUE
262+
CACHE INTERNAL "true if pybind11 and all required components found on the system")
263+
set(pybind11_INCLUDE_DIR
264+
"${PYBIND11_INCLUDE_DIR}"
265+
CACHE INTERNAL "Directory where pybind11 headers are located")
266+
endif()

libs/pybind11/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2525
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2626
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2727

28-
Please also refer to the file CONTRIBUTING.md, which clarifies licensing of
28+
Please also refer to the file .github/CONTRIBUTING.md, which clarifies licensing of
2929
external contributions to this project including patches, pull requests, etc.

0 commit comments

Comments
 (0)