Skip to content
Permalink
Browse files

use cmake native FindPython (#42497)

  • Loading branch information
3nids committed Mar 28, 2021
1 parent cb24fe4 commit 555f5169254a2278b6aa03d3be9dc93bbf75d35b
@@ -1,14 +1,15 @@
#############################################################
# CMake settings
cmake_minimum_required(VERSION 3.10.0)
cmake_minimum_required(VERSION 3.12.0)
set(CMAKE_COLOR_MAKEFILE ON)
set(CMAKE_AUTORCC ON)
# set path to additional CMake modules
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
# POLICIES
cmake_policy (SET CMP0048 NEW)
cmake_policy (SET CMP0053 NEW)
cmake_policy (SET CMP0071 NEW)
cmake_policy(SET CMP0048 NEW)
cmake_policy(SET CMP0053 NEW)
cmake_policy(SET CMP0071 NEW)
cmake_policy(SET CMP0094 NEW)

# don't relink it only the shared object changes
set(CMAKE_LINK_DEPENDS_NO_SHARED ON)
@@ -932,16 +933,15 @@ endif()
set(QGIS_INSTALL_SYS_LIBS TRUE CACHE BOOL "If set to TRUE install all required system libs in the output package")

#############################################################
# Python build dependency
# Python

find_package(PythonLibrary REQUIRED)
set(MIN_PYTHON_VERSION "3.7")
if(${PYTHON_SHORT_VERSION} VERSION_LESS ${MIN_PYTHON_VERSION})
message(FATAL_ERROR "Python version ${PYTHON_SHORT_VERSION} is too old. Minimum Python version is ${MIN_PYTHON_VERSION}.")
endif()
set(Python_FIND_FRAMEWORK "LAST")

#############################################################
# Python bindings
find_package(Python ${MIN_PYTHON_VERSION} REQUIRED COMPONENTS Interpreter Development)
message("-- Found Python executable: ${Python_EXECUTABLE} (version ${Python_VERSION})")
message("-- Python library: ${Python_LIBRARIES}")
message("-- Python site-packages: ${Python_SITEARCH}")

if (WITH_CORE AND WITH_BINDINGS AND NOT WITH_QT6)
# python support: check for interpreter, sip, pyqt5
@@ -960,15 +960,15 @@ if (WITH_CORE AND WITH_BINDINGS AND NOT WITH_QT6)
set(SIP_CONCAT_PARTS 11)

if (NOT BINDINGS_GLOBAL_INSTALL)
set(PYTHON_SITE_PACKAGES_DIR ${QGIS_DATA_DIR}/python)
set(Python_SITEARCH ${QGIS_DATA_DIR}/python)
endif()

if (WITH_CUSTOM_WIDGETS)
set(PYUIC_WIDGET_PLUGIN_DIRECTORY ${PYQT5_MOD_DIR}/uic/widget-plugins/)
endif()

endif()


#############################################################
# create qgsconfig.h
# installed with app target

Jürgen E. Fischer <jef@norbit.de> 2013-09-13

fix retrieval of PYTHON_SITE_PACKAGES_DIR - broke debian builds
fix retrieval of Python_SITEARCH - broke debian builds

Merge: b14e13388e 2b4e13930d
Marco Hugentobler <marco.hugentobler@sourcepole.ch> 2013-09-13

This file was deleted.

@@ -29,7 +29,7 @@ ELSE(EXISTS PYQT5_VERSION)

FIND_FILE(_find_pyqt5_py FindPyQt5.py PATHS ${CMAKE_MODULE_PATH} NO_CMAKE_FIND_ROOT_PATH)

EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} ${_find_pyqt5_py} OUTPUT_VARIABLE pyqt_config)
EXECUTE_PROCESS(COMMAND ${Python_EXECUTABLE} ${_find_pyqt5_py} OUTPUT_VARIABLE pyqt_config)
IF(pyqt_config)
STRING(REGEX REPLACE "^pyqt_version:([^\n]+).*$" "\\1" PYQT5_VERSION ${pyqt_config})
STRING(REGEX REPLACE ".*\npyqt_version_str:([^\n]+).*$" "\\1" PYQT5_VERSION_STR ${pyqt_config})

