From 3e317835ece617c7858c0f501b4d0d7c8ba68547 Mon Sep 17 00:00:00 2001 From: Henry Schreiner <henryschreineriii@gmail.com> Date: Wed, 19 Oct 2022 22:38:34 -0400 Subject: [PATCH] fix: add flag to opt-in to new (cross-compile) behavior Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> --- tools/FindPythonLibsNew.cmake | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/tools/FindPythonLibsNew.cmake b/tools/FindPythonLibsNew.cmake index bace3375147..debb69b0fb6 100644 --- a/tools/FindPythonLibsNew.cmake +++ b/tools/FindPythonLibsNew.cmake @@ -95,24 +95,9 @@ if(NOT PythonLibsNew_FIND_VERSION) set(PythonLibsNew_FIND_VERSION "3.6") endif() -# Save variables that get set by PythonInterp -macro(_PYBIND11_PUSH_IF_DEFINED name) - if(DEFINED "${name}") - set("_PYBIND11_ORIG_${name}" "${${name}}") - endif() -endmacro() - -_pybind11_push_if_defined(PYTHON_INCLUDE_DIR) -_pybind11_push_if_defined(PYTHON_MODULE_EXTENSION) -_pybind11_push_if_defined(PYTHON_IS_DEBUG) - find_package(PythonInterp ${PythonLibsNew_FIND_VERSION} ${_pythonlibs_required} ${_pythonlibs_quiet}) -unset(PYTHON_INCLUDE_DIR) -unset(PYTHON_MODULE_EXTENSION) -unset(PYTHON_IS_DEBUG) - if(NOT PYTHONINTERP_FOUND) set(PYTHONLIBS_FOUND FALSE) set(PythonLibsNew_FOUND FALSE) @@ -166,11 +151,14 @@ if(NOT _PYTHON_SUCCESS MATCHES 0) return() endif() +option( + PYBIND11_PYTHONLIBS_OVERRWRITE + ON + "Overwrite cached values read from Python library (classic search). Turn off if cross-compiling and manually setting these values." +) # Can manually set values when cross-compiling macro(_PYBIND11_GET_IF_UNDEF lst index name) - if(DEFINED "_PYBIND11_ORIG_${name}") - set("${name}" "${_PYBIND11_ORIG_${name}}") - elseif(NOT DEFINED "${name}") + if(PYBIND11_PYTHONLIBS_OVERRWRITE OR NOT DEFINED "${name}") list(GET "${lst}" "${index}" "${name}") endif() endmacro()