|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(PYTHONLIBS_FOUND AND PYTHON_MODULE_EXTENSION) |
|
|
return() |
|
|
endif() |
|
|
|
|
|
if(PythonLibsNew_FIND_QUIETLY) |
|
|
set(_pythonlibs_quiet QUIET) |
|
|
else() |
|
|
set(_pythonlibs_quiet "") |
|
|
endif() |
|
|
|
|
|
if(PythonLibsNew_FIND_REQUIRED) |
|
|
set(_pythonlibs_required REQUIRED) |
|
|
endif() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(NOT DEFINED PYTHON_EXECUTABLE) |
|
|
if(DEFINED ENV{VIRTUAL_ENV}) |
|
|
find_program( |
|
|
PYTHON_EXECUTABLE python |
|
|
PATHS "$ENV{VIRTUAL_ENV}" "$ENV{VIRTUAL_ENV}/bin" |
|
|
NO_DEFAULT_PATH) |
|
|
elseif(DEFINED ENV{CONDA_PREFIX}) |
|
|
find_program( |
|
|
PYTHON_EXECUTABLE python |
|
|
PATHS "$ENV{CONDA_PREFIX}" "$ENV{CONDA_PREFIX}/bin" |
|
|
NO_DEFAULT_PATH) |
|
|
elseif(DEFINED ENV{pythonLocation}) |
|
|
find_program( |
|
|
PYTHON_EXECUTABLE python |
|
|
PATHS "$ENV{pythonLocation}" "$ENV{pythonLocation}/bin" |
|
|
NO_DEFAULT_PATH) |
|
|
endif() |
|
|
if(NOT PYTHON_EXECUTABLE) |
|
|
unset(PYTHON_EXECUTABLE) |
|
|
endif() |
|
|
endif() |
|
|
|
|
|
|
|
|
if(NOT PythonLibsNew_FIND_VERSION) |
|
|
set(PythonLibsNew_FIND_VERSION "3.6") |
|
|
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} |
|
|
${_pythonlibs_quiet}) |
|
|
|
|
|
if(NOT PYTHONINTERP_FOUND) |
|
|
set(PYTHONLIBS_FOUND FALSE) |
|
|
set(PythonLibsNew_FOUND FALSE) |
|
|
return() |
|
|
endif() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
execute_process( |
|
|
COMMAND |
|
|
"${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); |
|
|
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')); |
|
|
print(s.get_config_var('LIBDIR') or ''); |
|
|
print(s.get_config_var('MULTIARCH') or ''); |
|
|
" |
|
|
RESULT_VARIABLE _PYTHON_SUCCESS |
|
|
OUTPUT_VARIABLE _PYTHON_VALUES |
|
|
ERROR_VARIABLE _PYTHON_ERROR_VALUE) |
|
|
|
|
|
if(NOT _PYTHON_SUCCESS MATCHES 0) |
|
|
if(PythonLibsNew_FIND_REQUIRED) |
|
|
message(FATAL_ERROR "Python config failure:\n${_PYTHON_ERROR_VALUE}") |
|
|
endif() |
|
|
set(PYTHONLIBS_FOUND FALSE) |
|
|
set(PythonLibsNew_FOUND FALSE) |
|
|
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) |
|
|
|
|
|
macro(_PYBIND11_GET_IF_UNDEF lst index name) |
|
|
if(PYBIND11_PYTHONLIBS_OVERWRITE OR NOT DEFINED "${name}") |
|
|
list(GET "${lst}" "${index}" "${name}") |
|
|
endif() |
|
|
endmacro() |
|
|
|
|
|
|
|
|
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}) |
|
|
_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() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(NOT CMAKE_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") |
|
|
message(FATAL_ERROR "Python config failure: Python is ${_PYTHON_BITS}-bit, " |
|
|
"chosen compiler is ${_CMAKE_BITS}-bit") |
|
|
endif() |
|
|
set(PYTHONLIBS_FOUND FALSE) |
|
|
set(PythonLibsNew_FOUND FALSE) |
|
|
return() |
|
|
endif() |
|
|
|
|
|
|
|
|
string(REGEX REPLACE "\\." ";" _PYTHON_VERSION_LIST ${_PYTHON_VERSION_LIST}) |
|
|
list(GET _PYTHON_VERSION_LIST 0 PYTHON_VERSION_MAJOR) |
|
|
list(GET _PYTHON_VERSION_LIST 1 PYTHON_VERSION_MINOR) |
|
|
list(GET _PYTHON_VERSION_LIST 2 PYTHON_VERSION_PATCH) |
|
|
set(PYTHON_VERSION "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}.${PYTHON_VERSION_PATCH}") |
|
|
|
|
|
|
|
|
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(DEFINED PYTHON_LIBRARY) |
|
|
|
|
|
elseif(CMAKE_HOST_WIN32) |
|
|
set(PYTHON_LIBRARY "${PYTHON_PREFIX}/libs/python${PYTHON_LIBRARY_SUFFIX}.lib") |
|
|
|
|
|
|
|
|
|
|
|
if(NOT EXISTS "${PYTHON_LIBRARY}") |
|
|
get_filename_component(_PYTHON_ROOT ${PYTHON_INCLUDE_DIR} DIRECTORY) |
|
|
set(PYTHON_LIBRARY "${_PYTHON_ROOT}/libs/python${PYTHON_LIBRARY_SUFFIX}.lib") |
|
|
endif() |
|
|
|
|
|
|
|
|
if(DEFINED ENV{MSYSTEM} |
|
|
AND MINGW |
|
|
AND NOT EXISTS "${PYTHON_LIBRARY}") |
|
|
if(PYTHON_MULTIARCH) |
|
|
set(_PYTHON_LIBS_SEARCH "${PYTHON_LIBDIR}/${PYTHON_MULTIARCH}" "${PYTHON_LIBDIR}") |
|
|
else() |
|
|
set(_PYTHON_LIBS_SEARCH "${PYTHON_LIBDIR}") |
|
|
endif() |
|
|
unset(PYTHON_LIBRARY) |
|
|
find_library( |
|
|
PYTHON_LIBRARY |
|
|
NAMES "python${PYTHON_LIBRARY_SUFFIX}" |
|
|
PATHS ${_PYTHON_LIBS_SEARCH} |
|
|
NO_DEFAULT_PATH) |
|
|
endif() |
|
|
|
|
|
|
|
|
if(NOT EXISTS "${PYTHON_LIBRARY}") |
|
|
message(FATAL_ERROR "Python libraries not found") |
|
|
endif() |
|
|
|
|
|
else() |
|
|
if(PYTHON_MULTIARCH) |
|
|
set(_PYTHON_LIBS_SEARCH "${PYTHON_LIBDIR}/${PYTHON_MULTIARCH}" "${PYTHON_LIBDIR}") |
|
|
else() |
|
|
set(_PYTHON_LIBS_SEARCH "${PYTHON_LIBDIR}") |
|
|
endif() |
|
|
|
|
|
|
|
|
|
|
|
find_library( |
|
|
PYTHON_LIBRARY |
|
|
NAMES "python${PYTHON_LIBRARY_SUFFIX}" |
|
|
PATHS ${_PYTHON_LIBS_SEARCH} |
|
|
NO_DEFAULT_PATH) |
|
|
|
|
|
|
|
|
if(NOT PYTHON_LIBRARY) |
|
|
set(PYTHON_LIBRARY python${PYTHON_LIBRARY_SUFFIX}) |
|
|
endif() |
|
|
endif() |
|
|
|
|
|
mark_as_advanced(PYTHON_LIBRARY PYTHON_INCLUDE_DIR) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}") |
|
|
set(PYTHON_LIBRARIES "${PYTHON_LIBRARY}") |
|
|
if(NOT PYTHON_DEBUG_LIBRARY) |
|
|
set(PYTHON_DEBUG_LIBRARY "") |
|
|
endif() |
|
|
set(PYTHON_DEBUG_LIBRARIES "${PYTHON_DEBUG_LIBRARY}") |
|
|
|
|
|
find_package_message(PYTHON "Found PythonLibs: ${PYTHON_LIBRARIES}" |
|
|
"${PYTHON_EXECUTABLE}${PYTHON_VERSION_STRING}") |
|
|
|
|
|
set(PYTHONLIBS_FOUND TRUE) |
|
|
set(PythonLibsNew_FOUND TRUE) |
|
|
|
|
|
if(NOT PYTHON_MODULE_PREFIX) |
|
|
set(PYTHON_MODULE_PREFIX "") |
|
|
endif() |
|
|
|