Salome HOME
6d0a7471ff42fefba04f4be4f07af7f3e4397122
[modules/jobmanager.git] / m4 / i2_check_qt4.m4
1 dnl Copyright (C) 2009-2019  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, or (at your option) any later version.
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
20 dnl the following variables are exported:
21 dnl  QT_MOC
22 dnl  QT_UIC
23 dnl  QT_DIR
24 dnl  qt4_cppflags
25 dnl  qt4_ldflags
26 dnl  qt4_libs
27 dnl  WITH_QT4
28 dnl qt4 is searched in the following order
29 dnl   path given with --with-qt4 options
30 dnl   presence of QTDIR variable
31 dnl   /usr
32 dnl when HAS_GUI is false (no salome gui) and nothing is said for qt4, qt4 is not checked
33 dnl usages
34 dnl ./configure --prefix=/home/prascle/partage/maquettes/install 
35 dnl ./configure --prefix=/home/prascle/partage/maquettes/install --with-qt4
36 dnl ./configure --prefix=/home/prascle/partage/maquettes/install --with-qt4=/opt/qt443
37 dnl ./configure --prefix=/home/prascle/partage/maquettes/install --with-qt4-includes=/usr/include/qt4
38 dnl ./configure --prefix=/home/prascle/partage/maquettes/install --with-qt4-includes=/usr/include/qt4 --with-qt4-libraries=/usr/lib -with-qt4-tools=/usr/bin
39 dnl ./configure --prefix=/home/prascle/partage/maquettes/install --without-qt4
40 dnl
41 AC_DEFUN([I2_CHECK_QT4],
42 [
43   AC_REQUIRE([AC_PROG_CXX])
44   AC_REQUIRE([AC_PROG_CPP])
45
46   qt_ok=no
47   qt4_wanted=yes
48   WITH_QT4=0
49
50   # --- check if qt4 standard install directory is defined (with subdirectories bin lib include)
51   qt4_install_path=""
52   AC_ARG_WITH([qt4],
53     AC_HELP_STRING([--with-qt4@<:@=DIR@:>@], [where the Qt4 package with a standard install is: default @<:@$QTDIR@:>@ or @<:@/usr@:>@]),
54                  [qt4_install_path=$withval], [withval=notset])
55
56   # --- if qt4 standard install directory is defined but with no path: QTDIR value if defined, or /usr
57   if test x${withval} = xyes
58   then
59     if test -z $QTDIR
60     then
61       qt4_install_path="/usr"
62     else
63       qt4_install_path=$QTDIR
64     fi
65   fi
66
67   # --- if qt4 standard install directory is not defined
68   #       if HAS_GUI= 0: Qt4 not wanted
69   #       else: QTDIR value if defined, or /usr
70   if test x${withval} = xnotset
71   then
72     if test x${HAS_GUI} = x0
73     then
74       qt4_wanted=no
75       AC_MSG_NOTICE([SALOME GUI not present, Qt4 not specified, skip detection])
76     else
77       if test -z $QTDIR
78       then
79         qt4_install_path="/usr"
80       else
81         if test $QTDIR = /usr/lib/qt3 ; then
82           if test -d /usr/lib/qt4 ; then
83             AC_MSG_RESULT(it is strange for a qt4 installation !)
84             AC_MSG_RESULT(/usr/lib/qt4 is present)
85             AC_MSG_RESULT(replacing QTDIR by /usr/lib/qt4)
86             QTDIR=/usr/lib/qt4
87           fi
88         fi
89         qt4_install_path=$QTDIR
90       fi
91     fi
92   fi
93   
94   # --- if qt4 standard install directory is not wanted: --without-qt4 or --with-qt4=no
95   if test x${withval} = xno
96   then
97     qt4_wanted=no
98     AC_MSG_NOTICE([Qt4 is not wanted, skip detection])
99   fi
100
101   QT_DIR=${qt4_install_path}
102   AC_SUBST(QT_DIR)
103
104   # ----------------------------------------------------------------------
105   # --- only when qt4 wanted (no explicit --without-qt4 nor --with-qt4=no)
106
107   if test x${qt4_wanted} = xyes
108   then
109
110   # --- check if qt4 includes directory is defined
111   qt4_include_path=""
112   AC_ARG_WITH([qt4-includes],
113     AC_HELP_STRING([--with-qt4-includes@<:@=DIR@:>@], [where the Qt4 includes are: default @<:@$QTDIR/include@:>@ or @<:@/usr/include@:>@]),
114                  [qt4_include_path=$withval], [withval=no])
115   if test x${withval} != xno
116   then
117     # --- qt4 includes directory is defined
118     if test x${qt4_include_path} = xyes
119     then
120       qt4_include_path="/usr/include"
121     fi
122   else
123     if test x${qt4_install_path} != x
124     then
125       qt4_include_path="${qt4_install_path}/include"
126     fi
127   fi
128
129
130   # --- check if qt4 libraries directory is defined
131   qt4_library_path=""
132   AC_ARG_WITH([qt4-libraries],
133     AC_HELP_STRING([--with-qt4-libraries@<:@=DIR@:>@], [where the Qt4 libraries are: default @<:@$QTDIR/lib@:>@ or @<:@/usr/lib@:>@]),
134                  [qt4_library_path=$withval], [withval=no])
135   if test x${withval} != xno
136   then
137     # --- qt4 libraries directory is defined
138     if test x${qt4_library_path} = xyes
139     then
140       qt4_library_path="/usr/lib"
141     fi
142   else
143     if test x${qt4_install_path} != x
144     then
145       qt4_library_path="${qt4_install_path}/lib"
146     fi
147   fi
148
149   # --- check if qt4 tools directory is defined
150   qt4_tools_path=""
151   AC_ARG_WITH([qt4-tools],
152     AC_HELP_STRING([--with-qt4-tools@<:@=DIR@:>@], [where the Qt4 executable tools are: default @<:@$QTDIR/bin@:>@ or @<:@/usr/bin@:>@]),
153                  [qt4_tools_path=$withval], [withval=no])
154   if test x${withval} != xno
155   then
156     # --- qt4 tools directory is defined
157     if test x${qt4_tools_path} = xyes
158     then
159       qt4_tools_path="/usr/bin"
160     fi
161   else
162     if test x${qt4_install_path} != x
163     then
164       qt4_tools_path="${qt4_install_path}/bin"
165     fi
166   fi
167
168
169   # test if qt4 is completely defined
170   qt4_defined=yes
171   if test x${qt4_include_path} = x
172   then
173     qt4_defined=no
174     AC_MSG_NOTICE([No Qt4 include path defined])
175   else
176     AC_MSG_NOTICE([Qt4 include path is ${qt4_include_path}])
177   fi
178   if test x${qt4_library_path} = x
179   then
180     qt4_defined=no
181     AC_MSG_NOTICE([No Qt4 library path defined])
182   else
183     AC_MSG_NOTICE([Qt4 library path is ${qt4_library_path}])
184   fi
185   if test x${qt4_tools_path} = x
186   then
187     qt4_defined=no
188     AC_MSG_NOTICE([No Qt4 tools path defined])
189   else
190     AC_MSG_NOTICE([Qt4 tools   path is ${qt4_tools_path}])
191   fi
192
193   # saving values for compilation variables
194   saved_CPPFLAGS=$CPPFLAGS
195   saved_LDFLAGS=$LDFLAGS
196   saved_LIBS=$LIBS
197
198   if ! test x${qt4_defined} = xno
199   then
200     # ask for qt4 support
201     AC_MSG_NOTICE([checking whether qt4 tools and headers are present])
202
203     # --- we test the presence of moc,first under the form moc-qt4, then moc
204     AC_PATH_PROGS(qt4_moc_found, [moc-qt4 moc], no, ${qt4_tools_path})
205     test x${qt4_moc_found} = xno && AC_MSG_ERROR([Qt4 moc command NOT FOUND])
206     QT_MOC=$qt4_moc_found
207     AC_SUBST(QT_MOC)
208
209     # --- we test the presence of uic,first under the form uic-qt4, then uic
210     AC_PATH_PROGS(qt4_uic_found, [uic-qt4 uic], no, ${qt4_tools_path})
211     test x${qt4_uic_found} = xno && AC_MSG_ERROR([Qt4 uic command NOT FOUND])
212     QT_UIC=$qt4_uic_found
213     AC_SUBST(QT_UIC)
214
215     # --- we test the presence of rcc,first under the form rcc-qt4, then rcc
216     AC_PATH_PROGS(qt4_rcc_found, [rcc-qt4 rcc], no, ${qt4_tools_path})
217     test x${qt4_rcc_found} = xno && AC_MSG_ERROR([Qt4 rcc command NOT FOUND])
218     QT_RCC=$qt4_rcc_found
219     AC_SUBST(QT_RCC)
220
221     # --- we test the header file presence and usability
222     QTINC=""
223     AC_CHECK_FILE($qt4_include_path/qt4/QtCore/qglobal.h,QTINC="/qt4",QTINC="")
224     qt4_include_path="$qt4_include_path${QTINC}"
225     qt4_cppflags=""
226     qt4_cppflags="${qt4_cppflags} -I$qt4_include_path/QtCore"
227     qt4_cppflags="${qt4_cppflags} -I$qt4_include_path/QtGui"
228     qt4_cppflags="${qt4_cppflags} -I$qt4_include_path/Qt"
229     qt4_cppflags="${qt4_cppflags} -I$qt4_include_path"
230     CPPFLAGS="${CPPFLAGS} ${qt4_cppflags}"
231     AC_LANG_PUSH(C++)
232     AC_CHECK_HEADERS([qapplication.h],
233                      [qt4_header_found=yes],
234                      [qt4_header_found=no],
235                      [])
236     AC_LANG_POP(C++)
237     test x${qt4_header_found} = xno && AC_MSG_ERROR([Qt4 include file NOT FOUND])
238     AC_SUBST(qt4_cppflags)
239
240     # --- we test the library file presence and usability
241     if test x${qt4_library_path} = x/usr/lib
242     then
243       qt4_ldflags=""
244     else
245       qt4_ldflags="-L$qt4_library_path"
246     fi
247
248     AC_MSG_NOTICE([checking whether link with qt4 is working])
249     qt4_libs="-lQtCore -lQtGui"
250     LDFLAGS="${LDFLAGS} ${qt4_ldflags}"
251     LIBS="${LIBS} ${qt4_libs}"
252     AC_LANG_PUSH(C++)
253
254     AC_LINK_IFELSE([AC_LANG_PROGRAM(
255     [[ #include <QApplication>
256        #include <QPushButton> ]],
257     [[ QApplication app(0, 0);
258        QPushButton hello("Hello world!");
259        hello.resize(100, 30);
260        hello.show(); ]] )],
261     [qt4_lib_found=yes], [qt4_lib_found=no] )
262
263     test x${qt4_lib_found} = xno && AC_MSG_ERROR([Qt4 library NOT FOUND])
264
265     AC_LANG_POP(C++)
266     AC_SUBST(qt4_ldflags)
267     AC_SUBST(qt4_libs)
268
269     # --- after all tests are successful, we support Qt4
270     WITH_QT4=1
271     qt_ok=yes
272     AC_MSG_NOTICE([Qt4 support is OK])
273
274   else
275     # --- no Qt4 support
276     AC_MSG_NOTICE([No Qt4 support])
277   fi
278
279   # restoring saved values
280   CPPFLAGS=$saved_CPPFLAGS
281   LDFLAGS=$saved_LDFLAGS
282   LIBS=$saved_LIBS
283
284   fi
285   # --- end: only when qt4 wanted (no explicit --without-qt4 nor --with-qt4=no)
286   # ----------------------------------------------------------------------
287
288   # Propagate test into atlocal
289   AC_SUBST(WITH_QT4)
290
291   # Propagate test into Makefiles...
292   AM_CONDITIONAL(WITH_QT4, test $WITH_QT4 = 1)
293
294   # ... and into source files
295   AC_DEFINE_UNQUOTED(HAS_QT4, $WITH_QT4, [Qt4 library])
296
297 ])
298
299
300 AC_DEFUN([I2_CHECK_QSCINTILLA],
301 [
302   AC_REQUIRE([I2_CHECK_QT4])
303   qscintilla_ok=no
304   WITH_QSCI4=0
305
306   # ----------------------------------------------------------------------
307   # --- check qscintilla only when qt4 OK
308
309   if test x${WITH_QT4} = x1
310   then
311
312   # --- check if qsci4 includes directory is defined
313   qsci4_include_path=""
314   qsci4_cppflags=""
315
316   AC_ARG_WITH([qsci4-includes],
317     AC_HELP_STRING([--with-qsci4-includes@<:@=DIR@:>@], [where the Qsci4 includes are: default @<:@$QTDIR/include/Qsci@:>@ or @<:@/usr/include/Qsci@:>@]),
318               [qsci4_include_path=$withval])
319
320   if test x${qsci4_include_path} = x ; then
321     # --- "" --- try to use QSCINTILLA_DIR/include/Qsci
322     if test "x${QSCINTILLA_DIR}" != "x" ; then
323       qsci4_include_path="${QSCINTILLA_DIR}/include"
324     else
325       qsci4_include_path=no
326     fi
327   fi
328
329   if test x${qsci4_include_path} = xno ; then
330     # --- "no" --- no native installation, try to find in Qt
331     qsci4_include_path="${QT_DIR}/include${QTINC}/Qsci"
332     qsci4_cppflags=" -I$qsci4_include_path"
333     # " -I${QT_DIR}/include${QTINC}" is included in qt4_cppflags
334   else
335     if test x${qsci4_include_path} = xyes ; then
336       # --- "yes" --- try to find in /usr/include/Qsci
337       qsci4_include_path="/usr/include${QTINC}/Qsci"
338       qsci4_cppflags=" -I$qsci4_include_path"
339       # " -I/usr/include${QTINC}" is included in qt4_cppflags or by default (if QTINC is empty)
340     else
341       # --- "other" --- try to find in given dir
342       qsci4_cppflags=" -I$qsci4_include_path/Qsci -I$qsci4_include_path"
343     fi
344   fi
345
346   AC_MSG_NOTICE($qsci4_cppflags)
347
348   # --- check if qsci4 libraries directory is defined
349   qsci4_library_path=""
350
351   AC_ARG_WITH([qsci4-libraries],
352     AC_HELP_STRING([--with-qsci4-libraries@<:@=DIR@:>@], [where the Qsci4 libraries are: default @<:@$QTDIR/lib@:>@ or @<:@/usr/lib@:>@]),
353               [qsci4_library_path=$withval])
354
355   if test x${qsci4_library_path} = x ; then
356     # --- "" --- try to use QSCINTILLA_DIR/lib
357     if test "x${QSCINTILLA_DIR}" != "x" ; then
358       qsci4_library_path="${QSCINTILLA_DIR}/lib"
359     else
360       qsci4_library_path=no
361     fi
362   fi
363
364   if test x${qsci4_library_path} = xno ; then
365     # --- "no" --- no native installation, try to find in Qt
366     qsci4_library_path="${QT_DIR}/lib"
367   else
368     if test x${qsci4_library_path} = xyes ; then
369       # --- "yes" --- try to find in /usr/lib
370       qsci4_library_path="/usr/lib"
371     fi
372   fi
373
374   AC_MSG_NOTICE($qsci4_library_path)
375
376   # saving values for compilation variables
377   saved_CPPFLAGS=$CPPFLAGS
378   saved_LDFLAGS=$LDFLAGS
379   saved_LIBS=$LIBS
380
381   # ask for qsci4 support
382   AC_MSG_NOTICE([checking whether qscintilla for qt4 headers are present])
383
384   # --- we test the header file presence and usability
385   CPPFLAGS="${CPPFLAGS} ${qsci4_cppflags} ${qt4_cppflags}"
386   AC_LANG_PUSH(C++)
387   AC_CHECK_HEADERS([qsciscintilla.h],
388                    [qsci4_header_found=yes],
389                    [qsci4_header_found=no],
390                    [])
391   AC_LANG_POP(C++)
392   if test x${qsci4_header_found} = xyes
393   then
394     AC_SUBST(qsci4_cppflags)
395
396     # --- we test the library file presence and usability
397     if test x${qsci4_library_path} = x/usr/lib/qt4/lib
398     then
399       qsci4_library_path=/usr/lib
400     fi
401     if test x${qsci4_library_path} = x/usr/lib
402     then
403       qsci4_ldflags=""
404     else
405       qsci4_ldflags="-L$qsci4_library_path"
406     fi
407
408     AC_MSG_NOTICE([checking whether qscintilla2 library is present])
409     qsci4_libs=-lqscintilla2
410     AC_CHECK_FILE([${qsci4_library_path}/libqscintilla2.so],
411                    [qsci4_library_found=yes],
412                    [qsci4_library_found=no])
413     if test x${qsci4_library_found} = xyes
414     then
415       AC_MSG_NOTICE([qscintilla for qt4 support])
416       AC_SUBST(qsci4_ldflags)
417       AC_SUBST(qsci4_libs)
418       WITH_QSCI4=1
419       qscintilla_ok=yes
420     fi
421
422   else
423     AC_MSG_NOTICE([no support for qscintilla for qt4])
424   fi
425
426   # restoring saved values
427   CPPFLAGS=$saved_CPPFLAGS
428   LDFLAGS=$saved_LDFLAGS
429   LIBS=$saved_LIBS
430
431   else
432   # --- end: check qscintilla only when qt4 OK
433   # ----------------------------------------------------------------------
434     AC_MSG_NOTICE([qscintilla for qt4 not checked because Qt4 not wanted or not detected])
435   fi
436
437   # Propagate test into atlocal
438   AC_SUBST(WITH_QSCI4)
439   
440   # Propagate test into Makefiles...
441   AM_CONDITIONAL(WITH_QSCI4, test $WITH_QSCI4 = 1)
442
443   # ... and into source files
444   AC_DEFINE_UNQUOTED(HAS_QSCI4, $WITH_QSCI4, [QsciScintilla library])
445
446 ])