Skip to content

Commit

Permalink
Use a single find_package(Python3) call
Browse files Browse the repository at this point in the history
  • Loading branch information
tttapa committed May 7, 2022
1 parent 49b2ec2 commit 77823eb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
3 changes: 1 addition & 2 deletions docs/Debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ In your CMakeLists.txt script, add a macro that defines the `MODULE_NAME` as the
base name of the extension module (which includes the `_d` suffix):

```cmake
Python3_add_library(_add_module MODULE "src/add_module.cpp")
target_link_libraries(_add_module PRIVATE pybind11::pybind11)
pybind11_add_module(_add_module MODULE "src/add_module.cpp")
target_compile_definitions(_add_module PRIVATE
MODULE_NAME=$<TARGET_FILE_BASE_NAME:_add_module>)
```
Expand Down
8 changes: 4 additions & 4 deletions docs/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ etc.

Even when using Setuptools, it's best to avoid `setup.py` if you can, and to use
declarative configuration files like `setup.cfg` and `pyproject.toml` instead.
From the [setuptools quickstart guide](https://setuptools.pypa.io/en/latest/userguide/quickstart.html):
From the [Setuptools quickstart guide](https://setuptools.pypa.io/en/latest/userguide/quickstart.html):

> The landscape of Python packaging is shifting and `Setuptools` has evolved to
> only provide backend support, no longer being the de-facto packaging tool in
Expand Down Expand Up @@ -45,7 +45,7 @@ You can enable py-build-cmake's verbose mode to make it print information about
the configuration, the exact subprocesses it invokes, the configure and build
environments, and so on.

When using a tool like PyPA `build`, you can use the `-C` option to pass the
When using a tool like PyPA `build`, you can use the `-C` flag to pass the
`verbose` option:
```sh
python -m build . -C verbose
Expand All @@ -56,14 +56,14 @@ can set the environment variable `PY_BUILD_CMAKE_VERBOSE`:
```sh
PY_BUILD_CMAKE_VERBOSE=1 pip install . -v # Linux/macOS
```
```ps1
```sh
$Env:PY_BUILD_CMAKE_VERBOSE=1 # Windows
pip install . -v
Remove-Item Env:PY_BUILD_CMAKE_VERBOSE
```
Also note the `-v` flag to get pip to print the build output.

When inspecting the output, beware that output of subprocesses is often much
When inspecting the output, be aware that output of subprocesses is often much
higher up than the final error message or backtrace. For example, if you get an
error saying that the invocation of CMake failed, you'll have to scroll up to
see the actual CMake output.
Expand Down
5 changes: 2 additions & 3 deletions examples/pybind11-project/cmake/QueryPythonForPybind11.cmake
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# First tries to find Python 3, then tries to import the pybind11 module to
# query the CMake config location, and finally imports pybind11 using
# find_package(pybind11).
# find_package(pybind11 REQUIRED CONFIG).
function(find_pybind11_python_first)

# Query Python to see if it knows where the headers are
find_package(Python3 REQUIRED COMPONENTS Interpreter)
find_package(Python3 COMPONENTS Development)
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
if (NOT pybind11_ROOT OR NOT EXISTS ${pybind11_ROOT})
execute_process(COMMAND ${Python3_EXECUTABLE}
-m pybind11 --cmakedir
Expand Down

0 comments on commit 77823eb

Please sign in to comment.