-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Native and faster compilation of python bindings (#2370)
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12774 c8812cc2-4d05-0410-92ff-de0c093fc19c
- Loading branch information
wonder
committed
Jan 16, 2010
1 parent
3218697
commit b5be69f
Showing
16 changed files
with
613 additions
and
585 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
# Copyright (c) 2007, Simon Edwards <simon@simonzone.com> | ||
# Redistribution and use is allowed according to the terms of the BSD license. | ||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file. | ||
|
||
import sys | ||
import distutils.sysconfig | ||
|
||
print("exec_prefix:%s" % sys.exec_prefix) | ||
print("short_version:%s" % sys.version[:3]) | ||
print("long_version:%s" % sys.version.split()[0]) | ||
print("py_inc_dir:%s" % distutils.sysconfig.get_python_inc()) | ||
print("site_packages_dir:%s" % distutils.sysconfig.get_python_lib(plat_specific=1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Copyright (c) 2007, Simon Edwards <simon@simonzone.com> | ||
# Redistribution and use is allowed according to the terms of the BSD license. | ||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file. | ||
|
||
import PyQt4.pyqtconfig | ||
|
||
pyqtcfg = PyQt4.pyqtconfig.Configuration() | ||
print("pyqt_version:%06.0x" % pyqtcfg.pyqt_version) | ||
print("pyqt_version_str:%s" % pyqtcfg.pyqt_version_str) | ||
|
||
pyqt_version_tag = "" | ||
in_t = False | ||
for item in pyqtcfg.pyqt_sip_flags.split(' '): | ||
if item=="-t": | ||
in_t = True | ||
elif in_t: | ||
if item.startswith("Qt_4"): | ||
pyqt_version_tag = item | ||
else: | ||
in_t = False | ||
print("pyqt_version_tag:%s" % pyqt_version_tag) | ||
|
||
print("pyqt_sip_dir:%s" % pyqtcfg.pyqt_sip_dir) | ||
print("pyqt_sip_flags:%s" % pyqtcfg.pyqt_sip_flags) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Find PyQt4 | ||
# ~~~~~~~~~~ | ||
# Copyright (c) 2007-2008, Simon Edwards <simon@simonzone.com> | ||
# Redistribution and use is allowed according to the terms of the BSD license. | ||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file. | ||
# | ||
# PyQt4 website: http://www.riverbankcomputing.co.uk/pyqt/index.php | ||
# | ||
# Find the installed version of PyQt4. FindPyQt4 should only be called after | ||
# Python has been found. | ||
# | ||
# This file defines the following variables: | ||
# | ||
# PYQT4_VERSION - The version of PyQt4 found expressed as a 6 digit hex number | ||
# suitable for comparision as a string | ||
# | ||
# PYQT4_VERSION_STR - The version of PyQt4 as a human readable string. | ||
# | ||
# PYQT4_VERSION_TAG - The PyQt version tag using by PyQt's sip files. | ||
# | ||
# PYQT4_SIP_DIR - The directory holding the PyQt4 .sip files. | ||
# | ||
# PYQT4_SIP_FLAGS - The SIP flags used to build PyQt. | ||
|
||
IF(EXISTS PYQT4_VERSION) | ||
# Already in cache, be silent | ||
SET(PYQT4_FOUND TRUE) | ||
ELSE(EXISTS PYQT4_VERSION) | ||
|
||
FIND_FILE(_find_pyqt_py FindPyQt.py PATHS ${CMAKE_MODULE_PATH}) | ||
|
||
EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} ${_find_pyqt_py} OUTPUT_VARIABLE pyqt_config) | ||
IF(pyqt_config) | ||
STRING(REGEX REPLACE "^pyqt_version:([^\n]+).*$" "\\1" PYQT4_VERSION ${pyqt_config}) | ||
STRING(REGEX REPLACE ".*\npyqt_version_str:([^\n]+).*$" "\\1" PYQT4_VERSION_STR ${pyqt_config}) | ||
STRING(REGEX REPLACE ".*\npyqt_version_tag:([^\n]+).*$" "\\1" PYQT4_VERSION_TAG ${pyqt_config}) | ||
STRING(REGEX REPLACE ".*\npyqt_sip_dir:([^\n]+).*$" "\\1" PYQT4_SIP_DIR ${pyqt_config}) | ||
STRING(REGEX REPLACE ".*\npyqt_sip_flags:([^\n]+).*$" "\\1" PYQT4_SIP_FLAGS ${pyqt_config}) | ||
|
||
SET(PYQT4_FOUND TRUE) | ||
ENDIF(pyqt_config) | ||
|
||
IF(PYQT4_FOUND) | ||
IF(NOT PYQT4_FIND_QUIETLY) | ||
MESSAGE(STATUS "Found PyQt4 version: ${PYQT4_VERSION_STR}") | ||
ENDIF(NOT PYQT4_FIND_QUIETLY) | ||
ELSE(PYQT4_FOUND) | ||
IF(PYQT4_FIND_REQUIRED) | ||
MESSAGE(FATAL_ERROR "Could not find Python") | ||
ENDIF(PYQT4_FIND_REQUIRED) | ||
ENDIF(PYQT4_FOUND) | ||
|
||
ENDIF(EXISTS PYQT4_VERSION) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# Find Python | ||
# ~~~~~~~~~~~ | ||
# Find the Python interpreter and related Python directories. | ||
# | ||
# This file defines the following variables: | ||
# | ||
# PYTHON_EXECUTABLE - The path and filename of the Python interpreter. | ||
# | ||
# PYTHON_SHORT_VERSION - The version of the Python interpreter found, | ||
# excluding the patch version number. (e.g. 2.5 and not 2.5.1)) | ||
# | ||
# PYTHON_LONG_VERSION - The version of the Python interpreter found as a human | ||
# readable string. | ||
# | ||
# PYTHON_SITE_PACKAGES_DIR - Location of the Python site-packages directory. | ||
# | ||
# PYTHON_INCLUDE_PATH - Directory holding the python.h include file. | ||
# | ||
# PYTHON_LIBRARY, PYTHON_LIBRARIES- Location of the Python library. | ||
|
||
# Copyright (c) 2007, Simon Edwards <simon@simonzone.com> | ||
# Redistribution and use is allowed according to the terms of the BSD license. | ||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file. | ||
|
||
|
||
|
||
INCLUDE(CMakeFindFrameworks) | ||
|
||
if(EXISTS PYTHON_LIBRARY) | ||
# Already in cache, be silent | ||
set(PYTHONLIBRARY_FOUND TRUE) | ||
else(EXISTS PYTHON_LIBRARY) | ||
|
||
FIND_PACKAGE(PythonInterp) | ||
|
||
if(PYTHONINTERP_FOUND) | ||
|
||
FIND_FILE(_find_lib_python_py FindLibPython.py PATHS ${CMAKE_MODULE_PATH}) | ||
|
||
EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} ${_find_lib_python_py} OUTPUT_VARIABLE python_config) | ||
if(python_config) | ||
STRING(REGEX REPLACE ".*exec_prefix:([^\n]+).*$" "\\1" PYTHON_PREFIX ${python_config}) | ||
STRING(REGEX REPLACE ".*\nshort_version:([^\n]+).*$" "\\1" PYTHON_SHORT_VERSION ${python_config}) | ||
STRING(REGEX REPLACE ".*\nlong_version:([^\n]+).*$" "\\1" PYTHON_LONG_VERSION ${python_config}) | ||
STRING(REGEX REPLACE ".*\npy_inc_dir:([^\n]+).*$" "\\1" PYTHON_INCLUDE_PATH ${python_config}) | ||
if(NOT PYTHON_SITE_PACKAGES_DIR) | ||
if(NOT PYTHON_LIBS_WITH_KDE_LIBS) | ||
STRING(REGEX REPLACE ".*\nsite_packages_dir:([^\n]+).*$" "\\1" PYTHON_SITE_PACKAGES_DIR ${python_config}) | ||
else(NOT PYTHON_LIBS_WITH_KDE_LIBS) | ||
set(PYTHON_SITE_PACKAGES_DIR ${KDE4_LIB_INSTALL_DIR}/python${PYTHON_SHORT_VERSION}/site-packages) | ||
endif(NOT PYTHON_LIBS_WITH_KDE_LIBS) | ||
endif(NOT PYTHON_SITE_PACKAGES_DIR) | ||
STRING(REGEX REPLACE "([0-9]+).([0-9]+)" "\\1\\2" PYTHON_SHORT_VERSION_NO_DOT ${PYTHON_SHORT_VERSION}) | ||
set(PYTHON_LIBRARY_NAMES python${PYTHON_SHORT_VERSION} python${PYTHON_SHORT_VERSION_NO_DOT}) | ||
if(WIN32) | ||
STRING(REPLACE "\\" "/" PYTHON_SITE_PACKAGES_DIR ${PYTHON_SITE_PACKAGES_DIR}) | ||
endif(WIN32) | ||
FIND_LIBRARY(PYTHON_LIBRARY NAMES ${PYTHON_LIBRARY_NAMES} PATHS ${PYTHON_PREFIX}/lib ${PYTHON_PREFIX}/libs NO_DEFAULT_PATH) | ||
set(PYTHONLIBRARY_FOUND TRUE) | ||
endif(python_config) | ||
|
||
# adapted from cmake's builtin FindPythonLibs | ||
if(APPLE) | ||
CMAKE_FIND_FRAMEWORKS(Python) | ||
set(PYTHON_FRAMEWORK_INCLUDES) | ||
if(Python_FRAMEWORKS) | ||
# If a framework has been selected for the include path, | ||
# make sure "-framework" is used to link it. | ||
if("${PYTHON_INCLUDE_PATH}" MATCHES "Python\\.framework") | ||
set(PYTHON_LIBRARY "") | ||
set(PYTHON_DEBUG_LIBRARY "") | ||
endif("${PYTHON_INCLUDE_PATH}" MATCHES "Python\\.framework") | ||
if(NOT PYTHON_LIBRARY) | ||
set (PYTHON_LIBRARY "-framework Python" CACHE FILEPATH "Python Framework" FORCE) | ||
endif(NOT PYTHON_LIBRARY) | ||
set(PYTHONLIBRARY_FOUND TRUE) | ||
endif(Python_FRAMEWORKS) | ||
endif(APPLE) | ||
endif(PYTHONINTERP_FOUND) | ||
|
||
if(PYTHONLIBRARY_FOUND) | ||
set(PYTHON_LIBRARIES ${PYTHON_LIBRARY}) | ||
if(NOT PYTHONLIBRARY_FIND_QUIETLY) | ||
message(STATUS "Found Python executable: ${PYTHON_EXECUTABLE}") | ||
message(STATUS "Found Python version: ${PYTHON_LONG_VERSION}") | ||
message(STATUS "Found Python library: ${PYTHON_LIBRARY}") | ||
endif(NOT PYTHONLIBRARY_FIND_QUIETLY) | ||
else(PYTHONLIBRARY_FOUND) | ||
if(PYTHONLIBRARY_FIND_REQUIRED) | ||
message(FATAL_ERROR "Could not find Python") | ||
endif(PYTHONLIBRARY_FIND_REQUIRED) | ||
endif(PYTHONLIBRARY_FOUND) | ||
|
||
endif (EXISTS PYTHON_LIBRARY) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Find SIP | ||
# ~~~~~~~~ | ||
# | ||
# SIP website: http://www.riverbankcomputing.co.uk/sip/index.php | ||
# | ||
# Find the installed version of SIP. FindSIP should be called after Python | ||
# has been found. | ||
# | ||
# This file defines the following variables: | ||
# | ||
# SIP_VERSION - The version of SIP found expressed as a 6 digit hex number | ||
# suitable for comparision as a string. | ||
# | ||
# SIP_VERSION_STR - The version of SIP found as a human readable string. | ||
# | ||
# SIP_EXECUTABLE - Path and filename of the SIP command line executable. | ||
# | ||
# SIP_INCLUDE_DIR - Directory holding the SIP C++ header file. | ||
# | ||
# SIP_DEFAULT_SIP_DIR - Default directory where .sip files should be installed | ||
# into. | ||
|
||
# Copyright (c) 2007, Simon Edwards <simon@simonzone.com> | ||
# Redistribution and use is allowed according to the terms of the BSD license. | ||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file. | ||
|
||
|
||
|
||
IF(SIP_VERSION) | ||
# Already in cache, be silent | ||
SET(SIP_FOUND TRUE) | ||
ELSE(SIP_VERSION) | ||
|
||
FIND_FILE(_find_sip_py FindSIP.py PATHS ${CMAKE_MODULE_PATH}) | ||
|
||
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_str:([^\n]+).*$" "\\1" SIP_VERSION_STR ${sip_config}) | ||
STRING(REGEX REPLACE ".*\nsip_bin:([^\n]+).*$" "\\1" SIP_EXECUTABLE ${sip_config}) | ||
STRING(REGEX REPLACE ".*\ndefault_sip_dir:([^\n]+).*$" "\\1" SIP_DEFAULT_SIP_DIR ${sip_config}) | ||
STRING(REGEX REPLACE ".*\nsip_inc_dir:([^\n]+).*$" "\\1" SIP_INCLUDE_DIR ${sip_config}) | ||
SET(SIP_FOUND TRUE) | ||
ENDIF(sip_config) | ||
|
||
IF(SIP_FOUND) | ||
IF(NOT SIP_FIND_QUIETLY) | ||
MESSAGE(STATUS "Found SIP version: ${SIP_VERSION_STR}") | ||
ENDIF(NOT SIP_FIND_QUIETLY) | ||
ELSE(SIP_FOUND) | ||
IF(SIP_FIND_REQUIRED) | ||
MESSAGE(FATAL_ERROR "Could not find SIP") | ||
ENDIF(SIP_FIND_REQUIRED) | ||
ENDIF(SIP_FOUND) | ||
|
||
ENDIF(SIP_VERSION) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# FindSIP.py | ||
# | ||
# Copyright (c) 2007, Simon Edwards <simon@simonzone.com> | ||
# Redistribution and use is allowed according to the terms of the BSD license. | ||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file. | ||
|
||
import sys | ||
import sipconfig | ||
|
||
sipcfg = sipconfig.Configuration() | ||
print("sip_version:%06.0x" % sipcfg.sip_version) | ||
print("sip_version_str:%s" % sipcfg.sip_version_str) | ||
print("sip_bin:%s" % sipcfg.sip_bin) | ||
print("default_sip_dir:%s" % sipcfg.default_sip_dir) | ||
print("sip_inc_dir:%s" % sipcfg.sip_inc_dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
|
||
|
||
IF(NOT PYUIC4_PROGRAM) | ||
IF (MSVC) | ||
FIND_PROGRAM(PYUIC4_PROGRAM | ||
NAMES pyuic4.bat | ||
PATHS $ENV{LIB_DIR}/bin | ||
) | ||
ELSE(MSVC) | ||
FIND_PROGRAM(PYUIC4_PROGRAM pyuic4) | ||
ENDIF (MSVC) | ||
|
||
IF (NOT PYUIC4_PROGRAM) | ||
MESSAGE(FATAL_ERROR "pyuic4 not found - aborting") | ||
ENDIF (NOT PYUIC4_PROGRAM) | ||
ENDIF(NOT PYUIC4_PROGRAM) | ||
|
||
# Adapted from QT4_WRAP_UI | ||
MACRO(PYQT4_WRAP_UI outfiles ) | ||
FOREACH(it ${ARGN}) | ||
GET_FILENAME_COMPONENT(outfile ${it} NAME_WE) | ||
GET_FILENAME_COMPONENT(infile ${it} ABSOLUTE) | ||
SET(outfile ${CMAKE_CURRENT_BINARY_DIR}/ui_${outfile}.py) | ||
ADD_CUSTOM_COMMAND(OUTPUT ${outfile} | ||
COMMAND ${PYUIC4_PROGRAM} ${infile} -o ${outfile} | ||
MAIN_DEPENDENCY ${infile} | ||
) | ||
SET(${outfiles} ${${outfiles}} ${outfile}) | ||
ENDFOREACH(it) | ||
ENDMACRO(PYQT4_WRAP_UI) | ||
|
||
IF(NOT PYRCC4_PROGRAM) | ||
IF (MSVC) | ||
FIND_PROGRAM(PYRCC4_PROGRAM | ||
NAMES pyrcc4.exe | ||
PATHS $ENV{LIB_DIR}/bin | ||
) | ||
ELSE(MSVC) | ||
FIND_PROGRAM(PYRCC4_PROGRAM pyrcc4) | ||
ENDIF (MSVC) | ||
|
||
IF (NOT PYRCC4_PROGRAM) | ||
MESSAGE(FATAL_ERROR "pyrcc4 not found - aborting") | ||
ENDIF (NOT PYRCC4_PROGRAM) | ||
ENDIF(NOT PYRCC4_PROGRAM) | ||
|
||
# Adapted from QT4_ADD_RESOURCES | ||
MACRO (PYQT4_ADD_RESOURCES outfiles ) | ||
FOREACH (it ${ARGN}) | ||
GET_FILENAME_COMPONENT(outfile ${it} NAME_WE) | ||
GET_FILENAME_COMPONENT(infile ${it} ABSOLUTE) | ||
GET_FILENAME_COMPONENT(rc_path ${infile} PATH) | ||
SET(outfile ${CMAKE_CURRENT_BINARY_DIR}/${outfile}_rc.py) | ||
# parse file for dependencies | ||
# all files are absolute paths or relative to the location of the qrc file | ||
FILE(READ "${infile}" _RC_FILE_CONTENTS) | ||
STRING(REGEX MATCHALL "<file[^<]+" _RC_FILES "${_RC_FILE_CONTENTS}") | ||
SET(_RC_DEPENDS) | ||
FOREACH(_RC_FILE ${_RC_FILES}) | ||
STRING(REGEX REPLACE "^<file[^>]*>" "" _RC_FILE "${_RC_FILE}") | ||
STRING(REGEX MATCH "^/|([A-Za-z]:/)" _ABS_PATH_INDICATOR "${_RC_FILE}") | ||
IF(NOT _ABS_PATH_INDICATOR) | ||
SET(_RC_FILE "${rc_path}/${_RC_FILE}") | ||
ENDIF(NOT _ABS_PATH_INDICATOR) | ||
SET(_RC_DEPENDS ${_RC_DEPENDS} "${_RC_FILE}") | ||
ENDFOREACH(_RC_FILE) | ||
ADD_CUSTOM_COMMAND(OUTPUT ${outfile} | ||
COMMAND ${PYRCC4_PROGRAM} -name ${outfile} -o ${outfile} ${infile} | ||
MAIN_DEPENDENCY ${infile} | ||
DEPENDS ${_RC_DEPENDS}) | ||
SET(${outfiles} ${${outfiles}} ${outfile}) | ||
ENDFOREACH (it) | ||
ENDMACRO (PYQT4_ADD_RESOURCES) |
Oops, something went wrong.