From 12159d5bb0781b9c394ae09424ea3ef627a21913 Mon Sep 17 00:00:00 2001 From: Pieter Pas Date: Wed, 29 May 2024 22:52:11 +0200 Subject: [PATCH] Use PYBIND11_CROSSCOMPILING instead of CMAKE_CROSSCOMPILING --- tools/pybind11Common.cmake | 19 ++++++++++++++++++- tools/pybind11NewTools.cmake | 4 ++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/tools/pybind11Common.cmake b/tools/pybind11Common.cmake index 06ee92534e..bbbac4c6b0 100644 --- a/tools/pybind11Common.cmake +++ b/tools/pybind11Common.cmake @@ -42,6 +42,23 @@ set(pybind11_INCLUDE_DIRS "${pybind11_INCLUDE_DIR}" CACHE INTERNAL "Include directory for pybind11 (Python not requested)") +# Cross-compilation support +if(NOT DEFINED PYBIND11_CROSSCOMPILING) + if(CMAKE_CROSSCOMPILING) + message( + WARNING + "A behavior change for cross-compilation is planned for future versions " + "of pybind11. To opt in to the improved cross-compilation logic now and " + "to silence this warning, use 'set(PYBIND11_CROSSCOMPILING ${CMAKE_CROSSCOMPILING})'.") + endif() + set(PYBIND11_CROSSCOMPILING + Off + CACHE + BOOL + "Enable cross-compilation mode and avoid using the build machine's Python interpreter to infer properties about the host machine." + ) +endif() + # --------------------- Shared targets ---------------------------- # Build an interface library target: @@ -195,7 +212,7 @@ endif() # --------------------- pybind11_find_import ------------------------------- -if(NOT _pybind11_nopython AND NOT CMAKE_CROSSCOMPILING) +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. _FOUND will be set if the # package was found (underscores replace dashes if present). QUIET will hide diff --git a/tools/pybind11NewTools.cmake b/tools/pybind11NewTools.cmake index dc3adfe920..ddd3aa2cff 100644 --- a/tools/pybind11NewTools.cmake +++ b/tools/pybind11NewTools.cmake @@ -33,7 +33,7 @@ if(NOT Python_FOUND AND NOT Python3_FOUND) endif() # Interpreter should not be found when cross-compiling - if(CMAKE_CROSSCOMPILING) + if(PYBIND11_CROSSCOMPILING) set(_pybind11_interp_component "") else() set(_pybind11_interp_component Interpreter) @@ -110,7 +110,7 @@ if(PYBIND11_MASTER_PROJECT) endif() endif() -if(NOT CMAKE_CROSSCOMPILING) +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.