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