1 # Copyright (C) 2013-2024 CEA, EDF, 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_SIPFLAGS - compilation flags extracted from PyQt
34 # pyqtconfig.Configuration().pyqt_sip_flags
35 # is called to get the compilation flags.
36 # Headers are located by looking for the header file
39 IF(NOT PyQt4_FIND_QUIETLY)
40 MESSAGE(STATUS "Looking for PyQt4 ...")
43 IF(NOT SIP_FOUND AND NOT PyQt4_FIND_QUIETLY)
44 MESSAGE(WARNING "PyQt4 needs SIP to be detected correctly!")
47 FIND_PROGRAM(PYQT_PYUIC_EXECUTABLE NAMES pyuic4 pyuic4.bat)
48 FIND_PROGRAM(PYQT_PYRCC_EXECUTABLE NAMES pyrcc4 pyrcc4.bat)
50 # Get root dir locally, going up two levels from the exec:
51 GET_FILENAME_COMPONENT(_tmp_ROOT_DIR "${PYQT_PYUIC_EXECUTABLE}" PATH)
52 GET_FILENAME_COMPONENT(_tmp_ROOT_DIR "${_tmp_ROOT_DIR}" PATH)
55 # Typical locations of qobject.sip are:
56 # - /usr/share/sip/PyQt4/QtCore, for a system install
57 # - or <xyz>/sip/QtCore, for a custom install
58 # - or <xyz>/share/sip/QtCore, for a custom install
59 FIND_FILE(PYQT_SIP_MAIN_FILE qobject.sip PATH_SUFFIXES share/sip/QtCore sip/QtCore share/sip/PyQt4/QtCore)
61 IF(PYQT_SIP_MAIN_FILE)
62 GET_FILENAME_COMPONENT(PYQT_SIPS_DIR "${PYQT_SIP_MAIN_FILE}" PATH)
63 GET_FILENAME_COMPONENT(PYQT_SIPS_DIR "${PYQT_SIPS_DIR}" PATH)
65 MARK_AS_ADVANCED(PYQT_SIP_MAIN_FILE)
67 # Get PyQt compilation flags:
68 SET(PYQT_PYTHONPATH "${_tmp_ROOT_DIR}/PyQt4;${_tmp_ROOT_DIR}/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages/PyQt4")
71 EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c "import sys;
72 sys.path[:0] = '${PYQT_PYTHONPATH}'.split(';');
73 sys.path[:0] = '${SIP_PYTHONPATH}'.split(';');
74 from PyQt4 import pyqtconfig;
75 sys.stdout.write(pyqtconfig.Configuration().pyqt_sip_flags)"
76 OUTPUT_VARIABLE PYQT_SIPFLAGS)
77 SEPARATE_ARGUMENTS(PYQT_SIPFLAGS)
79 SET(PYQT_SIPFLAGS ${PYQT_SIPFLAGS} -I "${PYQT_SIPS_DIR}")
81 INCLUDE(FindPackageHandleStandardArgs)
82 FIND_PACKAGE_HANDLE_STANDARD_ARGS(PyQt4 REQUIRED_VARS PYQT_PYUIC_EXECUTABLE PYQT_PYRCC_EXECUTABLE PYQT_SIPS_DIR PYQT_SIPFLAGS )
84 # Wrap the final executables so that they always use the proper environment (PYTHONPATH):
85 # The results are put to variables:
86 # PYQT_PYUIC_PATH - command to launch pyuic with the correct PYTHONPATH
87 # PYQT_PYRCC_PATH - command to launch pyrcc with the correct PYTHONPATH
88 # TODO: should be done like Sphinx in KERNEL (i.e. generating a shell script)?
90 IF(WIN32 AND NOT CYGWIN)
91 SET(PYQT_PYUIC_PATH set PYTHONPATH=${PYQT_PYTHONPATH};${SIP_PYTHONPATH};%PYTHONPATH% && ${PYQT_PYUIC_EXECUTABLE})
92 SET(PYQT_PYRCC_PATH set PYTHONPATH=${PYQT_PYTHONPATH};${SIP_PYTHONPATH};%PYTHONPATH% && ${PYQT_PYRCC_EXECUTABLE})
94 STRING(REPLACE ";" ":" PYQT_PYTHONPATH "${PYQT_PYTHONPATH}")
95 SET(PYQT_PYUIC_PATH /usr/bin/env PYTHONPATH="${PYQT_PYTHONPATH}:${SIP_PYTHONPATH}:$$PYTHONPATH" ${PYQT_PYUIC_EXECUTABLE})
96 SET(PYQT_PYRCC_PATH /usr/bin/env PYTHONPATH="${PYQT_PYTHONPATH}:${SIP_PYTHONPATH}:$$PYTHONPATH" ${PYQT_PYRCC_EXECUTABLE})