Skip to content

Commit

Permalink
Add cmake option WITH_PY_COMPILE (OFF by default)
Browse files Browse the repository at this point in the history
- Byte-compiles staged and intalled plugins/modules
  • Loading branch information
dakcarto committed Oct 26, 2012
1 parent 2159eda commit 1fdaa04
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Expand Up @@ -76,6 +76,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_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")
ENDIF (WITH_BINDINGS)
Expand Down Expand Up @@ -640,6 +641,10 @@ ENDIF (UNIX AND NOT APPLE)

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

#############################################################
# Post-install commands
ADD_SUBDIRECTORY(postinstall)

#############################################################
# Uninstall stuff see: http://www.vtk.org/Wiki/CMake_FAQ
CONFIGURE_FILE(
Expand Down
6 changes: 6 additions & 0 deletions postinstall/CMakeLists.txt
@@ -0,0 +1,6 @@

# for included scripts that set policies
INSTALL (CODE "cmake_policy(SET CMP0011 NEW)")

CONFIGURE_FILE("PostInstall.cmake.in" "PostInstall.cmake" @ONLY)
INSTALL(SCRIPT "${CMAKE_BINARY_DIR}/postinstall/PostInstall.cmake")
9 changes: 9 additions & 0 deletions postinstall/PostInstall.cmake.in
@@ -0,0 +1,9 @@

# kill boolean warnings
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.*" "@CMAKE_INSTALL_PREFIX@/@QGIS_DATA_DIR@/python")
ENDIF(@WITH_PY_COMPILE@)
10 changes: 10 additions & 0 deletions python/CMakeLists.txt
Expand Up @@ -167,3 +167,13 @@ INSTALL(FILES ${PY_FILES} ${PYUI_FILES} DESTINATION "${QGIS_PYTHON_DIR}")

ADD_SUBDIRECTORY(console_help)

# Byte-compile staged PyQGIS utilities
IF(WITH_PY_COMPILE)
ADD_CUSTOM_TARGET(pycompile_pyutils ALL
COMMAND ${PYTHON_EXECUTABLE} -m compileall -q "${PYTHON_OUTPUT_DIRECTORY}/qgis"
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
COMMENT "Byte-compiling staged PyQGIS utility modules..."
DEPENDS pyutils
)
ENDIF(WITH_PY_COMPILE)

10 changes: 10 additions & 0 deletions python/plugins/CMakeLists.txt
@@ -1,8 +1,18 @@
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)

MACRO (PLUGIN_INSTALL plugin subdir )
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_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
Expand Down

0 comments on commit 1fdaa04

Please sign in to comment.