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