Skip to content
Permalink
Browse files
[cmake] generalize Python output directory in UseTest macro (#43191)
* [cmake] generalize Python output directory in UseTest macro

this is helpful in case we set up another python output directory (eg PySide2)

* define python output directories to the parent scope

* try with target_include_directories

* define vars on top level

* Update UsePythonTest.cmake

* some cleanup

* more cleanup

* fix uic

* fix path for all platforms

* fix var
  • Loading branch information
3nids committed May 13, 2021
1 parent ef14092 commit da08c8a4357c9bd602497f33a958390dd1b7c8d0
@@ -449,7 +449,7 @@ if(WITH_CORE)
set(QT_VERSION_BASE "Qt6")
else()
set(QT_MIN_VERSION 5.12.0)
set(QT_VERSION_BASE "Qt5")
set(QT_VERSION_BASE "Qt5")
endif()

# Use Qt5SerialPort optionally for GPS
@@ -947,6 +947,9 @@ message("-- Python library: ${Python_LIBRARIES}")
message("-- Python site-packages: ${Python_SITEARCH}")

if (WITH_CORE AND WITH_BINDINGS AND NOT WITH_QT6)
set(PYTHON_OUTPUT_DIRECTORY ${QGIS_OUTPUT_DIRECTORY}/python)
set (QGIS_PYTHON_OUTPUT_DIRECTORY ${PYTHON_OUTPUT_DIRECTORY}/qgis)

# python support: check for interpreter, sip, pyqt5
find_package(PyQt5 REQUIRED)
set(PYQT_SIP_FLAGS ${PYQT5_SIP_FLAGS})
@@ -36,7 +36,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}" "${PYTHON_OUTPUT_DIRECTORY}" "${Python_EXECUTABLE}" ${infile} -o ${outfile}
MAIN_DEPENDENCY ${infile}
DEPENDS pygui pycore pyqtcompat
)
@@ -35,14 +35,14 @@ MACRO(ADD_PYTHON_TEST TESTNAME FILENAME)
FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME}.cmake "
SET(ENV{QGIS_PREFIX_PATH} \"${QGIS_OUTPUT_DIRECTORY}/bin\")
SET(ENV{PATH} \"${QGIS_OUTPUT_DIRECTORY}/bin;\$ENV{PATH}\")
SET(ENV{PYTHONPATH} \"${QGIS_OUTPUT_DIRECTORY}/python/;${QGIS_OUTPUT_DIRECTORY}/python/plugins;${CMAKE_SOURCE_DIR}/tests/src/python;\$ENV{PYTHONPATH}\")
SET(ENV{PYTHONPATH} \"${PYTHON_OUTPUT_DIRECTORY};${PYTHON_OUTPUT_DIRECTORY}/plugins;${CMAKE_SOURCE_DIR}/tests/src/python;\$ENV{PYTHONPATH}\")
MESSAGE(\"PATH:\$ENV{PATH}\")
")
ELSE(USING_NINJA OR USING_NMAKE)
FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME}.cmake "
SET(ENV{QGIS_PREFIX_PATH} \"${QGIS_OUTPUT_DIRECTORY}/bin/\${CMAKE_BUILD_TYPE}\")
SET(ENV{PATH} \"${QGIS_OUTPUT_DIRECTORY}/bin/\${CMAKE_BUILD_TYPE};\$ENV{PATH}\")
SET(ENV{PYTHONPATH} \"${QGIS_OUTPUT_DIRECTORY}/python/;${QGIS_OUTPUT_DIRECTORY}/python/plugins;${CMAKE_SOURCE_DIR}/tests/src/python;\$ENV{PYTHONPATH}\")
SET(ENV{PYTHONPATH} \"${PYTHON_OUTPUT_DIRECTORY};${PYTHON_OUTPUT_DIRECTORY}/plugins;${CMAKE_SOURCE_DIR}/tests/src/python;\$ENV{PYTHONPATH}\")
MESSAGE(\"PATH:\$ENV{PATH}\")
")
ENDIF(USING_NINJA OR USING_NMAKE)
@@ -51,7 +51,7 @@ MESSAGE(\"PATH:\$ENV{PATH}\")
FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME}.cmake "
SET(ENV{QGIS_PREFIX_PATH} \"${QGIS_OUTPUT_DIRECTORY}\")
SET(ENV{LD_LIBRARY_PATH} \"${pyenv}${QGIS_OUTPUT_DIRECTORY}/lib:\$ENV{LD_LIBRARY_PATH}\")
SET(ENV{PYTHONPATH} \"${QGIS_OUTPUT_DIRECTORY}/python/:${QGIS_OUTPUT_DIRECTORY}/python/plugins:${CMAKE_SOURCE_DIR}/tests/src/python:\$ENV{PYTHONPATH}\")
SET(ENV{PYTHONPATH} \"${PYTHON_OUTPUT_DIRECTORY}:${PYTHON_OUTPUT_DIRECTORY}/plugins:${CMAKE_SOURCE_DIR}/tests/src/python:\$ENV{PYTHONPATH}\")
MESSAGE(\"export LD_LIBRARY_PATH=\$ENV{LD_LIBRARY_PATH}\")
")
ENDIF(WIN32)
@@ -60,7 +60,7 @@ MESSAGE(\"export LD_LIBRARY_PATH=\$ENV{LD_LIBRARY_PATH}\")

FOREACH(_in ${ARGN})
STRING(REGEX MATCH "^([^=]+)=(.*)$" _out ${_in})

IF("${CMAKE_MATCH_1}" STREQUAL "TEST_TIMEOUT")
SET(TEST_TIMEOUT ${CMAKE_MATCH_2})
# Remove TEST_TIMEOUT=VALUE from the list of optional parameters
@@ -99,7 +99,7 @@ ENDIF(import_res)
ENDIF(CMAKE_CONFIGURATION_TYPES)

IF (${TEST_TIMEOUT} GREATER 0)
SET_TESTS_PROPERTIES(${TESTNAME} PROPERTIES TIMEOUT ${TEST_TIMEOUT})
SET_TESTS_PROPERTIES(${TESTNAME} PROPERTIES TIMEOUT ${TEST_TIMEOUT})
ENDIF()

ENDMACRO(ADD_PYTHON_TEST)
@@ -1,6 +1,3 @@
set(PYTHON_OUTPUT_DIRECTORY ${QGIS_OUTPUT_DIRECTORY}/python)

set (QGIS_PYTHON_OUTPUT_DIRECTORY ${PYTHON_OUTPUT_DIRECTORY}/qgis)
file (MAKE_DIRECTORY ${QGIS_PYTHON_OUTPUT_DIRECTORY})
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${QGIS_PYTHON_OUTPUT_DIRECTORY})
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${QGIS_PYTHON_OUTPUT_DIRECTORY})
@@ -1,5 +1,4 @@
set (QGIS_PYQT_DIR ${Python_SITEARCH}/qgis/PyQt)
set (PYTHON_OUTPUT_DIRECTORY ${QGIS_OUTPUT_DIRECTORY}/python/qgis/PyQt)

set(PYQT_COMPAT_FILES
__init__.py
@@ -32,8 +31,8 @@ foreach(pyfile ${PYQT_COMPAT_FILES})
set(pyfile ${PYQT_PREFIX}/${pyfile})
add_custom_command(TARGET pyqtcompat
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${PYTHON_OUTPUT_DIRECTORY}/${_dir}
COMMAND ${CMAKE_COMMAND} -E copy ${pyfile} ${PYTHON_OUTPUT_DIRECTORY}/${_dir}
COMMAND ${CMAKE_COMMAND} -E make_directory ${QGIS_PYTHON_OUTPUT_DIRECTORY}/PyQt/${_dir}
COMMAND ${CMAKE_COMMAND} -E copy ${pyfile} ${QGIS_PYTHON_OUTPUT_DIRECTORY}/PyQt/${_dir}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${pyfile}
)
@@ -1,5 +1,4 @@
set (QGIS_CONSOLE_DIR ${QGIS_DATA_DIR}/python/console)
set (PYTHON_OUTPUT_DIRECTORY ${QGIS_OUTPUT_DIRECTORY}/python)

set(PY_CONSOLE_FILES
console.py
@@ -1,7 +1,6 @@
# See ../CMakeLists.txt for info on staged-plugins* and clean-staged-plugins targets

set (QGIS_PYTHON_DIR ${QGIS_DATA_DIR}/python)
set (PYTHON_OUTPUT_DIRECTORY ${QGIS_OUTPUT_DIRECTORY}/python)

macro(EXT_PYLIB lib enable_by_default)
string(TOUPPER ${lib} ulib)
@@ -1,25 +1,23 @@
# See ../CMakeLists.txt for info on staged-plugins* and clean-staged-plugins targets

set(QGIS_PYTHON_DIR ${Python_SITEARCH}/qgis)
set (PYTHON_OUTPUT_DIRECTORY ${QGIS_OUTPUT_DIRECTORY}/python)
set (NAME processing)

set(PY_FILES
__init__.py
algfactory.py
)

file (MAKE_DIRECTORY ${QGIS_PYTHON_OUTPUT_DIRECTORY}/${NAME})
install(FILES ${PY_FILES} DESTINATION "${QGIS_PYTHON_DIR}/${NAME}")
file (MAKE_DIRECTORY ${QGIS_PYTHON_OUTPUT_DIRECTORY}/processing)
install(FILES ${PY_FILES} DESTINATION "${QGIS_PYTHON_DIR}/processing")

add_custom_target(py${NAME} ALL)
add_custom_target(pyprocessing ALL)
# stage to output to make available when QGIS is run from build directory
foreach(pyfile ${PY_FILES})
add_custom_command(TARGET py${NAME}
add_custom_command(TARGET pyprocessing
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${pyfile} "${QGIS_PYTHON_OUTPUT_DIRECTORY}/${NAME}"
COMMAND ${CMAKE_COMMAND} -E copy ${pyfile} "${QGIS_PYTHON_OUTPUT_DIRECTORY}/processing"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${pyfile}
)
PY_COMPILE(pyutils "${QGIS_PYTHON_OUTPUT_DIRECTORY}/${NAME}/${pyfile}")
PY_COMPILE(pyutils "${QGIS_PYTHON_OUTPUT_DIRECTORY}/processing/${pyfile}")
endforeach(pyfile)
@@ -1,5 +1,4 @@
set (QGIS_PLUGININSTALLER_DIR ${QGIS_DATA_DIR}/python/pyplugin_installer)
set (PYTHON_OUTPUT_DIRECTORY ${QGIS_OUTPUT_DIRECTORY}/python)

set(PY_PLUGININSTALLER_FILES
__init__.py
@@ -1,7 +1,6 @@
# See ../CMakeLists.txt for info on staged-plugins* and clean-staged-plugins targets

set(QGIS_PYTHON_DIR ${Python_SITEARCH}/qgis)
set (PYTHON_OUTPUT_DIRECTORY ${QGIS_OUTPUT_DIRECTORY}/python)

set(PY_FILES
__init__.py

0 comments on commit da08c8a

Please sign in to comment.