This file was deleted.

@@ -25,7 +25,7 @@ ELSE(QSCI_MOD_VERSION_STR)

SET(QSCI_VER 5)

EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} ${_find_qsci_py} ${QSCI_VER} OUTPUT_VARIABLE qsci_ver)
EXECUTE_PROCESS(COMMAND ${Python_EXECUTABLE} ${_find_qsci_py} ${QSCI_VER} OUTPUT_VARIABLE qsci_ver)

IF(qsci_ver)
STRING(REGEX REPLACE "^qsci_version_str:([^\n]+).*$" "\\1" QSCI_MOD_VERSION_STR ${qsci_ver})
@@ -33,7 +33,7 @@ ELSE(SIP_VERSION)

FIND_FILE(_find_sip_py FindSIP.py PATHS ${CMAKE_MODULE_PATH} NO_CMAKE_FIND_ROOT_PATH)

EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} ${_find_sip_py} OUTPUT_VARIABLE sip_config)
EXECUTE_PROCESS(COMMAND ${Python_EXECUTABLE} ${_find_sip_py} OUTPUT_VARIABLE sip_config)
IF(sip_config)
STRING(REGEX REPLACE "^sip_version:([^\n]+).*$" "\\1" SIP_VERSION ${sip_config})
STRING(REGEX REPLACE ".*\nsip_version_num:([^\n]+).*$" "\\1" SIP_VERSION_NUM ${sip_config})
@@ -44,7 +44,7 @@ MACRO(PYQT_WRAP_UI outfiles )
GET_FILENAME_COMPONENT(infile ${it} ABSOLUTE)
SET(outfile ${CMAKE_CURRENT_BINARY_DIR}/ui_${outfile}.py)
ADD_CUSTOM_COMMAND(OUTPUT ${outfile}
COMMAND ${PYUIC_WRAPPER} "${PYUIC_PROGRAM}" "${PYUIC_WRAPPER_PATH}" "${QGIS_OUTPUT_DIRECTORY}/python" "${PYTHON_EXECUTABLE}" ${infile} -o ${outfile}
COMMAND ${PYUIC_WRAPPER} "${PYUIC_PROGRAM}" "${PYUIC_WRAPPER_PATH}" "${QGIS_OUTPUT_DIRECTORY}/python" "${Python_EXECUTABLE}" ${infile} -o ${outfile}
MAIN_DEPENDENCY ${infile}
DEPENDS pygui pycore pyqtcompat
)
@@ -44,15 +44,15 @@ MACRO(PYTHON_INSTALL SOURCE_FILE DESTINATION_DIR)
ADD_CUSTOM_COMMAND(
TARGET compile_python_files
COMMAND ${CMAKE_COMMAND} -E echo ${message}
COMMAND ${PYTHON_EXECUTABLE} ${_python_compile_py} ${_bin_py}
COMMAND ${Python_EXECUTABLE} ${_python_compile_py} ${_bin_py}
DEPENDS ${_absfilename}
)
ELSE(_abs_bin_py STREQUAL ${_absfilename})
ADD_CUSTOM_COMMAND(
TARGET compile_python_files
COMMAND ${CMAKE_COMMAND} -E echo ${message}
COMMAND ${CMAKE_COMMAND} -E copy ${_absfilename} ${_bin_py}
COMMAND ${PYTHON_EXECUTABLE} ${_python_compile_py} ${_bin_py}
COMMAND ${Python_EXECUTABLE} ${_python_compile_py} ${_bin_py}
DEPENDS ${_absfilename}
)
ENDIF(_abs_bin_py STREQUAL ${_absfilename})
@@ -151,7 +151,7 @@ MACRO(BUILD_SIP_PYTHON_MODULE MODULE_NAME SIP_FILES EXTRA_OBJECTS)

