Skip to content

Commit 6d72785

Browse files
Teach pybind11 to find NumPy as a component
1 parent 9d0f3df commit 6d72785

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

tools/pybind11Config.cmake.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,14 @@ set(${PN}_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_INCLUDEDIR@")
5959
set(${PN}_LIBRARY "")
6060
set(${PN}_DEFINITIONS USING_${PN})
6161

62-
check_required_components(${PN})
63-
6462
# make detectable the FindPythonLibsNew.cmake module
6563
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
6664

6765
include(pybind11Tools)
6866

67+
# Check for required components (note: found by pybind11Tools)
68+
check_required_components(${PN})
69+
6970
if(NOT (CMAKE_VERSION VERSION_LESS 3.0))
7071
#-----------------------------------------------------------------------------
7172
# Don't include targets if this file is being picked up by another

tools/pybind11Tools.cmake

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,23 @@ endif()
1414

1515
set(Python_ADDITIONAL_VERSIONS 3.7 3.6 3.5 3.4)
1616
find_package(PythonLibsNew ${PYBIND11_PYTHON_VERSION} REQUIRED)
17-
find_package(NumPy)
17+
if(pybind11_FIND_QUIETLY)
18+
set(_pybind_find_quiet QUIET)
19+
else()
20+
set(_pybind_find_quiet)
21+
endif()
22+
if(pybind11_FIND_COMPONENTS MATCHES NumPy)
23+
if(pybind11_FIND_REQUIRED AND pybind11_FIND_REQUIRED_NumPy)
24+
find_package(NumPy ${_pybind_find_quiet} REQUIRED)
25+
else()
26+
find_package(NumPy ${_pybind_find_quiet})
27+
if(pybind11_FIND_REQUIRED_NumPy AND NOT NumPy_FOUND)
28+
set(pybind11_NOT_FOUND_MESSAGE "pybind11 could not be found because required component NumPy could not be found.")
29+
set(pybind11_FOUND False)
30+
endif()
31+
endif()
32+
set(pybind11_NumPy_FOUND ${NumPy_FOUND})
33+
endif()
1834

1935
include(CheckCXXCompilerFlag)
2036
include(CMakeParseArguments)

0 commit comments

Comments
 (0)