From 9164468851c7eb3b64fc89b4041114be2b6fdaeb Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sat, 11 Jan 2025 01:04:26 +0100 Subject: [PATCH] Python bindings: on Debian, fix install target with non-Debian provided python version Fixes #11636 --- swig/python/CMakeLists.txt | 17 ++++++++++++++++- swig/python/install_python.cmake.in | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/swig/python/CMakeLists.txt b/swig/python/CMakeLists.txt index d694c71c208b..1dfb13a8a691 100644 --- a/swig/python/CMakeLists.txt +++ b/swig/python/CMakeLists.txt @@ -454,7 +454,22 @@ if __name__ == '__main__': set(INSTALL_ARGS "${INSTALL_ARGS} --install-layout=${GDAL_PYTHON_INSTALL_LAYOUT}") set(SETUPTOOLS_USE_DISTUTILS stdlib) elseif ("${SITE_PACKAGE_DIR}" MATCHES "dist-packages") - set(INSTALL_ARGS "${INSTALL_ARGS} --install-layout=deb") + + # We are running on Debian, but test if our setuptools version supports + # Debian --install-layout + # This might not be the case if using a regular (non-Debian patched) Python + # installation or setuptools (cf https://github.com/OSGeo/gdal/issues/11636) + execute_process( + COMMAND env GDAL_PYTHON_BINDINGS_WITHOUT_NUMPY=yes ${Python_EXECUTABLE_CMAKE} setup.py install --help + OUTPUT_VARIABLE SETUP_INSTALL_HELP + OUTPUT_STRIP_TRAILING_WHITESPACE + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + # If so, uses it. + if ("${SETUP_INSTALL_HELP}" MATCHES "install-layout") + set(INSTALL_ARGS "${INSTALL_ARGS} --install-layout=deb") + endif() + if (NOT DEFINED GDAL_PYTHON_INSTALL_LIB AND "${PREFIX_FOR_TRIMMEDSYSCONFIG}" STREQUAL "/usr/local") # Scenario of https://github.com/OSGeo/gdal/issues/10242 # For some reason patched setuptools of Debian fails to install by default diff --git a/swig/python/install_python.cmake.in b/swig/python/install_python.cmake.in index 186d8b4a0e85..dd679ade2478 100644 --- a/swig/python/install_python.cmake.in +++ b/swig/python/install_python.cmake.in @@ -1,4 +1,4 @@ -cmake_policy(VERSION 3.9) +cmake_policy(VERSION 3.16) if(DEFINED ENV{DESTDIR}) set(ROOT_DIR_ARG "--root=$ENV{DESTDIR}")