Skip to content

Commit

Permalink
cmake: Require at least CMake 3.26 and update Python dependency code
Browse files Browse the repository at this point in the history
CMake 3.26 is the version available across all supported Fedora
releases, CentOS Stream 10, and Mageia Cauldron (to be Mageia 10).

To deal with the eventual removal of PythonInterp, switch over to
the Python3 module.
  • Loading branch information
Conan-Kudo committed Sep 8, 2024
1 parent 4403619 commit 0b84709
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
30 changes: 15 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
cmake_minimum_required(VERSION 3.26)

if(POLICY CMP0048)
cmake_policy(SET CMP0048 NEW)
endif(POLICY CMP0048)

project(dnfdragora VERSION 3.0.0 LANGUAGES NONE)
cmake_minimum_required(VERSION 3.4)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")

find_package(PythonInterp 3.4 REQUIRED)
find_package(Python3 3.9 COMPONENTS Interpreter REQUIRED)
find_package(Gettext)
find_program(SPHINX_EXECUTABLE
NAMES sphinx-build-${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}
sphinx-build-${PYTHON_VERSION_MAJOR}
NAMES sphinx-build-${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}
sphinx-build-${Python3_VERSION_MAJOR}
sphinx-build)
if(SPHINX_EXECUTABLE STREQUAL "SPHINX_EXECUTABLE-NOTFOUND")
message(STATUS "Could NOT find sphinx-build.")
else(SPHINX_EXECUTABLE STREQUAL "SPHINX_EXECUTABLE-NOTFOUND")
message(STATUS "Found sphinx-build: ${SPHINX_EXECUTABLE}")
endif(SPHINX_EXECUTABLE STREQUAL "SPHINX_EXECUTABLE-NOTFOUND")

execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(), end='')" OUTPUT_VARIABLE PYTHON_INSTALL_DIR)
execute_process(COMMAND ${Python3_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(), end='')" OUTPUT_VARIABLE PYTHON_INSTALL_DIR)
string(REGEX REPLACE "\n$" "" ${PYTHON_INSTALL_DIR} "${PYTHON_INSTALL_DIR}")
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import sys; sys.stdout.write('%s.%s' % (sys.version_info.major, sys.version_info.minor))" OUTPUT_VARIABLE PYTHON_MAJOR_DOT_MINOR_VERSION)
message(STATUS "Python install dir is ${PYTHON_INSTALL_DIR}")

option(CHECK_RUNTIME_DEPENDENCIES "Verify the presence of runtime-only dependencies?" ON)

if(CHECK_RUNTIME_DEPENDENCIES)
include(FindPythonModule)
include(FindPython3Module)

# Find yui module
find_python_module(yui REQUIRED)
find_python3_module(yui REQUIRED)

# Find manatools module
find_python_module(manatools REQUIRED)
find_python3_module(manatools REQUIRED)

# Find libdnf5 module
find_python_module(libdnf5 REQUIRED)
find_python3_module(libdnf5 REQUIRED)

# Find yaml module
find_python_module(yaml REQUIRED)
find_python3_module(yaml REQUIRED)

# Find xdg module
find_python_module(xdg REQUIRED)
find_python3_module(xdg REQUIRED)

# Find cairosvg module
find_python_module(cairosvg REQUIRED)
find_python3_module(cairosvg REQUIRED)

# Find PIL module
find_python_module(PIL REQUIRED)
find_python3_module(PIL REQUIRED)

# Find pystray module
find_python_module(pystray REQUIRED)
find_python3_module(pystray REQUIRED)

endif(CHECK_RUNTIME_DEPENDENCIES)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Find if a Python module is installed
# Found at http://www.cmake.org/pipermail/cmake/2011-January/041666.html
# To use do: find_python_module(PyQt5 REQUIRED)
function(find_python_module module)
# To use do: find_python3_module(PyQt6 REQUIRED)
function(find_python3_module module)
string(TOUPPER ${module} module_upper)
if(NOT PY_${module_upper})
if(ARGC GREATER 1 AND ARGV1 STREQUAL "REQUIRED")
set(${module}_FIND_REQUIRED TRUE)
endif()
# A module's location is usually a directory, but for binary modules
# it's a .so file.
execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
execute_process(COMMAND "${Python3_EXECUTABLE}" "-c"
"import re, ${module}; print(re.compile('/__init__.py.*').sub('',${module}.__file__))"
RESULT_VARIABLE _${module}_status
OUTPUT_VARIABLE _${module}_location
Expand Down

0 comments on commit 0b84709

Please sign in to comment.