Salome HOME
Fix n.3 of hack_libtool utility to workaround problems on some Linux configurations
[modules/kernel.git] / salome_adm / unix / config_files / check_vtk.m4
1 dnl  Copyright (C) 2007-2010  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 dnl  OPTIONS_VTK
24 dnl  ------------------------------------------------------------------------
25 dnl  Adds the --with-vtk=path, --with-vtk-version and --with-paraview configure options
26 dnl
27 AC_DEFUN([OPTIONS_VTK], [
28   AC_ARG_WITH([vtk],
29               [AC_HELP_STRING([--with-vtk], [The prefix where VTK is installed (default "" means taking from environment variable unless VTK from ParaView is detected)])],
30               [with_vtk=$withval], [with_vtk=""])
31
32   AC_ARG_WITH([vtk-version],
33               [AC_HELP_STRING([--with-vtk-version], [VTK include directory name is vtk-suffix, e.g. vtk-5.0/. What is the suffix? (Default "yes" means taking from environment variable)])],
34               [vtk_suffix=$withval], [vtk_suffix="yes"])
35
36   AC_ARG_WITH([paraview],
37               [AC_HELP_STRING([--with-paraview], [ParaView from the specified location is used instead of VTK (default "" means taking from environment variable)])])
38 ])
39
40 dnl
41 dnl  CHECK_VTK
42 dnl  ------------------------------------------------------------------------
43 dnl
44 AC_DEFUN([CHECK_VTK], [
45 AC_REQUIRE([AC_PROG_CC])dnl
46 AC_REQUIRE([AC_PROG_CXX])dnl
47 AC_REQUIRE([AC_PROG_CPP])dnl
48 AC_REQUIRE([AC_PROG_CXXCPP])dnl
49 AC_REQUIRE([AC_LINKER_OPTIONS])dnl
50
51 AC_REQUIRE([OPTIONS_VTK])dnl
52
53 AC_LANG_SAVE
54 AC_LANG_CPLUSPLUS
55
56 AC_SUBST(VTK_INCLUDES)
57 AC_SUBST(VTK_LIBS)
58 AC_SUBST(VTKPY_MODULES)
59
60 VTK_INCLUDES=""
61 VTK_LIBS=""
62 VTKPY_MODULES=""
63
64 vtk_ok=no
65
66 if test "x$OpenGL_ok" != "xyes" ; then
67    AC_MSG_WARN(VTK needs OpenGL correct configuration, check configure output)
68 fi
69
70 AC_PATH_X
71 if test "x$x_libraries" != "x"
72 then
73    LXLIB="-L$x_libraries"
74 else
75    LXLIB=""
76 fi
77
78 if test "x$x_libraries" = "x/usr/lib"
79 then
80    LXLIB=""
81 fi
82
83 if test "x$x_libraries" = "x/usr/lib${LIB_LOCATION_SUFFIX}"
84 then
85    LXLIB=""
86 fi
87
88 LOCAL_INCLUDES="$OGL_INCLUDES"
89 LOCAL_LIBS="-lvtkCommon -lvtkGraphics -lvtkImaging -lvtkFiltering -lvtkIO -lvtkRendering -lvtkHybrid -lvtkParallel -lvtkWidgets $LXLIB -lX11 -lXt"
90 TRY_LINK_LIBS="-lvtkCommon $LXLIB -lX11 -lXt"
91
92 dnl VTK version suffix
93 if test -z $vtk_suffix ; then
94   vtk_suffix="yes"
95 fi
96 if test "x$vtk_suffix" = "xno" ; then
97   dnl in case user wrote --with-vtk-version=no, use empty suffix
98   vtk_suffix=""
99 fi
100 if test "x$vtk_suffix" != "xyes" ; then
101   VTKSUFFIX="$vtk_suffix"
102 else
103   dnl in case user wrote --with-vtk-version=yes, get the suffix from env
104   if test -z $VTKSUFFIX ; then
105     VTKSUFFIX="-5.0"
106   fi
107 fi
108
109 dnl
110 dnl Use VTK from ParaView unless --with-paraview=no is given
111 dnl
112
113 pv_vtk_ok=no
114
115 case "x$with_paraview" in
116
117   xno )
118     PVHOME=""
119     ;;
120
121   xyes | x )
122   
123     if test -z $PVHOME ; then
124       AC_PATH_PROG(para_path, paraview)
125       if test "x$para_path" != "x" ; then
126          para_path=`dirname $para_path`
127          PVHOME=`dirname $para_path`
128       else
129         for d in /usr/local /usr ; do
130           if test -f ${d}/include/paraview${PVVERSION}/pqDialog.h ; then
131             AC_MSG_RESULT(trying ${d})
132             PVHOME="${d}"
133             break
134           fi
135           if test -f ${d}/include/paraview-3.7/pqDialog.h ; then
136             AC_MSG_RESULT(trying ${d})
137             PVHOME="${d}"
138             PVVERSION="-3.7"
139             break
140           fi
141           if test -f ${d}/include/paraview-3.8/pqDialog.h ; then
142             AC_MSG_RESULT(trying ${d})
143             PVHOME="${d}"
144             PVVERSION="-3.8"
145             break
146           fi
147           if test -f ${d}/include/paraview/pqDialog.h ; then
148             AC_MSG_RESULT(trying ${d})
149             PVHOME="${d}"
150             PVVERSION=""
151             break
152           fi
153         done
154       fi
155     fi
156     ;;
157
158   * )
159     PVHOME=${with_paraview}
160     ;;
161 esac
162
163 dnl Check VTK from ParaView.
164
165 if test "x$PVHOME" != "x" ; then
166
167   if test "x$PVVERSION" = "x" ; then
168     for suffix in 3.7 3.8 ; do
169       if test -f $PVHOME/include/paraview-$suffix/vtkPVConfig.h ; then
170         PVVERSION=$suffix
171         break;
172       fi
173     done
174   fi    
175   if test "x$PVVERSION" = "x" ; then
176     PVVERSION=`basename $PVHOME | sed -e "s,[[^-]]*,,"`
177   else
178     if test "${PVVERSION:0:1}" != "-" ; then
179       PVVERSION="-$PVVERSION"
180     fi
181   fi
182
183   AC_CHECKING(for VTK from ParaView)
184
185   PV_LOCAL_INCLUDES="-I$PVHOME/include/paraview$PVVERSION $LOCAL_INCLUDES"
186   PV_LOCAL_LIBS="-L$PVHOME/lib/paraview$PVVERSION -lvtksys -lvtkzlib -lvtkpng -lvtkjpeg -lvtktiff -lvtkexpat -lvtksqlite -lvtkmetaio -lvtkverdict -lvtkNetCDF -lvtkDICOMParser -lvtkfreetype -lvtkftgl -lvtkexoIIc $LOCAL_LIBS"
187   PV_TRY_LINK_LIBS="-L$PVHOME/lib/paraview$PVVERSION -lvtksys $TRY_LINK_LIBS"
188
189   dnl vtk headers
190   CPPFLAGS_old="$CPPFLAGS"
191   CPPFLAGS="$CPPFLAGS $PV_LOCAL_INCLUDES"
192   
193   AC_CHECK_HEADER(vtkPoints.h,pv_vtk_ok="yes",pv_vtk_ok="no")
194   
195   CPPFLAGS="$CPPFLAGS_old"
196   
197   if test "x$pv_vtk_ok" = "xyes"; then
198
199      dnl vtk libraries
200   
201      AC_MSG_CHECKING(linking VTK library from ParaView)
202   
203      LIBS_old="$LIBS"
204      LIBS="$LIBS $PV_TRY_LINK_LIBS"
205      CPPFLAGS_old="$CPPFLAGS"
206      CPPFLAGS="$CPPFLAGS $PV_LOCAL_INCLUDES"
207   
208      AC_CACHE_VAL(salome_cv_lib_pvvtk,[
209        AC_TRY_LINK([#include "vtkPoints.h"
210                    ],
211                  [vtkPoints::New()],
212                  [salome_cv_lib_pvvtk=yes],
213                  [salome_cv_lib_pvvtk=no])
214      ])
215      pv_vtk_ok="$salome_cv_lib_pvvtk"
216      LIBS="$LIBS_old"
217      CPPFLAGS="$CPPFLAGS_old"
218      AC_MSG_RESULT($pv_vtk_ok)
219   fi
220
221   dnl Find out version of VTK from ParaView
222   PVVTKVERSION=" Undefined"
223   if test "x$pv_vtk_ok" = "xyes"; then
224      AC_MSG_CHECKING(VTK version)
225      PVVTKVERSION=`grep VTK_VERSION $PVHOME/include/paraview$PVVERSION/vtkConfigure.h`
226      AC_MSG_RESULT(${PVVTKVERSION:20:10})
227   fi
228 fi
229
230 dnl
231 dnl Use regular VTK if no ParaView found or a newer version is provided via --with-vtk
232 dnl 
233
234 try_regular_vtk=no
235 if test "$pv_vtk_ok" = "no"; then
236   try_regular_vtk=yes
237 fi
238
239 if test -z $with_vtk ; then
240   with_vtk=""
241 fi
242 case "x$with_vtk" in
243   xyes)
244     dnl in case user wrote --with-vtk=yes
245     with_vtk=""
246     ;;
247   xno)
248     dnl in case user wrote --with-vtk=no
249     with_vtk=""
250     AC_MSG_WARN(Value "no", specified for option --with-vtk, is not supported)
251     ;;
252   x)
253     ;;
254   *)
255     try_regular_vtk=yes
256     ;;
257 esac
258
259 if test "$try_regular_vtk" = "yes"; then
260
261   dnl Check regular VTK installation
262   AC_CHECKING(for regular VTK)
263   
264   dnl VTK install dir
265
266   if test "x$with_vtk" != "x" ; then
267     VTKHOME="$with_vtk"
268   else
269     if test -z $VTKHOME ; then
270       AC_MSG_WARN(undefined VTKHOME variable which specify where vtk was compiled)
271       for d in /usr/local /usr ; do
272         if test -f ${d}/include/vtk${VTKSUFFIX}/vtkPlane.h ; then
273           AC_MSG_RESULT(trying ${d})
274           VTKHOME="${d}"
275           break
276         fi
277         if test -f ${d}/include/vtk-5.0/vtkPlane.h ; then
278           AC_MSG_RESULT(trying ${d})
279           VTKHOME="${d}"
280           VTKSUFFIX="-5.0"
281           break
282         fi
283         if test -f ${d}/include/vtk-5.2/vtkPlane.h ; then
284           AC_MSG_RESULT(trying ${d})
285           VTKHOME="${d}"
286           VTKSUFFIX="-5.2"
287           break
288         fi
289         if test -f ${d}/include/vtk/vtkPlane.h ; then
290           AC_MSG_RESULT(trying ${d})
291           VTKHOME="${d}"
292           VTKSUFFIX=""
293           break
294         fi
295       done
296     fi
297   fi
298   
299   VTK_LOCAL_INCLUDES="-I$VTKHOME/include/vtk${VTKSUFFIX} $LOCAL_INCLUDES"
300   VTK_LOCAL_LIBS="-L$VTKHOME/lib${LIB_LOCATION_SUFFIX}/vtk${VTKSUFFIX} $LOCAL_LIBS"
301   VTK_TRY_LINK_LIBS="-L$VTKHOME/lib${LIB_LOCATION_SUFFIX} -L$VTKHOME/lib${LIB_LOCATION_SUFFIX}/vtk${VTKSUFFIX} $TRY_LINK_LIBS"
302   if test "x$VTKHOME" != "x/usr" ; then
303     VTK_LOCAL_LIBS="-L$VTKHOME/lib${LIB_LOCATION_SUFFIX}/vtk${VTKSUFFIX} $LOCAL_LIBS"
304   fi
305   
306   dnl vtk headers
307   CPPFLAGS_old="$CPPFLAGS"
308   CPPFLAGS="$CPPFLAGS $VTK_LOCAL_INCLUDES"
309   
310   AC_CHECK_HEADER(vtkPlane.h,vtk_ok="yes",vtk_ok="no")
311   
312   CPPFLAGS="$CPPFLAGS_old"
313   
314   if test "x$vtk_ok" = "xyes"; then
315   
316   #   VTK_INCLUDES="$LOCAL_INCLUDES"
317   
318      dnl vtk libraries
319   
320      AC_MSG_CHECKING(linking regular VTK library)
321   
322      LIBS_old="$LIBS"
323      LIBS="$LIBS $VTK_TRY_LINK_LIBS"
324      CPPFLAGS_old="$CPPFLAGS"
325      CPPFLAGS="$CPPFLAGS $VTK_LOCAL_INCLUDES"
326   
327      dnl VTKPY_MODULES="$VTKHOME/python"
328   
329      AC_CACHE_VAL(salome_cv_lib_vtk,[
330        AC_TRY_LINK([#include "vtkPlane.h"
331                    ],
332                  [vtkPlane::New()],
333                  [salome_cv_lib_vtk=yes],
334                  [salome_cv_lib_vtk=no])
335      ])
336      vtk_ok="$salome_cv_lib_vtk"
337      LIBS="$LIBS_old"
338      CPPFLAGS="$CPPFLAGS_old"
339      AC_MSG_RESULT($vtk_ok)
340   fi
341   
342   VTKVERSION=" Undefined"
343   if test "x$vtk_ok" = "xyes"; then
344      AC_MSG_CHECKING(VTK version)
345      VTKVERSION=`grep VTK_VERSION $VTKHOME/include/vtk${VTKSUFFIX}/vtkConfigure.h`
346      AC_MSG_RESULT(${VTKVERSION:20:10})
347   fi
348 fi
349
350 dnl Select either of VTKs
351 if  test "x$pv_vtk_ok" = "xyes" ; then
352   if test "x$vtk_ok" = "xyes" ; then
353      if test "$VTKVERSION" \> "$PVVTKVERSION" ; then
354        AC_MSG_RESULT([VTK from ParaView is older, ignored])
355        pv_vtk_ok=no
356      else
357        AC_MSG_RESULT([regular VTK is older, ignored])
358        vtk_ok=no
359      fi
360   fi
361 fi  
362
363 if  test "x$pv_vtk_ok" = "xyes" ; then
364   AC_MSG_RESULT(for VTK: yes)
365   VTK_INCLUDES="$PV_LOCAL_INCLUDES -DVTK_EXCLUDE_STRSTREAM_HEADERS"
366   VTK_LIBS="$PV_LOCAL_LIBS"
367   VTK_MT_LIBS="$VTK_LIBS"
368   #VTKPY_MODULES=
369   vtk_ok=yes
370 else
371     if  test "x$vtk_ok" = "xyes" ; then
372       AC_MSG_RESULT(for VTK: yes)
373       VTK_INCLUDES="$VTK_LOCAL_INCLUDES -DVTK_EXCLUDE_STRSTREAM_HEADERS"
374       VTK_LIBS="$VTK_LOCAL_LIBS"
375       VTK_MT_LIBS="$VTK_LIBS"
376       #VTKPY_MODULES=
377     else
378       AC_MSG_RESULT(for VTK: no)
379       AC_MSG_WARN(unable to link with vtk library)
380     fi
381 fi
382
383 AC_LANG_RESTORE
384
385 # Save cache
386 AC_CACHE_SAVE
387
388 ])dnl