Merge branch 'master' into sh_merge_master

This commit is contained in:
Ralf W. Grosse-Kunstleve 2024-08-14 22:34:20 -07:00
commit 205da0d7c1
25 changed files with 261 additions and 316 deletions

View File

@ -81,7 +81,7 @@ nox -s build
### Full setup ### Full setup
To setup an ideal development environment, run the following commands on a To setup an ideal development environment, run the following commands on a
system with CMake 3.14+: system with CMake 3.15+:
```bash ```bash
python3 -m venv venv python3 -m venv venv
@ -96,8 +96,8 @@ Tips:
* You can use `virtualenv` (faster, from PyPI) instead of `venv`. * You can use `virtualenv` (faster, from PyPI) instead of `venv`.
* You can select any name for your environment folder; if it contains "env" it * You can select any name for your environment folder; if it contains "env" it
will be ignored by git. will be ignored by git.
* If you don't have CMake 3.14+, just add "cmake" to the pip install command. * If you don't have CMake 3.15+, just add "cmake" to the pip install command.
* You can use `-DPYBIND11_FINDPYTHON=ON` to use FindPython on CMake 3.12+ * You can use `-DPYBIND11_FINDPYTHON=ON` to use FindPython.
* In classic mode, you may need to set `-DPYTHON_EXECUTABLE=/path/to/python`. * In classic mode, you may need to set `-DPYTHON_EXECUTABLE=/path/to/python`.
FindPython uses `-DPython_ROOT_DIR=/path/to` or FindPython uses `-DPython_ROOT_DIR=/path/to` or
`-DPython_EXECUTABLE=/path/to/python`. `-DPython_EXECUTABLE=/path/to/python`.
@ -149,8 +149,8 @@ To run the tests, you can "build" the check target:
cmake --build build --target check cmake --build build --target check
``` ```
`--target` can be spelled `-t` in CMake 3.15+. You can also run individual `--target` can be spelled `-t`. You can also run individual tests with these
tests with these targets: targets:
* `pytest`: Python tests only, using the * `pytest`: Python tests only, using the
[pytest](https://docs.pytest.org/en/stable/) framework [pytest](https://docs.pytest.org/en/stable/) framework

View File

@ -32,7 +32,7 @@ jobs:
include: include:
- runs-on: ubuntu-20.04 - runs-on: ubuntu-20.04
arch: x64 arch: x64
cmake: "3.5" cmake: "3.15"
- runs-on: ubuntu-20.04 - runs-on: ubuntu-20.04
arch: x64 arch: x64
@ -40,7 +40,7 @@ jobs:
- runs-on: macos-13 - runs-on: macos-13
arch: x64 arch: x64
cmake: "3.8" cmake: "3.15"
- runs-on: windows-2019 - runs-on: windows-2019
arch: x64 # x86 compilers seem to be missing on 2019 image arch: x64 # x86 compilers seem to be missing on 2019 image

View File

@ -10,16 +10,7 @@ if(NOT CMAKE_VERSION VERSION_LESS "3.27")
cmake_policy(GET CMP0148 _pybind11_cmp0148) cmake_policy(GET CMP0148 _pybind11_cmp0148)
endif() endif()
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.15...3.30)
# The `cmake_minimum_required(VERSION 3.5...3.29)` syntax does not work with
# some versions of VS that have a patched CMake 3.11. This forces us to emulate
# the behavior using the following workaround:
if(${CMAKE_VERSION} VERSION_LESS 3.29)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
else()
cmake_policy(VERSION 3.29)
endif()
if(_pybind11_cmp0148) if(_pybind11_cmp0148)
cmake_policy(SET CMP0148 ${_pybind11_cmp0148}) cmake_policy(SET CMP0148 ${_pybind11_cmp0148})
@ -27,9 +18,7 @@ if(_pybind11_cmp0148)
endif() endif()
# Avoid infinite recursion if tests include this as a subdirectory # Avoid infinite recursion if tests include this as a subdirectory
if(DEFINED PYBIND11_MASTER_PROJECT) include_guard(GLOBAL)
return()
endif()
# Extract project version from source # Extract project version from source
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/include/pybind11/detail/common.h" file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/include/pybind11/detail/common.h"
@ -74,14 +63,6 @@ if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
set(PYBIND11_MASTER_PROJECT ON) set(PYBIND11_MASTER_PROJECT ON)
if(OSX AND CMAKE_VERSION VERSION_LESS 3.7)
# Bug in macOS CMake < 3.7 is unable to download catch
message(WARNING "CMAKE 3.7+ needed on macOS to download catch, and newer HIGHLY recommended")
elseif(WINDOWS AND CMAKE_VERSION VERSION_LESS 3.8)
# Only tested with 3.8+ in CI.
message(WARNING "CMAKE 3.8+ tested on Windows, previous versions untested")
endif()
message(STATUS "CMake ${CMAKE_VERSION}") message(STATUS "CMake ${CMAKE_VERSION}")
if(CMAKE_CXX_STANDARD) if(CMAKE_CXX_STANDARD)
@ -133,8 +114,7 @@ cmake_dependent_option(
"Install pybind11 headers in Python include directory instead of default installation prefix" "Install pybind11 headers in Python include directory instead of default installation prefix"
OFF "PYBIND11_INSTALL" OFF) OFF "PYBIND11_INSTALL" OFF)
cmake_dependent_option(PYBIND11_FINDPYTHON "Force new FindPython" ${_pybind11_findpython_default} option(PYBIND11_FINDPYTHON "Force new FindPython" ${_pybind11_findpython_default})
"NOT CMAKE_VERSION VERSION_LESS 3.12" OFF)
# Allow PYTHON_EXECUTABLE if in FINDPYTHON mode and building pybind11's tests # Allow PYTHON_EXECUTABLE if in FINDPYTHON mode and building pybind11's tests
# (makes transition easier while we support both modes). # (makes transition easier while we support both modes).
@ -188,7 +168,7 @@ set(PYBIND11_HEADERS
include/pybind11/typing.h) include/pybind11/typing.h)
# Compare with grep and warn if mismatched # Compare with grep and warn if mismatched
if(PYBIND11_MASTER_PROJECT AND NOT CMAKE_VERSION VERSION_LESS 3.12) if(PYBIND11_MASTER_PROJECT)
file( file(
GLOB_RECURSE _pybind11_header_check GLOB_RECURSE _pybind11_header_check
LIST_DIRECTORIES false LIST_DIRECTORIES false
@ -206,10 +186,7 @@ if(PYBIND11_MASTER_PROJECT AND NOT CMAKE_VERSION VERSION_LESS 3.12)
endif() endif()
endif() endif()
# CMake 3.12 added list(TRANSFORM <list> PREPEND list(TRANSFORM PYBIND11_HEADERS PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/")
# But we can't use it yet
string(REPLACE "include/" "${CMAKE_CURRENT_SOURCE_DIR}/include/" PYBIND11_HEADERS
"${PYBIND11_HEADERS}")
# Cache variable so this can be used in parent projects # Cache variable so this can be used in parent projects
set(pybind11_INCLUDE_DIR set(pybind11_INCLUDE_DIR
@ -279,25 +256,11 @@ if(PYBIND11_INSTALL)
tools/${PROJECT_NAME}Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" tools/${PROJECT_NAME}Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR}) INSTALL_DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR})
if(CMAKE_VERSION VERSION_LESS 3.14) # CMake natively supports header-only libraries
# Remove CMAKE_SIZEOF_VOID_P from ConfigVersion.cmake since the library does write_basic_package_version_file(
# not depend on architecture specific settings or libraries. ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
set(_PYBIND11_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P}) VERSION ${PROJECT_VERSION}
unset(CMAKE_SIZEOF_VOID_P) COMPATIBILITY AnyNewerVersion ARCH_INDEPENDENT)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion)
set(CMAKE_SIZEOF_VOID_P ${_PYBIND11_CMAKE_SIZEOF_VOID_P})
else()
# CMake 3.14+ natively supports header-only libraries
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion ARCH_INDEPENDENT)
endif()
install( install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake

View File

@ -18,7 +18,7 @@ information, see :doc:`/compiling`.
.. code-block:: cmake .. code-block:: cmake
cmake_minimum_required(VERSION 3.5...3.29) cmake_minimum_required(VERSION 3.15...3.30)
project(example) project(example)
find_package(pybind11 REQUIRED) # or `add_subdirectory(pybind11)` find_package(pybind11 REQUIRED) # or `add_subdirectory(pybind11)`

View File

@ -20,7 +20,28 @@ New Features:
* Support for Python 3.7 was removed. (Official end-of-life: 2023-06-27). * Support for Python 3.7 was removed. (Official end-of-life: 2023-06-27).
`#5191 <https://github.com/pybind/pybind11/pull/5191>`_ `#5191 <https://github.com/pybind/pybind11/pull/5191>`_
Support for CMake older than 3.15 and some older compilers will also be removed. * stl.h ``list|set|map_caster`` were made more user friendly: it is no longer
necessary to explicitly convert Python iterables to ``tuple()``, ``set()``,
or ``map()`` in many common situations.
`#4686 <https://github.com/pybind/pybind11/pull/4686>`_
* Support for CMake older than 3.15 removed. CMake 3.15-3.30 supported.
`#5304 <https://github.com/pybind/pybind11/pull/5304>`_
Version 2.13.4 (August 14, 2024)
--------------------------------
Bug fixes:
* Fix paths with spaces, including on Windows.
(Replaces regression from `#5302 <https://github.com/pybind/pybind11/pull/5302>`_)
`#4874 <https://github.com/pybind/pybind11/pull/4874>`_
Documentation:
* Remove repetitive words.
`#5308 <https://github.com/pybind/pybind11/pull/5308>`_
Version 2.13.3 (August 13, 2024) Version 2.13.3 (August 13, 2024)
-------------------------------- --------------------------------

View File

@ -18,7 +18,7 @@ A Python extension module can be created with just a few lines of code:
.. code-block:: cmake .. code-block:: cmake
cmake_minimum_required(VERSION 3.15...3.29) cmake_minimum_required(VERSION 3.15...3.30)
project(example LANGUAGES CXX) project(example LANGUAGES CXX)
set(PYBIND11_FINDPYTHON ON) set(PYBIND11_FINDPYTHON ON)
@ -319,11 +319,11 @@ Building with CMake
For C++ codebases that have an existing CMake-based build system, a Python For C++ codebases that have an existing CMake-based build system, a Python
extension module can be created with just a few lines of code, as seen above in extension module can be created with just a few lines of code, as seen above in
the module section. Pybind11 currently supports a lower minimum if you don't the module section. Pybind11 currently defaults to the old mechanism, though be
use the modern FindPython, though be aware that CMake 3.27 removed the old aware that CMake 3.27 removed the old mechanism, so pybind11 will automatically
mechanism, so pybind11 will automatically switch if the old mechanism is not switch if the old mechanism is not available. Please opt into the new mechanism
available. Please opt into the new mechanism if at all possible. Our default if at all possible. Our default may change in future versions. This is the
may change in future versions. This is the minimum required: minimum required:
@ -333,6 +333,9 @@ may change in future versions. This is the minimum required:
.. versionchanged:: 2.11 .. versionchanged:: 2.11
CMake 3.5+ is required. CMake 3.5+ is required.
.. versionchanged:: 2.14
CMake 3.15+ is required.
Further information can be found at :doc:`cmake/index`. Further information can be found at :doc:`cmake/index`.
@ -444,7 +447,7 @@ See the `Config file`_ docstring for details of relevant CMake variables.
.. code-block:: cmake .. code-block:: cmake
cmake_minimum_required(VERSION 3.4...3.18) cmake_minimum_required(VERSION 3.15...3.30)
project(example LANGUAGES CXX) project(example LANGUAGES CXX)
find_package(pybind11 REQUIRED) find_package(pybind11 REQUIRED)
@ -483,14 +486,13 @@ can refer to the same [cmake_example]_ repository for a full sample project
FindPython mode FindPython mode
--------------- ---------------
CMake 3.12+ (3.15+ recommended, 3.18.2+ ideal) added a new module called Modern CMake (3.18.2+ ideal) added a new module called FindPython that had a
FindPython that had a highly improved search algorithm and modern targets highly improved search algorithm and modern targets and tools. If you use
and tools. If you use FindPython, pybind11 will detect this and use the FindPython, pybind11 will detect this and use the existing targets instead:
existing targets instead:
.. code-block:: cmake .. code-block:: cmake
cmake_minimum_required(VERSION 3.15...3.22) cmake_minimum_required(VERSION 3.15...3.30)
project(example LANGUAGES CXX) project(example LANGUAGES CXX)
find_package(Python 3.8 COMPONENTS Interpreter Development REQUIRED) find_package(Python 3.8 COMPONENTS Interpreter Development REQUIRED)
@ -541,7 +543,7 @@ available in all modes. The targets provided are:
Just the "linking" part of pybind11:module Just the "linking" part of pybind11:module
``pybind11::module`` ``pybind11::module``
Everything for extension modules - ``pybind11::pybind11`` + ``Python::Module`` (FindPython CMake 3.15+) or ``pybind11::python_link_helper`` Everything for extension modules - ``pybind11::pybind11`` + ``Python::Module`` (FindPython) or ``pybind11::python_link_helper``
``pybind11::embed`` ``pybind11::embed``
Everything for embedding the Python interpreter - ``pybind11::pybind11`` + ``Python::Python`` (FindPython) or Python libs Everything for embedding the Python interpreter - ``pybind11::pybind11`` + ``Python::Python`` (FindPython) or Python libs
@ -568,7 +570,7 @@ You can use these targets to build complex applications. For example, the
.. code-block:: cmake .. code-block:: cmake
cmake_minimum_required(VERSION 3.5...3.29) cmake_minimum_required(VERSION 3.15...3.30)
project(example LANGUAGES CXX) project(example LANGUAGES CXX)
find_package(pybind11 REQUIRED) # or add_subdirectory(pybind11) find_package(pybind11 REQUIRED) # or add_subdirectory(pybind11)
@ -626,7 +628,7 @@ information about usage in C++, see :doc:`/advanced/embedding`.
.. code-block:: cmake .. code-block:: cmake
cmake_minimum_required(VERSION 3.5...3.29) cmake_minimum_required(VERSION 3.15...3.30)
project(example LANGUAGES CXX) project(example LANGUAGES CXX)
find_package(pybind11 REQUIRED) # or add_subdirectory(pybind11) find_package(pybind11 REQUIRED) # or add_subdirectory(pybind11)

View File

@ -258,9 +258,9 @@ CMake configure line. (Replace ``$(which python)`` with a path to python if
your prefer.) your prefer.)
You can alternatively try ``-DPYBIND11_FINDPYTHON=ON``, which will activate the You can alternatively try ``-DPYBIND11_FINDPYTHON=ON``, which will activate the
new CMake FindPython support instead of pybind11's custom search. Requires new CMake FindPython support instead of pybind11's custom search. Newer CMake,
CMake 3.12+, and 3.15+ or 3.18.2+ are even better. You can set this in your like, 3.18.2+, is recommended. You can set this in your ``CMakeLists.txt``
``CMakeLists.txt`` before adding or finding pybind11, as well. before adding or finding pybind11, as well.
Inconsistent detection of Python version in CMake and pybind11 Inconsistent detection of Python version in CMake and pybind11
============================================================== ==============================================================
@ -281,11 +281,11 @@ There are three possible solutions:
from CMake and rely on pybind11 in detecting Python version. If this is not from CMake and rely on pybind11 in detecting Python version. If this is not
possible, the CMake machinery should be called *before* including pybind11. possible, the CMake machinery should be called *before* including pybind11.
2. Set ``PYBIND11_FINDPYTHON`` to ``True`` or use ``find_package(Python 2. Set ``PYBIND11_FINDPYTHON`` to ``True`` or use ``find_package(Python
COMPONENTS Interpreter Development)`` on modern CMake (3.12+, 3.15+ better, COMPONENTS Interpreter Development)`` on modern CMake ( 3.18.2+ best).
3.18.2+ best). Pybind11 in these cases uses the new CMake FindPython instead Pybind11 in these cases uses the new CMake FindPython instead of the old,
of the old, deprecated search tools, and these modules are much better at deprecated search tools, and these modules are much better at finding the
finding the correct Python. If FindPythonLibs/Interp are not available correct Python. If FindPythonLibs/Interp are not available (CMake 3.27+),
(CMake 3.27+), then this will be ignored and FindPython will be used. then this will be ignored and FindPython will be used.
3. Set ``PYBIND11_NOPYTHON`` to ``TRUE``. Pybind11 will not search for Python. 3. Set ``PYBIND11_NOPYTHON`` to ``TRUE``. Pybind11 will not search for Python.
However, you will have to use the target-based system, and do more setup However, you will have to use the target-based system, and do more setup
yourself, because it does not know about or include things that depend on yourself, because it does not know about or include things that depend on

