From d6184e5cff4d3bf3a210e398e1c2ac20c9e526e1 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 22 Jul 2024 23:11:49 +0200 Subject: [PATCH] CMake: make finding-python-version a little more flexible My development machine has Python 3.11 installed, with all the development tools, and 3.12 with only the interpreter. I can't get find_package(Python3) to find 3.11 unless specifying EXACT, since it always ends up preferring 3.12 which doesn't have the required components. --- CMakeLists.txt | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f055352a..5825a8e53 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,7 @@ # - SCHEMA_TESTING (requires Python, see ci/configvalidator.py) # - TESTING (standard CMake option) # DEBUG_ : special developer flags for debugging. +# PYTHONLIBS_VERSION : if set on the command-line, use a specific Python version # # Example usage: # @@ -101,6 +102,14 @@ option(BUILD_CRASH_REPORTING "Enable crash reporting with KCrash." ON) # - DEBUG_PARTITION_UNSAFE (see partition/CMakeLists.txt) # - DEBUG_PARTITION_BAIL_OUT (see partition/CMakeLists.txt) +# Special handling for Python versions: +# - If you set PYTHONLIBS_VERSION on the command-line, then +# that **exact** version will be searched for, and no other. +# - If you do not set PYTHONLIBS_VERSION on the command-line, +# any suitable version will be found -- but this can fail if +# you have multiple Python versions installed, only some of +# which include the development headers. + ### USE_* # # By convention, when there are multiple modules that implement similar @@ -208,7 +217,12 @@ else() endif() set(BOOSTPYTHON_VERSION 1.72.0) -set(PYTHONLIBS_VERSION 3.6) +if(DEFINED PYTHONLIBS_VERSION) + set(PYTHONLIBS_EXTRA "EXACT") +else() + set(PYTHONLIBS_VERSION 3.6) + set(PYTHONLIBS_EXTRA "") +endif() set(YAMLCPP_VERSION 0.5.1) ### CMAKE SETUP @@ -412,7 +426,7 @@ if(NOT TARGET ${kfname}::Crash) set(BUILD_CRASH_REPORTING OFF) endif() -find_package(Python ${PYTHONLIBS_VERSION} COMPONENTS Interpreter Development) +find_package(Python ${PYTHONLIBS_VERSION} ${PYTHONLIBS_EXTRA} COMPONENTS Interpreter Development) set_package_properties( Python PROPERTIES