FindPython: Registry search does not work on ARM64 Windows
I have found that find_package(Python3 3.11 REQUIRED)
doesn't work on ARM64 Windows.
After digging into the code at https://gitlab.kitware.com/cmake/cmake/-/blob/master/Modules/FindPython/Support.cmake, I can see that it is only using CMAKE_SIZEOF_VOID_P
to determine the architecture as 32-bit or 64-bit but there is nothing to differentiate between x86 and Arm. I haven't been able to find any variables similar to CMAKE_SIZEOF_VOID_P
for determining the target architecture (e.g. even the recent REGISTRY_VIEW
option added to find_package()
doesn't take into account that there could be an Arm architecture). If you use the Visual Studio generator, then CMAKE_VS_PLATFORM_NAME
can be used to get the target architecture, but I couldn't find anything more generic for other generators.
FindPython
currently uses registry keys like:
[HKEY_CURRENT_USER/SOFTWARE/Python/PythonCore/${version}-${_${_PYTHON_PREFIX}_ARCH}/InstallPath]
Where ${version}
is something like 3.11
and ${_${_PYTHON_PREFIX}_ARCH}
is either 32
or 64
. However, for the ARM64 version of Python, the variable part of registry path is 3.11-arm64
. This means no match is found because the actual registry path is not in the search list.
Simply adding an Arm variant to the existing search paths doesn't seem like it would work well since it is possible to install and run x86 versions of Python on an ARM64 host. And even if this sort of works, it breaks when you target a foreign architecture, e.g. use the -A
option + the Visual Studio generator.
So, it seems like we need to add an argument to FindPython
to specify the build target architecture for cases where it can't be automatically detected (using the host architecture doesn't work because it may not be the same as the target architecture). Making use of EDIT: after reading up on windows registry, it doesn't seem to have any special handling for Windows on Arm.REGISTRY_VIEW
seems like the way to go but it would need support for an arm64
option first.