← All tasks
cppOSGeo/gdal #14770Not a task: not reproduced

Fix cross-compilation failure with CMake 4.1+ (CMP0190) in FindPython

envgap__OSGeo__gdal-14770

01 / FAILURE SIGNATURE

As reported upstream

Python: When cross-compiling, Interpreter and/or Compiler components cannot
Not a benchmark task.
  • In a clean container the reported failure did not reproduce, or the known fix did not make the project run.

02 / ENVIRONMENT RECIPE

Base commit
53e11e22f7a8b5f4ff7400b91ee83da66a28e301
Manifest
CMakeLists.txt
Reproduce
Awaiting issue-specific recipe
Run under trace
Awaiting a meaningful runtime command

03 / ORIGINAL ISSUE TEXT

OSGeo/gdal #14770 · read the original issue
### What is the bug?

When cross-compiling GDAL, CMake 4.1+ throws a fatal error during the find_package(Python) step if CMAKE_CROSSCOMPILING_EMULATOR is not set:

```
-- Could NOT find SWIG (missing: SWIG_EXECUTABLE SWIG_DIR) 
CMake Error at /opt/homebrew/share/cmake/Modules/FindPython/Support.cmake:46 (message):
  Python: When cross-compiling, Interpreter and/or Compiler components cannot
  be searched when CMAKE_CROSSCOMPILING_EMULATOR variable is not specified
  (see policy CMP0190).
Call Stack (most recent call first):
  /opt/homebrew/share/cmake/Modules/FindPython/Support.cmake:1592 (_python_display_failure)
  /opt/homebrew/share/cmake/Modules/FindPython.cmake:700 (include)
  CMakeLists.txt:229 (find_package)
```


### Steps to reproduce the issue

Please run provided apple targets script
 python3 /Users/sl0nius/Documents/globe-kit/Tools/osgeo/build_xcframeworks.py --platforms iOS visionos

[build_xcframeworks.py](https://github.com/user-attachments/files/28836458/build_xcframeworks.py)

### Versions and provenance

OSX 26.3.1 (Macbook M5), GDAL 3.13.1

### Additional context

Proposed fix: Skip the host Python search block completely when CMAKE_CROSSCOMPILING is active, as proposed in the patch below.

```
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -222,6 +222,9 @@ endif()
 set(ENV{MKL_ENABLE_INSTRUCTIONS} "SSE4_2")
 
+# Allow Python discovery only if not cross-compiling OR if an emulator is provided to avoid CMP0190 errors
+if(NOT CMAKE_CROSSCOMPILING OR CMAKE_CROSSCOMPILING_EMULATOR)
+
 if (Python_LOOKUP_VERSION)
     set(Python_FIND_STRATEGY VERSION)
     find_package(Python ${Python_LOOKUP_VERSION} EXACT COMPONENTS Interpreter Development NumPy)
 else ()
     set(Python_FIND_STRATEGY LOCATION)
     find_package(Python 3.8 COMPONENTS Interpreter Development NumPy)
 endif ()
 set_package_properties(Python PROPERTIES PURPOSE "SWIG_PYTHON: Python binding")
+endif() # cross-compile Python guard
```
Continue on GitHub ↗

04 / LABELS

Labels from the report text only; not yet run

No supported category has been assigned.

Label rules and the text that matched
[]