SET_TARGET_PROPERTIES(${_logical_name} PROPERTIES CXX_VISIBILITY_PRESET default)
IF (NOT APPLE)
TARGET_LINK_LIBRARIES(${_logical_name} ${PYTHON_LIBRARY})
TARGET_LINK_LIBRARIES(${_logical_name} ${Python_LIBRARIES})
ENDIF (NOT APPLE)
TARGET_LINK_LIBRARIES(${_logical_name} ${EXTRA_LINK_LIBRARIES})
IF (APPLE)
@@ -172,5 +172,5 @@ MACRO(BUILD_SIP_PYTHON_MODULE MODULE_NAME SIP_FILES EXTRA_OBJECTS)
)
ENDIF(WIN32)

INSTALL(TARGETS ${_logical_name} DESTINATION "${PYTHON_SITE_PACKAGES_DIR}/${_parent_module_path}")
INSTALL(TARGETS ${_logical_name} DESTINATION "${Python_SITEARCH}/${_parent_module_path}")
ENDMACRO(BUILD_SIP_PYTHON_MODULE MODULE_NAME SIP_FILES EXTRA_OBJECTS)
@@ -19,9 +19,6 @@
# For details see the accompanying COPYING-CMAKE-SCRIPTS
#

# Need python interpreter:
FIND_PACKAGE(PythonInterp 3 REQUIRED)
MARK_AS_ADVANCED(PYTHON_EXECUTABLE)

