diff --git a/CMakeLists.txt b/CMakeLists.txt index 96e04401a08..b06e6f12536 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -83,7 +83,7 @@ IF (WITH_BINDINGS) # as otherwise user has to use PYTHONPATH environemnt variable to add # QGIS bindings to package search path SET (BINDINGS_GLOBAL_INSTALL FALSE CACHE BOOL "Install bindings to global python directory? (might need root)") - SET (WITH_STAGED_PLUGINS TRUE CACHE BOOL "Stage-install core Python plugins to run from build directory? (utilities, console and installer are always staged)") + SET (WITH_STAGED_PLUGINS TRUE CACHE BOOL "Stage-install core Python plugins to run from build directory? (utilities and console are always staged)") SET (WITH_PY_COMPILE FALSE CACHE BOOL "Determines whether Python modules in staged or installed locations are byte-compiled") # concatenate QScintilla2 API files SET (WITH_QSCIAPI TRUE CACHE BOOL "Determines whether the QScintilla2 API files will be updated and concatenated") diff --git a/python/plugins/CMakeLists.txt b/python/plugins/CMakeLists.txt index eeae287856b..c8ab8688e07 100644 --- a/python/plugins/CMakeLists.txt +++ b/python/plugins/CMakeLists.txt @@ -1,29 +1,75 @@ -IF(WITH_PY_COMPILE) - ADD_CUSTOM_TARGET(pycompile_staged ALL - COMMAND ${PYTHON_EXECUTABLE} -m compileall -q "${PYTHON_OUTPUT_DIRECTORY}/plugins" - WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" - COMMENT "Byte-compiling staged Python plugins..." - ) -ENDIF(WITH_PY_COMPILE) +# Python plugins can be staged to PYTHON_OUTPUT_DIRECTORY so plugins +# will function when app is run from build directory + +# When staging all plugins, use the following make targets: +# staged_plugins - stage plugins (usually after repo pull/build and project make) +# staged_plugins_pyc - stage and byte-compile all Python scripts +# clean_staged_plugins - removes the plugins directory and all contents +# +# When developing on a plugin, use the following make targets: +# staged_[plugin_dir_name] - stage specific plugin, regenerating any changed resources +# clean_staged_[plugin_dir_name] - removes the plugin directory and its contents +# +# NOTE: regular project 'make install' is unaffected + +ADD_CUSTOM_TARGET(staged_plugins) + +ADD_CUSTOM_TARGET(staged_plugins_pyc DEPENDS staged_plugins + COMMAND ${PYTHON_EXECUTABLE} -m compileall -q "${PYTHON_OUTPUT_DIRECTORY}/plugins" + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" + COMMENT "Byte-compiling staged Python plugins..." +) + +# plugins can also be staged with CMake option at build time +IF(WITH_STAGED_PLUGINS) + IF(WITH_PY_COMPILE) + ADD_CUSTOM_TARGET(staged_plugins_on_build ALL DEPENDS staged_plugins_pyc) + ELSE(WITH_PY_COMPILE) + ADD_CUSTOM_TARGET(staged_plugins_on_build ALL DEPENDS staged_plugins) + ENDIF(WITH_PY_COMPILE) +ENDIF(WITH_STAGED_PLUGINS) + +ADD_CUSTOM_TARGET(clean_staged_plugins + COMMAND ${CMAKE_COMMAND} -E remove_directory ${PYTHON_OUTPUT_DIRECTORY}/plugins +) MACRO (PLUGIN_INSTALL plugin subdir ) + + # regular project build's install command and target INSTALL(FILES ${ARGN} DESTINATION ${QGIS_DATA_DIR}/python/plugins/${plugin}/${subdir}) STRING(REPLACE "/" "_" subdir_sane "${subdir}") - ADD_CUSTOM_TARGET(${plugin}_${subdir_sane}_stageinstall ALL DEPENDS ${ARGN}) - IF(WITH_STAGED_PLUGINS OR "${plugin}" STREQUAL "plugin_installer") - IF(WITH_PY_COMPILE) - ADD_DEPENDENCIES(pycompile_staged ${plugin}_${subdir_sane}_stageinstall) - ENDIF(WITH_PY_COMPILE) - FOREACH(file ${ARGN}) - ADD_CUSTOM_COMMAND(TARGET ${plugin}_${subdir_sane}_stageinstall - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E make_directory ${PYTHON_OUTPUT_DIRECTORY}/plugins/${plugin}/${subdir} - COMMAND ${CMAKE_COMMAND} -E copy \"${file}\" ${PYTHON_OUTPUT_DIRECTORY}/plugins/${plugin}/${subdir} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - #COMMENT "copying ${file} to ${PYTHON_OUTPUT_DIRECTORY}/plugins/${plugin}/${subdir}" - ) - ENDFOREACH(file) - ENDIF() + IF(WITH_STAGED_PLUGINS) + ADD_CUSTOM_TARGET(${plugin}_${subdir_sane} DEPENDS ${ARGN}) + ELSE(WITH_STAGED_PLUGINS) + ADD_CUSTOM_TARGET(${plugin}_${subdir_sane} ALL DEPENDS ${ARGN}) + ENDIF(WITH_STAGED_PLUGINS) + + # for staged plugin install (to run from build directory) + ADD_CUSTOM_TARGET(${plugin}_${subdir_sane}_stageinstall DEPENDS ${ARGN}) + ADD_CUSTOM_COMMAND(TARGET ${plugin}_${subdir_sane}_stageinstall + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory ${PYTHON_OUTPUT_DIRECTORY}/plugins/${plugin}/${subdir} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + FOREACH(file ${ARGN}) + ADD_CUSTOM_COMMAND(TARGET ${plugin}_${subdir_sane}_stageinstall + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different \"${file}\" ${PYTHON_OUTPUT_DIRECTORY}/plugins/${plugin}/${subdir} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + #COMMENT "copying ${file} to ${PYTHON_OUTPUT_DIRECTORY}/plugins/${plugin}/${subdir}" + ) + ENDFOREACH(file) + ADD_DEPENDENCIES(staged_plugins ${plugin}_${subdir_sane}_stageinstall) + + IF(TARGET staged_${plugin}) + ADD_DEPENDENCIES(staged_${plugin} ${plugin}_${subdir_sane}_stageinstall) + ELSE(TARGET staged_${plugin}) + ADD_CUSTOM_TARGET(staged_${plugin} DEPENDS ${plugin}_${subdir_sane}_stageinstall) + ADD_CUSTOM_TARGET(clean_staged_${plugin} + COMMAND ${CMAKE_COMMAND} -E remove_directory ${PYTHON_OUTPUT_DIRECTORY}/plugins/${plugin} + ) + ENDIF(TARGET staged_${plugin}) + ENDMACRO (PLUGIN_INSTALL)