Skip to content

Commit

Permalink
fix: add flag to opt-in to new (cross-compile) behavior
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii committed Oct 20, 2022
1 parent 0e5b772 commit e0b0766
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions tools/FindPythonLibsNew.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -166,11 +151,13 @@ if(NOT _PYTHON_SUCCESS MATCHES 0)
return()
endif()

option(
PYBIND11_PYTHONLIBS_OVERRWRITE
"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(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()
Expand Down

0 comments on commit e0b0766

Please sign in to comment.