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 <kchai@redhat.com>
This commit is contained in:
Kefu Chai 2019-07-23 13:57:43 +08:00
parent 492efbd694
commit 1e33464c0a
2 changed files with 11 additions and 3 deletions

View File

@ -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})

View File

@ -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