View File

@ -11,11 +11,14 @@
#include "pybind11.h" #include "pybind11.h"
#include "detail/common.h" #include "detail/common.h"
#include "detail/descr.h"
#include "detail/type_caster_base.h"
#include <deque> #include <deque>
#include <initializer_list> #include <initializer_list>
#include <list> #include <list>
#include <map> #include <map>
#include <memory>
#include <ostream> #include <ostream>
#include <set> #include <set>
#include <unordered_map> #include <unordered_map>
@ -349,39 +352,68 @@ struct type_caster<std::deque<Type, Alloc>> : list_caster<std::deque<Type, Alloc
template <typename Type, typename Alloc> template <typename Type, typename Alloc>
struct type_caster<std::list<Type, Alloc>> : list_caster<std::list<Type, Alloc>, Type> {}; struct type_caster<std::list<Type, Alloc>> : list_caster<std::list<Type, Alloc>, Type> {};
template <typename ArrayType, typename V, size_t... I>
ArrayType vector_to_array_impl(V &&v, index_sequence<I...>) {
return {{std::move(v[I])...}};
}
// Based on https://en.cppreference.com/w/cpp/container/array/to_array
template <typename ArrayType, size_t N, typename V>
ArrayType vector_to_array(V &&v) {
return vector_to_array_impl<ArrayType, V>(std::forward<V>(v), make_index_sequence<N>{});
}
template <typename ArrayType, typename Value, bool Resizable, size_t Size = 0> template <typename ArrayType, typename Value, bool Resizable, size_t Size = 0>
struct array_caster { struct array_caster {
using value_conv = make_caster<Value>; using value_conv = make_caster<Value>;
private: private:
template <bool R = Resizable> std::unique_ptr<ArrayType> value;
bool require_size(enable_if_t<R, size_t> size) {
if (value.size() != size) {
value.resize(size);
}
return true;
}
template <bool R = Resizable>
bool require_size(enable_if_t<!R, size_t> size) {
return size == Size;
}
template <bool R = Resizable, enable_if_t<R, int> = 0>
bool convert_elements(handle seq, bool convert) { bool convert_elements(handle seq, bool convert) {
auto l = reinterpret_borrow<sequence>(seq); auto l = reinterpret_borrow<sequence>(seq);
if (!require_size(l.size())) { value.reset(new ArrayType{});
return false; // Using `resize` to preserve the behavior exactly as it was before PR #5305
} // For the `resize` to work, `Value` must be default constructible.
// For `std::valarray`, this is a requirement:
// https://en.cppreference.com/w/cpp/named_req/NumericType
value->resize(l.size());
size_t ctr = 0; size_t ctr = 0;
for (const auto &it : l) { for (const auto &it : l) {
value_conv conv; value_conv conv;
if (!conv.load(it, convert)) { if (!conv.load(it, convert)) {
return false; return false;
} }
value[ctr++] = cast_op<Value &&>(std::move(conv)); (*value)[ctr++] = cast_op<Value &&>(std::move(conv));
} }
return true; return true;
} }
template <bool R = Resizable, enable_if_t<!R, int> = 0>
bool convert_elements(handle seq, bool convert) {
auto l = reinterpret_borrow<sequence>(seq);
if (l.size() != Size) {
return false;
}
// The `temp` storage is needed to support `Value` types that are not
// default-constructible.
// Deliberate choice: no template specializations, for simplicity, and
// because the compile time overhead for the specializations is deemed
// more significant than the runtime overhead for the `temp` storage.
std::vector<Value> temp;
temp.reserve(l.size());
for (auto it : l) {
value_conv conv;
if (!conv.load(it, convert)) {
return false;
}
temp.emplace_back(cast_op<Value &&>(std::move(conv)));
}
value.reset(new ArrayType(vector_to_array<ArrayType, Size>(std::move(temp))));
return true;
}
public: public:
bool load(handle src, bool convert) { bool load(handle src, bool convert) {
if (!PyObjectTypeIsConvertibleToStdVector(src.ptr())) { if (!PyObjectTypeIsConvertibleToStdVector(src.ptr())) {
@ -416,12 +448,36 @@ public:
return l.release(); return l.release();
} }
PYBIND11_TYPE_CASTER(ArrayType, // Code copied from PYBIND11_TYPE_CASTER macro.
const_name<Resizable>(const_name(""), const_name("Annotated[")) // Intentionally preserving the behavior exactly as it was before PR #5305
+ const_name("list[") + value_conv::name + const_name("]") template <typename T_, enable_if_t<std::is_same<ArrayType, remove_cv_t<T_>>::value, int> = 0>
+ const_name<Resizable>(const_name(""), static handle cast(T_ *src, return_value_policy policy, handle parent) {
const_name(", FixedSize(") if (!src) {
+ const_name<Size>() + const_name(")]"))); return none().release();
}
if (policy == return_value_policy::take_ownership) {
auto h = cast(std::move(*src), policy, parent);
delete src; // WARNING: Assumes `src` was allocated with `new`.
return h;
}
return cast(*src, policy, parent);
}
// NOLINTNEXTLINE(google-explicit-constructor)
operator ArrayType *() { return &(*value); }
// NOLINTNEXTLINE(google-explicit-constructor)
operator ArrayType &() { return *value; }
// NOLINTNEXTLINE(google-explicit-constructor)
operator ArrayType &&() && { return std::move(*value); }
template <typename T_>
using cast_op_type = movable_cast_op_type<T_>;
static constexpr auto name
= const_name<Resizable>(const_name(""), const_name("Annotated[")) + const_name("list[")
+ value_conv::name + const_name("]")
+ const_name<Resizable>(
const_name(""), const_name(", FixedSize(") + const_name<Size>() + const_name(")]"));
}; };
template <typename Type, size_t Size> template <typename Type, size_t Size>

View File

@ -2,13 +2,35 @@
from __future__ import annotations from __future__ import annotations
import argparse import argparse
import shlex import re
import sys import sys
import sysconfig import sysconfig
from ._version import __version__ from ._version import __version__
from .commands import get_cmake_dir, get_include, get_pkgconfig_dir from .commands import get_cmake_dir, get_include, get_pkgconfig_dir
# This is the conditional used for os.path being posixpath
if "posix" in sys.builtin_module_names:
from shlex import quote
elif "nt" in sys.builtin_module_names:
# See https://github.com/mesonbuild/meson/blob/db22551ed9d2dd7889abea01cc1c7bba02bf1c75/mesonbuild/utils/universal.py#L1092-L1121
# and the original documents:
# https://docs.microsoft.com/en-us/cpp/c-language/parsing-c-command-line-arguments and
# https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/
UNSAFE = re.compile("[ \t\n\r]")
def quote(s: str) -> str:
if s and not UNSAFE.search(s):
return s
# Paths cannot contain a '"' on Windows, so we don't need to worry
# about nuanced counting here.
return f'"{s}\\"' if s.endswith("\\") else f'"{s}"'
else:
def quote(s: str) -> str:
return s
def print_includes() -> None: def print_includes() -> None:
dirs = [ dirs = [
@ -23,7 +45,7 @@ def print_includes() -> None:
if d and d not in unique_dirs: if d and d not in unique_dirs:
unique_dirs.append(d) unique_dirs.append(d)
print(" ".join(shlex.quote(f"-I{d}") for d in unique_dirs)) print(" ".join(quote(f"-I{d}") for d in unique_dirs))
def main() -> None: def main() -> None:
@ -55,9 +77,9 @@ def main() -> None:
if args.includes: if args.includes:
print_includes() print_includes()
if args.cmakedir: if args.cmakedir:
print(shlex.quote(get_cmake_dir())) print(quote(get_cmake_dir()))
if args.pkgconfigdir: if args.pkgconfigdir:
print(shlex.quote(get_pkgconfig_dir())) print(quote(get_pkgconfig_dir()))
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -5,16 +5,7 @@
# All rights reserved. Use of this source code is governed by a # All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file. # BSD-style license that can be found in the LICENSE file.
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.15...3.30)
# The `cmake_minimum_required(VERSION 3.5...3.29)` syntax does not work with
# some versions of VS that have a patched CMake 3.11. This forces us to emulate
# the behavior using the following workaround:
if(${CMAKE_VERSION} VERSION_LESS 3.29)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
else()
cmake_policy(VERSION 3.29)
endif()
# Filter out items; print an optional message if any items filtered. This ignores extensions. # Filter out items; print an optional message if any items filtered. This ignores extensions.
# #
@ -76,8 +67,8 @@ project(pybind11_tests CXX)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../tools") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../tools")
option(PYBIND11_WERROR "Report all warnings as errors" OFF) option(PYBIND11_WERROR "Report all warnings as errors" OFF)
option(DOWNLOAD_EIGEN "Download EIGEN (requires CMake 3.11+)" OFF) option(DOWNLOAD_EIGEN "Download EIGEN" OFF)
option(PYBIND11_CUDA_TESTS "Enable building CUDA tests (requires CMake 3.12+)" OFF) option(PYBIND11_CUDA_TESTS "Enable building CUDA tests" OFF)
set(PYBIND11_TEST_OVERRIDE set(PYBIND11_TEST_OVERRIDE
"" ""
CACHE STRING "Tests from ;-separated list of *.cpp files will be built instead of all tests") CACHE STRING "Tests from ;-separated list of *.cpp files will be built instead of all tests")
@ -267,25 +258,21 @@ endif()
if(PYBIND11_TEST_FILES_EIGEN_I GREATER -1) if(PYBIND11_TEST_FILES_EIGEN_I GREATER -1)
# Try loading via newer Eigen's Eigen3Config first (bypassing tools/FindEigen3.cmake). # Try loading via newer Eigen's Eigen3Config first (bypassing tools/FindEigen3.cmake).
# Eigen 3.3.1+ exports a cmake 3.0+ target for handling dependency requirements, but also # Eigen 3.3.1+ exports a cmake 3.0+ target for handling dependency requirements, but also
# produces a fatal error if loaded from a pre-3.0 cmake.
if(DOWNLOAD_EIGEN) if(DOWNLOAD_EIGEN)
if(CMAKE_VERSION VERSION_LESS 3.11) if(CMAKE_VERSION VERSION_LESS 3.18)
message(FATAL_ERROR "CMake 3.11+ required when using DOWNLOAD_EIGEN") set(_opts)
else()
set(_opts SOURCE_SUBDIR no-cmake-build)
endif() endif()
include(FetchContent) include(FetchContent)
FetchContent_Declare( FetchContent_Declare(
eigen eigen
GIT_REPOSITORY "${PYBIND11_EIGEN_REPO}" GIT_REPOSITORY "${PYBIND11_EIGEN_REPO}"
GIT_TAG "${PYBIND11_EIGEN_VERSION_HASH}") GIT_TAG "${PYBIND11_EIGEN_VERSION_HASH}"
${_opts})
FetchContent_GetProperties(eigen) FetchContent_MakeAvailable(eigen)
if(NOT eigen_POPULATED) if(NOT CMAKE_VERSION VERSION_LESS 3.18)
message( set(EIGEN3_INCLUDE_DIR "${eigen_SOURCE_DIR}")
STATUS
"Downloading Eigen ${PYBIND11_EIGEN_VERSION_STRING} (${PYBIND11_EIGEN_VERSION_HASH}) from ${PYBIND11_EIGEN_REPO}"
)
FetchContent_Populate(eigen)
endif() endif()
set(EIGEN3_INCLUDE_DIR ${eigen_SOURCE_DIR}) set(EIGEN3_INCLUDE_DIR ${eigen_SOURCE_DIR})
@ -333,8 +320,7 @@ if(PYBIND11_TEST_FILES_EIGEN_I GREATER -1)
if(PYBIND11_TEST_FILES_EIGEN_I GREATER -1) if(PYBIND11_TEST_FILES_EIGEN_I GREATER -1)
list(REMOVE_AT PYBIND11_TEST_FILES ${PYBIND11_TEST_FILES_EIGEN_I}) list(REMOVE_AT PYBIND11_TEST_FILES ${PYBIND11_TEST_FILES_EIGEN_I})
endif() endif()
message( message(STATUS "Building tests WITHOUT Eigen, use -DDOWNLOAD_EIGEN=ON to download")
STATUS "Building tests WITHOUT Eigen, use -DDOWNLOAD_EIGEN=ON on CMake 3.11+ to download")
endif() endif()
endif() endif()
@ -519,12 +505,10 @@ foreach(target ${test_targets})
endforeach() endforeach()
# Provide nice organisation in IDEs # Provide nice organisation in IDEs
if(NOT CMAKE_VERSION VERSION_LESS 3.8) source_group(
source_group( TREE "${CMAKE_CURRENT_SOURCE_DIR}/../include"
TREE "${CMAKE_CURRENT_SOURCE_DIR}/../include" PREFIX "Header Files"
PREFIX "Header Files" FILES ${PYBIND11_HEADERS})
FILES ${PYBIND11_HEADERS})
endif()
# Make sure pytest is found or produce a warning # Make sure pytest is found or produce a warning
pybind11_find_import(pytest VERSION 3.1) pybind11_find_import(pytest VERSION 3.1)

View File

@ -9,7 +9,6 @@ import tarfile
import zipfile import zipfile
# These tests must be run explicitly # These tests must be run explicitly
# They require CMake 3.15+ (--install)
DIR = os.path.abspath(os.path.dirname(__file__)) DIR = os.path.abspath(os.path.dirname(__file__))
MAIN_DIR = os.path.dirname(os.path.dirname(DIR)) MAIN_DIR = os.path.dirname(os.path.dirname(DIR))

View File

@ -10,10 +10,6 @@ name = "pybind11_tests"
version = "0.0.1" version = "0.0.1"
dependencies = ["pytest", "pytest-timeout", "numpy", "scipy"] dependencies = ["pytest", "pytest-timeout", "numpy", "scipy"]
[tool.scikit-build]
# Hide a warning while we also support CMake < 3.15
cmake.version = ">=3.15"
[tool.scikit-build.cmake.define] [tool.scikit-build.cmake.define]
PYBIND11_FINDPYTHON = true PYBIND11_FINDPYTHON = true

View File

@ -1,13 +1,4 @@
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.15...3.30)
# The `cmake_minimum_required(VERSION 3.5...3.29)` syntax does not work with
# some versions of VS that have a patched CMake 3.11. This forces us to emulate
# the behavior using the following workaround:
if(${CMAKE_VERSION} VERSION_LESS 3.29)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
else()
cmake_policy(VERSION 3.29)
endif()
project(test_installed_embed CXX) project(test_installed_embed CXX)

View File

@ -1,14 +1,4 @@
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.15...3.30)
project(test_installed_module CXX)
# The `cmake_minimum_required(VERSION 3.5...3.29)` syntax does not work with
# some versions of VS that have a patched CMake 3.11. This forces us to emulate
# the behavior using the following workaround:
if(${CMAKE_VERSION} VERSION_LESS 3.29)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
else()
cmake_policy(VERSION 3.29)
endif()
project(test_installed_function CXX) project(test_installed_function CXX)