MACRO(ADD_PYTHON_TEST TESTNAME FILENAME)
GET_SOURCE_FILE_PROPERTY(loc ${FILENAME} LOCATION)
@@ -84,9 +81,9 @@ MESSAGE(\"export LD_LIBRARY_PATH=\$ENV{LD_LIBRARY_PATH}\")

FILE(APPEND ${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME}.cmake "
MESSAGE(\"export PYTHONPATH=\$ENV{PYTHONPATH}\")
MESSAGE(STATUS \"Running ${PYTHON_TEST_WRAPPER_PROCESSED} ${PYTHON_EXECUTABLE} ${loc} ${wo_semicolon}\")
MESSAGE(STATUS \"Running ${PYTHON_TEST_WRAPPER_PROCESSED} ${Python_EXECUTABLE} ${loc} ${wo_semicolon}\")
EXECUTE_PROCESS(
COMMAND ${PYTHON_TEST_WRAPPER_PROCESSED} ${PYTHON_EXECUTABLE} ${loc} ${wo_semicolon}
COMMAND ${PYTHON_TEST_WRAPPER_PROCESSED} ${Python_EXECUTABLE} ${loc} ${wo_semicolon}
RESULT_VARIABLE import_res
)
# Pass the output back to ctest
@@ -114,5 +111,5 @@ MACRO(ADD_PYTHON_COMPILEALL_TEST DIRNAME)
# Find the python script:
GET_FILENAME_COMPONENT(PYTHON_COMPILE_ALL_PY "${temp_path}/../compileall.py" ABSOLUTE)
# add test, use DIRNAME to create unique name for the test:
ADD_TEST(COMPILE_ALL-${DIRNAME} ${PYTHON_EXECUTABLE} "${PYTHON_COMPILE_ALL_PY}" -q ${DIRNAME})
ADD_TEST(COMPILE_ALL-${DIRNAME} ${Python_EXECUTABLE} "${PYTHON_COMPILE_ALL_PY}" -q ${DIRNAME})
ENDMACRO(ADD_PYTHON_COMPILEALL_TEST)
@@ -145,9 +145,9 @@ ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE
# Pass them in list form, e.g.: "-j;2" for -j 2
FUNCTION(SETUP_TARGET_FOR_COVERAGE_COBERTURA _targetname _testrunner _outputname)

IF(NOT PYTHON_EXECUTABLE)
IF(NOT Python_EXECUTABLE)
MESSAGE(FATAL_ERROR "Python not found! Aborting...")
ENDIF() # NOT PYTHON_EXECUTABLE
ENDIF() # NOT Python_EXECUTABLE

IF(NOT GCOVR_PATH)
MESSAGE(FATAL_ERROR "gcovr not found! Aborting...")
@@ -31,7 +31,7 @@ if (UNIX AND NOT APPLE AND PYQT5_FOUND)
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/org.qgis.qgis.desktop ${CMAKE_BINARY_DIR}/org.qgis.qgis.appdata.xml
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
COMMAND ${PYTHON_EXECUTABLE}
COMMAND ${Python_EXECUTABLE}
ARGS ${CMAKE_SOURCE_DIR}/scripts/ts2appinfo.py "${CMAKE_BINARY_DIR}"
COMMENT "Updating appinfo files..."
DEPENDS ${QM_FILES} ${CMAKE_SOURCE_DIR}/linux/org.qgis.qgis.desktop.in ${CMAKE_SOURCE_DIR}/linux/org.qgis.qgis.appdata.xml.in
@@ -143,7 +143,7 @@ cmake -G "%CMAKEGEN%" ^
-D SPATIALITE_LIBRARY=%O4W_ROOT%/lib/spatialite_i.lib ^
-D PYTHON_EXECUTABLE=%O4W_ROOT%/bin/python3.exe ^
-D SIP_BINARY_PATH=%PYTHONHOME:\=/%/sip.exe ^
-D PYTHON_INCLUDE_PATH=%PYTHONHOME:\=/%/include ^
-D PYTHON_INCLUDE_DIR=%PYTHONHOME:\=/%/include ^
-D PYTHON_LIBRARY=%PYTHONHOME:\=/%/libs/%PYVER%.lib ^
-D QT_LIBRARY_DIR=%O4W_ROOT%/lib ^
-D QT_HEADERS_DIR=%O4W_ROOT%/apps/qt5/include ^
@@ -142,7 +142,7 @@ cmake -G "%CMAKEGEN%" ^
-D SPATIALITE_LIBRARY=%O4W_ROOT%/lib/spatialite_i.lib ^
-D PYTHON_EXECUTABLE=%O4W_ROOT%/bin/python3.exe ^
-D SIP_BINARY_PATH=%PYTHONHOME:\=/%/sip.exe ^
-D PYTHON_INCLUDE_PATH=%PYTHONHOME:\=/%/include ^
-D PYTHON_INCLUDE_DIR=%PYTHONHOME:\=/%/include ^
-D PYTHON_LIBRARY=%PYTHONHOME:\=/%/libs/%PYVER%.lib ^
-D QT_LIBRARY_DIR=%O4W_ROOT%/lib ^
-D QT_HEADERS_DIR=%O4W_ROOT%/apps/qt5/include ^
@@ -5,7 +5,7 @@ CMAKE_POLICY(SET CMP0012 NEW)
IF(@WITH_PY_COMPILE@)
MESSAGE(STATUS "Byte-compiling core Python utilities and plugins...")
# exclude Python 3 modules in PyQt4.uic package
EXECUTE_PROCESS(COMMAND @PYTHON_EXECUTABLE@ -m compileall -q -x ".*uic.port_v3.*" "$ENV{DESTDIR}@CMAKE_INSTALL_PREFIX@/@QGIS_DATA_DIR@/python")
EXECUTE_PROCESS(COMMAND @Python_EXECUTABLE@ -m compileall -q -x ".*uic.port_v3.*" "$ENV{DESTDIR}@CMAKE_INSTALL_PREFIX@/@QGIS_DATA_DIR@/python")
ENDIF(@WITH_PY_COMPILE@)

set(ENV{QGIS_PREFIX_PATH} "$ENV{DESTDIR}@CMAKE_INSTALL_PREFIX@")

0 comments on commit 555f516

Please sign in to comment.