Unknown CMake command "python3_add_library".

Hi,

In my CMakeLists for a Python wrapper, I’ve got:

find_package(Python3 REQUIRED)
add_subdirectory(<path to pybind 11 CMakeLists>)

When calling cmake I’ve got (on CMake 3.19+, same behaviour on Linux or windows)

CMake Error at …/third_party/pybind11/tools/pybind11NewTools.cmake:189 (python3_add_library):
Unknown CMake command “python3_add_library”.

I find numerous references to this error on the net but without solution.

Regards,
A.
I’ve just stumbled on https://gitlab.kitware.com/cmake/cmake/-/issues/23133
thus I replaced find_package(Python3 REQUIRED) by

find_package(Python3 REQUIRED Development)
find_package(Python3 REQUIRED Interpreter)

which helped me going through the configuration and generation phase.
But why is it needed to require both component, omitting component is not the same as requiring all of them?
OK, from doc:
For calls where no components are specified, there is no single expected behavior and target packages should clearly define what occurs in such cases. Common arrangements include assuming it should find all components, no components or some well-defined subset of the available components.
and in FindPython3 doc
If no COMPONENTS are specified, Interpreter is assumed.

I leave the post though as I assume, from my google search, that other may have the same issue and I hope that this may be of some help.

PS I’d like to mark my own post as solution but it seems to be forbidden :yum:

Without components specified, only Interpreter is requested. Moreover, to ensure consistency between components, required all needed components at once (It is in the documentation):

find_package(Python3 REQUIRED COMPONENTS Interpreter Development)