1 # Copyright (C) 2013-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 # - Find PyQt4 installation
21 # Sets the following variables:
22 # PYQT_PYUIC_EXECUTABLE - path to the pyuic executable
23 # PYQT_PYRCC_EXECUTABLE - path to the pyrcc executable
24 # PYQT_PYUIC_PATH - command to launch pyuic with the correct PYTHONPATH
25 # PYQT_PYRCC_PATH - command to launch pyrcc with the correct PYTHONPATH
26 # PYQT_PYTHONPATH - path to the PyQt Python modules
27 # PYQT_SIPS_DIR - path to main include directory (which contains several sub folders)
28 # PYQT_INCLUDE_DIRS - list of paths to include when compiling (all rooted on PYQT_SIP_DIRS)
29 # PYQT_SIPFLAGS - compilation flags extracted from PyQt
35 # pyqtconfig.Configuration().pyqt_sip_flags
36 # is called to get the compilation flags.
37 # Headers are located by looking for the header file
40 IF(NOT PyQt4_FIND_QUIETLY)
41 MESSAGE(STATUS "Looking for PyQt4 ...")
44 IF(NOT SIP_FOUND AND NOT PyQt4_FIND_QUIETLY)
45 MESSAGE(WARNING "PyQt4 needs SIP to be detected correctly!")
48 FIND_PROGRAM(PYQT_PYUIC_EXECUTABLE NAMES pyuic4 pyuic4.bat)
49 FIND_PROGRAM(PYQT_PYRCC_EXECUTABLE NAMES pyrcc4 pyrcc4.bat)
51 # Get root dir locally, going up two levels from the exec:
52 GET_FILENAME_COMPONENT(_tmp_ROOT_DIR "${PYQT_PYUIC_EXECUTABLE}" PATH)
53 GET_FILENAME_COMPONENT(_tmp_ROOT_DIR "${_tmp_ROOT_DIR}" PATH)
56 # Typical locations of qobject.sip are:
57 # - /usr/share/sip/PyQt4/QtCore, for a system install
58 # - or <xyz>/sip/QtCore, for a custom install
59 # - or <xyz>/share/sip/QtCore, for a custom install
60 FIND_FILE(PYQT_SIP_MAIN_FILE qobject.sip PATH_SUFFIXES share/sip/QtCore sip/QtCore share/sip/PyQt4/QtCore)
62 IF(PYQT_SIP_MAIN_FILE)
63 GET_FILENAME_COMPONENT(PYQT_SIPS_DIR "${PYQT_SIP_MAIN_FILE}" PATH)
64 GET_FILENAME_COMPONENT(PYQT_SIPS_DIR "${PYQT_SIPS_DIR}" PATH)
66 MARK_AS_ADVANCED(PYQT_SIP_MAIN_FILE)
68 # Get PyQt compilation flags:
69 SET(PYQT_PYTHONPATH ${_tmp_ROOT_DIR}/PyQt4)
72 EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c "import sys;
73 sys.path[:0] = '${PYQT_PYTHONPATH}'.split(';');
74 sys.path[:0] = '${SIP_PYTHONPATH}'.split(';');
75 from PyQt4 import pyqtconfig;
76 sys.stdout.write(pyqtconfig.Configuration().pyqt_sip_flags)"
77 OUTPUT_VARIABLE PYQT_SIPFLAGS)
78 SEPARATE_ARGUMENTS(PYQT_SIPFLAGS)
82 "${PYQT_SIPS_DIR}/QtCore"
83 "${PYQT_SIPS_DIR}/QtGui"
84 "${PYQT_SIPS_DIR}/QtXml"
85 "${PYQT_SIPS_DIR}/QtOpenGL"
86 "${PYQT_SIPS_DIR}/QtAssistant"
87 "${PYQT_SIPS_DIR}/QtDesigner"
88 "${PYQT_SIPS_DIR}/QtNetwork"
89 "${PYQT_SIPS_DIR}/QtSql"
90 "${PYQT_SIPS_DIR}/QtSvg"
91 "${PYQT_SIPS_DIR}/QtTest"
94 SET(PYQT_CXX_EXT ".cc")
95 SET(PYQT_SIPFLAGS ${PYQT_SIPFLAGS} -s ${PYQT_CXX_EXT} -c .)
96 FOREACH(_dir ${PYQT_INCLUDE_DIRS})
97 LIST(APPEND PYQT_SIPFLAGS -I ${_dir})
100 INCLUDE(FindPackageHandleStandardArgs)
101 FIND_PACKAGE_HANDLE_STANDARD_ARGS(PyQt4 REQUIRED_VARS PYQT_PYUIC_EXECUTABLE PYQT_PYRCC_EXECUTABLE PYQT_SIPS_DIR PYQT_SIPFLAGS )
103 # Wrap the final executables so that they always use the proper environment (PYTHONPATH):
104 # The results are put to variables:
105 # PYQT_PYUIC_PATH - command to launch pyuic with the correct PYTHONPATH
106 # PYQT_PYRCC_PATH - command to launch pyrcc with the correct PYTHONPATH
107 # TODO: should be done like Sphinx in KERNEL (i.e. generating a shell script)?
109 IF(WIN32 AND NOT CYGWIN)
110 SET(PYQT_PYUIC_PATH set PYTHONPATH=${PYQT_PYTHONPATH};${SIP_PYTHONPATH};%PYTHONPATH% && ${PYQT_PYUIC_EXECUTABLE})
111 SET(PYQT_PYRCC_PATH set PYTHONPATH=${PYQT_PYTHONPATH};${SIP_PYTHONPATH};%PYTHONPATH% && ${PYQT_PYRCC_EXECUTABLE})
113 STRING(REPLACE ";" ":" PYQT_PYTHONPATH "${PYQT_PYTHONPATH}")
114 SET(PYQT_PYUIC_PATH /usr/bin/env PYTHONPATH="${PYQT_PYTHONPATH}:${SIP_PYTHONPATH}:$$PYTHONPATH" ${PYQT_PYUIC_EXECUTABLE})
115 SET(PYQT_PYRCC_PATH /usr/bin/env PYTHONPATH="${PYQT_PYTHONPATH}:${SIP_PYTHONPATH}:$$PYTHONPATH" ${PYQT_PYRCC_EXECUTABLE})