mirror of
https://github.com/thelsing/knx.git
synced 2026-02-23 13:50:35 +01:00
update pybind11
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
# CATCH_INCLUDE_DIR - path to catch.hpp
|
||||
# CATCH_VERSION - version number
|
||||
|
||||
option(DOWNLOAD_CATCH "Download catch2 if not found")
|
||||
|
||||
if(NOT Catch_FIND_VERSION)
|
||||
message(FATAL_ERROR "A version number must be specified.")
|
||||
elseif(Catch_FIND_REQUIRED)
|
||||
@@ -34,10 +36,14 @@ endfunction()
|
||||
function(_download_catch version destination_dir)
|
||||
message(STATUS "Downloading catch v${version}...")
|
||||
set(url https://github.com/philsquared/Catch/releases/download/v${version}/catch.hpp)
|
||||
file(DOWNLOAD ${url} "${destination_dir}/catch.hpp" STATUS status)
|
||||
file(
|
||||
DOWNLOAD ${url} "${destination_dir}/catch.hpp"
|
||||
STATUS status
|
||||
LOG log)
|
||||
list(GET status 0 error)
|
||||
if(error)
|
||||
message(FATAL_ERROR "Could not download ${url}")
|
||||
string(REPLACE "\n" "\n " log " ${log}")
|
||||
message(FATAL_ERROR "Could not download URL:\n" " ${url}\n" "Log:\n" "${log}")
|
||||
endif()
|
||||
set(CATCH_INCLUDE_DIR
|
||||
"${destination_dir}"
|
||||
|
||||
@@ -64,6 +64,9 @@ if(EIGEN3_INCLUDE_DIR)
|
||||
set(EIGEN3_FOUND ${EIGEN3_VERSION_OK})
|
||||
|
||||
else(EIGEN3_INCLUDE_DIR)
|
||||
if(NOT DEFINED KDE4_INCLUDE_DIR)
|
||||
set(KDE4_INCLUDE_DIR "")
|
||||
endif()
|
||||
|
||||
find_path(
|
||||
EIGEN3_INCLUDE_DIR
|
||||
|
||||
@@ -57,6 +57,8 @@ endif()
|
||||
|
||||
if(PythonLibsNew_FIND_QUIETLY)
|
||||
set(_pythonlibs_quiet QUIET)
|
||||
else()
|
||||
set(_pythonlibs_quiet "")
|
||||
endif()
|
||||
|
||||
if(PythonLibsNew_FIND_REQUIRED)
|
||||
@@ -90,7 +92,23 @@ endif()
|
||||
|
||||
# Use the Python interpreter to find the libs.
|
||||
if(NOT PythonLibsNew_FIND_VERSION)
|
||||
set(PythonLibsNew_FIND_VERSION "")
|
||||
set(PythonLibsNew_FIND_VERSION "3.7")
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_VERSION VERSION_LESS "3.27")
|
||||
cmake_policy(GET CMP0148 _pybind11_cmp0148)
|
||||
if(NOT _pybind11_cmp0148)
|
||||
message(
|
||||
AUTHOR_WARNING
|
||||
"Policy CMP0148 is not set: The FindPythonInterp and FindPythonLibs "
|
||||
"modules are removed. Run \"cmake --help-policy CMP0148\" for policy "
|
||||
"details. Use the cmake_policy command to set the policy and suppress "
|
||||
"this warning, or preferably upgrade to using FindPython, either by "
|
||||
"calling it explicitly before pybind11, or by setting "
|
||||
"PYBIND11_FINDPYTHON ON before pybind11.")
|
||||
endif()
|
||||
cmake_policy(SET CMP0148 OLD)
|
||||
unset(_pybind11_cmp0148)
|
||||
endif()
|
||||
|
||||
find_package(PythonInterp ${PythonLibsNew_FIND_VERSION} ${_pythonlibs_required}
|
||||
@@ -110,12 +128,26 @@ endif()
|
||||
# VERSION. VERSION will typically be like "2.7" on unix, and "27" on windows.
|
||||
execute_process(
|
||||
COMMAND
|
||||
"${PYTHON_EXECUTABLE}" "-c" "from distutils import sysconfig as s;import sys;import struct;
|
||||
"${PYTHON_EXECUTABLE}" "-c" "
|
||||
import sys;import struct;
|
||||
import sysconfig as s
|
||||
USE_SYSCONFIG = sys.version_info >= (3, 10)
|
||||
if not USE_SYSCONFIG:
|
||||
from distutils import sysconfig as ds
|
||||
print('.'.join(str(v) for v in sys.version_info));
|
||||
print(sys.prefix);
|
||||
print(s.get_python_inc(plat_specific=True));
|
||||
print(s.get_python_lib(plat_specific=True));
|
||||
print(s.get_config_var('SO') or s.get_config_var('EXT_SUFFIX'));
|
||||
if USE_SYSCONFIG:
|
||||
scheme = s.get_default_scheme()
|
||||
if scheme == 'posix_local':
|
||||
# Debian's default scheme installs to /usr/local/ but we want to find headers in /usr/
|
||||
scheme = 'posix_prefix'
|
||||
print(s.get_path('platinclude', scheme))
|
||||
print(s.get_path('platlib'))
|
||||
print(s.get_config_var('EXT_SUFFIX') or s.get_config_var('SO'))
|
||||
else:
|
||||
print(ds.get_python_inc(plat_specific=True));
|
||||
print(ds.get_python_lib(plat_specific=True));
|
||||
print(ds.get_config_var('EXT_SUFFIX') or ds.get_config_var('SO'));
|
||||
print(hasattr(sys, 'gettotalrefcount')+0);
|
||||
print(struct.calcsize('@P'));
|
||||
print(s.get_config_var('LDVERSION') or s.get_config_var('VERSION'));
|
||||
@@ -135,26 +167,47 @@ if(NOT _PYTHON_SUCCESS MATCHES 0)
|
||||
return()
|
||||
endif()
|
||||
|
||||
option(
|
||||
PYBIND11_PYTHONLIBS_OVERWRITE
|
||||
"Overwrite cached values read from Python library (classic search). Turn off if cross-compiling and manually setting these values."
|
||||
ON)
|
||||
# Can manually set values when cross-compiling
|
||||
macro(_PYBIND11_GET_IF_UNDEF lst index name)
|
||||
if(PYBIND11_PYTHONLIBS_OVERWRITE OR NOT DEFINED "${name}")
|
||||
list(GET "${lst}" "${index}" "${name}")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# Convert the process output into a list
|
||||
if(WIN32)
|
||||
string(REGEX REPLACE "\\\\" "/" _PYTHON_VALUES ${_PYTHON_VALUES})
|
||||
endif()
|
||||
string(REGEX REPLACE ";" "\\\\;" _PYTHON_VALUES ${_PYTHON_VALUES})
|
||||
string(REGEX REPLACE "\n" ";" _PYTHON_VALUES ${_PYTHON_VALUES})
|
||||
list(GET _PYTHON_VALUES 0 _PYTHON_VERSION_LIST)
|
||||
list(GET _PYTHON_VALUES 1 PYTHON_PREFIX)
|
||||
list(GET _PYTHON_VALUES 2 PYTHON_INCLUDE_DIR)
|
||||
list(GET _PYTHON_VALUES 3 PYTHON_SITE_PACKAGES)
|
||||
list(GET _PYTHON_VALUES 4 PYTHON_MODULE_EXTENSION)
|
||||
list(GET _PYTHON_VALUES 5 PYTHON_IS_DEBUG)
|
||||
list(GET _PYTHON_VALUES 6 PYTHON_SIZEOF_VOID_P)
|
||||
list(GET _PYTHON_VALUES 7 PYTHON_LIBRARY_SUFFIX)
|
||||
list(GET _PYTHON_VALUES 8 PYTHON_LIBDIR)
|
||||
list(GET _PYTHON_VALUES 9 PYTHON_MULTIARCH)
|
||||
_pybind11_get_if_undef(_PYTHON_VALUES 0 _PYTHON_VERSION_LIST)
|
||||
_pybind11_get_if_undef(_PYTHON_VALUES 1 PYTHON_PREFIX)
|
||||
_pybind11_get_if_undef(_PYTHON_VALUES 2 PYTHON_INCLUDE_DIR)
|
||||
_pybind11_get_if_undef(_PYTHON_VALUES 3 PYTHON_SITE_PACKAGES)
|
||||
_pybind11_get_if_undef(_PYTHON_VALUES 5 PYTHON_IS_DEBUG)
|
||||
_pybind11_get_if_undef(_PYTHON_VALUES 6 PYTHON_SIZEOF_VOID_P)
|
||||
_pybind11_get_if_undef(_PYTHON_VALUES 7 PYTHON_LIBRARY_SUFFIX)
|
||||
_pybind11_get_if_undef(_PYTHON_VALUES 8 PYTHON_LIBDIR)
|
||||
_pybind11_get_if_undef(_PYTHON_VALUES 9 PYTHON_MULTIARCH)
|
||||
|
||||
list(GET _PYTHON_VALUES 4 _PYTHON_MODULE_EXT_SUFFIX)
|
||||
if(PYBIND11_PYTHONLIBS_OVERWRITE OR NOT DEFINED PYTHON_MODULE_DEBUG_POSTFIX)
|
||||
get_filename_component(PYTHON_MODULE_DEBUG_POSTFIX "${_PYTHON_MODULE_EXT_SUFFIX}" NAME_WE)
|
||||
endif()
|
||||
if(PYBIND11_PYTHONLIBS_OVERWRITE OR NOT DEFINED PYTHON_MODULE_EXTENSION)
|
||||
get_filename_component(PYTHON_MODULE_EXTENSION "${_PYTHON_MODULE_EXT_SUFFIX}" EXT)
|
||||
endif()
|
||||
|
||||
# Make sure the Python has the same pointer-size as the chosen compiler
|
||||
# Skip if CMAKE_SIZEOF_VOID_P is not defined
|
||||
if(CMAKE_SIZEOF_VOID_P AND (NOT "${PYTHON_SIZEOF_VOID_P}" STREQUAL "${CMAKE_SIZEOF_VOID_P}"))
|
||||
# This should be skipped for (non-Apple) cross-compiles (like EMSCRIPTEN)
|
||||
if(NOT _PYBIND11_CROSSCOMPILING
|
||||
AND CMAKE_SIZEOF_VOID_P
|
||||
AND (NOT "${PYTHON_SIZEOF_VOID_P}" STREQUAL "${CMAKE_SIZEOF_VOID_P}"))
|
||||
if(PythonLibsNew_FIND_REQUIRED)
|
||||
math(EXPR _PYTHON_BITS "${PYTHON_SIZEOF_VOID_P} * 8")
|
||||
math(EXPR _CMAKE_BITS "${CMAKE_SIZEOF_VOID_P} * 8")
|
||||
@@ -178,7 +231,9 @@ string(REGEX REPLACE "\\\\" "/" PYTHON_PREFIX "${PYTHON_PREFIX}")
|
||||
string(REGEX REPLACE "\\\\" "/" PYTHON_INCLUDE_DIR "${PYTHON_INCLUDE_DIR}")
|
||||
string(REGEX REPLACE "\\\\" "/" PYTHON_SITE_PACKAGES "${PYTHON_SITE_PACKAGES}")
|
||||
|
||||
if(CMAKE_HOST_WIN32)
|
||||
if(DEFINED PYTHON_LIBRARY)
|
||||
# Don't write to PYTHON_LIBRARY if it's already set
|
||||
elseif(CMAKE_HOST_WIN32)
|
||||
set(PYTHON_LIBRARY "${PYTHON_PREFIX}/libs/python${PYTHON_LIBRARY_SUFFIX}.lib")
|
||||
|
||||
# when run in a venv, PYTHON_PREFIX points to it. But the libraries remain in the
|
||||
@@ -244,7 +299,7 @@ if(NOT PYTHON_DEBUG_LIBRARY)
|
||||
endif()
|
||||
set(PYTHON_DEBUG_LIBRARIES "${PYTHON_DEBUG_LIBRARY}")
|
||||
|
||||
find_package_message(PYTHON "Found PythonLibs: ${PYTHON_LIBRARY}"
|
||||
find_package_message(PYTHON "Found PythonLibs: ${PYTHON_LIBRARIES}"
|
||||
"${PYTHON_EXECUTABLE}${PYTHON_VERSION_STRING}")
|
||||
|
||||
set(PYTHONLIBS_FOUND TRUE)
|
||||
|
||||
23
examples/knxPython/pybind11/tools/JoinPaths.cmake
Normal file
23
examples/knxPython/pybind11/tools/JoinPaths.cmake
Normal file
@@ -0,0 +1,23 @@
|
||||
# This module provides function for joining paths
|
||||
# known from most languages
|
||||
#
|
||||
# SPDX-License-Identifier: (MIT OR CC0-1.0)
|
||||
# Copyright 2020 Jan Tojnar
|
||||
# https://github.com/jtojnar/cmake-snips
|
||||
#
|
||||
# Modelled after Python’s os.path.join
|
||||
# https://docs.python.org/3.7/library/os.path.html#os.path.join
|
||||
# Windows not supported
|
||||
function(join_paths joined_path first_path_segment)
|
||||
set(temp_path "${first_path_segment}")
|
||||
foreach(current_segment IN LISTS ARGN)
|
||||
if(NOT ("${current_segment}" STREQUAL ""))
|
||||
if(IS_ABSOLUTE "${current_segment}")
|
||||
set(temp_path "${current_segment}")
|
||||
else()
|
||||
set(temp_path "${temp_path}/${current_segment}")
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
set(${joined_path} "${temp_path}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
@@ -16,11 +16,11 @@ check_style_errors=0
|
||||
IFS=$'\n'
|
||||
|
||||
|
||||
found="$(grep '\<\(if\|for\|while\|catch\)(\|){' $@ -rn --color=always)"
|
||||
found="$(grep '\<\(if\|for\|while\|catch\)(\|){' "$@" -rn --color=always)"
|
||||
if [ -n "$found" ]; then
|
||||
echo -e '\033[31;01mError: found the following coding style problems:\033[0m'
|
||||
check_style_errors=1
|
||||
echo "$found" | sed -e 's/^/ /'
|
||||
echo "${found//^/ /}"
|
||||
fi
|
||||
|
||||
found="$(awk '
|
||||
@@ -34,7 +34,7 @@ last && /^\s*{/ {
|
||||
last=""
|
||||
}
|
||||
{ last = /(if|for|while|catch|switch)\s*\(.*\)\s*$/ ? $0 : "" }
|
||||
' $(find include -type f) $@)"
|
||||
' "$(find include -type f)" "$@")"
|
||||
if [ -n "$found" ]; then
|
||||
check_style_errors=1
|
||||
echo -e '\033[31;01mError: braces should occur on the same line as the if/while/.. statement. Found issues in the following files:\033[0m'
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
"""Simple script for rebuilding .codespell-ignore-lines
|
||||
|
||||
Usage:
|
||||
|
||||
cat < /dev/null > .codespell-ignore-lines
|
||||
pre-commit run --all-files codespell >& /tmp/codespell_errors.txt
|
||||
python3 tools/codespell_ignore_lines_from_errors.py /tmp/codespell_errors.txt > .codespell-ignore-lines
|
||||
|
||||
git diff to review changes, then commit, push.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
def run(args: list[str]) -> None:
|
||||
assert len(args) == 1, "codespell_errors.txt"
|
||||
cache = {}
|
||||
done = set()
|
||||
with open(args[0]) as f:
|
||||
lines = f.read().splitlines()
|
||||
|
||||
for line in sorted(lines):
|
||||
i = line.find(" ==> ")
|
||||
if i > 0:
|
||||
flds = line[:i].split(":")
|
||||
if len(flds) >= 2:
|
||||
filename, line_num = flds[:2]
|
||||
if filename not in cache:
|
||||
with open(filename) as f:
|
||||
cache[filename] = f.read().splitlines()
|
||||
supp = cache[filename][int(line_num) - 1]
|
||||
if supp not in done:
|
||||
print(supp)
|
||||
done.add(supp)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run(args=sys.argv[1:])
|
||||
@@ -1,5 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import print_function, division
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
@@ -15,7 +15,7 @@ lib = sys.argv[1]
|
||||
save = sys.argv[2]
|
||||
|
||||
if not os.path.exists(lib):
|
||||
sys.exit("Error: requested file ({}) does not exist".format(lib))
|
||||
sys.exit(f"Error: requested file ({lib}) does not exist")
|
||||
|
||||
libsize = os.path.getsize(lib)
|
||||
|
||||
@@ -30,7 +30,7 @@ if os.path.exists(save):
|
||||
if change == 0:
|
||||
print(" (no change)")
|
||||
else:
|
||||
print(" (change of {:+} bytes = {:+.2%})".format(change, change / oldsize))
|
||||
print(f" (change of {change:+} bytes = {change / oldsize:+.2%})")
|
||||
else:
|
||||
print()
|
||||
|
||||
|
||||
92
examples/knxPython/pybind11/tools/make_changelog.py
Executable file
92
examples/knxPython/pybind11/tools/make_changelog.py
Executable file
@@ -0,0 +1,92 @@
|
||||
#!/usr/bin/env python3
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
|
||||
import ghapi.all
|
||||
from rich import print
|
||||
from rich.syntax import Syntax
|
||||
|
||||
ENTRY = re.compile(
|
||||
r"""
|
||||
Suggested \s changelog \s entry:
|
||||
.*
|
||||
```rst
|
||||
\s*
|
||||
(.*?)
|
||||
\s*
|
||||
```
|
||||
""",
|
||||
re.DOTALL | re.VERBOSE,
|
||||
)
|
||||
|
||||
print()
|
||||
|
||||
|
||||
api = ghapi.all.GhApi(owner="pybind", repo="pybind11")
|
||||
|
||||
issues_pages = ghapi.page.paged(
|
||||
api.issues.list_for_repo, labels="needs changelog", state="closed"
|
||||
)
|
||||
issues = (issue for page in issues_pages for issue in page)
|
||||
missing = []
|
||||
cats_descr = {
|
||||
"feat": "New Features",
|
||||
"feat(types)": "",
|
||||
"feat(cmake)": "",
|
||||
"fix": "Bug fixes",
|
||||
"fix(types)": "",
|
||||
"fix(cmake)": "",
|
||||
"docs": "Documentation",
|
||||
"tests": "Tests",
|
||||
"ci": "CI",
|
||||
"chore": "Other",
|
||||
"unknown": "Uncategorised",
|
||||
}
|
||||
cats: dict[str, list[str]] = {c: [] for c in cats_descr}
|
||||
|
||||
for issue in issues:
|
||||
changelog = ENTRY.findall(issue.body or "")
|
||||
if not changelog or not changelog[0]:
|
||||
missing.append(issue)
|
||||
else:
|
||||
(msg,) = changelog
|
||||
if msg.startswith("- "):
|
||||
msg = msg[2:]
|
||||
if not msg.startswith("* "):
|
||||
msg = "* " + msg
|
||||
if not msg.endswith("."):
|
||||
msg += "."
|
||||
|
||||
msg += f"\n `#{issue.number} <{issue.html_url}>`_"
|
||||
for cat in cats:
|
||||
if issue.title.lower().startswith(f"{cat}:"):
|
||||
cats[cat].append(msg)
|
||||
break
|
||||
else:
|
||||
cats["unknown"].append(msg)
|
||||
|
||||
for cat, msgs in cats.items():
|
||||
if msgs:
|
||||
desc = cats_descr[cat]
|
||||
print(f"[bold]{desc}:" if desc else f".. {cat}")
|
||||
print()
|
||||
for msg in msgs:
|
||||
print(Syntax(msg, "rst", theme="ansi_light", word_wrap=True))
|
||||
print()
|
||||
print()
|
||||
|
||||
if missing:
|
||||
print()
|
||||
print("[blue]" + "-" * 30)
|
||||
print()
|
||||
|
||||
for issue in missing:
|
||||
print(f"[red bold]Missing:[/red bold][red] {issue.title}")
|
||||
print(f"[red] {issue.html_url}\n")
|
||||
|
||||
print("[bold]Template:\n")
|
||||
msg = "## Suggested changelog entry:\n\n```rst\n\n```"
|
||||
print(Syntax(msg, "md", theme="ansi_light"))
|
||||
|
||||
print()
|
||||
7
examples/knxPython/pybind11/tools/pybind11.pc.in
Normal file
7
examples/knxPython/pybind11/tools/pybind11.pc.in
Normal file
@@ -0,0 +1,7 @@
|
||||
prefix=@prefix_for_pc_file@
|
||||
includedir=@includedir_for_pc_file@
|
||||
|
||||
Name: @PROJECT_NAME@
|
||||
Description: Seamless operability between C++11 and Python
|
||||
Version: @PROJECT_VERSION@
|
||||
Cflags: -I${includedir}
|
||||
@@ -5,10 +5,9 @@ Adds the following targets::
|
||||
pybind11::pybind11 - link to headers and pybind11
|
||||
pybind11::module - Adds module links
|
||||
pybind11::embed - Adds embed links
|
||||
pybind11::lto - Link time optimizations (manual selection)
|
||||
pybind11::thin_lto - Link time optimizations (manual selection)
|
||||
pybind11::lto - Link time optimizations (only if CMAKE_INTERPROCEDURAL_OPTIMIZATION is not set)
|
||||
pybind11::thin_lto - Link time optimizations (only if CMAKE_INTERPROCEDURAL_OPTIMIZATION is not set)
|
||||
pybind11::python_link_helper - Adds link to Python libraries
|
||||
pybind11::python2_no_register - Avoid warning/error with Python 2 + C++14/7
|
||||
pybind11::windows_extras - MSVC bigobj and mp for building multithreaded
|
||||
pybind11::opt_size - avoid optimizations that increase code size
|
||||
|
||||
@@ -20,7 +19,8 @@ Adds the following functions::
|
||||
#]======================================================]
|
||||
|
||||
# CMake 3.10 has an include_guard command, but we can't use that yet
|
||||
if(TARGET pybind11::lto)
|
||||
# include_guard(global) (pre-CMake 3.10)
|
||||
if(TARGET pybind11::pybind11)
|
||||
return()
|
||||
endif()
|
||||
|
||||
@@ -36,6 +36,22 @@ if(NOT is_config)
|
||||
set(optional_global GLOBAL)
|
||||
endif()
|
||||
|
||||
# If not run in Python mode, we still would like this to at least
|
||||
# include pybind11's include directory:
|
||||
set(pybind11_INCLUDE_DIRS
|
||||
"${pybind11_INCLUDE_DIR}"
|
||||
CACHE INTERNAL "Include directory for pybind11 (Python not requested)")
|
||||
|
||||
if(CMAKE_CROSSCOMPILING AND PYBIND11_USE_CROSSCOMPILING)
|
||||
set(_PYBIND11_CROSSCOMPILING
|
||||
ON
|
||||
CACHE INTERNAL "")
|
||||
else()
|
||||
set(_PYBIND11_CROSSCOMPILING
|
||||
OFF
|
||||
CACHE INTERNAL "")
|
||||
endif()
|
||||
|
||||
# --------------------- Shared targets ----------------------------
|
||||
|
||||
# Build an interface library target:
|
||||
@@ -59,31 +75,6 @@ set_property(
|
||||
APPEND
|
||||
PROPERTY INTERFACE_LINK_LIBRARIES pybind11::pybind11)
|
||||
|
||||
# ----------------------- no register ----------------------
|
||||
|
||||
# Workaround for Python 2.7 and C++17 (C++14 as a warning) incompatibility
|
||||
# This adds the flags -Wno-register and -Wno-deprecated-register if the compiler
|
||||
# is Clang 3.9+ or AppleClang and the compile language is CXX, or /wd5033 for MSVC (all languages,
|
||||
# since MSVC didn't recognize COMPILE_LANGUAGE until CMake 3.11+).
|
||||
|
||||
add_library(pybind11::python2_no_register INTERFACE IMPORTED ${optional_global})
|
||||
set(clang_4plus
|
||||
"$<AND:$<CXX_COMPILER_ID:Clang>,$<NOT:$<VERSION_LESS:$<CXX_COMPILER_VERSION>,3.9>>>")
|
||||
set(no_register "$<OR:${clang_4plus},$<CXX_COMPILER_ID:AppleClang>>")
|
||||
|
||||
if(MSVC AND CMAKE_VERSION VERSION_LESS 3.11)
|
||||
set(cxx_no_register "${no_register}")
|
||||
else()
|
||||
set(cxx_no_register "$<AND:$<COMPILE_LANGUAGE:CXX>,${no_register}>")
|
||||
endif()
|
||||
|
||||
set(msvc "$<CXX_COMPILER_ID:MSVC>")
|
||||
|
||||
set_property(
|
||||
TARGET pybind11::python2_no_register
|
||||
PROPERTY INTERFACE_COMPILE_OPTIONS
|
||||
"$<${cxx_no_register}:-Wno-register;-Wno-deprecated-register>" "$<${msvc}:/wd5033>")
|
||||
|
||||
# --------------------------- link helper ---------------------------
|
||||
|
||||
add_library(pybind11::python_link_helper IMPORTED INTERFACE ${optional_global})
|
||||
@@ -109,28 +100,32 @@ endif()
|
||||
|
||||
add_library(pybind11::windows_extras IMPORTED INTERFACE ${optional_global})
|
||||
|
||||
if(MSVC)
|
||||
# /MP enables multithreaded builds (relevant when there are many files), /bigobj is
|
||||
# needed for bigger binding projects due to the limit to 64k addressable sections
|
||||
if(MSVC) # That's also clang-cl
|
||||
# /bigobj is needed for bigger binding projects due to the limit to 64k
|
||||
# addressable sections
|
||||
set_property(
|
||||
TARGET pybind11::windows_extras
|
||||
APPEND
|
||||
PROPERTY INTERFACE_COMPILE_OPTIONS /bigobj)
|
||||
PROPERTY INTERFACE_COMPILE_OPTIONS $<$<COMPILE_LANGUAGE:CXX>:/bigobj>)
|
||||
|
||||
if(CMAKE_VERSION VERSION_LESS 3.11)
|
||||
set_property(
|
||||
TARGET pybind11::windows_extras
|
||||
APPEND
|
||||
PROPERTY INTERFACE_COMPILE_OPTIONS $<$<NOT:$<CONFIG:Debug>>:/MP>)
|
||||
else()
|
||||
# Only set these options for C++ files. This is important so that, for
|
||||
# instance, projects that include other types of source files like CUDA
|
||||
# .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>>)
|
||||
# /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_VERSION VERSION_LESS 3.11)
|
||||
set_property(
|
||||
TARGET pybind11::windows_extras
|
||||
APPEND
|
||||
PROPERTY INTERFACE_COMPILE_OPTIONS $<$<NOT:$<CONFIG:Debug>>:/MP>)
|
||||
else()
|
||||
# Only set these options for C++ files. This is important so that, for
|
||||
# instance, projects that include other types of source files like CUDA
|
||||
# .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()
|
||||
|
||||
@@ -178,14 +173,26 @@ endif()
|
||||
|
||||
# --------------------- Python specifics -------------------------
|
||||
|
||||
# CMake 3.27 removes the classic FindPythonInterp if CMP0148 is NEW
|
||||
if(CMAKE_VERSION VERSION_LESS "3.27")
|
||||
set(_pybind11_missing_old_python "OLD")
|
||||
else()
|
||||
cmake_policy(GET CMP0148 _pybind11_missing_old_python)
|
||||
endif()
|
||||
|
||||
# Check to see which Python mode we are in, new, old, or no python
|
||||
if(PYBIND11_NOPYTHON)
|
||||
set(_pybind11_nopython ON)
|
||||
# We won't use new FindPython if PYBIND11_FINDPYTHON is defined and falselike
|
||||
# Otherwise, we use if FindPythonLibs is missing or if FindPython was already used
|
||||
elseif(
|
||||
PYBIND11_FINDPYTHON
|
||||
OR Python_FOUND
|
||||
OR Python2_FOUND
|
||||
OR Python3_FOUND)
|
||||
(NOT DEFINED PYBIND11_FINDPYTHON OR PYBIND11_FINDPYTHON)
|
||||
AND (_pybind11_missing_old_python STREQUAL "NEW"
|
||||
OR PYBIND11_FINDPYTHON
|
||||
OR Python_FOUND
|
||||
OR Python3_FOUND
|
||||
))
|
||||
|
||||
# New mode
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/pybind11NewTools.cmake")
|
||||
|
||||
@@ -198,7 +205,7 @@ endif()
|
||||
|
||||
# --------------------- pybind11_find_import -------------------------------
|
||||
|
||||
if(NOT _pybind11_nopython)
|
||||
if(NOT _pybind11_nopython AND NOT _PYBIND11_CROSSCOMPILING)
|
||||
# Check to see if modules are importable. Use REQUIRED to force an error if
|
||||
# one of the modules is not found. <package_name>_FOUND will be set if the
|
||||
# package was found (underscores replace dashes if present). QUIET will hide
|
||||
@@ -225,8 +232,15 @@ if(NOT _pybind11_nopython)
|
||||
|
||||
execute_process(
|
||||
COMMAND
|
||||
${${_Python}_EXECUTABLE} -c
|
||||
"from pkg_resources import get_distribution; print(get_distribution('${PYPI_NAME}').version)"
|
||||
${${_Python}_EXECUTABLE} -c "
|
||||
try:
|
||||
from importlib.metadata import version
|
||||
except ImportError:
|
||||
from pkg_resources import get_distribution
|
||||
def version(s):
|
||||
return get_distribution(s).version
|
||||
print(version('${PYPI_NAME}'))
|
||||
"
|
||||
RESULT_VARIABLE RESULT_PRESENT
|
||||
OUTPUT_VARIABLE PKG_VERSION
|
||||
ERROR_QUIET)
|
||||
@@ -292,27 +306,53 @@ function(_pybind11_return_if_cxx_and_linker_flags_work result cxxflags linkerfla
|
||||
endfunction()
|
||||
|
||||
function(_pybind11_generate_lto target prefer_thin_lto)
|
||||
if(MINGW)
|
||||
message(STATUS "${target} disabled (problems with undefined symbols for MinGW for now)")
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
|
||||
set(cxx_append "")
|
||||
set(linker_append "")
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT APPLE)
|
||||
# Clang Gold plugin does not support -Os; append -O3 to MinSizeRel builds to override it
|
||||
set(linker_append ";$<$<CONFIG:MinSizeRel>:-O3>")
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND NOT MINGW)
|
||||
set(cxx_append ";-fno-fat-lto-objects")
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND prefer_thin_lto)
|
||||
_pybind11_return_if_cxx_and_linker_flags_work(
|
||||
HAS_FLTO_THIN "-flto=thin${cxx_append}" "-flto=thin${linker_append}"
|
||||
PYBIND11_LTO_CXX_FLAGS PYBIND11_LTO_LINKER_FLAGS)
|
||||
if(prefer_thin_lto)
|
||||
set(thin "=thin")
|
||||
else()
|
||||
set(thin "")
|
||||
endif()
|
||||
|
||||
if(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le" OR CMAKE_SYSTEM_PROCESSOR MATCHES "mips64")
|
||||
# Do nothing
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES emscripten)
|
||||
# This compile is very costly when cross-compiling, so set this without checking
|
||||
set(PYBIND11_LTO_CXX_FLAGS "-flto${thin}${cxx_append}")
|
||||
set(PYBIND11_LTO_LINKER_FLAGS "-flto${thin}${linker_append}")
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
_pybind11_return_if_cxx_and_linker_flags_work(
|
||||
HAS_FLTO_THIN "-flto${thin}${cxx_append}" "-flto=${thin}${linker_append}"
|
||||
PYBIND11_LTO_CXX_FLAGS PYBIND11_LTO_LINKER_FLAGS)
|
||||
endif()
|
||||
if(NOT HAS_FLTO_THIN)
|
||||
_pybind11_return_if_cxx_and_linker_flags_work(
|
||||
HAS_FLTO "-flto${cxx_append}" "-flto${linker_append}" PYBIND11_LTO_CXX_FLAGS
|
||||
PYBIND11_LTO_LINKER_FLAGS)
|
||||
endif()
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "IntelLLVM")
|
||||
# IntelLLVM equivalent to LTO is called IPO; also IntelLLVM is WIN32/UNIX
|
||||
# WARNING/HELP WANTED: This block of code is currently not covered by pybind11 GitHub Actions!
|
||||
if(WIN32)
|
||||
_pybind11_return_if_cxx_and_linker_flags_work(
|
||||
HAS_INTEL_IPO "-Qipo" "-Qipo" PYBIND11_LTO_CXX_FLAGS PYBIND11_LTO_LINKER_FLAGS)
|
||||
else()
|
||||
_pybind11_return_if_cxx_and_linker_flags_work(
|
||||
HAS_INTEL_IPO "-ipo" "-ipo" PYBIND11_LTO_CXX_FLAGS PYBIND11_LTO_LINKER_FLAGS)
|
||||
endif()
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
|
||||
# Intel equivalent to LTO is called IPO
|
||||
_pybind11_return_if_cxx_and_linker_flags_work(HAS_INTEL_IPO "-ipo" "-ipo"
|
||||
@@ -364,11 +404,13 @@ function(_pybind11_generate_lto target prefer_thin_lto)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
add_library(pybind11::lto IMPORTED INTERFACE ${optional_global})
|
||||
_pybind11_generate_lto(pybind11::lto FALSE)
|
||||
if(NOT DEFINED CMAKE_INTERPROCEDURAL_OPTIMIZATION)
|
||||
add_library(pybind11::lto IMPORTED INTERFACE ${optional_global})
|
||||
_pybind11_generate_lto(pybind11::lto FALSE)
|
||||
|
||||
add_library(pybind11::thin_lto IMPORTED INTERFACE ${optional_global})
|
||||
_pybind11_generate_lto(pybind11::thin_lto TRUE)
|
||||
add_library(pybind11::thin_lto IMPORTED INTERFACE ${optional_global})
|
||||
_pybind11_generate_lto(pybind11::thin_lto TRUE)
|
||||
endif()
|
||||
|
||||
# ---------------------- pybind11_strip -----------------------------
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ This module sets the following variables in your project:
|
||||
``pybind11_VERSION``
|
||||
pybind11 version in format Major.Minor.Release
|
||||
``pybind11_VERSION_TYPE``
|
||||
pybind11 version type (dev, release)
|
||||
pybind11 version type (``dev*`` or empty for a release)
|
||||
``pybind11_INCLUDE_DIRS``
|
||||
Directories where pybind11 and python headers are located.
|
||||
``pybind11_INCLUDE_DIR``
|
||||
@@ -51,8 +51,6 @@ complex applications, and they are available in all modes:
|
||||
Python headers too.
|
||||
``pybind11::python_link_helper``
|
||||
Just the "linking" part of ``pybind11:module``, for CMake < 3.15.
|
||||
``pybind11::python2_no_register``
|
||||
Quiets the warning/error when mixing C++14+ and Python 2, also included in ``pybind11::module``.
|
||||
``pybind11::thin_lto``
|
||||
An alternative to ``INTERPROCEDURAL_OPTIMIZATION``.
|
||||
``pybind11::lto``
|
||||
@@ -65,7 +63,9 @@ Modes
|
||||
|
||||
There are two modes provided; classic, which is built on the old Python
|
||||
discovery packages in CMake, or the new FindPython mode, which uses FindPython
|
||||
from 3.12+ forward (3.15+ _highly_ recommended).
|
||||
from 3.12+ forward (3.15+ _highly_ recommended). If you set the minimum or
|
||||
maximum version of CMake to 3.27+, then FindPython is the default (since
|
||||
FindPythonInterp/FindPythonLibs has been removed via policy `CMP0148`).
|
||||
|
||||
New FindPython mode
|
||||
^^^^^^^^^^^^^^^^^^^
|
||||
@@ -87,8 +87,8 @@ you can either use the basic targets, or use the FindPython tools:
|
||||
target_link_libraries(MyModule2 pybind11::headers)
|
||||
set_target_properties(MyModule2 PROPERTIES
|
||||
INTERPROCEDURAL_OPTIMIZATION ON
|
||||
CXX__VISIBILITY_PRESET ON
|
||||
VISIBLITY_INLINES_HIDDEN ON)
|
||||
CXX_VISIBILITY_PRESET ON
|
||||
VISIBILITY_INLINES_HIDDEN ON)
|
||||
|
||||
If you build targets yourself, you may be interested in stripping the output
|
||||
for reduced size; this is the one other feature that the helper function gives you.
|
||||
@@ -139,7 +139,7 @@ This module defines the following commands to assist with creating Python module
|
||||
|
||||
pybind11_add_module(<target>
|
||||
[STATIC|SHARED|MODULE]
|
||||
[THIN_LTO] [OPT_SIZE] [NO_EXTRAS] [WITHOUT_SOBAI]
|
||||
[THIN_LTO] [OPT_SIZE] [NO_EXTRAS] [WITHOUT_SOABI]
|
||||
<files>...
|
||||
)
|
||||
|
||||
@@ -147,9 +147,9 @@ Add a module and setup all helpers. You can select the type of the library; the
|
||||
default is ``MODULE``. There are several options:
|
||||
|
||||
``OPT_SIZE``
|
||||
Optimize for size, even if the ``CMAKE_BUILD_TYPE`` is not ``RelSize``.
|
||||
Optimize for size, even if the ``CMAKE_BUILD_TYPE`` is not ``MinSizeRel``.
|
||||
``THIN_LTO``
|
||||
Use thin TLO instead of regular if there's a choice (pybind11's selection
|
||||
Use thin LTO instead of regular if there's a choice (pybind11's selection
|
||||
is disabled if ``CMAKE_INTERPROCEDURAL_OPTIMIZATIONS`` is set).
|
||||
``WITHOUT_SOABI``
|
||||
Disable the SOABI component (``PYBIND11_NEWPYTHON`` mode only).
|
||||
@@ -195,13 +195,14 @@ Using ``find_package`` with version info is not recommended except for release v
|
||||
.. code-block:: cmake
|
||||
|
||||
find_package(pybind11 CONFIG)
|
||||
find_package(pybind11 2.0 EXACT CONFIG REQUIRED)
|
||||
find_package(pybind11 2.9 EXACT CONFIG REQUIRED)
|
||||
|
||||
#]=============================================================================]
|
||||
@PACKAGE_INIT@
|
||||
|
||||
# Location of pybind11/pybind11.h
|
||||
set(pybind11_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_INCLUDEDIR@")
|
||||
# This will be relative unless explicitly set as absolute
|
||||
set(pybind11_INCLUDE_DIR "@pybind11_INCLUDEDIR@")
|
||||
|
||||
set(pybind11_LIBRARY "")
|
||||
set(pybind11_DEFINITIONS USING_pybind11)
|
||||
@@ -227,6 +228,6 @@ include("${CMAKE_CURRENT_LIST_DIR}/pybind11Common.cmake")
|
||||
if(NOT pybind11_FIND_QUIETLY)
|
||||
message(
|
||||
STATUS
|
||||
"Found pybind11: ${pybind11_INCLUDE_DIR} (found version \"${pybind11_VERSION}\" ${pybind11_VERSION_TYPE})"
|
||||
"Found pybind11: ${pybind11_INCLUDE_DIR} (found version \"${pybind11_VERSION}${pybind11_VERSION_TYPE}\")"
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
function(pybind11_guess_python_module_extension python)
|
||||
|
||||
# The SETUPTOOLS_EXT_SUFFIX environment variable takes precedence:
|
||||
if(NOT DEFINED PYTHON_MODULE_EXT_SUFFIX AND DEFINED ENV{SETUPTOOLS_EXT_SUFFIX})
|
||||
message(
|
||||
STATUS
|
||||
"Getting Python extension suffix from ENV{SETUPTOOLS_EXT_SUFFIX}: $ENV{SETUPTOOLS_EXT_SUFFIX}"
|
||||
)
|
||||
set(PYTHON_MODULE_EXT_SUFFIX
|
||||
"$ENV{SETUPTOOLS_EXT_SUFFIX}"
|
||||
CACHE
|
||||
STRING
|
||||
"Extension suffix for Python extension modules (Initialized from SETUPTOOLS_EXT_SUFFIX)")
|
||||
endif()
|
||||
# If that didn't work, use the Python_SOABI variable:
|
||||
if(NOT DEFINED PYTHON_MODULE_EXT_SUFFIX AND DEFINED ${python}_SOABI)
|
||||
message(
|
||||
STATUS "Determining Python extension suffix based on ${python}_SOABI: ${${python}_SOABI}")
|
||||
# The final extension depends on the system
|
||||
set(_PY_BUILD_EXTENSION "${CMAKE_SHARED_MODULE_SUFFIX}")
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
set(_PY_BUILD_EXTENSION ".pyd")
|
||||
endif()
|
||||
# If the SOABI already has an extension, use it as the full suffix
|
||||
# (used for debug versions of Python on Windows)
|
||||
if(${python}_SOABI MATCHES "\\.")
|
||||
set(PYTHON_MODULE_EXT_SUFFIX "${${python}_SOABI}")
|
||||
# If the SOABI is empty, this is usually a bug, but we generate a
|
||||
# correct extension anyway, which is the best we can do
|
||||
elseif("${${python}_SOABI}" STREQUAL "")
|
||||
message(
|
||||
WARNING
|
||||
"${python}_SOABI is defined but empty. You may want to set PYTHON_MODULE_EXT_SUFFIX explicitly."
|
||||
)
|
||||
set(PYTHON_MODULE_EXT_SUFFIX "${_PY_BUILD_EXTENSION}")
|
||||
# Otherwise, add the system-dependent extension to it
|
||||
else()
|
||||
set(PYTHON_MODULE_EXT_SUFFIX ".${${python}_SOABI}${_PY_BUILD_EXTENSION}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# If we could not deduce the extension suffix, unset the results:
|
||||
if(NOT DEFINED PYTHON_MODULE_EXT_SUFFIX)
|
||||
unset(PYTHON_MODULE_DEBUG_POSTFIX PARENT_SCOPE)
|
||||
unset(PYTHON_MODULE_EXTENSION PARENT_SCOPE)
|
||||
unset(PYTHON_IS_DEBUG PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# Sanity checks:
|
||||
if(${python}_SOABI AND NOT (PYTHON_MODULE_EXT_SUFFIX STREQUAL ${python}_SOABI
|
||||
OR PYTHON_MODULE_EXT_SUFFIX MATCHES "\\.${${python}_SOABI}\\."))
|
||||
message(
|
||||
WARNING
|
||||
"Python extension suffix (${PYTHON_MODULE_EXT_SUFFIX}) does not match ${python}_SOABI (${${python}_SOABI})."
|
||||
)
|
||||
endif()
|
||||
|
||||
# Separate file name postfix from extension: (https://github.com/pybind/pybind11/issues/4699)
|
||||
get_filename_component(_PYTHON_MODULE_DEBUG_POSTFIX "${PYTHON_MODULE_EXT_SUFFIX}" NAME_WE)
|
||||
get_filename_component(_PYTHON_MODULE_EXTENSION "${PYTHON_MODULE_EXT_SUFFIX}" EXT)
|
||||
|
||||
# Try to deduce the debug ABI from the extension suffix:
|
||||
if(NOT DEFINED _PYTHON_IS_DEBUG)
|
||||
if(_PYTHON_MODULE_EXTENSION MATCHES "^\\.(cpython-|cp|pypy)[0-9]+dm?-"
|
||||
OR _PYTHON_MODULE_DEBUG_POSTFIX MATCHES "^_d")
|
||||
set(_PYTHON_IS_DEBUG On)
|
||||
else()
|
||||
set(_PYTHON_IS_DEBUG Off)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Return results
|
||||
set(PYTHON_MODULE_DEBUG_POSTFIX
|
||||
"${_PYTHON_MODULE_DEBUG_POSTFIX}"
|
||||
PARENT_SCOPE)
|
||||
set(PYTHON_MODULE_EXTENSION
|
||||
"${_PYTHON_MODULE_EXTENSION}"
|
||||
PARENT_SCOPE)
|
||||
set(PYTHON_IS_DEBUG
|
||||
"${_PYTHON_IS_DEBUG}"
|
||||
PARENT_SCOPE)
|
||||
|
||||
endfunction()
|
||||
@@ -5,6 +5,12 @@
|
||||
# All rights reserved. Use of this source code is governed by a
|
||||
# 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)
|
||||
|
||||
get_property(
|
||||
is_config
|
||||
TARGET pybind11::headers
|
||||
@@ -12,15 +18,11 @@ get_property(
|
||||
|
||||
if(pybind11_FIND_QUIETLY)
|
||||
set(_pybind11_quiet QUIET)
|
||||
else()
|
||||
set(_pybind11_quiet "")
|
||||
endif()
|
||||
|
||||
if(CMAKE_VERSION VERSION_LESS 3.12)
|
||||
message(FATAL_ERROR "You cannot use the new FindPython module with CMake < 3.12")
|
||||
endif()
|
||||
|
||||
if(NOT Python_FOUND
|
||||
AND NOT Python3_FOUND
|
||||
AND NOT Python2_FOUND)
|
||||
if(NOT Python_FOUND AND NOT Python3_FOUND)
|
||||
if(NOT DEFINED Python_FIND_IMPLEMENTATIONS)
|
||||
set(Python_FIND_IMPLEMENTATIONS CPython PyPy)
|
||||
endif()
|
||||
@@ -30,36 +32,74 @@ if(NOT Python_FOUND
|
||||
set(Python_ROOT_DIR "$ENV{pythonLocation}")
|
||||
endif()
|
||||
|
||||
find_package(Python REQUIRED COMPONENTS Interpreter Development ${_pybind11_quiet})
|
||||
# Interpreter should not be found when cross-compiling
|
||||
if(_PYBIND11_CROSSCOMPILING)
|
||||
set(_pybind11_interp_component "")
|
||||
else()
|
||||
set(_pybind11_interp_component Interpreter)
|
||||
endif()
|
||||
|
||||
# Development.Module support (required for manylinux) started in 3.18
|
||||
if(CMAKE_VERSION VERSION_LESS 3.18)
|
||||
set(_pybind11_dev_component Development)
|
||||
else()
|
||||
set(_pybind11_dev_component Development.Module OPTIONAL_COMPONENTS Development.Embed)
|
||||
endif()
|
||||
|
||||
# Callers need to be able to access Python_EXECUTABLE
|
||||
set(_pybind11_global_keyword "")
|
||||
if(NOT is_config AND NOT DEFINED Python_ARTIFACTS_INTERACTIVE)
|
||||
set(Python_ARTIFACTS_INTERACTIVE TRUE)
|
||||
if(NOT CMAKE_VERSION VERSION_LESS 3.24)
|
||||
set(_pybind11_global_keyword "GLOBAL")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
find_package(
|
||||
Python 3.7 REQUIRED COMPONENTS ${_pybind11_interp_component} ${_pybind11_dev_component}
|
||||
${_pybind11_quiet} ${_pybind11_global_keyword})
|
||||
|
||||
# If we are in submodule mode, export the Python targets to global targets.
|
||||
# If this behavior is not desired, FindPython _before_ pybind11.
|
||||
if(NOT is_config)
|
||||
set_property(TARGET Python::Python PROPERTY IMPORTED_GLOBAL TRUE)
|
||||
set_property(TARGET Python::Interpreter PROPERTY IMPORTED_GLOBAL TRUE)
|
||||
if(NOT is_config
|
||||
AND Python_ARTIFACTS_INTERACTIVE
|
||||
AND _pybind11_global_keyword STREQUAL "")
|
||||
if(TARGET Python::Python)
|
||||
set_property(TARGET Python::Python PROPERTY IMPORTED_GLOBAL TRUE)
|
||||
endif()
|
||||
if(TARGET Python::Interpreter)
|
||||
set_property(TARGET Python::Interpreter PROPERTY IMPORTED_GLOBAL TRUE)
|
||||
endif()
|
||||
if(TARGET Python::Module)
|
||||
set_property(TARGET Python::Module PROPERTY IMPORTED_GLOBAL TRUE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Explicitly export version for callers (including our own functions)
|
||||
if(NOT is_config AND Python_ARTIFACTS_INTERACTIVE)
|
||||
set(Python_VERSION
|
||||
"${Python_VERSION}"
|
||||
CACHE INTERNAL "")
|
||||
set(Python_VERSION_MAJOR
|
||||
"${Python_VERSION_MAJOR}"
|
||||
CACHE INTERNAL "")
|
||||
set(Python_VERSION_MINOR
|
||||
"${Python_VERSION_MINOR}"
|
||||
CACHE INTERNAL "")
|
||||
set(Python_VERSION_PATCH
|
||||
"${Python_VERSION_PATCH}"
|
||||
CACHE INTERNAL "")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(Python_FOUND)
|
||||
set(_Python
|
||||
Python
|
||||
CACHE INTERNAL "" FORCE)
|
||||
elseif(Python3_FOUND AND NOT Python2_FOUND)
|
||||
elseif(Python3_FOUND)
|
||||
set(_Python
|
||||
Python3
|
||||
CACHE INTERNAL "" FORCE)
|
||||
elseif(Python2_FOUND AND NOT Python3_FOUND)
|
||||
set(_Python
|
||||
Python2
|
||||
CACHE INTERNAL "" FORCE)
|
||||
else()
|
||||
message(AUTHOR_WARNING "Python2 and Python3 both present, pybind11 in "
|
||||
"PYBIND11_NOPYTHON mode (manually activate to silence warning)")
|
||||
set(_pybind11_nopython ON)
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(PYBIND11_MASTER_PROJECT)
|
||||
@@ -70,47 +110,90 @@ if(PYBIND11_MASTER_PROJECT)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# If a user finds Python, they may forget to include the Interpreter component
|
||||
# and the following two steps require it. It is highly recommended by CMake
|
||||
# when finding development libraries anyway, so we will require it.
|
||||
if(NOT DEFINED ${_Python}_EXECUTABLE)
|
||||
message(
|
||||
FATAL_ERROR
|
||||
"${_Python} was found without the Interpreter component. Pybind11 requires this component.")
|
||||
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED PYTHON_IS_DEBUG)
|
||||
# Debug check - see https://stackoverflow.com/questions/646518/python-how-to-detect-debug-Interpreter
|
||||
execute_process(
|
||||
COMMAND "${${_Python}_EXECUTABLE}" "-c"
|
||||
"import sys; sys.exit(hasattr(sys, 'gettotalrefcount'))"
|
||||
RESULT_VARIABLE _PYTHON_IS_DEBUG)
|
||||
set(PYTHON_IS_DEBUG
|
||||
"${_PYTHON_IS_DEBUG}"
|
||||
CACHE INTERNAL "Python debug status")
|
||||
endif()
|
||||
|
||||
# Get the suffix - SO is deprecated, should use EXT_SUFFIX, but this is
|
||||
# required for PyPy3 (as of 7.3.1)
|
||||
if(NOT DEFINED PYTHON_MODULE_EXTENSION)
|
||||
execute_process(
|
||||
COMMAND "${${_Python}_EXECUTABLE}" "-c"
|
||||
"from distutils import sysconfig; print(sysconfig.get_config_var('SO'))"
|
||||
OUTPUT_VARIABLE _PYTHON_MODULE_EXTENSION
|
||||
ERROR_VARIABLE _PYTHON_MODULE_EXTENSION_ERR
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
if(_PYTHON_MODULE_EXTENSION STREQUAL "")
|
||||
if(NOT _PYBIND11_CROSSCOMPILING)
|
||||
# If a user finds Python, they may forget to include the Interpreter component
|
||||
# and the following two steps require it. It is highly recommended by CMake
|
||||
# when finding development libraries anyway, so we will require it.
|
||||
if(NOT DEFINED ${_Python}_EXECUTABLE)
|
||||
message(
|
||||
FATAL_ERROR "pybind11 could not query the module file extension, likely the 'distutils'"
|
||||
"package is not installed. Full error message:\n${_PYTHON_MODULE_EXTENSION_ERR}")
|
||||
FATAL_ERROR
|
||||
"${_Python} was found without the Interpreter component. Pybind11 requires this component."
|
||||
)
|
||||
|
||||
endif()
|
||||
|
||||
# This needs to be available for the pybind11_extension function
|
||||
set(PYTHON_MODULE_EXTENSION
|
||||
"${_PYTHON_MODULE_EXTENSION}"
|
||||
CACHE INTERNAL "")
|
||||
if(DEFINED PYBIND11_PYTHON_EXECUTABLE_LAST AND NOT ${_Python}_EXECUTABLE STREQUAL
|
||||
PYBIND11_PYTHON_EXECUTABLE_LAST)
|
||||
# Detect changes to the Python version/binary in subsequent CMake runs, and refresh config if needed
|
||||
unset(PYTHON_IS_DEBUG CACHE)
|
||||
unset(PYTHON_MODULE_EXTENSION CACHE)
|
||||
endif()
|
||||
|
||||
set(PYBIND11_PYTHON_EXECUTABLE_LAST
|
||||
"${${_Python}_EXECUTABLE}"
|
||||
CACHE INTERNAL "Python executable during the last CMake run")
|
||||
|
||||
if(NOT DEFINED PYTHON_IS_DEBUG)
|
||||
# Debug check - see https://stackoverflow.com/questions/646518/python-how-to-detect-debug-Interpreter
|
||||
execute_process(
|
||||
COMMAND "${${_Python}_EXECUTABLE}" "-c"
|
||||
"import sys; sys.exit(hasattr(sys, 'gettotalrefcount'))"
|
||||
RESULT_VARIABLE _PYTHON_IS_DEBUG)
|
||||
set(PYTHON_IS_DEBUG
|
||||
"${_PYTHON_IS_DEBUG}"
|
||||
CACHE INTERNAL "Python debug status")
|
||||
endif()
|
||||
|
||||
# Get the suffix - SO is deprecated, should use EXT_SUFFIX, but this is
|
||||
# required for PyPy3 (as of 7.3.1)
|
||||
if(NOT DEFINED PYTHON_MODULE_EXTENSION OR NOT DEFINED PYTHON_MODULE_DEBUG_POSTFIX)
|
||||
execute_process(
|
||||
COMMAND
|
||||
"${${_Python}_EXECUTABLE}" "-c"
|
||||
"import sys, importlib; s = importlib.import_module('distutils.sysconfig' if sys.version_info < (3, 10) else 'sysconfig'); print(s.get_config_var('EXT_SUFFIX') or s.get_config_var('SO'))"
|
||||
OUTPUT_VARIABLE _PYTHON_MODULE_EXT_SUFFIX
|
||||
ERROR_VARIABLE _PYTHON_MODULE_EXT_SUFFIX_ERR
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
if(_PYTHON_MODULE_EXT_SUFFIX STREQUAL "")
|
||||
message(
|
||||
FATAL_ERROR
|
||||
"pybind11 could not query the module file extension, likely the 'distutils'"
|
||||
"package is not installed. Full error message:\n${_PYTHON_MODULE_EXT_SUFFIX_ERR}")
|
||||
endif()
|
||||
|
||||
# This needs to be available for the pybind11_extension function
|
||||
if(NOT DEFINED PYTHON_MODULE_DEBUG_POSTFIX)
|
||||
get_filename_component(_PYTHON_MODULE_DEBUG_POSTFIX "${_PYTHON_MODULE_EXT_SUFFIX}" NAME_WE)
|
||||
set(PYTHON_MODULE_DEBUG_POSTFIX
|
||||
"${_PYTHON_MODULE_DEBUG_POSTFIX}"
|
||||
CACHE INTERNAL "")
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED PYTHON_MODULE_EXTENSION)
|
||||
get_filename_component(_PYTHON_MODULE_EXTENSION "${_PYTHON_MODULE_EXT_SUFFIX}" EXT)
|
||||
set(PYTHON_MODULE_EXTENSION
|
||||
"${_PYTHON_MODULE_EXTENSION}"
|
||||
CACHE INTERNAL "")
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
if(NOT DEFINED PYTHON_IS_DEBUG
|
||||
OR NOT DEFINED PYTHON_MODULE_EXTENSION
|
||||
OR NOT DEFINED PYTHON_MODULE_DEBUG_POSTFIX)
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/pybind11GuessPythonExtSuffix.cmake")
|
||||
pybind11_guess_python_module_extension("${_Python}")
|
||||
endif()
|
||||
# When cross-compiling, we cannot query the Python interpreter, so we require
|
||||
# the user to set these variables explicitly.
|
||||
if(NOT DEFINED PYTHON_IS_DEBUG
|
||||
OR NOT DEFINED PYTHON_MODULE_EXTENSION
|
||||
OR NOT DEFINED PYTHON_MODULE_DEBUG_POSTFIX)
|
||||
message(
|
||||
FATAL_ERROR
|
||||
"When cross-compiling, you should set the PYTHON_IS_DEBUG, PYTHON_MODULE_EXTENSION and PYTHON_MODULE_DEBUG_POSTFIX \
|
||||
variables appropriately before loading pybind11 (e.g. in your CMake toolchain file)")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Python debug libraries expose slightly different objects before 3.8
|
||||
@@ -123,28 +206,34 @@ if(PYTHON_IS_DEBUG)
|
||||
PROPERTY INTERFACE_COMPILE_DEFINITIONS Py_DEBUG)
|
||||
endif()
|
||||
|
||||
# Check on every access - since Python2 and Python3 could have been used - do nothing in that case.
|
||||
# Check on every access - since Python can change - do nothing in that case.
|
||||
|
||||
if(DEFINED ${_Python}_INCLUDE_DIRS)
|
||||
# Only add Python for build - must be added during the import for config
|
||||
# since it has to be re-discovered.
|
||||
#
|
||||
# This needs to be a target to be included after the local pybind11
|
||||
# directory, just in case there there is an installed pybind11 sitting
|
||||
# next to Python's includes. It also ensures Python is a SYSTEM library.
|
||||
add_library(pybind11::python_headers INTERFACE IMPORTED)
|
||||
set_property(
|
||||
TARGET pybind11::python_headers PROPERTY INTERFACE_INCLUDE_DIRECTORIES
|
||||
"$<BUILD_INTERFACE:${${_Python}_INCLUDE_DIRS}>")
|
||||
set_property(
|
||||
TARGET pybind11::pybind11
|
||||
APPEND
|
||||
PROPERTY INTERFACE_INCLUDE_DIRECTORIES $<BUILD_INTERFACE:${${_Python}_INCLUDE_DIRS}>)
|
||||
endif()
|
||||
|
||||
if(DEFINED ${_Python}_VERSION AND ${_Python}_VERSION VERSION_LESS 3)
|
||||
set_property(
|
||||
TARGET pybind11::pybind11
|
||||
APPEND
|
||||
PROPERTY INTERFACE_LINK_LIBRARIES pybind11::python2_no_register)
|
||||
PROPERTY INTERFACE_LINK_LIBRARIES pybind11::python_headers)
|
||||
set(pybind11_INCLUDE_DIRS
|
||||
"${pybind11_INCLUDE_DIR}" "${${_Python}_INCLUDE_DIRS}"
|
||||
CACHE INTERNAL "Directories where pybind11 and possibly Python headers are located")
|
||||
endif()
|
||||
|
||||
# In CMake 3.18+, you can find these separately, so include an if
|
||||
if(TARGET ${_Python}::${_Python})
|
||||
if(TARGET ${_Python}::Python)
|
||||
set_property(
|
||||
TARGET pybind11::embed
|
||||
APPEND
|
||||
PROPERTY INTERFACE_LINK_LIBRARIES ${_Python}::${_Python})
|
||||
PROPERTY INTERFACE_LINK_LIBRARIES ${_Python}::Python)
|
||||
endif()
|
||||
|
||||
# CMake 3.15+ has this
|
||||
@@ -166,27 +255,25 @@ function(pybind11_add_module target_name)
|
||||
cmake_parse_arguments(PARSE_ARGV 1 ARG
|
||||
"STATIC;SHARED;MODULE;THIN_LTO;OPT_SIZE;NO_EXTRAS;WITHOUT_SOABI" "" "")
|
||||
|
||||
if(ARG_ADD_LIBRARY_STATIC)
|
||||
set(type STATIC)
|
||||
elseif(ARG_ADD_LIBRARY_SHARED)
|
||||
set(type SHARED)
|
||||
if(ARG_STATIC)
|
||||
set(lib_type STATIC)
|
||||
elseif(ARG_SHARED)
|
||||
set(lib_type SHARED)
|
||||
else()
|
||||
set(type MODULE)
|
||||
set(lib_type MODULE)
|
||||
endif()
|
||||
|
||||
if("${_Python}" STREQUAL "Python")
|
||||
python_add_library(${target_name} ${type} ${ARG_UNPARSED_ARGUMENTS})
|
||||
python_add_library(${target_name} ${lib_type} ${ARG_UNPARSED_ARGUMENTS})
|
||||
elseif("${_Python}" STREQUAL "Python3")
|
||||
python3_add_library(${target_name} ${type} ${ARG_UNPARSED_ARGUMENTS})
|
||||
elseif("${_Python}" STREQUAL "Python2")
|
||||
python2_add_library(${target_name} ${type} ${ARG_UNPARSED_ARGUMENTS})
|
||||
python3_add_library(${target_name} ${lib_type} ${ARG_UNPARSED_ARGUMENTS})
|
||||
else()
|
||||
message(FATAL_ERROR "Cannot detect FindPython version: ${_Python}")
|
||||
endif()
|
||||
|
||||
target_link_libraries(${target_name} PRIVATE pybind11::headers)
|
||||
|
||||
if(type STREQUAL "MODULE")
|
||||
if(lib_type STREQUAL "MODULE")
|
||||
target_link_libraries(${target_name} PRIVATE pybind11::module)
|
||||
else()
|
||||
target_link_libraries(${target_name} PRIVATE pybind11::embed)
|
||||
@@ -196,16 +283,21 @@ function(pybind11_add_module target_name)
|
||||
target_link_libraries(${target_name} PRIVATE pybind11::windows_extras)
|
||||
endif()
|
||||
|
||||
if(DEFINED ${_Python}_VERSION AND ${_Python}_VERSION VERSION_LESS 3)
|
||||
target_link_libraries(${target_name} PRIVATE pybind11::python2_no_register)
|
||||
# -fvisibility=hidden is required to allow multiple modules compiled against
|
||||
# different pybind versions to work properly, and for some features (e.g.
|
||||
# py::module_local). We force it on everything inside the `pybind11`
|
||||
# namespace; also turning it on for a pybind module compilation here avoids
|
||||
# potential warnings or issues from having mixed hidden/non-hidden types.
|
||||
if(NOT DEFINED CMAKE_CXX_VISIBILITY_PRESET)
|
||||
set_target_properties(${target_name} PROPERTIES CXX_VISIBILITY_PRESET "hidden")
|
||||
endif()
|
||||
|
||||
set_target_properties(${target_name} PROPERTIES CXX_VISIBILITY_PRESET "hidden"
|
||||
CUDA_VISIBILITY_PRESET "hidden")
|
||||
if(NOT DEFINED CMAKE_CUDA_VISIBILITY_PRESET)
|
||||
set_target_properties(${target_name} PROPERTIES CUDA_VISIBILITY_PRESET "hidden")
|
||||
endif()
|
||||
|
||||
# If we don't pass a WITH_SOABI or WITHOUT_SOABI, use our own default handling of extensions
|
||||
if("${type}" STREQUAL "MODULE" AND (NOT ARG_WITHOUT_SOABI OR NOT "WITH_SOABI" IN_LIST
|
||||
ARG_UNPARSED_ARGUMENTS))
|
||||
if(NOT ARG_WITHOUT_SOABI AND NOT "WITH_SOABI" IN_LIST ARG_UNPARSED_ARGUMENTS)
|
||||
pybind11_extension(${target_name})
|
||||
endif()
|
||||
|
||||
@@ -221,9 +313,13 @@ function(pybind11_add_module target_name)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT MSVC AND NOT ${CMAKE_BUILD_TYPE} MATCHES Debug|RelWithDebInfo)
|
||||
# Strip unnecessary sections of the binary on Linux/macOS
|
||||
pybind11_strip(${target_name})
|
||||
if(DEFINED CMAKE_BUILD_TYPE) # see https://github.com/pybind/pybind11/issues/4454
|
||||
# Use case-insensitive comparison to match the result of $<CONFIG:cfgs>
|
||||
string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
|
||||
if(NOT MSVC AND NOT "${uppercase_CMAKE_BUILD_TYPE}" MATCHES DEBUG|RELWITHDEBINFO)
|
||||
# Strip unnecessary sections of the binary on Linux/macOS
|
||||
pybind11_strip(${target_name})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
@@ -237,6 +333,9 @@ endfunction()
|
||||
|
||||
function(pybind11_extension name)
|
||||
# The extension is precomputed
|
||||
set_target_properties(${name} PROPERTIES PREFIX "" SUFFIX "${PYTHON_MODULE_EXTENSION}")
|
||||
|
||||
set_target_properties(
|
||||
${name}
|
||||
PROPERTIES PREFIX ""
|
||||
DEBUG_POSTFIX "${PYTHON_MODULE_DEBUG_POSTFIX}"
|
||||
SUFFIX "${PYTHON_MODULE_EXTENSION}")
|
||||
endfunction()
|
||||
|
||||
@@ -5,11 +5,18 @@
|
||||
# All rights reserved. Use of this source code is governed by a
|
||||
# BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
# include_guard(global) (pre-CMake 3.10)
|
||||
if(TARGET pybind11::python_headers)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# Built-in in CMake 3.5+
|
||||
include(CMakeParseArguments)
|
||||
|
||||
if(pybind11_FIND_QUIETLY)
|
||||
set(_pybind11_quiet QUIET)
|
||||
else()
|
||||
set(_pybind11_quiet "")
|
||||
endif()
|
||||
|
||||
# If this is the first run, PYTHON_VERSION can stand in for PYBIND11_PYTHON_VERSION
|
||||
@@ -22,47 +29,47 @@ if(NOT DEFINED PYBIND11_PYTHON_VERSION AND DEFINED PYTHON_VERSION)
|
||||
CACHE STRING "Python version to use for compiling modules")
|
||||
unset(PYTHON_VERSION)
|
||||
unset(PYTHON_VERSION CACHE)
|
||||
else()
|
||||
# If this is set as a normal variable, promote it, otherwise, make an empty cache variable.
|
||||
elseif(DEFINED PYBIND11_PYTHON_VERSION)
|
||||
# If this is set as a normal variable, promote it
|
||||
set(PYBIND11_PYTHON_VERSION
|
||||
"${PYBIND11_PYTHON_VERSION}"
|
||||
CACHE STRING "Python version to use for compiling modules")
|
||||
else()
|
||||
# Make an empty cache variable.
|
||||
set(PYBIND11_PYTHON_VERSION
|
||||
""
|
||||
CACHE STRING "Python version to use for compiling modules")
|
||||
endif()
|
||||
|
||||
# A user can set versions manually too
|
||||
set(Python_ADDITIONAL_VERSIONS
|
||||
"3.9;3.8;3.7;3.6;3.5;3.4"
|
||||
"3.12;3.11;3.10;3.9;3.8;3.7"
|
||||
CACHE INTERNAL "")
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
|
||||
find_package(PythonLibsNew ${PYBIND11_PYTHON_VERSION} MODULE REQUIRED ${_pybind11_quiet})
|
||||
list(REMOVE_AT CMAKE_MODULE_PATH -1)
|
||||
|
||||
# Makes a normal variable a cached variable
|
||||
macro(_PYBIND11_PROMOTE_TO_CACHE NAME)
|
||||
set(_tmp_ptc "${${NAME}}")
|
||||
# CMake 3.21 complains if a cached variable is shadowed by a normal one
|
||||
unset(${NAME})
|
||||
set(${NAME}
|
||||
"${_tmp_ptc}"
|
||||
CACHE INTERNAL "")
|
||||
endmacro()
|
||||
|
||||
# Cache variables so pybind11_add_module can be used in parent projects
|
||||
set(PYTHON_INCLUDE_DIRS
|
||||
${PYTHON_INCLUDE_DIRS}
|
||||
CACHE INTERNAL "")
|
||||
set(PYTHON_LIBRARIES
|
||||
${PYTHON_LIBRARIES}
|
||||
CACHE INTERNAL "")
|
||||
set(PYTHON_MODULE_PREFIX
|
||||
${PYTHON_MODULE_PREFIX}
|
||||
CACHE INTERNAL "")
|
||||
set(PYTHON_MODULE_EXTENSION
|
||||
${PYTHON_MODULE_EXTENSION}
|
||||
CACHE INTERNAL "")
|
||||
set(PYTHON_VERSION_MAJOR
|
||||
${PYTHON_VERSION_MAJOR}
|
||||
CACHE INTERNAL "")
|
||||
set(PYTHON_VERSION_MINOR
|
||||
${PYTHON_VERSION_MINOR}
|
||||
CACHE INTERNAL "")
|
||||
set(PYTHON_VERSION
|
||||
${PYTHON_VERSION}
|
||||
CACHE INTERNAL "")
|
||||
set(PYTHON_IS_DEBUG
|
||||
"${PYTHON_IS_DEBUG}"
|
||||
CACHE INTERNAL "")
|
||||
_pybind11_promote_to_cache(PYTHON_INCLUDE_DIRS)
|
||||
_pybind11_promote_to_cache(PYTHON_LIBRARIES)
|
||||
_pybind11_promote_to_cache(PYTHON_MODULE_PREFIX)
|
||||
_pybind11_promote_to_cache(PYTHON_MODULE_EXTENSION)
|
||||
_pybind11_promote_to_cache(PYTHON_MODULE_DEBUG_POSTFIX)
|
||||
_pybind11_promote_to_cache(PYTHON_VERSION_MAJOR)
|
||||
_pybind11_promote_to_cache(PYTHON_VERSION_MINOR)
|
||||
_pybind11_promote_to_cache(PYTHON_VERSION)
|
||||
_pybind11_promote_to_cache(PYTHON_IS_DEBUG)
|
||||
|
||||
if(PYBIND11_MASTER_PROJECT)
|
||||
if(PYTHON_MODULE_EXTENSION MATCHES "pypy")
|
||||
@@ -81,11 +88,23 @@ if(PYBIND11_MASTER_PROJECT)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Only add Python for build - must be added during the import for config since it has to be re-discovered.
|
||||
# Only add Python for build - must be added during the import for config since
|
||||
# it has to be re-discovered.
|
||||
#
|
||||
# This needs to be an target to it is included after the local pybind11
|
||||
# directory, just in case there are multiple versions of pybind11, we want the
|
||||
# one we expect.
|
||||
add_library(pybind11::python_headers INTERFACE IMPORTED)
|
||||
set_property(TARGET pybind11::python_headers PROPERTY INTERFACE_INCLUDE_DIRECTORIES
|
||||
"$<BUILD_INTERFACE:${PYTHON_INCLUDE_DIRS}>")
|
||||
set_property(
|
||||
TARGET pybind11::pybind11
|
||||
APPEND
|
||||
PROPERTY INTERFACE_INCLUDE_DIRECTORIES $<BUILD_INTERFACE:${PYTHON_INCLUDE_DIRS}>)
|
||||
PROPERTY INTERFACE_LINK_LIBRARIES pybind11::python_headers)
|
||||
|
||||
set(pybind11_INCLUDE_DIRS
|
||||
"${pybind11_INCLUDE_DIR}" "${PYTHON_INCLUDE_DIRS}"
|
||||
CACHE INTERNAL "Directories where pybind11 and possibly Python headers are located")
|
||||
|
||||
# Python debug libraries expose slightly different objects before 3.8
|
||||
# https://docs.python.org/3.6/c-api/intro.html#debugging-builds
|
||||
@@ -97,29 +116,44 @@ if(PYTHON_IS_DEBUG)
|
||||
PROPERTY INTERFACE_COMPILE_DEFINITIONS Py_DEBUG)
|
||||
endif()
|
||||
|
||||
set_property(
|
||||
TARGET pybind11::module
|
||||
APPEND
|
||||
PROPERTY
|
||||
INTERFACE_LINK_LIBRARIES pybind11::python_link_helper
|
||||
"$<$<OR:$<PLATFORM_ID:Windows>,$<PLATFORM_ID:Cygwin>>:$<BUILD_INTERFACE:${PYTHON_LIBRARIES}>>")
|
||||
|
||||
if(PYTHON_VERSION VERSION_LESS 3)
|
||||
# The <3.11 code here does not support release/debug builds at the same time, like on vcpkg
|
||||
if(CMAKE_VERSION VERSION_LESS 3.11)
|
||||
set_property(
|
||||
TARGET pybind11::pybind11
|
||||
TARGET pybind11::module
|
||||
APPEND
|
||||
PROPERTY INTERFACE_LINK_LIBRARIES pybind11::python2_no_register)
|
||||
endif()
|
||||
PROPERTY
|
||||
INTERFACE_LINK_LIBRARIES
|
||||
pybind11::python_link_helper
|
||||
"$<$<OR:$<PLATFORM_ID:Windows>,$<PLATFORM_ID:Cygwin>>:$<BUILD_INTERFACE:${PYTHON_LIBRARIES}>>"
|
||||
)
|
||||
|
||||
set_property(
|
||||
TARGET pybind11::embed
|
||||
APPEND
|
||||
PROPERTY INTERFACE_LINK_LIBRARIES pybind11::pybind11 $<BUILD_INTERFACE:${PYTHON_LIBRARIES}>)
|
||||
set_property(
|
||||
TARGET pybind11::embed
|
||||
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)
|
||||
# The prefix and extension are provided by FindPythonLibsNew.cmake
|
||||
set_target_properties(${name} PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}"
|
||||
SUFFIX "${PYTHON_MODULE_EXTENSION}")
|
||||
set_target_properties(
|
||||
${name}
|
||||
PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}"
|
||||
DEBUG_POSTFIX "${PYTHON_MODULE_DEBUG_POSTFIX}"
|
||||
SUFFIX "${PYTHON_MODULE_EXTENSION}")
|
||||
endfunction()
|
||||
|
||||
# Build a Python extension module:
|
||||
@@ -162,8 +196,13 @@ function(pybind11_add_module target_name)
|
||||
# py::module_local). We force it on everything inside the `pybind11`
|
||||
# namespace; also turning it on for a pybind module compilation here avoids
|
||||
# potential warnings or issues from having mixed hidden/non-hidden types.
|
||||
set_target_properties(${target_name} PROPERTIES CXX_VISIBILITY_PRESET "hidden"
|
||||
CUDA_VISIBILITY_PRESET "hidden")
|
||||
if(NOT DEFINED CMAKE_CXX_VISIBILITY_PRESET)
|
||||
set_target_properties(${target_name} PROPERTIES CXX_VISIBILITY_PRESET "hidden")
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED CMAKE_CUDA_VISIBILITY_PRESET)
|
||||
set_target_properties(${target_name} PROPERTIES CUDA_VISIBILITY_PRESET "hidden")
|
||||
endif()
|
||||
|
||||
if(ARG_NO_EXTRAS)
|
||||
return()
|
||||
@@ -177,8 +216,12 @@ function(pybind11_add_module target_name)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT MSVC AND NOT ${CMAKE_BUILD_TYPE} MATCHES Debug|RelWithDebInfo)
|
||||
pybind11_strip(${target_name})
|
||||
if(DEFINED CMAKE_BUILD_TYPE) # see https://github.com/pybind/pybind11/issues/4454
|
||||
# Use case-insensitive comparison to match the result of $<CONFIG:cfgs>
|
||||
string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
|
||||
if(NOT MSVC AND NOT "${uppercase_CMAKE_BUILD_TYPE}" MATCHES DEBUG|RELWITHDEBINFO)
|
||||
pybind11_strip(${target_name})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
|
||||
@@ -1,17 +1,11 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Setup script for pybind11-global (in the sdist or in tools/setup_global.py in the repository)
|
||||
# This package is targeted for easy use from CMake.
|
||||
|
||||
import contextlib
|
||||
import glob
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
# Setuptools has to be before distutils
|
||||
from setuptools import setup
|
||||
@@ -33,8 +27,11 @@ class InstallHeadersNested(install_headers):
|
||||
|
||||
main_headers = glob.glob("pybind11/include/pybind11/*.h")
|
||||
detail_headers = glob.glob("pybind11/include/pybind11/detail/*.h")
|
||||
eigen_headers = glob.glob("pybind11/include/pybind11/eigen/*.h")
|
||||
stl_headers = glob.glob("pybind11/include/pybind11/stl/*.h")
|
||||
cmake_files = glob.glob("pybind11/share/cmake/pybind11/*.cmake")
|
||||
headers = main_headers + detail_headers
|
||||
pkgconfig_files = glob.glob("pybind11/share/pkgconfig/*.pc")
|
||||
headers = main_headers + detail_headers + stl_headers + eigen_headers
|
||||
|
||||
cmdclass = {"install_headers": InstallHeadersNested}
|
||||
$extra_cmd
|
||||
@@ -56,8 +53,11 @@ setup(
|
||||
headers=headers,
|
||||
data_files=[
|
||||
(base + "share/cmake/pybind11", cmake_files),
|
||||
(base + "share/pkgconfig", pkgconfig_files),
|
||||
(base + "include/pybind11", main_headers),
|
||||
(base + "include/pybind11/detail", detail_headers),
|
||||
(base + "include/pybind11/eigen", eigen_headers),
|
||||
(base + "include/pybind11/stl", stl_headers),
|
||||
],
|
||||
cmdclass=cmdclass,
|
||||
)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Setup script (in the sdist or in tools/setup_main.py in the repository)
|
||||
|
||||
@@ -16,13 +15,19 @@ setup(
|
||||
"pybind11",
|
||||
"pybind11.include.pybind11",
|
||||
"pybind11.include.pybind11.detail",
|
||||
"pybind11.include.pybind11.eigen",
|
||||
"pybind11.include.pybind11.stl",
|
||||
"pybind11.share.cmake.pybind11",
|
||||
"pybind11.share.pkgconfig",
|
||||
],
|
||||
package_data={
|
||||
"pybind11": ["py.typed", "*.pyi"],
|
||||
"pybind11": ["py.typed"],
|
||||
"pybind11.include.pybind11": ["*.h"],
|
||||
"pybind11.include.pybind11.detail": ["*.h"],
|
||||
"pybind11.include.pybind11.eigen": ["*.h"],
|
||||
"pybind11.include.pybind11.stl": ["*.h"],
|
||||
"pybind11.share.cmake.pybind11": ["*.cmake"],
|
||||
"pybind11.share.pkgconfig": ["*.pc"],
|
||||
},
|
||||
extras_require={
|
||||
"global": ["pybind11_global==$version"]
|
||||
@@ -30,6 +35,9 @@ setup(
|
||||
entry_points={
|
||||
"console_scripts": [
|
||||
"pybind11-config = pybind11.__main__:main",
|
||||
],
|
||||
"pipx.run": [
|
||||
"pybind11 = pybind11.__main__:main",
|
||||
]
|
||||
},
|
||||
cmdclass=cmdclass
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
# Tests for pybind11_guess_python_module_extension
|
||||
# Run using `cmake -P tools/test-pybind11GuessPythonExtSuffix.cmake`
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/pybind11GuessPythonExtSuffix.cmake")
|
||||
|
||||
macro(expect_streq actual expected)
|
||||
if(NOT "${actual}" STREQUAL "${expected}")
|
||||
message(SEND_ERROR "Fail\n *** actual: '${actual}'\n *** expected: '${expected}'")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
macro(expect_false actual)
|
||||
if("${actual}")
|
||||
message(SEND_ERROR "Fail\n *** actual: '${actual}'\n *** expected: false")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
macro(expect_true actual)
|
||||
if(NOT "${actual}")
|
||||
message(SEND_ERROR "Fail\n *** actual: '${actual}'\n *** expected: true")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# Windows
|
||||
set(CMAKE_SYSTEM_NAME "Windows")
|
||||
set(CMAKE_SHARED_MODULE_SUFFIX ".dll")
|
||||
|
||||
set(Python3_SOABI "")
|
||||
pybind11_guess_python_module_extension("Python3")
|
||||
expect_streq("${PYTHON_MODULE_EXTENSION}" ".pyd")
|
||||
expect_streq("${PYTHON_MODULE_DEBUG_POSTFIX}" "")
|
||||
expect_false("${PYTHON_IS_DEBUG}")
|
||||
unset(PYTHON_MODULE_EXT_SUFFIX)
|
||||
unset(PYTHON_MODULE_EXT_SUFFIX CACHE)
|
||||
|
||||
set(Python3_SOABI "cp311-win_arm64")
|
||||
pybind11_guess_python_module_extension("Python3")
|
||||
expect_streq("${PYTHON_MODULE_EXTENSION}" ".cp311-win_arm64.pyd")
|
||||
expect_streq("${PYTHON_MODULE_DEBUG_POSTFIX}" "")
|
||||
expect_false("${PYTHON_IS_DEBUG}")
|
||||
unset(PYTHON_MODULE_EXT_SUFFIX)
|
||||
unset(PYTHON_MODULE_EXT_SUFFIX CACHE)
|
||||
|
||||
set(Python3_SOABI "cp311d-win_arm64")
|
||||
pybind11_guess_python_module_extension("Python3")
|
||||
expect_streq("${PYTHON_MODULE_EXTENSION}" ".cp311d-win_arm64.pyd")
|
||||
expect_streq("${PYTHON_MODULE_DEBUG_POSTFIX}" "")
|
||||
expect_true("${PYTHON_IS_DEBUG}")
|
||||
unset(PYTHON_MODULE_EXT_SUFFIX)
|
||||
unset(PYTHON_MODULE_EXT_SUFFIX CACHE)
|
||||
|
||||
set(Python3_SOABI "pypy310-pp73-win_amd64")
|
||||
pybind11_guess_python_module_extension("Python3")
|
||||
expect_streq("${PYTHON_MODULE_EXTENSION}" ".pypy310-pp73-win_amd64.pyd")
|
||||
expect_streq("${PYTHON_MODULE_DEBUG_POSTFIX}" "")
|
||||
expect_false("${PYTHON_IS_DEBUG}")
|
||||
unset(PYTHON_MODULE_EXT_SUFFIX)
|
||||
unset(PYTHON_MODULE_EXT_SUFFIX CACHE)
|
||||
|
||||
set(Python3_SOABI "_d.cp311-win_amd64.pyd") # This is a quirk of FindPython3
|
||||
pybind11_guess_python_module_extension("Python3")
|
||||
expect_streq("${PYTHON_MODULE_EXTENSION}" ".cp311-win_amd64.pyd")
|
||||
expect_streq("${PYTHON_MODULE_DEBUG_POSTFIX}" "_d")
|
||||
expect_true("${PYTHON_IS_DEBUG}")
|
||||
unset(PYTHON_MODULE_EXT_SUFFIX)
|
||||
unset(PYTHON_MODULE_EXT_SUFFIX CACHE)
|
||||
|
||||
unset(Python3_SOABI)
|
||||
set(ENV{SETUPTOOLS_EXT_SUFFIX} ".cp39-win_arm64.pyd") # Set by cibuildwheel
|
||||
pybind11_guess_python_module_extension("Python3")
|
||||
expect_streq("${PYTHON_MODULE_EXTENSION}" ".cp39-win_arm64.pyd")
|
||||
expect_streq("${PYTHON_MODULE_DEBUG_POSTFIX}" "")
|
||||
expect_false("${PYTHON_IS_DEBUG}")
|
||||
unset(PYTHON_MODULE_EXT_SUFFIX)
|
||||
unset(PYTHON_MODULE_EXT_SUFFIX CACHE)
|
||||
unset(ENV{SETUPTOOLS_EXT_SUFFIX})
|
||||
|
||||
set(Python3_SOABI "cp311-win_arm64")
|
||||
set(ENV{SETUPTOOLS_EXT_SUFFIX} "") # Should not be used
|
||||
pybind11_guess_python_module_extension("Python3")
|
||||
expect_streq("${PYTHON_MODULE_EXTENSION}" ".cp311-win_arm64.pyd")
|
||||
expect_streq("${PYTHON_MODULE_DEBUG_POSTFIX}" "")
|
||||
expect_false("${PYTHON_IS_DEBUG}")
|
||||
unset(PYTHON_MODULE_EXT_SUFFIX)
|
||||
unset(PYTHON_MODULE_EXT_SUFFIX CACHE)
|
||||
unset(ENV{SETUPTOOLS_EXT_SUFFIX})
|
||||
|
||||
# macOS
|
||||
set(CMAKE_SYSTEM_NAME "Darwin")
|
||||
set(CMAKE_SHARED_MODULE_SUFFIX ".so")
|
||||
|
||||
set(Python3_SOABI "")
|
||||
pybind11_guess_python_module_extension("Python3")
|
||||
expect_streq("${PYTHON_MODULE_EXTENSION}" ".so")
|
||||
expect_streq("${PYTHON_MODULE_DEBUG_POSTFIX}" "")
|
||||
expect_false("${PYTHON_IS_DEBUG}")
|
||||
unset(PYTHON_MODULE_EXT_SUFFIX)
|
||||
unset(PYTHON_MODULE_EXT_SUFFIX CACHE)
|
||||
|
||||
set(Python3_SOABI "cpython-312-darwin")
|
||||
pybind11_guess_python_module_extension("Python3")
|
||||
expect_streq("${PYTHON_MODULE_EXTENSION}" ".cpython-312-darwin.so")
|
||||
expect_streq("${PYTHON_MODULE_DEBUG_POSTFIX}" "")
|
||||
expect_false("${PYTHON_IS_DEBUG}")
|
||||
unset(PYTHON_MODULE_EXT_SUFFIX)
|
||||
unset(PYTHON_MODULE_EXT_SUFFIX CACHE)
|
||||
|
||||
set(Python3_SOABI "cpython-312d-darwin")
|
||||
pybind11_guess_python_module_extension("Python3")
|
||||
expect_streq("${PYTHON_MODULE_EXTENSION}" ".cpython-312d-darwin.so")
|
||||
expect_streq("${PYTHON_MODULE_DEBUG_POSTFIX}" "")
|
||||
expect_true("${PYTHON_IS_DEBUG}")
|
||||
unset(PYTHON_MODULE_EXT_SUFFIX)
|
||||
unset(PYTHON_MODULE_EXT_SUFFIX CACHE)
|
||||
|
||||
# Linux
|
||||
set(CMAKE_SYSTEM_NAME "Linux")
|
||||
set(CMAKE_SHARED_MODULE_SUFFIX ".so")
|
||||
|
||||
set(Python3_SOABI "")
|
||||
pybind11_guess_python_module_extension("Python3")
|
||||
expect_streq("${PYTHON_MODULE_EXTENSION}" ".so")
|
||||
expect_streq("${PYTHON_MODULE_DEBUG_POSTFIX}" "")
|
||||
expect_false("${PYTHON_IS_DEBUG}")
|
||||
unset(PYTHON_MODULE_EXT_SUFFIX)
|
||||
unset(PYTHON_MODULE_EXT_SUFFIX CACHE)
|
||||
|
||||
set(Python3_SOABI "cpython-312-arm-linux-gnueabihf")
|
||||
pybind11_guess_python_module_extension("Python3")
|
||||
expect_streq("${PYTHON_MODULE_EXTENSION}" ".cpython-312-arm-linux-gnueabihf.so")
|
||||
expect_streq("${PYTHON_MODULE_DEBUG_POSTFIX}" "")
|
||||
expect_false("${PYTHON_IS_DEBUG}")
|
||||
unset(PYTHON_MODULE_EXT_SUFFIX)
|
||||
unset(PYTHON_MODULE_EXT_SUFFIX CACHE)
|
||||
|
||||
set(Python3_SOABI "cpython-312d-arm-linux-gnueabihf")
|
||||
pybind11_guess_python_module_extension("Python3")
|
||||
expect_streq("${PYTHON_MODULE_EXTENSION}" ".cpython-312d-arm-linux-gnueabihf.so")
|
||||
expect_streq("${PYTHON_MODULE_DEBUG_POSTFIX}" "")
|
||||
expect_true("${PYTHON_IS_DEBUG}")
|
||||
unset(PYTHON_MODULE_EXT_SUFFIX)
|
||||
unset(PYTHON_MODULE_EXT_SUFFIX CACHE)
|
||||
|
||||
set(Python3_SOABI "pypy310-pp73-x86_64-linux-gnu")
|
||||
pybind11_guess_python_module_extension("Python3")
|
||||
expect_streq("${PYTHON_MODULE_EXTENSION}" ".pypy310-pp73-x86_64-linux-gnu.so")
|
||||
expect_streq("${PYTHON_MODULE_DEBUG_POSTFIX}" "")
|
||||
expect_false("${PYTHON_IS_DEBUG}")
|
||||
unset(PYTHON_MODULE_EXT_SUFFIX)
|
||||
unset(PYTHON_MODULE_EXT_SUFFIX CACHE)
|
||||
|
||||
set(Python3_SOABI "pypy310d-pp73-x86_64-linux-gnu")
|
||||
# TODO: I'm not sure if this is the right SOABI for PyPy debug builds
|
||||
pybind11_guess_python_module_extension("Python3")
|
||||
expect_streq("${PYTHON_MODULE_EXTENSION}" ".pypy310d-pp73-x86_64-linux-gnu.so")
|
||||
expect_streq("${PYTHON_MODULE_DEBUG_POSTFIX}" "")
|
||||
expect_true("${PYTHON_IS_DEBUG}")
|
||||
unset(PYTHON_MODULE_EXT_SUFFIX)
|
||||
unset(PYTHON_MODULE_EXT_SUFFIX CACHE)
|
||||
Reference in New Issue
Block a user