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