FindPython: CMake can't find Python when cross-compiling on Windows host
I have a project which cross-compiles to a custom target platform using a toolchain file, and before the build I have custom commands that run a Python script to generate some sources before proceeding to build some C using the cross-compiler.
I want these scripts to run using the host interpreter, and I use find_package(Python3)
to locate the interpreter.
If Python is in the PATH, everything works fine. If the user installed Python without adding Python to the PATH, the mechanism inside FindPython/Support.cmake
that scans the Windows registry for the installation directory is not run, because when cross compiling WIN32
is not defined.
At the moment I use a hack to work around this in my CMakeLists.txt
:
if(CMAKE_HOST_WIN32)
set(WIN32 True)
endif()
find_package(Python3 REQUIRED)
...and so Python is then found using the registry entries.
Can FindPython
be improved to handle this (admittedly unusual) scenario?
Many thanks!