Salome HOME
e8a937e2296cd55703d986c63df9dad14dcb5907
[modules/yacs.git] / adm / unix / config_files / 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       qt4_install_path=$QTDIR
71     fi
72   fi
73   
74   # --- if qt4 standard install directory is not wanted: --without-qt4 or --with-qt4=no
75   if test x${withval} = xno
76   then
77     qt4_install_path=""
78   fi
79
80   QT_DIR=${qt4_install_path}
81   AC_SUBST(QT_DIR)
82
83   # --- check if qt4 includes directory is defined
84   qt4_include_path=""
85   AC_ARG_WITH([qt4-includes],
86     AC_HELP_STRING([--with-qt4-includes@<:@=DIR@:>@], [where the Qt4 includes are: default @<:@$QTDIR/include@:>@ or @<:@/usr/include@:>@]),
87                  [qt4_include_path=$withval], [withval=no])
88   if test x${withval} != xno
89   then
90     # --- qt4 includes directory is defined
91     if test x${qt4_include_path} = xyes
92     then
93       qt4_include_path="/usr/include"
94     fi
95   else
96     if test x${qt4_install_path} != x
97     then
98       qt4_include_path="${qt4_install_path}/include"
99     fi
100   fi
101
102
103   # --- check if qt4 libraries directory is defined
104   qt4_library_path=""
105   AC_ARG_WITH([qt4-libraries],
106     AC_HELP_STRING([--with-qt4-libraries@<:@=DIR@:>@], [where the Qt4 libraries are: default @<:@$QTDIR/lib@:>@ or @<:@/usr/lib@:>@]),
107                  [qt4_library_path=$withval], [withval=no])
108   if test x${withval} != xno
109   then
110     # --- qt4 libraries directory is defined
111     if test x${qt4_library_path} = xyes
112     then
113       qt4_library_path="/usr/lib"
114     fi
115   else
116     if test x${qt4_install_path} != x
117     then
118       qt4_library_path="${qt4_install_path}/lib"
119     fi
120   fi
121
122   # --- check if qt4 tools directory is defined
123   qt4_tools_path=""
124   AC_ARG_WITH([qt4-tools],
125     AC_HELP_STRING([--with-qt4-tools@<:@=DIR@:>@], [where the Qt4 executable tools are: default @<:@$QTDIR/bin@:>@ or @<:@/usr/bin@:>@]),
126                  [qt4_tools_path=$withval], [withval=no])
127   if test x${withval} != xno
128   then
129     # --- qt4 tools directory is defined
130     if test x${qt4_tools_path} = xyes
131     then
132       qt4_tools_path="/usr/bin"
133     fi
134   else
135     if test x${qt4_install_path} != x
136     then
137       qt4_tools_path="${qt4_install_path}/bin"
138     fi
139   fi
140
141   WITH_QT4=0
142
143   AC_MSG_NOTICE(${qt4_include_path})
144   AC_MSG_NOTICE(${qt4_library_path})
145   AC_MSG_NOTICE(${qt4_tools_path})
146
147   # test if qt4 is completely defined
148   qt4_defined=yes
149   if test x${qt4_include_path} = x
150   then
151     qt4_defined=no
152     AC_MSG_NOTICE([No Qt4 include path defined])
153   fi
154   if test x${qt4_library_path} = x
155   then
156     qt4_defined=no
157     AC_MSG_NOTICE([No Qt4 library path defined])
158   fi
159   if test x${qt4_tools_path} = x
160   then
161     qt4_defined=no
162     AC_MSG_NOTICE([No Qt4 tools path defined])
163   fi
164
165   # saving values for compilation variables
166   saved_CPPFLAGS=$CPPFLAGS
167   saved_LDFLAGS=$LDFLAGS
168   saved_LIBS=$LIBS
169
170   if ! test x${qt4_defined} = xno
171   then
172     # ask for qt4 support
173     AC_MSG_NOTICE([checking whether qt4 tools and headers are present])
174
175     # --- we test the presence of moc,first under the form moc-qt4, then moc
176     AC_PATH_PROGS(qt4_moc_found, [moc-qt4 moc], no, ${qt4_tools_path})
177     test x${qt4_moc_found} = xno && AC_MSG_ERROR([Qt4 moc command NOT FOUND])
178     QT_MOC=$qt4_moc_found
179     AC_SUBST(QT_MOC)
180
181     # --- we test the presence of uic,first under the form uic-qt4, then uic
182     AC_PATH_PROGS(qt4_uic_found, [uic-qt4 uic], no, ${qt4_tools_path})
183     test x${qt4_uic_found} = xno && AC_MSG_ERROR([Qt4 uic command NOT FOUND])
184     QT_UIC=$qt4_uic_found
185     AC_SUBST(QT_UIC)
186
187     # --- we test the presence of rcc,first under the form rcc-qt4, then rcc
188     AC_PATH_PROGS(qt4_rcc_found, [rcc-qt4 rcc], no, ${qt4_tools_path})
189     test x${qt4_rcc_found} = xno && AC_MSG_ERROR([Qt4 rcc command NOT FOUND])
190     QT_RCC=$qt4_rcc_found
191     AC_SUBST(QT_RCC)
192
193     # --- we test the header file presence and usability
194     QTINC=""
195     AC_CHECK_FILE($qt4_include_path/qt4/QtCore/qglobal.h,QTINC="/qt4",QTINC="")
196     qt4_include_path="$qt4_include_path${QTINC}"
197     qt4_cppflags=""
198     qt4_cppflags="${qt4_cppflags} -I$qt4_include_path/QtCore"
199     qt4_cppflags="${qt4_cppflags} -I$qt4_include_path/QtGui"
200     qt4_cppflags="${qt4_cppflags} -I$qt4_include_path/Qt"
201     qt4_cppflags="${qt4_cppflags} -I$qt4_include_path"
202     CPPFLAGS="${CPPFLAGS} ${qt4_cppflags}"
203     AC_LANG_PUSH(C++)
204     AC_CHECK_HEADERS([qapplication.h],
205                      [qt4_header_found=yes],
206                      [qt4_header_found=no],
207                      [])
208     AC_LANG_POP(C++)
209     test x${qt4_header_found} = xno && AC_MSG_ERROR([Qt4 include file NOT FOUND])
210     AC_SUBST(qt4_cppflags)
211
212     # --- we test the library file presence and usability
213     if test x${qt4_library_path} = /usr/lib
214     then
215       qt4_ldflags=""
216     else
217       qt4_ldflags="-L$qt4_library_path"
218     fi
219
220     AC_MSG_NOTICE([checking whether link with qt4 is working])
221     qt4_lib_name=QtGui
222     qt4_libs="-l$qt4_lib_name"
223     LDFLAGS="${LDFLAGS} ${qt4_ldflags}"
224     LIBS="${LIBS} ${qt4_libs}"
225     AC_LANG_PUSH(C++)
226
227     AC_LINK_IFELSE([AC_LANG_PROGRAM(
228     [[ #include <QApplication>
229        #include <QPushButton> ]],
230     [[ QApplication app(0, 0);
231        QPushButton hello("Hello world!");
232        hello.resize(100, 30);
233        hello.show(); ]] )],
234     [qt4_lib_found=yes], [qt4_lib_found=no] )
235
236     test x${qt4_lib_found} = xno && AC_MSG_ERROR([Qt4 library NOT FOUND])
237
238     AC_LANG_POP(C++)
239     AC_SUBST(qt4_ldflags)
240     AC_SUBST(qt4_libs)
241
242     # --- after all tests are successful, we support Qt4
243     WITH_QT4=1
244     qt_ok=yes
245     AC_MSG_NOTICE([Qt4 support is OK])
246
247   else
248     # --- no Qt4 support
249     AC_MSG_NOTICE([No Qt4 support])
250   fi
251
252   # Propagate test into atlocal
253   AC_SUBST(WITH_QT4)
254
255   # Propagate test into Makefiles...
256   AM_CONDITIONAL(WITH_QT4, test $WITH_QT4 = 1)
257
258   # ... and into source files
259   AC_DEFINE_UNQUOTED(HAS_QT4, $WITH_QT4, [Qt4 library])
260
261   # restoring saved values
262   CPPFLAGS=$saved_CPPFLAGS
263   LDFLAGS=$saved_LDFLAGS
264   LIBS=$saved_LIBS
265
266 ])
267
268
269 AC_DEFUN([I2_CHECK_QSCINTILLA],
270 [
271   AC_REQUIRE([I2_CHECK_QT4])
272
273   qscintilla_ok=no
274   WITH_QSCI4=0
275
276   # --- check if qsci4 includes directory is defined
277   qsci4_include_path=""
278   qsci4_cppflags=""
279
280   AC_ARG_WITH([qsci4-includes],
281     AC_HELP_STRING([--with-qsci4-includes@<:@=DIR@:>@], [where the Qsci4 includes are: default @<:@$QTDIR/include/Qsci@:>@ or @<:@/usr/include/Qsci@:>@]),
282               [qsci4_include_path=$withval])
283
284   if test x${qsci4_include_path} = x ; then
285     # --- "" --- try to use QSCINTILLA_DIR/include/Qsci
286     if test "x${QSCINTILLA_DIR}" != "x" ; then
287       qsci4_include_path="${QSCINTILLA_DIR}/include"
288     else
289       qsci4_include_path=no
290     fi
291   fi
292
293   if test x${qsci4_include_path} = xno ; then
294     # --- "no" --- no native installation, try to find in Qt
295     qsci4_include_path="${QT_DIR}/include${QTINC}/Qsci"
296     qsci4_cppflags=" -I$qsci4_include_path"
297     # " -I${QT_DIR}/include${QTINC}" is included in qt4_cppflags
298   else
299     if test x${qsci4_include_path} = xyes ; then
300       # --- "yes" --- try to find in /usr/include/Qsci
301       qsci4_include_path="/usr/include${QTINC}/Qsci"
302       qsci4_cppflags=" -I$qsci4_include_path"
303       # " -I/usr/include${QTINC}" is included in qt4_cppflags or by default (if QTINC is empty)
304     else
305       # --- "other" --- try to find in given dir
306       qsci4_cppflags=" -I$qsci4_include_path/Qsci -I$qsci4_include_path"
307     fi
308   fi
309
310   AC_MSG_NOTICE($qsci4_cppflags)
311
312   # --- check if qsci4 libraries directory is defined
313   qsci4_library_path=""
314
315   AC_ARG_WITH([qsci4-libraries],
316     AC_HELP_STRING([--with-qsci4-libraries@<:@=DIR@:>@], [where the Qsci4 libraries are: default @<:@$QTDIR/lib@:>@ or @<:@/usr/lib@:>@]),
317               [qsci4_library_path=$withval])
318
319   if test x${qsci4_library_path} = x ; then
320     # --- "" --- try to use QSCINTILLA_DIR/lib
321     if test "x${QSCINTILLA_DIR}" != "x" ; then
322       qsci4_library_path="${QSCINTILLA_DIR}/lib"
323     else
324       qsci4_library_path=no
325     fi
326   fi
327
328   if test x${qsci4_library_path} = xno ; then
329     # --- "no" --- no native installation, try to find in Qt
330     qsci4_library_path="${QT_DIR}/lib"
331   else
332     if test x${qsci4_library_path} = xyes ; then
333       # --- "yes" --- try to find in /usr/lib
334       qsci4_library_path="/usr/lib"
335     fi
336   fi
337
338   AC_MSG_NOTICE($qsci4_library_path)
339
340   # saving values for compilation variables
341   saved_CPPFLAGS=$CPPFLAGS
342   saved_LDFLAGS=$LDFLAGS
343   saved_LIBS=$LIBS
344
345   # ask for qsci4 support
346   AC_MSG_NOTICE([checking whether qscintilla for qt4 headers are present])
347
348   # --- we test the header file presence and usability
349   CPPFLAGS="${CPPFLAGS} ${qsci4_cppflags} ${qt4_cppflags}"
350   AC_LANG_PUSH(C++)
351   AC_CHECK_HEADERS([qsciscintilla.h],
352                    [qsci4_header_found=yes],
353                    [qsci4_header_found=no],
354                    [])
355   AC_LANG_POP(C++)
356   if test x${qsci4_header_found} = xyes
357   then
358     AC_SUBST(qsci4_cppflags)
359
360     # --- we test the library file presence and usability
361     if test x${qsci4_library_path} = x/usr/lib
362     then
363       qsci4_ldflags=""
364     else
365       qsci4_ldflags="-L$qsci4_library_path"
366     fi
367
368     AC_MSG_NOTICE([checking whether qscintilla2 library is present])
369     qsci4_libs=-lqscintilla2
370     AC_CHECK_FILE([${qsci4_library_path}/libqscintilla2.so],
371                    [qsci4_library_found=yes],
372                    [qsci4_library_found=no])
373     if test x${qsci4_library_found} = xyes
374     then
375       AC_MSG_NOTICE([qscintilla for qt4 support])
376       AC_SUBST(qsci4_ldflags)
377       AC_SUBST(qsci4_libs)
378       WITH_QSCI4=1
379       qscintilla_ok=yes
380       # Propagate test into atlocal
381       AC_SUBST(WITH_QSCI4)
382     fi
383
384   else
385     AC_MSG_NOTICE([no support for qscintilla for qt4])
386   fi
387
388   # Propagate test into Makefiles...
389   AM_CONDITIONAL(WITH_QSCI4, test $WITH_QSCI4 = 1)
390
391   # ... and into source files
392   AC_DEFINE_UNQUOTED(HAS_QSCI4, $WITH_QSCI4, [QsciScintilla library])
393
394   # restoring saved values
395   CPPFLAGS=$saved_CPPFLAGS
396   LDFLAGS=$saved_LDFLAGS
397   LIBS=$saved_LIBS
398
399 ])