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