diff --git a/CMakeLists.txt b/CMakeLists.txt index bca0c22dc..73c5928b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,6 +102,11 @@ option(PYBIND11_SIMPLE_GIL_MANAGEMENT set(PYBIND11_INTERNALS_VERSION "" CACHE STRING "Override the ABI version, may be used to enable the unstable ABI.") +# Record whether the project set this before option() supplies its OFF default, so +# pybind11Common.cmake can apply its CMP0190-aware default without clobbering an explicit value. +if(NOT DEFINED PYBIND11_USE_CROSSCOMPILING) + set(_PYBIND11_USE_CROSSCOMPILING_DEFAULTED ON) +endif() option(PYBIND11_USE_CROSSCOMPILING "Respect CMAKE_CROSSCOMPILING" OFF) if(PYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION) diff --git a/tools/pybind11Common.cmake b/tools/pybind11Common.cmake index 5d787d3f2..e215dd458 100644 --- a/tools/pybind11Common.cmake +++ b/tools/pybind11Common.cmake @@ -45,9 +45,12 @@ set(pybind11_INCLUDE_DIRS # when cross-compiling, unless the CMAKE_CROSSCOMPILING_EMULATOR variable is defined. # Default PYBIND11_USE_CROSSCOMPILING to ON in that case, but never override a value the # project set explicitly (e.g. Emscripten/Pyodide defines an emulator yet still wants it ON). +# PYBIND11_USE_CROSSCOMPILING is undefined for find_package() consumers, but our own +# CMakeLists.txt always defines it via option(); _PYBIND11_USE_CROSSCOMPILING_DEFAULTED tells +# us whether that came from the project or from the option() default. if(CMAKE_VERSION VERSION_GREATER_EQUAL "4.1" - AND NOT DEFINED PYBIND11_USE_CROSSCOMPILING - AND NOT DEFINED CMAKE_CROSSCOMPILING_EMULATOR) + AND NOT DEFINED CMAKE_CROSSCOMPILING_EMULATOR + AND (NOT DEFINED PYBIND11_USE_CROSSCOMPILING OR _PYBIND11_USE_CROSSCOMPILING_DEFAULTED)) cmake_policy(GET CMP0190 _pybind11_cmp0190) if(_pybind11_cmp0190 STREQUAL "NEW") set(PYBIND11_USE_CROSSCOMPILING "ON")