Skip to content

Commit a18c10f

Browse files
authored
fix(cmake): make library component optional (#4805)
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
1 parent 3aece81 commit a18c10f

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

tools/pybind11NewTools.cmake

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,22 @@ if(NOT Python_FOUND AND NOT Python3_FOUND)
3232
set(Python_ROOT_DIR "$ENV{pythonLocation}")
3333
endif()
3434

35-
find_package(Python 3.6 REQUIRED COMPONENTS Interpreter Development ${_pybind11_quiet})
35+
# Development.Module support (required for manylinux) started in 3.18
36+
if(CMAKE_VERSION VERSION_LESS 3.18)
37+
set(_pybind11_dev_component Development)
38+
else()
39+
set(_pybind11_dev_component Development.Module OPTIONAL_COMPONENTS Development.Embed)
40+
endif()
41+
42+
find_package(Python 3.6 REQUIRED COMPONENTS Interpreter ${_pybind11_dev_component}
43+
${_pybind11_quiet})
3644

3745
# If we are in submodule mode, export the Python targets to global targets.
3846
# If this behavior is not desired, FindPython _before_ pybind11.
3947
if(NOT is_config)
40-
set_property(TARGET Python::Python PROPERTY IMPORTED_GLOBAL TRUE)
48+
if(TARGET Python::Python)
49+
set_property(TARGET Python::Python PROPERTY IMPORTED_GLOBAL TRUE)
50+
endif()
4151
set_property(TARGET Python::Interpreter PROPERTY IMPORTED_GLOBAL TRUE)
4252
if(TARGET Python::Module)
4353
set_property(TARGET Python::Module PROPERTY IMPORTED_GLOBAL TRUE)

0 commit comments

Comments
 (0)