Skip to content

Commit

Permalink
Stop using deprecated CMake code
Browse files Browse the repository at this point in the history
Use the FindPython module instead of the deprecated FindPythonInterp
module. Require a reasonably new version of CMake instead of 2.8.2
due to deprecated compatibility with CMake older than 3.5.

Fixes: #13073
  • Loading branch information
jan-cerny committed Feb 20, 2025
1 parent 0ae8d83 commit fa84309
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 92 deletions.
9 changes: 3 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.8.12)
cmake_minimum_required(VERSION 3.16)

# Strictly speaking in-source will work but will be very messy so it is not supported.
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
Expand Down Expand Up @@ -131,11 +131,8 @@ else()
endif()
message(STATUS "PYTHONPATH: $ENV{PYTHONPATH}")

# Setting Python_ADDITIONAL_VERSIONS before calling PythonInterp can influence the priority of
# python executables in a scenario where multiple versions are present.
set(Python_ADDITIONAL_VERSIONS 3 2)
# Required Packages
find_package(PythonInterp REQUIRED)
find_package(Python REQUIRED)
find_package(OpenSCAP REQUIRED)

find_program(ANSIBLE_LINT_EXECUTABLE NAMES ansible-lint)
Expand Down Expand Up @@ -230,7 +227,7 @@ configure_file("${CMAKE_SOURCE_DIR}/build_config.yml.in" "${CMAKE_BINARY_DIR}/bu
message(STATUS " ")
message(STATUS "Summary of Python Tools and Modules:")
# Required Python Tools
message(STATUS "python: ${PYTHON_EXECUTABLE} (version: ${PYTHON_VERSION_STRING})")
message(STATUS "python: ${Python_EXECUTABLE} (version: ${Python_VERSION})")
message(STATUS "python yaml module: ${PY_YAML}")
message(STATUS "python jinja2 module: ${PY_JINJA2}")
# Optional Python Tools
Expand Down
4 changes: 2 additions & 2 deletions cmake/FindPythonModule.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function(find_python_module module)
set(PY_${module}_FIND_REQUIRED TRUE)
endif()
if($ENV{SSG_USE_PIP_PACKAGES})
execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
execute_process(COMMAND "${Python_EXECUTABLE}" "-c"
"import platform; print(''.join('python'+platform.python_version()[:-2]))"
RESULT_VARIABLE _python_version_status
OUTPUT_VARIABLE _python_version
Expand All @@ -26,7 +26,7 @@ function(find_python_module module)
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 "${Python_EXECUTABLE}" "-c"
"import re, ${module}; print(re.compile('/__init__.py.*').sub('',${module}.__file__))"
RESULT_VARIABLE _${module}_status
OUTPUT_VARIABLE _${module}_location
Expand Down
Loading

0 comments on commit fa84309

Please sign in to comment.