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