Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/gui.git] / adm_local / unix / config_files / check_qwt.m4
1 dnl Copyright (C) 2007-2012  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
23 AC_DEFUN([CHECK_QWT],[
24 AC_REQUIRE([CHECK_QT])dnl
25 AC_REQUIRE([AC_LINKER_OPTIONS])dnl
26
27 AC_CHECKING(for qwt)
28
29 AC_LANG_SAVE
30 AC_LANG_CPLUSPLUS
31
32 qwt_ok=yes
33
34 dnl where is qwt ?
35
36 AC_ARG_WITH(qwt,
37     [  --with-qwt=DIR     directory path to QWT installation ],
38     [QWTHOME="$withval"
39       AC_MSG_RESULT("select $withval as path to QWT")
40     ])
41
42 AC_ARG_WITH(qwt_inc,
43     [  --with-qwt_inc=DIR   directory path to QWT includes ],
44     [QWT_INCDIR="$withval"
45       AC_MSG_RESULT("select $withval as path to QWT includes")
46     ])
47
48 libqwt_name=qwt
49 if test -z $QWTHOME; then
50   AC_MSG_RESULT(QWTHOME not defined)
51   AC_MSG_NOTICE(Trying native Qwt...)
52   exist_ok=no   
53   if test "x$exist_ok" = "xno"; then
54      for d in /usr /usr/local ; do
55         for extension in qwt-qt4 qwt; do
56            AC_CHECK_FILE(${d}/lib${LIB_LOCATION_SUFFIX}/lib${extension}.so,exist_ok=yes,exist_ok=no)
57            if test "x$exist_ok" = "xyes"; then
58               QWTHOME=$d
59               AC_MSG_RESULT(lib${extension}.so detected in $d/lib)
60               libqwt_name=${extension}
61               dnl  break, libqwt-qt4.so is choosen before libqwt.so since it is surely the Qt4 version.
62               break
63            fi
64         done
65         if test "x$exist_ok" = "xyes"; then
66            break
67         fi
68      done
69   fi
70   if test "x$exist_ok" = "xno"; then
71      if test "${build_cpu::6}" = "x86_64" ; then
72        for d in /usr /usr/local ; do
73           for extension in qwt-qt4 qwt; do
74              AC_CHECK_FILE(${d}/lib64/lib${extension}.so,exist_ok=yes,exist_ok=no)
75              if test "x$exist_ok" = "xyes"; then
76                 QWTHOME=$d
77                 AC_MSG_RESULT(lib${extension}.so detected in $d/lib)
78                 libqwt_name=${extension}
79                 dnl  break, libqwt-qt4.so is choosen before libqwt.so since it is surely the Qt4 version.
80                 break
81              fi
82           done
83           if test "x$exist_ok" = "xyes"; then
84              break
85           fi
86        done
87     fi
88   fi
89   if test "x$exist_ok" = "xno"; then
90      for d in `echo $LD_LIBRARY_PATH | sed -e "s/:/ /g"` ; do
91         if test -f $d/libqwt.so ; then
92            AC_MSG_RESULT(libqwt.so detected in $d)
93            QWTHOME=$d
94            QWTHOME=`echo ${QWTHOME} | sed -e "s,[[^/]]*$,,;s,/$,,;s,^$,.,"`
95            exist_ok=yes
96            break
97         fi
98      done
99   fi
100   if test "x$exist_ok" = "xyes"; then
101      if test -z $QWT_INCDIR; then
102         QWT_INCDIR=$QWTHOME"/include/qwt-qt4"
103         if test ! -f $QWT_INCDIR/qwt.h ; then
104           QWT_INCDIR=/usr/include/qwt
105         fi
106         if test ! -f $QWT_INCDIR/qwt.h ; then
107           QWT_INCDIR=$QWTHOME"/include"
108         fi
109         if test ! -f $QWT_INCDIR/qwt.h ; then
110           QWT_INCDIR=/usr/lib/qt4/include/qwt
111         fi
112      fi
113   else
114      qwt_ok=no
115   fi
116 else
117   AC_MSG_NOTICE(Trying Qwt from $QWTHOME ...)
118   if test -z $QWT_INCDIR; then
119      QWT_INCDIR="$QWTHOME/include"
120   fi    
121 fi
122
123 if test "x$qwt_ok" = xno -o ! -d "$QWTHOME" ; then
124   AC_MSG_RESULT(no)
125   AC_MSG_WARN(qwt not found)
126   qwt_ok=no
127 else
128   CPPFLAGS_old=$CPPFLAGS
129   CPPFLAGS="$CPPFLAGS $QT_INCLUDES -I$QWT_INCDIR"
130
131   AC_CHECK_HEADER(qwt.h,qwt_ok=yes,qwt_ok=no) 
132   CPPFLAGS=$CPPFLAGS_old
133
134   AC_MSG_CHECKING(include of qwt headers)
135
136   if test "x$qwt_ok" = xno ; then
137     AC_MSG_RESULT(no)
138     AC_MSG_WARN(qwt not found)
139   else
140     AC_MSG_RESULT(yes)
141     QWT_INCLUDES=-I$QWT_INCDIR
142   fi
143
144   #
145   # test Qwt libraries
146   #
147   if test "x$qwt_ok" = "xyes" ; then
148     AC_MSG_CHECKING(linking qwt library)
149
150     LIBS_old=$LIBS
151     LIBS="$LIBS $QT_LIBS"
152     if test "x$QWTHOME" = "x/usr" ; then
153       LIBS="$LIBS -l${libqwt_name}"
154     else
155       LIBS="$LIBS -L$QWTHOME/lib -l${libqwt_name}"
156     fi
157
158     CXXFLAGS_old=$CXXFLAGS
159     CXXFLAGS="$CXXFLAGS $QT_INCLUDES $QWT_INCLUDES"
160
161     AC_CACHE_VAL(salome_cv_lib_qwt,[
162       AC_TRY_LINK(
163 #include <QApplication>
164 #include <qwt_plot.h>
165 ,     int n;
166       char **s;
167       QApplication a(n, s);
168       QwtPlot p;
169       p.resize( 600, 400 );
170       p.show();
171       a.exec();,
172       eval "salome_cv_lib_qwt=yes",eval "salome_cv_lib_qwt=no")
173     ])
174     qwt_ok="$salome_cv_lib_qwt"
175
176     if  test "x$qwt_ok" = "xno" ; then
177       AC_MSG_RESULT(unable to link with qwt library)
178       AC_MSG_RESULT(QWTHOME environment variable may be wrong)
179     else
180       AC_MSG_RESULT(yes)
181       if test "x$QWTHOME" = "x/usr" ; then
182         QWT_LIBS=" -l${libqwt_name}"
183       else
184         QWT_LIBS="-L$QWTHOME/lib -l${libqwt_name}"
185       fi
186     fi
187
188     LIBS=$LIBS_old
189     CXXFLAGS=$CXXFLAGS_old
190   fi
191 fi
192
193 AC_SUBST(QWT_INCLUDES)
194 AC_SUBST(QWT_LIBS)
195
196 AC_LANG_RESTORE
197
198 AC_MSG_RESULT(for qwt: $qwt_ok)
199
200 # Save cache
201 AC_CACHE_SAVE
202
203 ])dnl
204 dnl