]> SALOME platform Git repositories - tools/hxx2salome.git/blob - config_files/check_qt.m4
Salome HOME
Rename Engines::Component to Engines::EngineComponent
[tools/hxx2salome.git] / config_files / check_qt.m4
1 dnl  Copyright (C) 2007-2010  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 dnl  OPTIONS_QT
23 dnl  ------------------------------------------------------------------------
24 dnl  Adds the --with-qt=path
25 dnl
26 AC_DEFUN([OPTIONS_QT], [
27   AC_ARG_WITH([qt],
28               [AC_HELP_STRING([--with-qt], [Possible usage:
29                                              "Qt_Install_Path" - prefix to path where Qt was installd;
30                                              "" or "yes" or "auto" - means seaching installed Qt product in the system (checking $QTDIR and then - standard system paths );
31                                              "no" - not use Qt product (is not supported)
32                                             By default "" option is used)])],
33               [with_qt=$withval], [with_qt=""])
34 ])
35
36 AC_DEFUN([CHECK_QT],[
37 AC_REQUIRE([AC_PROG_CC])dnl
38 AC_REQUIRE([AC_PROG_CXX])dnl
39 AC_REQUIRE([AC_PROG_CPP])dnl
40 AC_REQUIRE([AC_PROG_CXXCPP])dnl
41 AC_REQUIRE([CHECK_OPENGL])dnl
42 AC_REQUIRE([AC_LINKER_OPTIONS])dnl
43
44 AC_REQUIRE([OPTIONS_QT])dnl
45
46 AC_CHECKING(for Qt)
47
48 if test "x$OpenGL_ok" != "xyes" ; then
49    AC_MSG_WARN(Qt needs OpenGL correct configuration, check configure output)
50 fi
51
52 qt_ok=yes
53
54 QTDIR=$(echo $QTDIR | sed 's%[/]\+$%%')
55
56 AC_LANG_SAVE
57 AC_LANG_CPLUSPLUS
58
59 dnl QT install dir
60 if test -z $with_qt ; then
61   with_qt=""
62 fi
63 if test "x$with_qt" = "xyes" ; then
64   dnl in case user wrote --with-qt=yes
65   with_qt=""
66 fi
67 if test "x$with_qt" = "xauto" ; then
68   dnl in case user wrote --with-qt=auto
69   with_qt=""
70 fi
71 if test "x$with_qt" = "xno" ; then
72   dnl in case user wrote --with-qt=no
73   with_qt=""
74   AC_MSG_WARN(Value no, specified for option --with-qt, is not supported)
75 fi
76
77 if test "x$with_qt" != "x" ; then
78   dnl Using "--with-qt" prefix path
79   QTDIR="$with_qt"
80 elif test "$QTDIR" = "/usr/lib/qt3" ; then
81   dnl Using QTDIR environment variable
82   AC_MSG_RESULT(current QTDIR is $QTDIR)
83   dnl 
84   if test -d /usr/lib/qt4 ; then
85     AC_MSG_RESULT(it is strange for a qt4 installation !)
86     AC_MSG_RESULT(/usr/lib/qt4 is present)
87     AC_MSG_RESULT(replacing QTDIR by /usr/lib/qt4)
88     QTDIR=/usr/lib/qt4
89   fi
90 elif test -z $QTDIR ; then
91   AC_MSG_WARN(undefined QTDIR variable which specify where Qt product was installed)
92   for d in /usr/local/lib/qt4 /usr/lib/qt4 /usr ; do
93     if test -f ${d}/lib/libQtCore.so ; then
94       AC_MSG_RESULT(trying ${d})
95       QTDIR="${d}"
96       break
97     elif test -f ${d}/lib64/libQtCore.so ; then
98       AC_MSG_RESULT(trying ${d})
99       QTDIR="${d}"
100       break
101     elif test -f ${d}/libQtCore.so ; then
102       AC_MSG_RESULT(trying ${d})
103       QTDIR="${d}"
104       break
105     fi
106   done
107 fi
108
109 #
110 # check QTDIR environment variable
111 #
112 if test "x$QTDIR" = "x"
113 then
114    AC_MSG_RESULT(Please define correct path in "--with-qt" option or use correct $QTDIR variable)
115    qt_ok=no
116 fi
117
118 #
119 # check Qt version
120 #
121 if  test "x$qt_ok" = "xyes"
122 then
123    qt_inc_ok=no
124    QTINC=""
125    AC_CHECK_FILE(${QTDIR}/include/qt4/QtCore/qglobal.h,QTINC="/qt4",QTINC="")
126    if test "x$QTINC" = "x"
127    then
128      AC_CHECK_FILE(${QTDIR}/include${QTINC}/QtCore/qglobal.h,qt_inc_ok=yes,qt_inc_ok=no)
129    else
130      qt_inc_ok=yes
131    fi
132    if test "x$qt_inc_ok" = "xyes"
133    then
134      AC_MSG_CHECKING(whether Qt version >= 4.0)
135      QT_VERSION=`grep "QT_VERSION_STR" ${QTDIR}/include${QTINC}/QtCore/qglobal.h | sed -e 's%^#define QT_VERSION_STR[[:space:]]*\"\([[:digit:]\.]*\)\"%\1%g'`
136      QT_VERSION_ID=`echo $QT_VERSION | awk -F. '{v=$[1]*10000+$[2]*100+$[3];print v}'`
137      if test $QT_VERSION_ID -ge 40000
138      then
139        AC_MSG_RESULT(yes)
140      else
141        AC_MSG_RESULT(no)
142        qt_ok=no
143      fi
144      AC_MSG_CHECKING(Qt version)
145      AC_MSG_RESULT($QT_VERSION)
146    else
147      qt_ok=no
148    fi
149 fi
150
151 #
152 # check moc presence (meta-object compiler)
153 #
154 if  test "x$qt_ok" = "xyes"
155 then
156   if test -f ${QTDIR}/bin/moc
157   then
158     MOC=${QTDIR}/bin/moc
159   else
160     AC_PATH_PROG(MOC, moc)
161   fi
162   if test "x$MOC" = "x"
163   then
164     qt_ok=no
165     AC_MSG_RESULT(moc (Qt meta-object compiler) is not in the PATH variable)
166   else
167     qt_ok=yes
168     AC_MSG_RESULT(moc (Qt meta-object compiler) is found)
169   fi
170
171   if test "x$qt_ok" = "xyes"
172   then
173     dnl check moc version
174     AC_MSG_CHECKING(cheching equality Qt and moc tool version)
175     MOC_VERSION=`$MOC -v 2>&1 | awk 'BEGIN{FS="[[ ()]]"};{print $(NF-1)}'`
176     if test "x$QT_VERSION" = "x$MOC_VERSION"
177     then
178       AC_MSG_RESULT(yes)
179       qt_ok=yes
180     else
181       AC_MSG_RESULT(moc tool and Qt product are incompatible $MOC_VERSION)
182       qt_ok=no
183     fi
184   fi
185 fi
186
187 #
188 # check uic presence (user interface compiler)
189 #
190 if  test "x$qt_ok" = "xyes"
191 then
192   if test -f ${QTDIR}/bin/uic
193   then
194     UIC=${QTDIR}/bin/uic
195   else
196     AC_PATH_PROG(UIC, uic)
197   fi
198   if test "x$UIC" = "x"
199   then
200     qt_ok=no
201     AC_MSG_RESULT(uic (Qt user interface compiler) is not in the PATH variable)
202   else
203     qt_ok=yes
204     AC_MSG_RESULT(uic (Qt user interface compiler) is found)
205   fi
206 fi
207
208 #
209 # check rcc presence (resources compiler)
210 #
211 if  test "x$qt_ok" = "xyes"
212 then
213   if test -f ${QTDIR}/bin/rcc
214   then
215     QRCC=${QTDIR}/bin/rcc
216   else
217     AC_PATH_PROG(QRCC, rcc)
218   fi
219   if test "x$QRCC" = "x"
220   then
221     qt_ok=no
222     AC_MSG_RESULT(rcc (Qt resources compiler) is not in the PATH variable)
223   else
224     qt_ok=yes
225     AC_MSG_RESULT(rcc (Qt resources compiler) is found)
226   fi
227
228   if test "x$qt_ok" = "xyes"
229   then
230     dnl check rcc version
231     AC_MSG_CHECKING(cheching equality Qt and rcc tool version)
232     QRCC_VERSION=`$QRCC -v 2>&1 | awk '{print $NF}'`
233     if test "x$QT_VERSION" = "x$QRCC_VERSION"
234     then
235       AC_MSG_RESULT(yes)
236       qt_ok=yes
237     else
238       AC_MSG_RESULT(rcc tool and Qt product are incompatible)
239       qt_ok=no
240     fi
241   fi
242 fi
243
244 #
245 # check lrelease presence (translation files compiler)
246 #
247 if  test "x$qt_ok" = "xyes"
248 then
249   if test -f ${QTDIR}/bin/lrelease
250   then
251     LRELEASE=${QTDIR}/bin/lrelease
252   else
253     AC_PATH_PROG(LRELEASE, lrelease)
254   fi
255   if test "x$LRELEASE" = "x"
256   then
257     qt_ok=no
258     AC_MSG_RESULT(lrelease (Qt translation files compiler) is not in the PATH variable)
259   else
260     qt_ok=yes
261     AC_MSG_RESULT(lrelease (Qt translation files compiler) is found)
262   fi
263   
264   if test "x$qt_ok" = "xyes"
265   then
266     dnl check lrelease version
267     AC_MSG_CHECKING( equality of Qt and lrelease tool version)
268     LRELEASE_VERSION=`$LRELEASE -version 2>&1 | awk '{print $NF}'`
269     if test "x$QT_VERSION" = "x$LRELEASE_VERSION"
270     then
271       AC_MSG_RESULT(yes)
272       qt_ok=yes
273     else
274       AC_MSG_RESULT(lrelease tool and Qt product are incompatible)
275       qt_ok=no
276     fi
277   fi
278 fi
279
280 QT_ROOT=$QTDIR
281
282 #
283 # check Qt header files
284 #
285 if  test "x$qt_ok" = "xyes"
286 then
287   AC_CHECKING(include Qt header files)
288
289   CPPFLAGS_old=$CPPFLAGS
290   CPPFLAGS="$CPPFLAGS -I${QTDIR}/include${QTINC} -I${QTDIR}/include${QTINC}/QtCore"
291   AC_CHECK_HEADER(QObject,qt_ok=yes,qt_ok=no)
292   CPPFLAGS=$CPPFLAGS_old
293
294   if  test "x$qt_ok" = "xno"
295   then
296     AC_MSG_RESULT(qt header files are not found in $QTDIR/include${QTINC}/QtCore)
297     AC_MSG_RESULT(QTDIR environment variable may be wrong (probably too old Qt version))
298   else
299     AC_MSG_RESULT(qt header files seem to be OK)
300     QT_INCLUDES="-I${QTDIR}/include${QTINC}"
301     # user header files
302     QT_INCLUDES="${QT_INCLUDES} -I${QTDIR}/include${QTINC}/QtCore"
303     QT_INCLUDES="${QT_INCLUDES} -I${QTDIR}/include${QTINC}/QtGui"
304     QT_INCLUDES="${QT_INCLUDES} -I${QTDIR}/include${QTINC}/QtOpenGL"
305     QT_INCLUDES="${QT_INCLUDES} -I${QTDIR}/include${QTINC}/QtXml"
306     # not used currently header files (uncomment if required)
307     #QT_INCLUDES="${QT_INCLUDES} -I$(QTDIR)/include${QTINC}/QtAssistant"
308     #QT_INCLUDES="${QT_INCLUDES} -I$(QTDIR)/include${QTINC}/QtDBus"
309     #QT_INCLUDES="${QT_INCLUDES} -I$(QTDIR)/include${QTINC}/QtDesigner"
310     #QT_INCLUDES="${QT_INCLUDES} -I$(QTDIR)/include${QTINC}/QtNetwork"
311     #QT_INCLUDES="${QT_INCLUDES} -I$(QTDIR)/include${QTINC}/QtSql"
312     #QT_INCLUDES="${QT_INCLUDES} -I$(QTDIR)/include${QTINC}/QtSvg"
313     #QT_INCLUDES="${QT_INCLUDES} -I$(QTDIR)/include${QTINC}/QtTest"
314     #QT_INCLUDES="${QT_INCLUDES} -I$(QTDIR)/include${QTINC}/QtUiTools"
315
316     QT_ASSISTANT_INCLUDES="${QT_ASSISTANT_INCLUDES} -I${QTDIR}/include${QTINC}/QtAssistant"
317     QT_ASSISTANT_INCLUDES="${QT_ASSISTANT_INCLUDES} -I${QTDIR}/include${QTINC}/QtNetwork"
318
319     # this flag is obsolete with Qt 4
320     QT_MT_INCLUDES="$QT_INCLUDES"
321   fi
322 fi
323
324 #
325 # test Qt libraries
326 #
327 if  test "x$qt_ok" = "xyes"
328 then
329   AC_MSG_CHECKING(linking against Qt library)
330
331   CXXFLAGS_old=$CXXFLAGS
332   CXXFLAGS="$CXXFLAGS $QT_INCLUDES"
333
334   LIBS_old=$LIBS
335   if test "x$QTDIR" = "x/usr" ; then
336     QT_LIB_DIR=""
337   elif test -d ${QTDIR}/lib; then
338     QT_LIB_DIR="-L$QTDIR/lib"
339   elif test -d ${QTDIR}/lib64; then
340     QT_LIB_DIR="-L$QTDIR/lib64"
341   elif test "x$QTDIR" = "x/usr/lib/qt4" ; then
342     QT_LIB_DIR=""
343   else
344     AC_MSG_ERROR(Can't detect of Qt library directory )
345     qt_ok=no
346   fi
347   LIBS="$LIBS $QT_LIB_DIR -lQtCore"
348
349   AC_CACHE_VAL(salome_cv_lib_qt,[
350     AC_TRY_LINK(
351 #include <QCoreApplication>
352 ,   int n;
353     char **s;
354     QCoreApplication a(n, s);
355     a.exec();,
356     eval "salome_cv_lib_qt=yes",eval "salome_cv_lib_qt=no")
357   ])
358   qt_ok="$salome_cv_lib_qt"
359
360   # BEGIN: for CCRT (installation of qt have only a "lib" directory)
361   if  test "x$qt_ok" = "xno"
362   then
363     QT_LIB_DIR="-L$QTDIR/lib"
364     LIBS="$LIBS_old $QT_LIB_DIR -lQtCore"
365
366     AC_CACHE_VAL(salome_cv_lib_qt,[
367       AC_TRY_LINK(
368 #include <QCoreApplication>
369 ,     int n;
370       char **s;
371       QCoreApplication a(n, s);
372       a.exec();,
373       eval "salome_cv_lib_qt=yes",eval "salome_cv_lib_qt=no")
374     ])
375     qt_ok="$salome_cv_lib_qt"
376   fi
377   # END: for CCRT
378
379   if  test "x$qt_ok" = "xno"
380   then
381     AC_MSG_RESULT(no)
382     AC_MSG_RESULT(unable to link with qt library)
383     AC_MSG_RESULT(QTDIR environment variable may be wrong (probably too old Qt version))
384   else
385     AC_MSG_RESULT(yes)
386     # core libs
387     QT_CORE_LIBS="$QT_LIB_DIR -lQtCore -lQtXml"
388     # gui libs
389     QT_GUI_LIBS="$QT_LIB_DIR -lQtGui -lQtOpenGL"
390     # other libs (currently not used)
391     QT_OTHER_LIBS="$QT_LIB_DIR"
392     # other libs (can be used if necessary)
393     #QT_OTHER_LIBS="$QT_LIB_DIR -lQt3Support -lQtAssistantClient -lQtDesigner -lQtNetwork -lQtSql -lQtSvg -lQtTest -ltQtUiTools"
394     QT_ASSISTANT_LIBS="$QT_LIB_DIR -lQtAssistantClient -lQtNetwork"
395     # all libs
396     QT_LIBS="$QT_CORE_LIBS $QT_GUI_LIBS $QT_OTHER_LIBS"
397     # this flag is obsolete with Qt 4
398     QT_MT_LIBS="$QT_LIBS"
399   fi
400   LIBS=$LIBS_old
401   CXXFLAGS=$CXXFLAGS_old
402 fi
403
404 AC_SUBST(QTDIR)
405 AC_SUBST(MOC)
406 AC_SUBST(UIC)
407 AC_SUBST(QRCC)
408 AC_SUBST(LRELEASE)
409
410 AC_SUBST(QT_ROOT)
411 AC_SUBST(QT_INCLUDES)
412 AC_SUBST(QT_MT_INCLUDES)
413 AC_SUBST(QT_ASSISTANT_INCLUDES)
414 AC_SUBST(QT_LIB_DIR)
415 AC_SUBST(QT_CORE_LIBS)
416 AC_SUBST(QT_GUI_LIBS)
417 AC_SUBST(QT_OTHER_LIBS)
418 AC_SUBST(QT_LIBS)
419 AC_SUBST(QT_MT_LIBS)
420 AC_SUBST(QT_ASSISTANT_LIBS)
421 AC_SUBST(QT_VERSION)
422 AC_SUBST(QT_VERSION_ID)
423
424 AC_LANG_RESTORE
425
426 AC_MSG_RESULT(for Qt: $qt_ok)
427
428 # Save cache
429 AC_CACHE_SAVE
430
431 ])dnl
432 dnl