]> SALOME platform Git repositories - modules/gui.git/blob - adm_local/cmake_files/FindPyQt4.cmake
Salome HOME
821ce3b34448ae5c87eda48d19008ab36b4b82c2
[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 FIND_FILE(PYQT_SIP_MAIN_FILE qobject.sip PATH_SUFFIXES sip/QtCore share/sip/PyQt4/QtCore)
55
56 IF(PYQT_SIP_MAIN_FILE)
57   GET_FILENAME_COMPONENT(PYQT_SIPS_DIR "${PYQT_SIP_MAIN_FILE}" PATH)
58   GET_FILENAME_COMPONENT(PYQT_SIPS_DIR "${PYQT_SIPS_DIR}" PATH)
59 ENDIF()
60 MARK_AS_ADVANCED(PYQT_SIP_MAIN_FILE)
61
62 # Get PyQt compilation flags:
63 SET(PYQT_PYTHONPATH "${PYQT_PYTHONPATH}/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages")
64 SET(PYQT_SIPFLAGS)
65 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)"
66   OUTPUT_VARIABLE PYQT_SIPFLAGS)
67 SEPARATE_ARGUMENTS(PYQT_SIPFLAGS)
68
69 SET(PYQT_INCLUDE_DIRS
70   "${PYQT_SIPS_DIR}"
71   "${PYQT_SIPS_DIR}/QtCore"
72   "${PYQT_SIPS_DIR}/QtGui"
73   "${PYQT_SIPS_DIR}/QtXml"
74   "${PYQT_SIPS_DIR}/QtOpenGL"
75   "${PYQT_SIPS_DIR}/QtAssistant"
76   "${PYQT_SIPS_DIR}/QtDesigner"
77   "${PYQT_SIPS_DIR}/QtNetwork"
78   "${PYQT_SIPS_DIR}/QtSql"
79   "${PYQT_SIPS_DIR}/QtSvg"
80   "${PYQT_SIPS_DIR}/QtTest"
81 )
82
83 SET(PYQT_SIPFLAGS ${PYQT_SIPFLAGS} -s .cc -c .)
84 FOREACH(_dir ${PYQT_INCLUDE_DIRS})
85   LIST(APPEND PYQT_SIPFLAGS -I ${_dir})
86 ENDFOREACH()
87
88 INCLUDE(FindPackageHandleStandardArgs)
89 FIND_PACKAGE_HANDLE_STANDARD_ARGS(PyQt4 REQUIRED_VARS PYQT_PYUIC_EXECUTABLE PYQT_SIPS_DIR PYQT_SIPFLAGS)
90