Skip to content

Commit 1fdaa04

Browse files
committed
Add cmake option WITH_PY_COMPILE (OFF by default)
- Byte-compiles staged and intalled plugins/modules
1 parent 2159eda commit 1fdaa04

File tree

5 files changed

+40
-0
lines changed

5 files changed

+40
-0
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ IF (WITH_BINDINGS)
7676
# as otherwise user has to use PYTHONPATH environemnt variable to add
7777
# QGIS bindings to package search path
7878
SET (BINDINGS_GLOBAL_INSTALL FALSE CACHE BOOL "Install bindings to global python directory? (might need root)")
79+
SET (WITH_PY_COMPILE FALSE CACHE BOOL "Determines whether Python modules in staged or installed locations are byte-compiled")
7980
# concatenate QScintilla2 API files
8081
SET (WITH_QSCIAPI TRUE CACHE BOOL "Determines whether the QScintilla2 API files will be updated and concatenated")
8182
ENDIF (WITH_BINDINGS)
@@ -640,6 +641,10 @@ ENDIF (UNIX AND NOT APPLE)
640641

641642
INSTALL(FILES cmake/FindQGIS.cmake DESTINATION ${QGIS_DATA_DIR})
642643

644+
#############################################################
645+
# Post-install commands
646+
ADD_SUBDIRECTORY(postinstall)
647+
643648
#############################################################
644649
# Uninstall stuff see: http://www.vtk.org/Wiki/CMake_FAQ
645650
CONFIGURE_FILE(

postinstall/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
# for included scripts that set policies
3+
INSTALL (CODE "cmake_policy(SET CMP0011 NEW)")
4+
5+
CONFIGURE_FILE("PostInstall.cmake.in" "PostInstall.cmake" @ONLY)
6+
INSTALL(SCRIPT "${CMAKE_BINARY_DIR}/postinstall/PostInstall.cmake")

postinstall/PostInstall.cmake.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
# kill boolean warnings
3+
CMAKE_POLICY(SET CMP0012 NEW)
4+
5+
IF(@WITH_PY_COMPILE@)
6+
MESSAGE(STATUS "Byte-compiling core Python utilities and plugins...")
7+
# exclude Python 3 modules in PyQt4.uic package
8+
EXECUTE_PROCESS(COMMAND @PYTHON_EXECUTABLE@ -m compileall -q -x ".*uic.port_v3.*" "@CMAKE_INSTALL_PREFIX@/@QGIS_DATA_DIR@/python")
9+
ENDIF(@WITH_PY_COMPILE@)

python/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,13 @@ INSTALL(FILES ${PY_FILES} ${PYUI_FILES} DESTINATION "${QGIS_PYTHON_DIR}")
167167

168168
ADD_SUBDIRECTORY(console_help)
169169

170+
# Byte-compile staged PyQGIS utilities
171+
IF(WITH_PY_COMPILE)
172+
ADD_CUSTOM_TARGET(pycompile_pyutils ALL
173+
COMMAND ${PYTHON_EXECUTABLE} -m compileall -q "${PYTHON_OUTPUT_DIRECTORY}/qgis"
174+
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
175+
COMMENT "Byte-compiling staged PyQGIS utility modules..."
176+
DEPENDS pyutils
177+
)
178+
ENDIF(WITH_PY_COMPILE)
179+

python/plugins/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1+
IF(WITH_PY_COMPILE)
2+
ADD_CUSTOM_TARGET(pycompile_staged ALL
3+
COMMAND ${PYTHON_EXECUTABLE} -m compileall -q "${PYTHON_OUTPUT_DIRECTORY}/plugins"
4+
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
5+
COMMENT "Byte-compiling staged Python plugins..."
6+
)
7+
ENDIF(WITH_PY_COMPILE)
18

29
MACRO (PLUGIN_INSTALL plugin subdir )
310
INSTALL(FILES ${ARGN} DESTINATION ${QGIS_DATA_DIR}/python/plugins/${plugin}/${subdir})
411
STRING(REPLACE "/" "_" subdir_sane "${subdir}")
512
ADD_CUSTOM_TARGET(${plugin}_${subdir_sane}_stageinstall ALL DEPENDS ${ARGN})
13+
IF(WITH_PY_COMPILE)
14+
ADD_DEPENDENCIES(pycompile_staged ${plugin}_${subdir_sane}_stageinstall)
15+
ENDIF(WITH_PY_COMPILE)
616
FOREACH(file ${ARGN})
717
ADD_CUSTOM_COMMAND(TARGET ${plugin}_${subdir_sane}_stageinstall
818
POST_BUILD

0 commit comments

Comments
 (0)