Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / adm_local / unix / config_files / check_pyqt.m4
1 dnl  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 dnl
3 dnl  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 dnl  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 dnl
6 dnl  This library is free software; you can redistribute it and/or
7 dnl  modify it under the terms of the GNU Lesser General Public
8 dnl  License as published by the Free Software Foundation; either
9 dnl  version 2.1 of the License.
10 dnl
11 dnl  This library is distributed in the hope that it will be useful,
12 dnl  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 dnl  Lesser General Public License for more details.
15 dnl
16 dnl  You should have received a copy of the GNU Lesser General Public
17 dnl  License along with this library; if not, write to the Free Software
18 dnl  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 dnl
20 dnl  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 dnl
22 AC_DEFUN([CHECK_PYQT],[
23 AC_REQUIRE([CHECK_PYTHON])dnl
24 AC_REQUIRE([CHECK_QT])dnl
25 AC_REQUIRE([CHECK_SIP])dnl
26 AC_REQUIRE([AC_LINKER_OPTIONS])dnl
27
28 dnl AC_LANG_SAVE
29 dnl AC_LANG_CPLUSPLUS
30
31 AC_ARG_WITH(pyqt,
32     [  --with-pyqt=DIR      root directory path to PyQt installation ],
33     [PYQTDIR="$withval"
34       AC_MSG_RESULT([Try $withval as path to the PyQt])
35     ])
36
37 AC_ARG_WITH(pyqt_sips,
38     [  --with-pyqt_sips=DIR      a directory path to PyQt sips installation ],
39     [PYQT_SIPS="$withval"
40       AC_MSG_RESULT([Try $withval as path to the PyQt sip files])
41     ])
42
43 AC_ARG_WITH(pyuic4,
44     [  --with-pyuic4=EXEC pyuic4 executable ],
45     [PYUIC="$withval"
46       AC_MSG_RESULT([Try $withval as pyuic4 executable])
47     ])
48
49 AC_CHECKING(for pyqt)
50
51 pyqt_ok=no
52
53 dnl check pyuic4
54 if test "x$PYUIC" != "x" ; then
55     dnl try $withval value
56     AC_CHECK_FILE($PYUIC,pyqt_ok=yes,pyqt_ok=no)
57 else
58     TEST_BIN_DIRS=""
59     if test "x${PYQTDIR}" != "x" ; then
60         TEST_BIN_DIRS="${TEST_BIN_DIRS} ${PYQTDIR} ${PYQTDIR}/bin"
61     fi
62     TEST_BIN_DIRS="${TEST_BIN_DIRS} __CHECK__PATH__"
63     if test "x${SIPDIR}" != "x" ; then
64         TEST_BIN_DIRS="${TEST_BIN_DIRS} ${SIPDIR} ${SIPDIR}/bin"
65     fi
66     if test "x${PYTHONHOME}" != "x" ; then
67         TEST_BIN_DIRS="${TEST_BIN_DIRS} ${PYTHONHOME}/bin"
68     fi
69     TEST_BIN_DIRS="${TEST_BIN_DIRS} /usr/bin"
70
71     dnl search pyuic4
72     pyqt_ok=no
73     for d in ${TEST_BIN_DIRS} ; do
74         if test "x${d}" = "x__CHECK__PATH__" ; then
75             AC_PATH_PROG(TEMP, pyuic4)
76             if test "x${TEMP}" != "x" ; then
77                 PYUIC=${TEMP}
78                 if test "x$PYQTDIR" = "x" ; then
79                     PYQTDIR=`dirname ${PYUIC}`
80                     PYQTDIR=`dirname ${PYQTDIR}`
81                 fi
82                 pyqt_ok=yes
83                 break
84             fi
85         else
86             if test -d $d ; then
87                 AC_CHECK_FILE(${d}/pyuic4,pyqt_ok=yes,pyqt_ok=no)
88                 if test "x$pyqt_ok" == "xyes" ; then
89                     PYUIC=${d}/pyuic4
90                     break
91                 fi
92             fi
93         fi
94     done
95 fi
96
97 dnl check PyQt version
98 if test "x$pyqt_ok" == "xyes" ; then
99     AC_MSG_CHECKING(whether PyQt version >= 4.2)
100     PYQT_VERSION=`${PYUIC} --version 2>&1 | grep "Python User Interface Compiler"`
101     if test "$?" != "0" ; then
102         PYQT_VERSION=`${PYUIC} -version 2>&1 | grep "Python User Interface Compiler"`
103     fi
104     if test "x${PYQT_VERSION}" != "x" ; then
105         PYQT_VERSION=`echo $PYQT_VERSION | sed -e 's%[[[:alpha:][:space:]]]*\([[[:digit:].]]*\).*%\1%g'`
106         PYQT_VERSION_ID=`echo $PYQT_VERSION | awk -F. '{v=$[1]*10000+$[2]*100+$[3];print v}'`
107     else
108         PYQT_VERSION="<unknown>"
109         PYQT_VERSION_ID=0
110     fi
111     if test $PYQT_VERSION_ID -ge 40200 ; then 
112         AC_MSG_RESULT(yes)
113         AC_MSG_RESULT(PyQt version is $PYQT_VERSION)
114     else
115         AC_MSG_RESULT(no)
116         AC_MSG_RESULT(WARNING! PyQt version $PYQT_VERSION is not supported (at least 4.2 is required)!)
117         pyqt_ok=no
118     fi
119 else
120     AC_MSG_RESULT(Warning! pyuic4 is not found!)
121 fi
122
123 if test "x$pyqt_ok" == "xyes" ; then
124     TESTLIBFILE=QtCore.so
125     TESTSIPFILE=QtCore/QtCoremod.sip
126     TEST_LIB_DIRS=""
127     TEST_SIPS_DIRS=""
128     if test "x${PYQT_SIPS}" != "x" ; then
129         TEST_SIPS_DIRS="${TEST_SIPS_DIRS} ${PYQT_SIPS}"
130     fi
131     if test "x${PYQTDIR}" != "x" ; then
132         TEST_LIB_DIRS="${TEST_LIB_DIRS} ${PYQTDIR} ${PYQTDIR}/lib ${PYQTDIR}/PyQt4"
133         TEST_LIB_DIRS="${TEST_LIB_DIRS} ${PYQTDIR}/lib${LIB_LOCATION_SUFFIX}/python${PYTHON_VERSION}/site-packages"
134         TEST_LIB_DIRS="${TEST_LIB_DIRS} ${PYQTDIR}/lib${LIB_LOCATION_SUFFIX}/python${PYTHON_VERSION}/site-packages/PyQt4"
135         TEST_SIPS_DIRS="${TEST_SIPS_DIRS} ${PYQTDIR} ${PYQTDIR}/sip"
136         TEST_SIPS_DIRS="${TEST_SIPS_DIRS} ${PYQTDIR}/share ${PYQTDIR}/share/sip"
137     fi
138     if test "x${SIPDIR}" != "x" ; then
139         TEST_LIB_DIRS="${TEST_LIB_DIRS} ${SIPDIR} ${SIPDIR}/lib ${SIPDIR}/PyQt4"
140         TEST_LIB_DIRS="${TEST_LIB_DIRS} ${SIPDIR}/lib${LIB_LOCATION_SUFFIX}/python${PYTHON_VERSION}/site-packages"
141         TEST_LIB_DIRS="${TEST_LIB_DIRS} ${SIPDIR}/lib${LIB_LOCATION_SUFFIX}/python${PYTHON_VERSION}/site-packages/PyQt4"
142         TEST_SIPS_DIRS="${TEST_SIPS_DIRS} ${SIPDIR} ${SIPDIR}/sip"
143         TEST_SIPS_DIRS="${TEST_SIPS_DIRS} ${SIPDIR}/share ${SIPDIR}/share/sip ${SIPDIR}/share/sip/PyQt4"
144     fi
145     if test "x${PYTHONHOME}" != "x" ; then
146         TEST_LIB_DIRS="${TEST_LIB_DIRS} ${PYTHONHOME}/lib${LIB_LOCATION_SUFFIX}/python${PYTHON_VERSION}/site-packages"
147         TEST_LIB_DIRS="${TEST_LIB_DIRS} ${PYTHONHOME}/lib${LIB_LOCATION_SUFFIX}/python${PYTHON_VERSION}/site-packages/PyQt4"
148     fi
149     TEST_LIB_DIRS="${TEST_LIB_DIRS} /usr/lib${LIB_LOCATION_SUFFIX} /usr/lib${LIB_LOCATION_SUFFIX}/python${PYTHON_VERSION}/site-packages"
150     TEST_LIB_DIRS="${TEST_LIB_DIRS} /usr/lib${LIB_LOCATION_SUFFIX}/python${PYTHON_VERSION}/site-packages/PyQt4"
151     TEST_SIPS_DIRS="${TEST_SIPS_DIRS} /usr/share/sip"
152     TEST_SIPS_DIRS="${TEST_SIPS_DIRS} /usr/share/sip/PyQt4"
153
154     dnl check PyQt libs
155     pyqt_ok=no
156     for d in ${TEST_LIB_DIRS} ; do
157         if test -d $d ; then
158             AC_CHECK_FILE(${d}/${TESTLIBFILE},pyqt_ok=yes,pyqt_ok=no)
159             if test "x$pyqt_ok" == "xyes" ; then
160                 if test "x${d}" = "x/usr/lib${LIB_LOCATION_SUFFIX}" ; then
161                     PYQT_LIBS=""
162                 else
163                     PYQT_LIBS="-L${d}"
164                 fi
165                 break
166             fi
167         fi
168     done
169
170     dnl check PyQt sips
171     if test "x$pyqt_ok" == "xyes" ; then
172         pyqt_ok=no
173         for d in ${TEST_SIPS_DIRS} ; do
174             if test -d $d ; then
175                 AC_CHECK_FILE(${d}/${TESTSIPFILE},pyqt_ok=yes,pyqt_ok=no)
176                 if test "x$pyqt_ok" == "xyes" ; then
177                     PYQT_SIPS=${d}
178                     PYQT_INCLUDES="-I ${d}"
179                     PYQT_INCLUDES="${PYQT_INCLUDES} -I ${d}/QtCore -I ${d}/QtGui"
180                     PYQT_INCLUDES="${PYQT_INCLUDES} -I ${d}/QtXml -I ${d}/QtOpenGL"
181                     PYQT_INCLUDES="${PYQT_INCLUDES} -I ${d}/QtAssistant -I ${d}/QtDesigner"
182                     PYQT_INCLUDES="${PYQT_INCLUDES} -I ${d}/QtNetwork -I ${d}/QtSql"
183                     PYQT_INCLUDES="${PYQT_INCLUDES} -I ${d}/QtSvg -I ${d}/QtTest"
184
185                     # check compatibility with Qt
186                     SUPPORTED=`grep -e "[[[:space:]]]*Qt_[[[:digit:]_]]\+}" ${PYQT_SIPS}/QtCore/QtCoremod.sip | sed -e "s/\(.*\)[[[:space:]]]*\(Qt_[[[:digit:]_]]\+\)}/\2/g"`
187                     SUPPORTED=`echo $SUPPORTED | sed -e "s/Qt_//g" -e "s/_/./g"`
188                     SUPPORTED_ID=`echo $SUPPORTED | awk -F. '{v=$[1]*10000+$[2]*100+$[3];print v}'`
189                     if test $SUPPORTED_ID -lt $QT_VERSION_ID ; then 
190                         AC_MSG_RESULT(Warning! Used Qt version ($QT_VERSION) is not supported by PyQt)
191                         AC_MSG_RESULT(Latest supported Qt version is ${SUPPORTED})
192                     else
193                         SUPPORTED=${QT_VERSION}
194                     fi
195                     SUPPORTED="Qt_`echo ${SUPPORTED} | sed -e 's/\./_/g'`"
196                     PYQT_SIPFLAGS="-x VendorID -x PyQt_NoPrintRangeBug -t WS_X11 -t ${SUPPORTED} -g -s ".cc" -c . ${PYQT_INCLUDES}"
197                     break
198                 fi
199             fi
200         done
201     fi
202 fi
203
204 AC_SUBST(PYQT_INCLUDES)
205 AC_SUBST(PYQT_LIBS)
206 AC_SUBST(PYQT_SIPS)
207 AC_SUBST(PYUIC)
208 AC_SUBST(PYQT_SIPFLAGS)
209
210 dnl AC_LANG_RESTORE
211
212 AC_MSG_RESULT(for pyqt: $pyqt_ok)
213
214 ])dnl
215 dnl
216
217