FindPython3 uses host's python ABI flags instead of toolchain's.
Hello,
I'm using CMake 3.17.2 on Ubuntu 16.04, and I'm having an issue on a project I'm working on. It's a project that builds a Python module, sometimes using the host system Python library, sometimes compiled with a cross-toolchain for a Linux with another architecture that has its own cross-compiled Python library.
In the toolchain file, we have:
list(APPEND CMAKE_PREFIX_PATH "${TOOLCHAIN_TARGET_SYSROOT}")
list(PREPEND CMAKE_FIND_ROOT_PATH "${TOOLCHAIN_TARGET_SYSROOT}")
# search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
Right now that toolchain uses a Python 3.8 library, that is located at ${TOOLCHAIN_TARGET_SYSROOT}/usr/lib/libpython3.8.so
but it does not have a python3.8-config
executable. In my project CMakeLists.txt
, I tried setting Python3_ROOT_DIR
directly:
if(TOOLCHAIN_TARGET_SYSROOT)
set(Python3_ROOT_DIR ${TOOLCHAIN_TARGET_SYSROOT}/usr)
endif()
find_package(Python3 REQUIRED COMPONENTS Development)
But it fails:
Could NOT find Python3 (missing: Python3_LIBRARIES Python3_INCLUDE_DIRS
Development)
I tried running cmake with --debug-find
and I get something like this:
find_program called with the following settings:
VAR: _Python3_CONFIG
NAMES: "python3.9-config"
"python3.8-config"
"python3.7-config"
"python3.6-config"
"python3.5-config"
"python3.4-config"
"python3.3-config"
"python3.2-config"
"python3.1-config"
"python3.0-config"
Documentation: Path to a program.
Framework
Only Search Frameworks: 0
Search Frameworks Last: 0
Search Frameworks First: 0
AppBundle
Only Search AppBundle: 0
Search AppBundle Last: 0
Search AppBundle First: 0
CMAKE_FIND_USE_CMAKE_PATH: 1
CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH: 1
CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH: 1
CMAKE_FIND_USE_CMAKE_SYSTEM_PATH: 1
find_program considered the following locations:
[A long list of paths in my toolchain target sysroot, and a few paths on my system]
The item was found at
/usr/bin/python3.5-config
And then later:
find_library called with the following settings:
VAR: _Python3_LIBRARY_RELEASE
NAMES: "python39"
"python3.9m"
"python38"
"python3.8m"
"python37"
"python3.7m"
"python36"
"python3.6m"
"python35"
"python3.5m"
"python34"
"python3.4m"
"python33"
"python3.3m"
"python32"
"python3.2m"
"python31"
"python3.1m"
"python30"
"python3.0m"
Documentation: Path to a library.
Framework
Only Search Frameworks: 0
Search Frameworks Last: 0
Search Frameworks First: 0
AppBundle
Only Search AppBundle: 0
Search AppBundle Last: 0
Search AppBundle First: 0
CMAKE_FIND_USE_CMAKE_PATH: 1
CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH: 1
CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH: 1
CMAKE_FIND_USE_CMAKE_SYSTEM_PATH: 1
find_library considered the following locations:
[...]
The item was not found.
It seems (from a --trace-expand
investigation) that the CMake module uses the python3.5-config
from my host to determine the ABI flags (here m
) and tries to find a library with that ABI flags in my toolchain target sysroot. This seems wrong to me, first because (if I understood correctly) the m
ABI flag has been removed since Python 3.8 and because my toolchain Python library ABI flags is not necessarily the same as my host.
Am I doing something wrong here ? should the toolchain have a python-config
built for the host system that points to the target sysroot ? how would that work ?
Thank you !