View File

@ -1,13 +1,4 @@
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.15...3.30)
# The `cmake_minimum_required(VERSION 3.5...3.29)` syntax does not work with
# some versions of VS that have a patched CMake 3.11. This forces us to emulate
# the behavior using the following workaround:
if(${CMAKE_VERSION} VERSION_LESS 3.29)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
else()
cmake_policy(VERSION 3.29)
endif()
project(test_installed_target CXX) project(test_installed_target CXX)

View File

@ -1,13 +1,4 @@
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.15...3.30)
# The `cmake_minimum_required(VERSION 3.5...3.29)` syntax does not work with
# some versions of VS that have a patched CMake 3.11. This forces us to emulate
# the behavior using the following workaround:
if(${CMAKE_VERSION} VERSION_LESS 3.29)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
else()
cmake_policy(VERSION 3.29)
endif()
project(test_subdirectory_embed CXX) project(test_subdirectory_embed CXX)

View File

@ -1,13 +1,4 @@
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.15...3.30)
# The `cmake_minimum_required(VERSION 3.5...3.29)` syntax does not work with
# some versions of VS that have a patched CMake 3.11. This forces us to emulate
# the behavior using the following workaround:
if(${CMAKE_VERSION} VERSION_LESS 3.29)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
else()
cmake_policy(VERSION 3.29)
endif()
project(test_subdirectory_function CXX) project(test_subdirectory_function CXX)

