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