Salome HOME
Initial commit
[modules/jobmanager.git] / m4 / i2_check_qt4.m4
1 dnl  Copyright (C) 2006-2008  CEA/DEN, EDF R&D
2 dnl
3 dnl  This library is free software; you can redistribute it and/or
4 dnl  modify it under the terms of the GNU Lesser General Public
5 dnl  License as published by the Free Software Foundation; either
6 dnl  version 2.1 of the License.
7 dnl
8 dnl  This library is distributed in the hope that it will be useful,
9 dnl  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 dnl  Lesser General Public License for more details.
12 dnl
13 dnl  You should have received a copy of the GNU Lesser General Public
14 dnl  License along with this library; if not, write to the Free Software
15 dnl  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 dnl
17 dnl  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 dnl
19 dnl the following variables are exported:
20 dnl  QT_MOC
21 dnl  QT_UIC
22 dnl  QT_DIR
23 dnl  qt4_cppflags
24 dnl  qt4_ldflags
25 dnl  qt4_libs
26 dnl  WITH_QT4
27 dnl qt4 is searched in the following order
28 dnl   path given with --with-qt4 options
29 dnl   presence of QTDIR variable
30 dnl   /usr
31 dnl usages
32 dnl ./configure --prefix=/home/prascle/partage/maquettes/install 
33 dnl ./configure --prefix=/home/prascle/partage/maquettes/install --with-qt4
34 dnl ./configure --prefix=/home/prascle/partage/maquettes/install --with-qt4=/opt/qt443
35 dnl ./configure --prefix=/home/prascle/partage/maquettes/install --with-qt4-includes=/usr/include/qt4
36 dnl ./configure --prefix=/home/prascle/partage/maquettes/install --with-qt4-includes=/usr/include/qt4 --with-qt4-libraries=/usr/lib -with-qt4-tools=/usr/bin
37 dnl ./configure --prefix=/home/prascle/partage/maquettes/install --without-qt4
38 dnl
39 AC_DEFUN([I2_CHECK_QT4],
40 [
41   AC_REQUIRE([AC_PROG_CXX])
42   AC_REQUIRE([AC_PROG_CPP])
43
44   qt_ok=no
45
46   # --- check if qt4 standard install directory is defined (with subdirectories bin lib include)
47   qt4_install_path=""
48   AC_ARG_WITH([qt4],
49     AC_HELP_STRING([--with-qt4@<:@=DIR@:>@], [where the Qt4 package with a standard install is: default @<:@$QTDIR@:>@ or @<:@/usr@:>@]),
50                  [qt4_install_path=$withval], [withval=notset])
51
52   # --- if qt4 standard install directory is defined but with no path: QTDIR value if defined, or /usr
53   if test x${withval} = xyes
54   then
55     if test -z $QTDIR
56     then
57       qt4_install_path="/usr"
58     else
59       qt4_install_path=$QTDIR
60     fi
61   fi
62
63   # --- if qt4 standard install directory is not defined: QTDIR value if defined, or /usr
64   if test x${withval} = xnotset
65   then
66     if test -z $QTDIR
67     then
68       qt4_install_path="/usr"
69     else
70       if test $QTDIR = /usr/lib/qt3 ; then
71         if test -d /usr/lib/qt4 ; then
72           AC_MSG_RESULT(it is strange for a qt4 installation !)
73           AC_MSG_RESULT(/usr/lib/qt4 is present)
74           AC_MSG_RESULT(replacing QTDIR by /usr/lib/qt4)
75           QTDIR=/usr/lib/qt4
76         fi
77       fi
78       qt4_install_path=$QTDIR
79     fi
80   fi
81   
82   # --- if qt4 standard install directory is not wanted: --without-qt4 or --with-qt4=no
83   if test x${withval} = xno
84   then
85     qt4_install_path=""
86   fi
87
88   QT_DIR=${qt4_install_path}
89   AC_SUBST(QT_DIR)
90
91   # --- check if qt4 includes directory is defined
92   qt4_include_path=""
93   AC_ARG_WITH([qt4-includes],
94     AC_HELP_STRING([--with-qt4-includes@<:@=DIR@:>@], [where the Qt4 includes are: default @<:@$QTDIR/include@:>@ or @<:@/usr/include@:>@]),
95                  [qt4_include_path=$withval], [withval=no])
96   if test x${withval} != xno
97   then
98     # --- qt4 includes directory is defined
99     if test x${qt4_include_path} = xyes
100     then
101       qt4_include_path="/usr/include"
102     fi
103   else
104     if test x${qt4_install_path} != x
105     then
106       qt4_include_path="${qt4_install_path}/include"
107     fi
108   fi
109
110
111   # --- check if qt4 libraries directory is defined
112   qt4_library_path=""
113   AC_ARG_WITH([qt4-libraries],
114     AC_HELP_STRING([--with-qt4-libraries@<:@=DIR@:>@], [where the Qt4 libraries are: default @<:@$QTDIR/lib@:>@ or @<:@/usr/lib@:>@]),
115                  [qt4_library_path=$withval], [withval=no])
116   if test x${withval} != xno
117   then
118     # --- qt4 libraries directory is defined
119     if test x${qt4_library_path} = xyes
120     then
121       qt4_library_path="/usr/lib"
122     fi
123   else
124     if test x${qt4_install_path} != x
125     then
126       qt4_library_path="${qt4_install_path}/lib"
127     fi
128   fi
129
130   # --- check if qt4 tools directory is defined
131   qt4_tools_path=""
132   AC_ARG_WITH([qt4-tools],
133     AC_HELP_STRING([--with-qt4-tools@<:@=DIR@:>@], [where the Qt4 executable tools are: default @<:@$QTDIR/bin@:>@ or @<:@/usr/bin@:>@]),
134                  [qt4_tools_path=$withval], [withval=no])
135   if test x${withval} != xno
136   then
137     # --- qt4 tools directory is defined
138     if test x${qt4_tools_path} = xyes
139     then
140       qt4_tools_path="/usr/bin"
141     fi
142   else
143     if test x${qt4_install_path} != x
144     then
145       qt4_tools_path="${qt4_install_path}/bin"
146     fi
147   fi
148
149   WITH_QT4=0
150
151   AC_MSG_NOTICE(${qt4_include_path})
152   AC_MSG_NOTICE(${qt4_library_path})
153   AC_MSG_NOTICE(${qt4_tools_path})
154
155   # test if qt4 is completely defined
156   qt4_defined=yes
157   if test x${qt4_include_path} = x
158   then
159     qt4_defined=no
160     AC_MSG_NOTICE([No Qt4 include path defined])
161   fi
162   if test x${qt4_library_path} = x
163   then
164     qt4_defined=no
165     AC_MSG_NOTICE([No Qt4 library path defined])
166   fi
167   if test x${qt4_tools_path} = x
168   then
169     qt4_defined=no
170     AC_MSG_NOTICE([No Qt4 tools path defined])
171   fi
172
173   # saving values for compilation variables
174   saved_CPPFLAGS=$CPPFLAGS
175   saved_LDFLAGS=$LDFLAGS
176   saved_LIBS=$LIBS
177
178   if ! test x${qt4_defined} = xno
179   then
180     # ask for qt4 support
181     AC_MSG_NOTICE([checking whether qt4 tools and headers are present])
182
183     # --- we test the presence of moc,first under the form moc-qt4, then moc
184     AC_PATH_PROGS(qt4_moc_found, [moc-qt4 moc], no, ${qt4_tools_path})
185     test x${qt4_moc_found} = xno && AC_MSG_ERROR([Qt4 moc command NOT FOUND])
186     QT_MOC=$qt4_moc_found
187     AC_SUBST(QT_MOC)
188
189     # --- we test the presence of uic,first under the form uic-qt4, then uic
190     AC_PATH_PROGS(qt4_uic_found, [uic-qt4 uic], no, ${qt4_tools_path})
191     test x${qt4_uic_found} = xno && AC_MSG_ERROR([Qt4 uic command NOT FOUND])
192     QT_UIC=$qt4_uic_found
193     AC_SUBST(QT_UIC)
194
195     # --- we test the presence of rcc,first under the form rcc-qt4, then rcc
196     AC_PATH_PROGS(qt4_rcc_found, [rcc-qt4 rcc], no, ${qt4_tools_path})
197     test x${qt4_rcc_found} = xno && AC_MSG_ERROR([Qt4 rcc command NOT FOUND])
198     QT_RCC=$qt4_rcc_found
199     AC_SUBST(QT_RCC)
200
201     # --- we test the header file presence and usability
202     QTINC=""
203     AC_CHECK_FILE($qt4_include_path/qt4/QtCore/qglobal.h,QTINC="/qt4",QTINC="")
204     qt4_include_path="$qt4_include_path${QTINC}"
205     qt4_cppflags=""
206     qt4_cppflags="${qt4_cppflags} -I$qt4_include_path/QtCore"
207     qt4_cppflags="${qt4_cppflags} -I$qt4_include_path/QtGui"
208     qt4_cppflags="${qt4_cppflags} -I$qt4_include_path/Qt"
209     qt4_cppflags="${qt4_cppflags} -I$qt4_include_path"
210     CPPFLAGS="${CPPFLAGS} ${qt4_cppflags}"
211     AC_LANG_PUSH(C++)
212     AC_CHECK_HEADERS([qapplication.h],
213                      [qt4_header_found=yes],
214                      [qt4_header_found=no],
215                      [])
216     AC_LANG_POP(C++)
217     test x${qt4_header_found} = xno && AC_MSG_ERROR([Qt4 include file NOT FOUND])
218     AC_SUBST(qt4_cppflags)
219
220     # --- we test the library file presence and usability
221     if test x${qt4_library_path} = /usr/lib
222     then
223       qt4_ldflags=""
224     else
225       qt4_ldflags="-L$qt4_library_path"
226     fi
227
228     AC_MSG_NOTICE([checking whether link with qt4 is working])
229     qt4_lib_name=QtGui
230     qt4_libs="-l$qt4_lib_name"
231     LDFLAGS="${LDFLAGS} ${qt4_ldflags}"
232     LIBS="${LIBS} ${qt4_libs}"
233     AC_LANG_PUSH(C++)
234
235     AC_LINK_IFELSE([AC_LANG_PROGRAM(
236     [[ #include <QApplication>
237        #include <QPushButton> ]],
238     [[ QApplication app(0, 0);
239        QPushButton hello("Hello world!");
240        hello.resize(100, 30);
241        hello.show(); ]] )],
242     [qt4_lib_found=yes], [qt4_lib_found=no] )
243
244     test x${qt4_lib_found} = xno && AC_MSG_ERROR([Qt4 library NOT FOUND])
245
246     AC_LANG_POP(C++)
247     AC_SUBST(qt4_ldflags)
248     AC_SUBST(qt4_libs)
249
250     # --- after all tests are successful, we support Qt4
251     WITH_QT4=1
252     qt_ok=yes
253     AC_MSG_NOTICE([Qt4 support is OK])
254
255   else
256     # --- no Qt4 support
257     AC_MSG_NOTICE([No Qt4 support])
258   fi
259
260   # Propagate test into atlocal
261   AC_SUBST(WITH_QT4)
262
263   # Propagate test into Makefiles...
264   AM_CONDITIONAL(WITH_QT4, test $WITH_QT4 = 1)
265
266   # ... and into source files
267   AC_DEFINE_UNQUOTED(HAS_QT4, $WITH_QT4, [Qt4 library])
268
269   # restoring saved values
270   CPPFLAGS=$saved_CPPFLAGS
271   LDFLAGS=$saved_LDFLAGS
272   LIBS=$saved_LIBS
273
274 ])
275
276
277 AC_DEFUN([I2_CHECK_QSCINTILLA],
278 [
279   AC_REQUIRE([I2_CHECK_QT4])
280
281   qscintilla_ok=no
282   WITH_QSCI4=0
283
284   # --- check if qsci4 includes directory is defined
285   qsci4_include_path=""
286   qsci4_cppflags=""
287
288   AC_ARG_WITH([qsci4-includes],
289     AC_HELP_STRING([--with-qsci4-includes@<:@=DIR@:>@], [where the Qsci4 includes are: default @<:@$QTDIR/include/Qsci@:>@ or @<:@/usr/include/Qsci@:>@]),
290               [qsci4_include_path=$withval])
291
292   if test x${qsci4_include_path} = x ; then
293     # --- "" --- try to use QSCINTILLA_DIR/include/Qsci
294     if test "x${QSCINTILLA_DIR}" != "x" ; then
295       qsci4_include_path="${QSCINTILLA_DIR}/include"
296     else
297       qsci4_include_path=no
298     fi
299   fi
300
301   if test x${qsci4_include_path} = xno ; then
302     # --- "no" --- no native installation, try to find in Qt
303     qsci4_include_path="${QT_DIR}/include${QTINC}/Qsci"
304     qsci4_cppflags=" -I$qsci4_include_path"
305     # " -I${QT_DIR}/include${QTINC}" is included in qt4_cppflags
306   else
307     if test x${qsci4_include_path} = xyes ; then
308       # --- "yes" --- try to find in /usr/include/Qsci
309       qsci4_include_path="/usr/include${QTINC}/Qsci"
310       qsci4_cppflags=" -I$qsci4_include_path"
311       # " -I/usr/include${QTINC}" is included in qt4_cppflags or by default (if QTINC is empty)
312     else
313       # --- "other" --- try to find in given dir
314       qsci4_cppflags=" -I$qsci4_include_path/Qsci -I$qsci4_include_path"
315     fi
316   fi
317
318   AC_MSG_NOTICE($qsci4_cppflags)
319
320   # --- check if qsci4 libraries directory is defined
321   qsci4_library_path=""
322
323   AC_ARG_WITH([qsci4-libraries],
324     AC_HELP_STRING([--with-qsci4-libraries@<:@=DIR@:>@], [where the Qsci4 libraries are: default @<:@$QTDIR/lib@:>@ or @<:@/usr/lib@:>@]),
325               [qsci4_library_path=$withval])
326
327   if test x${qsci4_library_path} = x ; then
328     # --- "" --- try to use QSCINTILLA_DIR/lib
329     if test "x${QSCINTILLA_DIR}" != "x" ; then
330       qsci4_library_path="${QSCINTILLA_DIR}/lib"
331     else
332       qsci4_library_path=no
333     fi
334   fi
335
336   if test x${qsci4_library_path} = xno ; then
337     # --- "no" --- no native installation, try to find in Qt
338     qsci4_library_path="${QT_DIR}/lib"
339   else
340     if test x${qsci4_library_path} = xyes ; then
341       # --- "yes" --- try to find in /usr/lib
342       qsci4_library_path="/usr/lib"
343     fi
344   fi
345
346   AC_MSG_NOTICE($qsci4_library_path)
347
348   # saving values for compilation variables
349   saved_CPPFLAGS=$CPPFLAGS
350   saved_LDFLAGS=$LDFLAGS
351   saved_LIBS=$LIBS
352
353   # ask for qsci4 support
354   AC_MSG_NOTICE([checking whether qscintilla for qt4 headers are present])
355
356   # --- we test the header file presence and usability
357   CPPFLAGS="${CPPFLAGS} ${qsci4_cppflags} ${qt4_cppflags}"
358   AC_LANG_PUSH(C++)
359   AC_CHECK_HEADERS([qsciscintilla.h],
360                    [qsci4_header_found=yes],
361                    [qsci4_header_found=no],
362                    [])
363   AC_LANG_POP(C++)
364   if test x${qsci4_header_found} = xyes
365   then
366     AC_SUBST(qsci4_cppflags)
367
368     # --- we test the library file presence and usability
369     if test x${qsci4_library_path} = x/usr/lib/qt4/lib
370     then
371       qsci4_library_path=/usr/lib
372     fi
373     if test x${qsci4_library_path} = x/usr/lib
374     then
375       qsci4_ldflags=""
376     else
377       qsci4_ldflags="-L$qsci4_library_path"
378     fi
379
380     AC_MSG_NOTICE([checking whether qscintilla2 library is present])
381     qsci4_libs=-lqscintilla2
382     AC_CHECK_FILE([${qsci4_library_path}/libqscintilla2.so],
383                    [qsci4_library_found=yes],
384                    [qsci4_library_found=no])
385     if test x${qsci4_library_found} = xyes
386     then
387       AC_MSG_NOTICE([qscintilla for qt4 support])
388       AC_SUBST(qsci4_ldflags)
389       AC_SUBST(qsci4_libs)
390       WITH_QSCI4=1
391       qscintilla_ok=yes
392       # Propagate test into atlocal
393       AC_SUBST(WITH_QSCI4)
394     fi
395
396   else
397     AC_MSG_NOTICE([no support for qscintilla for qt4])
398   fi
399
400   # Propagate test into Makefiles...
401   AM_CONDITIONAL(WITH_QSCI4, test $WITH_QSCI4 = 1)
402
403   # ... and into source files
404   AC_DEFINE_UNQUOTED(HAS_QSCI4, $WITH_QSCI4, [QsciScintilla library])
405
406   # restoring saved values
407   CPPFLAGS=$saved_CPPFLAGS
408   LDFLAGS=$saved_LDFLAGS
409   LIBS=$saved_LIBS
410
411 ])