View File

@ -1,13 +1,4 @@
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.15...3.30)
# The `cmake_minimum_required(VERSION 3.5...3.29)` syntax does not work with
# some versions of VS that have a patched CMake 3.11. This forces us to emulate
# the behavior using the following workaround:
if(${CMAKE_VERSION} VERSION_LESS 3.29)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
else()
cmake_policy(VERSION 3.29)
endif()
project(test_subdirectory_target CXX) project(test_subdirectory_target CXX)

View File

@ -201,6 +201,23 @@ TEST_SUBMODULE(stl, m) {
m.def("cast_array", []() { return std::array<int, 2>{{1, 2}}; }); m.def("cast_array", []() { return std::array<int, 2>{{1, 2}}; });
m.def("load_array", [](const std::array<int, 2> &a) { return a[0] == 1 && a[1] == 2; }); m.def("load_array", [](const std::array<int, 2> &a) { return a[0] == 1 && a[1] == 2; });
struct NoDefaultCtor {
explicit constexpr NoDefaultCtor(int val) : val{val} {}
int val;
};
struct NoDefaultCtorArray {
explicit constexpr NoDefaultCtorArray(int i)
: arr{{NoDefaultCtor(10 + i), NoDefaultCtor(20 + i)}} {}
std::array<NoDefaultCtor, 2> arr;
};
// test_array_no_default_ctor
py::class_<NoDefaultCtor>(m, "NoDefaultCtor").def_readonly("val", &NoDefaultCtor::val);
py::class_<NoDefaultCtorArray>(m, "NoDefaultCtorArray")
.def(py::init<int>())
.def_readwrite("arr", &NoDefaultCtorArray::arr);
// test_valarray // test_valarray
m.def("cast_valarray", []() { return std::valarray<int>{1, 4, 9}; }); m.def("cast_valarray", []() { return std::valarray<int>{1, 4, 9}; });
m.def("load_valarray", [](const std::valarray<int> &v) { m.def("load_valarray", [](const std::valarray<int> &v) {

View File

@ -48,6 +48,13 @@ def test_array(doc):
) )
def test_array_no_default_ctor():
lst = m.NoDefaultCtorArray(3)
assert [e.val for e in lst.arr] == [13, 23]
lst.arr = m.NoDefaultCtorArray(4).arr
assert [e.val for e in lst.arr] == [14, 24]
def test_valarray(doc): def test_valarray(doc):
"""std::valarray <-> list""" """std::valarray <-> list"""
lst = m.cast_valarray() lst = m.cast_valarray()

View File

@ -18,11 +18,7 @@ Adds the following functions::
#]======================================================] #]======================================================]
# CMake 3.10 has an include_guard command, but we can't use that yet include_guard(GLOBAL)
# include_guard(global) (pre-CMake 3.10)
if(TARGET pybind11::pybind11)
return()
endif()
# If we are in subdirectory mode, all IMPORTED targets must be GLOBAL. If we # If we are in subdirectory mode, all IMPORTED targets must be GLOBAL. If we
# are in CONFIG mode, they should be "normal" targets instead. # are in CONFIG mode, they should be "normal" targets instead.
@ -80,47 +76,31 @@ set_property(
# Please open an issue if you need to use it; it will be removed if no one # Please open an issue if you need to use it; it will be removed if no one
# needs it. # needs it.
if(CMAKE_SYSTEM_NAME MATCHES Emscripten AND NOT _pybind11_no_exceptions) if(CMAKE_SYSTEM_NAME MATCHES Emscripten AND NOT _pybind11_no_exceptions)
if(CMAKE_VERSION VERSION_LESS 3.13) if(is_config)
message(WARNING "CMake 3.13+ is required to build for Emscripten. Some flags will be missing") set(_tmp_config_target pybind11::pybind11_headers)
else() else()
if(is_config) set(_tmp_config_target pybind11_headers)
set(_tmp_config_target pybind11::pybind11_headers)
else()
set(_tmp_config_target pybind11_headers)
endif()
set_property(
TARGET ${_tmp_config_target}
APPEND
PROPERTY INTERFACE_LINK_OPTIONS -fexceptions)
set_property(
TARGET ${_tmp_config_target}
APPEND
PROPERTY INTERFACE_COMPILE_OPTIONS -fexceptions)
unset(_tmp_config_target)
endif() endif()
set_property(
TARGET ${_tmp_config_target}
APPEND
PROPERTY INTERFACE_LINK_OPTIONS -fexceptions)
set_property(
TARGET ${_tmp_config_target}
APPEND
PROPERTY INTERFACE_COMPILE_OPTIONS -fexceptions)
unset(_tmp_config_target)
endif() endif()
# --------------------------- link helper --------------------------- # --------------------------- link helper ---------------------------
add_library(pybind11::python_link_helper IMPORTED INTERFACE ${optional_global}) add_library(pybind11::python_link_helper IMPORTED INTERFACE ${optional_global})
if(CMAKE_VERSION VERSION_LESS 3.13) set_property(
# In CMake 3.11+, you can set INTERFACE properties via the normal methods, and TARGET pybind11::python_link_helper
# this would be simpler. APPEND
set_property( PROPERTY INTERFACE_LINK_OPTIONS "$<$<PLATFORM_ID:Darwin>:LINKER:-undefined,dynamic_lookup>")
TARGET pybind11::python_link_helper
APPEND
PROPERTY INTERFACE_LINK_LIBRARIES "$<$<PLATFORM_ID:Darwin>:-undefined dynamic_lookup>")
else()
# link_options was added in 3.13+
# This is safer, because you are ensured the deduplication pass in CMake will not consider
# these separate and remove one but not the other.
set_property(
TARGET pybind11::python_link_helper
APPEND
PROPERTY INTERFACE_LINK_OPTIONS "$<$<PLATFORM_ID:Darwin>:LINKER:-undefined,dynamic_lookup>")
endif()
# ------------------------ Windows extras ------------------------- # ------------------------ Windows extras -------------------------
@ -136,22 +116,14 @@ if(MSVC) # That's also clang-cl
# /MP enables multithreaded builds (relevant when there are many files) for MSVC # /MP enables multithreaded builds (relevant when there are many files) for MSVC
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") # no Clang no Intel if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") # no Clang no Intel
if(CMAKE_VERSION VERSION_LESS 3.11) # Only set these options for C++ files. This is important so that, for
set_property( # instance, projects that include other types of source files like CUDA
TARGET pybind11::windows_extras # .cu files don't get these options propagated to nvcc since that would
APPEND # cause the build to fail.
PROPERTY INTERFACE_COMPILE_OPTIONS $<$<NOT:$<CONFIG:Debug>>:/MP>) set_property(
else() TARGET pybind11::windows_extras
# Only set these options for C++ files. This is important so that, for APPEND
# instance, projects that include other types of source files like CUDA PROPERTY INTERFACE_COMPILE_OPTIONS $<$<NOT:$<CONFIG:Debug>>:$<$<COMPILE_LANGUAGE:CXX>:/MP>>)
# .cu files don't get these options propagated to nvcc since that would
# cause the build to fail.
set_property(
TARGET pybind11::windows_extras
APPEND
PROPERTY INTERFACE_COMPILE_OPTIONS
$<$<NOT:$<CONFIG:Debug>>:$<$<COMPILE_LANGUAGE:CXX>:/MP>>)
endif()
endif() endif()
endif() endif()
@ -397,11 +369,7 @@ function(_pybind11_generate_lto target prefer_thin_lto)
set(is_debug "$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>") set(is_debug "$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>")
set(not_debug "$<NOT:${is_debug}>") set(not_debug "$<NOT:${is_debug}>")
set(cxx_lang "$<COMPILE_LANGUAGE:CXX>") set(cxx_lang "$<COMPILE_LANGUAGE:CXX>")
if(MSVC AND CMAKE_VERSION VERSION_LESS 3.11) set(genex "$<AND:${not_debug},${cxx_lang}>")
set(genex "${not_debug}")
else()
set(genex "$<AND:${not_debug},${cxx_lang}>")
endif()
set_property( set_property(
TARGET ${target} TARGET ${target}
APPEND APPEND
@ -416,17 +384,10 @@ function(_pybind11_generate_lto target prefer_thin_lto)
endif() endif()
if(PYBIND11_LTO_LINKER_FLAGS) if(PYBIND11_LTO_LINKER_FLAGS)
if(CMAKE_VERSION VERSION_LESS 3.11) set_property(
set_property( TARGET ${target}
TARGET ${target} APPEND
APPEND PROPERTY INTERFACE_LINK_OPTIONS "$<${not_debug}:${PYBIND11_LTO_LINKER_FLAGS}>")
PROPERTY INTERFACE_LINK_LIBRARIES "$<${not_debug}:${PYBIND11_LTO_LINKER_FLAGS}>")
else()
set_property(
TARGET ${target}
APPEND
PROPERTY INTERFACE_LINK_OPTIONS "$<${not_debug}:${PYBIND11_LTO_LINKER_FLAGS}>")
endif()
endif() endif()
endfunction() endfunction()

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.15...3.30)
function(pybind11_guess_python_module_extension python) function(pybind11_guess_python_module_extension python)

View File

@ -5,10 +5,6 @@
# All rights reserved. Use of this source code is governed by a # All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file. # BSD-style license that can be found in the LICENSE file.
if(CMAKE_VERSION VERSION_LESS 3.12)
message(FATAL_ERROR "You cannot use the new FindPython module with CMake < 3.12")
endif()
include_guard(DIRECTORY) include_guard(DIRECTORY)
get_property( get_property(
@ -236,7 +232,6 @@ if(TARGET ${_Python}::Python)
PROPERTY INTERFACE_LINK_LIBRARIES ${_Python}::Python) PROPERTY INTERFACE_LINK_LIBRARIES ${_Python}::Python)
endif() endif()
# CMake 3.15+ has this
if(TARGET ${_Python}::Module) if(TARGET ${_Python}::Module)
set_property( set_property(
TARGET pybind11::module TARGET pybind11::module

View File

@ -5,13 +5,7 @@
# All rights reserved. Use of this source code is governed by a # All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file. # BSD-style license that can be found in the LICENSE file.
# include_guard(global) (pre-CMake 3.10) include_guard(GLOBAL)
if(TARGET pybind11::python_headers)
return()
endif()
# Built-in in CMake 3.5+
include(CMakeParseArguments)
if(pybind11_FIND_QUIETLY) if(pybind11_FIND_QUIETLY)
set(_pybind11_quiet QUIET) set(_pybind11_quiet QUIET)
@ -116,36 +110,19 @@ if(PYTHON_IS_DEBUG)
PROPERTY INTERFACE_COMPILE_DEFINITIONS Py_DEBUG) PROPERTY INTERFACE_COMPILE_DEFINITIONS Py_DEBUG)
endif() endif()
# The <3.11 code here does not support release/debug builds at the same time, like on vcpkg # The IMPORTED INTERFACE library here is to ensure that "debug" and "release" get processed outside
if(CMAKE_VERSION VERSION_LESS 3.11) # of a generator expression - https://gitlab.kitware.com/cmake/cmake/-/issues/18424, as they are
set_property( # target_link_library keywords rather than real libraries.
TARGET pybind11::module add_library(pybind11::_ClassicPythonLibraries IMPORTED INTERFACE)
APPEND target_link_libraries(pybind11::_ClassicPythonLibraries INTERFACE ${PYTHON_LIBRARIES})
PROPERTY target_link_libraries(
INTERFACE_LINK_LIBRARIES pybind11::module
pybind11::python_link_helper INTERFACE
"$<$<OR:$<PLATFORM_ID:Windows>,$<PLATFORM_ID:Cygwin>>:$<BUILD_INTERFACE:${PYTHON_LIBRARIES}>>" pybind11::python_link_helper
) "$<$<OR:$<PLATFORM_ID:Windows>,$<PLATFORM_ID:Cygwin>>:pybind11::_ClassicPythonLibraries>")
set_property( target_link_libraries(pybind11::embed INTERFACE pybind11::pybind11
TARGET pybind11::embed pybind11::_ClassicPythonLibraries)
APPEND
PROPERTY INTERFACE_LINK_LIBRARIES pybind11::pybind11 $<BUILD_INTERFACE:${PYTHON_LIBRARIES}>)
else()
# The IMPORTED INTERFACE library here is to ensure that "debug" and "release" get processed outside
# of a generator expression - https://gitlab.kitware.com/cmake/cmake/-/issues/18424, as they are
# target_link_library keywords rather than real libraries.
add_library(pybind11::_ClassicPythonLibraries IMPORTED INTERFACE)
target_link_libraries(pybind11::_ClassicPythonLibraries INTERFACE ${PYTHON_LIBRARIES})
target_link_libraries(
pybind11::module
INTERFACE
pybind11::python_link_helper
"$<$<OR:$<PLATFORM_ID:Windows>,$<PLATFORM_ID:Cygwin>>:pybind11::_ClassicPythonLibraries>")
target_link_libraries(pybind11::embed INTERFACE pybind11::pybind11
pybind11::_ClassicPythonLibraries)
endif()
function(pybind11_extension name) function(pybind11_extension name)
# The prefix and extension are provided by FindPythonLibsNew.cmake # The prefix and extension are provided by FindPythonLibsNew.cmake

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.15...3.30)
# Tests for pybind11_guess_python_module_extension # Tests for pybind11_guess_python_module_extension
# Run using `cmake -P tools/test-pybind11GuessPythonExtSuffix.cmake` # Run using `cmake -P tools/test-pybind11GuessPythonExtSuffix.cmake`