From 1e33464c0a9ec52d67e7aee502fbe1809629dbb5 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 23 Jul 2019 13:57:43 +0800 Subject: [PATCH] cmake: use exact version of python if minor version is specified `find_package(Python ${version}...)` tries to find the greater python version which is greater than `${version}`, on fc30, at the time of writing, both python3.8 and python3.7 are offered. but `python3-Cython` is packaged only for python3.7. so if user installs python3.8, this will prevent user from building Ceph. as Ceph will not be able to find Cython python module, as it will try to run `python3.8 -m cython --version`, where python3.8 is the greatest python version available in the system. but since cython module is not available to python3.8, cmake will fail to find cython even if is available to python3.7. in this change, if user specifies a python version with minor version, we will use the exact specified version instead of trying to use a version greater than the specified one. Signed-off-by: Kefu Chai --- CMakeLists.txt | 8 ++++++-- src/CMakeLists.txt | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b533465b9c9..ebf5cd92cda 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -499,9 +499,13 @@ if(WITH_MGR) # Please specify 3 or 3.[0-7] if you want to build with python3 support. # FindPython thinks they belong to different families. set(MGR_PYTHON_VERSION "2.7" CACHE - STRING "minimal required version of python runtime for running mgr plugins. ") - find_package(Python ${MGR_PYTHON_VERSION} REQUIRED + STRING "required version of python runtime for running mgr plugins. ") + if(NOT MGR_PYTHON_VERSION MATCHES "^[23]$") + set(find_python_exact "EXACT") + endif() + find_package(Python ${MGR_PYTHON_VERSION} ${find_python_exact} REQUIRED COMPONENTS Interpreter Development) + unset(find_python_exact) set(MGR_PYTHON_EXECUTABLE ${Python_EXECUTABLE}) set(MGR_PYTHON_LIBRARIES ${Python_LIBRARIES}) set(MGR_PYTHON_VERSION_MAJOR ${Python_VERSION_MAJOR}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d1334bda844..d945268f41f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -240,8 +240,12 @@ if(WITH_PYTHON3) if(WITH_PYTHON3 MATCHES "^(1|ON|YES|TRUE|Y)$") set(WITH_PYTHON3 "3") endif() - find_package(Python3 ${WITH_PYTHON3} REQUIRED + if(NOT WITH_PYTHON3 STREQUAL "3") + set(find_python3_exact "EXACT") + endif() + find_package(Python3 ${WITH_PYTHON3} ${find_python3_exact} REQUIRED COMPONENTS Interpreter Development) + unset(find_python3_exact) endif() # the major version of the python bindings as a dependency of other