Salome HOME
96257bda2c90328f87a31addc517e0544ca6dffb
[modules/gui.git] / adm_local / unix / config_files / check_pyqt.m4
1 dnl Copyright (C) 2007-2023  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, or (at your option) any later version.
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
23 AC_DEFUN([CHECK_PYQT],[
24 AC_REQUIRE([CHECK_PYTHON])dnl
25 AC_REQUIRE([CHECK_QT])dnl
26 AC_REQUIRE([CHECK_SIP])dnl
27 AC_REQUIRE([AC_LINKER_OPTIONS])dnl
28
29 dnl AC_LANG_SAVE
30 dnl AC_LANG_CPLUSPLUS
31
32 AC_ARG_WITH(pyqt,
33     [  --with-pyqt=DIR      root directory path to PyQt installation ],
34     [PYQTDIR="$withval"
35       AC_MSG_RESULT([Try $withval as path to the PyQt])
36     ])
37
38 AC_ARG_WITH(pyqt_sips,
39     [  --with-pyqt_sips=DIR      a directory path to PyQt sips installation ],
40     [PYQT_SIPS="$withval"
41       AC_MSG_RESULT([Try $withval as path to the PyQt sip files])
42     ])
43
44 AC_ARG_WITH(pyuic4,
45     [  --with-pyuic4=EXEC pyuic4 executable ],
46     [PYUIC="$withval"
47       AC_MSG_RESULT([Try $withval as pyuic4 executable])
48     ])
49
50 AC_ARG_WITH(pyrcc4,
51     [  --with-pyrcc4=EXEC pyrcc4 executable ],
52     [PYRCC="$withval"
53       AC_MSG_RESULT([Try $withval as pyrcc4 executable])
54     ])
55
56 AC_CHECKING(for pyqt)
57
58 pyqt_ok=no
59
60 TEST_BIN_DIRS=""
61 if test "x${PYQTDIR}" != "x" ; then
62     TEST_BIN_DIRS="${TEST_BIN_DIRS} ${PYQTDIR} ${PYQTDIR}/bin"
63 fi
64 TEST_BIN_DIRS="${TEST_BIN_DIRS} __CHECK__PATH__"
65 if test "x${SIPDIR}" != "x" ; then
66     TEST_BIN_DIRS="${TEST_BIN_DIRS} ${SIPDIR} ${SIPDIR}/bin"
67 fi
68 if test "x${PYTHONHOME}" != "x" ; then
69     TEST_BIN_DIRS="${TEST_BIN_DIRS} ${PYTHONHOME}/bin"
70 fi
71 TEST_BIN_DIRS="${TEST_BIN_DIRS} /usr/bin"
72
73 dnl check pyuic4
74 if test "x$PYUIC" != "x" ; then
75     dnl try $withval value
76     AC_CHECK_FILE($PYUIC,pyqt_ok=yes,pyqt_ok=no)
77 else
78     dnl search pyuic4
79     pyqt_ok=no
80     for d in ${TEST_BIN_DIRS} ; do
81         if test "x${d}" = "x__CHECK__PATH__" ; then
82             AC_PATH_PROG(TEMP, pyuic4)
83             if test "x${TEMP}" != "x" ; then
84                 PYUIC=${TEMP}
85                 if test "x$PYQTDIR" = "x" ; then
86                     PYQTDIR=`dirname ${PYUIC}`
87                     PYQTDIR=`dirname ${PYQTDIR}`
88                 fi
89                 pyqt_ok=yes
90                 break
91             fi
92         else
93             if test -d $d ; then
94                 AC_CHECK_FILE(${d}/pyuic4,pyqt_ok=yes,pyqt_ok=no)
95                 if test "x$pyqt_ok" == "xyes" ; then
96                     PYUIC=${d}/pyuic4
97                     break
98                 fi
99             fi
100         fi
101     done
102 fi
103
104 dnl check PyQt version
105 if test "x$pyqt_ok" == "xyes" ; then
106     AC_MSG_CHECKING(whether PyQt version >= 4.2)
107     PYQT_VERSION=`${PYUIC} --version 2>&1 | grep "Python User Interface Compiler"`
108     if test "$?" != "0" ; then
109         PYQT_VERSION=`${PYUIC} -version 2>&1 | grep "Python User Interface Compiler"`
110     fi
111     if test "x${PYQT_VERSION}" != "x" ; then
112         PYQT_VERSION=`echo $PYQT_VERSION | sed -e 's%[[[:alpha:][:space:]]]*\([[[:digit:].]]*\).*%\1%g'`
113         PYQT_VERSION_ID=`echo $PYQT_VERSION | awk -F. '{v=$[1]*10000+$[2]*100+$[3];print v}'`
114     else
115         PYQT_VERSION="<unknown>"
116         PYQT_VERSION_ID=0
117     fi
118     if test $PYQT_VERSION_ID -ge 40200 ; then 
119         AC_MSG_RESULT(yes)
120         AC_MSG_RESULT(PyQt version is $PYQT_VERSION)
121     else
122         AC_MSG_RESULT(no)
123         AC_MSG_RESULT(WARNING! PyQt version $PYQT_VERSION is not supported (at least 4.2 is required)!)
124         pyqt_ok=no
125     fi
126 else
127     AC_MSG_RESULT(Warning! pyuic4 is not found!)
128 fi
129
130 dnl check pyrcc4
131 if test "x$PYRCC" != "x" ; then
132     dnl try $withval value
133     AC_CHECK_FILE($PYRCC,pyqt_ok=yes,pyqt_ok=no)
134 else
135     dnl search pyrcc4
136     pyqt_ok=no
137     for d in ${TEST_BIN_DIRS} ; do
138         if test "x${d}" = "x__CHECK__PATH__" ; then
139             AC_PATH_PROG(TEMP, pyrcc4)
140             if test "x${TEMP}" != "x" ; then
141                 PYRCC=${TEMP}
142                 if test "x$PYQTDIR" = "x" ; then
143                     PYQTDIR=`dirname ${PYRCC}`
144                     PYQTDIR=`dirname ${PYQTDIR}`
145                 fi
146                 pyqt_ok=yes
147                 break
148             fi
149         else
150             if test -d $d ; then
151                 AC_CHECK_FILE(${d}/pyrcc4,pyqt_ok=yes,pyqt_ok=no)
152                 if test "x$pyqt_ok" == "xyes" ; then
153                     PYRCC=${d}/pyrcc4
154                     break
155                 fi
156             fi
157         fi
158     done
159 fi
160
161 if test "x$pyqt_ok" == "xyes" ; then
162     TESTLIBFILE=QtCore.so
163     TESTSIPFILE=QtCore/QtCoremod.sip
164     TEST_LIB_DIRS=""
165     TEST_SIPS_DIRS=""
166     if test "x${PYQT_SIPS}" != "x" ; then
167         TEST_SIPS_DIRS="${TEST_SIPS_DIRS} ${PYQT_SIPS}"
168     fi
169     if test "x${PYQTDIR}" != "x" ; then
170         TEST_LIB_DIRS="${TEST_LIB_DIRS} ${PYQTDIR} ${PYQTDIR}/lib ${PYQTDIR}/PyQt4"
171         TEST_LIB_DIRS="${TEST_LIB_DIRS} ${PYQTDIR}/lib${LIB_LOCATION_SUFFIX}/python${PYTHON_VERSION}/site-packages"
172         TEST_LIB_DIRS="${TEST_LIB_DIRS} ${PYQTDIR}/lib${LIB_LOCATION_SUFFIX}/python${PYTHON_VERSION}/site-packages/PyQt4"
173         TEST_SIPS_DIRS="${TEST_SIPS_DIRS} ${PYQTDIR} ${PYQTDIR}/sip"
174         TEST_SIPS_DIRS="${TEST_SIPS_DIRS} ${PYQTDIR}/share ${PYQTDIR}/share/sip"
175     fi
176     if test "x${SIPDIR}" != "x" ; then
177         TEST_LIB_DIRS="${TEST_LIB_DIRS} ${SIPDIR} ${SIPDIR}/lib ${SIPDIR}/PyQt4"
178         TEST_LIB_DIRS="${TEST_LIB_DIRS} ${SIPDIR}/lib${LIB_LOCATION_SUFFIX}/python${PYTHON_VERSION}/site-packages"
179         TEST_LIB_DIRS="${TEST_LIB_DIRS} ${SIPDIR}/lib${LIB_LOCATION_SUFFIX}/python${PYTHON_VERSION}/site-packages/PyQt4"
180         TEST_SIPS_DIRS="${TEST_SIPS_DIRS} ${SIPDIR} ${SIPDIR}/sip"
181         TEST_SIPS_DIRS="${TEST_SIPS_DIRS} ${SIPDIR}/share ${SIPDIR}/share/sip ${SIPDIR}/share/sip/PyQt4"
182     fi
183     if test "x${PYTHONHOME}" != "x" ; then
184         TEST_LIB_DIRS="${TEST_LIB_DIRS} ${PYTHONHOME}/lib${LIB_LOCATION_SUFFIX}/python${PYTHON_VERSION}/site-packages"
185         TEST_LIB_DIRS="${TEST_LIB_DIRS} ${PYTHONHOME}/lib${LIB_LOCATION_SUFFIX}/python${PYTHON_VERSION}/site-packages/PyQt4"
186     fi
187     TEST_LIB_DIRS="${TEST_LIB_DIRS} /usr/lib${LIB_LOCATION_SUFFIX} /usr/lib${LIB_LOCATION_SUFFIX}/python${PYTHON_VERSION}/site-packages"
188     TEST_LIB_DIRS="${TEST_LIB_DIRS} /usr/lib${LIB_LOCATION_SUFFIX}/python${PYTHON_VERSION}/site-packages/PyQt4"
189     TEST_LIB_DIRS="${TEST_LIB_DIRS} /usr/lib${LIB_LOCATION_SUFFIX}/python${PYTHON_VERSION}/dist-packages/PyQt4"
190     TEST_LIB_DIRS="${TEST_LIB_DIRS} /usr/lib${LIB_LOCATION_SUFFIX}/pymodules/python${PYTHON_VERSION}/PyQt4"
191     if test "${build_cpu::6}" = "x86_64" ; then
192       TEST_LIB_DIRS="${TEST_LIB_DIRS} /usr/lib64/python2.6/site-packages/PyQt4"
193     fi
194     TEST_SIPS_DIRS="${TEST_SIPS_DIRS} /usr/share/sip"
195     TEST_SIPS_DIRS="${TEST_SIPS_DIRS} /usr/share/sip/PyQt4"
196
197     dnl check PyQt libs
198     pyqt_ok=no
199     for d in ${TEST_LIB_DIRS} ; do
200         if test -d $d ; then
201             AC_CHECK_FILE(${d}/${TESTLIBFILE},pyqt_ok=yes,pyqt_ok=no)
202             if test "x$pyqt_ok" == "xyes" ; then
203                 if test "x${d}" = "x/usr/lib${LIB_LOCATION_SUFFIX}" ; then
204                     PYQT_LIBS=""
205                 else
206                     PYQT_LIBS="-L${d}"
207                 fi
208                 break
209             fi
210         fi
211     done
212
213     dnl check PyQt sips
214     if test "x$pyqt_ok" == "xyes" ; then
215         pyqt_ok=no
216         for d in ${TEST_SIPS_DIRS} ; do
217             if test -d $d ; then
218                 AC_CHECK_FILE(${d}/${TESTSIPFILE},pyqt_ok=yes,pyqt_ok=no)
219                 if test "x$pyqt_ok" == "xyes" ; then
220                     PYQT_SIPS=${d}
221                     PYQT_INCLUDES="-I ${d}"
222                     PYQT_INCLUDES="${PYQT_INCLUDES} -I ${d}/QtCore -I ${d}/QtGui"
223                     PYQT_INCLUDES="${PYQT_INCLUDES} -I ${d}/QtXml -I ${d}/QtOpenGL"
224                     PYQT_INCLUDES="${PYQT_INCLUDES} -I ${d}/QtAssistant -I ${d}/QtDesigner"
225                     PYQT_INCLUDES="${PYQT_INCLUDES} -I ${d}/QtNetwork -I ${d}/QtSql"
226                     PYQT_INCLUDES="${PYQT_INCLUDES} -I ${d}/QtSvg -I ${d}/QtTest"
227
228                     # check compatibility with Qt
229                     #SUPPORTED=`grep -e "[[[:space:]]]*Qt_[[[:digit:]_]]\+}" ${PYQT_SIPS}/QtCore/QtCoremod.sip | sed -e "s/\(.*\)[[[:space:]]]*\(Qt_[[[:digit:]_]]\+\)}/\2/g"`
230                     #SUPPORTED=`echo $SUPPORTED | sed -e "s/Qt_//g" -e "s/_/./g"`
231                     #SUPPORTED_ID=`echo $SUPPORTED | awk -F. '{v=$[1]*10000+$[2]*100+$[3];print v}'`
232                     #if test $SUPPORTED_ID -lt $QT_VERSION_ID ; then 
233                     #    AC_MSG_RESULT(Warning! Used Qt version ($QT_VERSION) is not supported by PyQt)
234                     #    AC_MSG_RESULT(Latest supported Qt version is ${SUPPORTED})
235                     #else
236                     #    SUPPORTED=${QT_VERSION}
237                     #fi
238                     #SUPPORTED="Qt_`echo ${SUPPORTED} | sed -e 's/\./_/g'`"
239                     PYQT_SIPFLAGS=`python -c "from PyQt4 import pyqtconfig; print(pyqtconfig.Configuration().pyqt_sip_flags)"`
240                     PYQT_SIPFLAGS="${PYQT_SIPFLAGS} -s .cc -c . ${PYQT_INCLUDES}"
241                     break
242                 fi
243             fi
244         done
245     fi
246 fi
247
248 AC_SUBST(PYQT_INCLUDES)
249 AC_SUBST(PYQT_LIBS)
250 AC_SUBST(PYQT_SIPS)
251 AC_SUBST(PYUIC)
252 AC_SUBST(PYRCC)
253 AC_SUBST(PYQT_SIPFLAGS)
254
255 dnl AC_LANG_RESTORE
256
257 AC_MSG_RESULT(for pyqt: $pyqt_ok)
258
259 ])dnl
260 dnl
261