Salome HOME
In openmpi need to link with libmpi_cxx and libmpi.so
[modules/kernel.git] / salome_adm / unix / config_files / check_vtk.m4
1 dnl Copyright (C) 2007-2011  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     ls -1d $PVHOME/include/paraview-* > /dev/null 2>&1
177     if test $? = 0 ; then
178       nb=$(ls -1d $PVHOME/include/paraview-* | wc -l)
179       if test $nb = 1 ; then
180         d=$(ls -1d $PVHOME/include/paraview-*)
181         PVVERSION=$(echo $d | awk -F "-" '{print $(NF)}')
182       fi
183     fi
184   fi
185   if test "x$PVVERSION" = "x" ; then
186     PVVERSION=`basename $PVHOME | sed -e "s,[[^-]]*,,"`
187   else
188     if test "${PVVERSION:0:1}" != "-" ; then
189       PVVERSION="-$PVVERSION"
190     fi
191   fi
192
193   AC_CHECKING(for VTK from ParaView)
194
195   PV_LOCAL_INCLUDES="-I$PVHOME/include/paraview$PVVERSION $LOCAL_INCLUDES"
196   PV_LOCAL_LIBS="-L$PVHOME/lib/paraview$PVVERSION -lvtksys -lvtkzlib -lvtkpng -lvtkjpeg -lvtktiff -lvtkexpat -lvtksqlite -lvtkmetaio -lvtkverdict -lvtkNetCDF -lvtkDICOMParser -lvtkfreetype -lvtkftgl -lvtkexoIIc $LOCAL_LIBS"
197   PV_TRY_LINK_LIBS="-L$PVHOME/lib/paraview$PVVERSION -lvtksys $TRY_LINK_LIBS"
198
199   dnl vtk headers
200   CPPFLAGS_old="$CPPFLAGS"
201   CPPFLAGS="$CPPFLAGS $PV_LOCAL_INCLUDES"
202   
203   AC_CHECK_HEADER(vtkPoints.h,pv_vtk_ok="yes",pv_vtk_ok="no")
204   
205   CPPFLAGS="$CPPFLAGS_old"
206   
207   if test "x$pv_vtk_ok" = "xyes"; then
208
209      dnl vtk libraries
210   
211      AC_MSG_CHECKING(linking VTK library from ParaView)
212   
213      LIBS_old="$LIBS"
214      LIBS="$LIBS $PV_TRY_LINK_LIBS"
215      CPPFLAGS_old="$CPPFLAGS"
216      CPPFLAGS="$CPPFLAGS $PV_LOCAL_INCLUDES"
217   
218      AC_CACHE_VAL(salome_cv_lib_pvvtk,[
219        AC_TRY_LINK([#include "vtkPoints.h"
220                    ],
221                  [vtkPoints::New()],
222                  [salome_cv_lib_pvvtk=yes],
223                  [salome_cv_lib_pvvtk=no])
224      ])
225      pv_vtk_ok="$salome_cv_lib_pvvtk"
226      LIBS="$LIBS_old"
227      CPPFLAGS="$CPPFLAGS_old"
228      AC_MSG_RESULT($pv_vtk_ok)
229   fi
230
231   dnl Find out version of VTK from ParaView
232   PVVTKVERSION=" Undefined"
233   if test "x$pv_vtk_ok" = "xyes"; then
234      AC_MSG_CHECKING(VTK version)
235      PVVTKVERSION=`grep VTK_VERSION $PVHOME/include/paraview$PVVERSION/vtkConfigure.h`
236      AC_MSG_RESULT(${PVVTKVERSION:20:10})
237   fi
238 fi
239
240 dnl
241 dnl Use regular VTK if no ParaView found or a newer version is provided via --with-vtk
242 dnl 
243
244 try_regular_vtk=no
245 if test "$pv_vtk_ok" = "no"; then
246   try_regular_vtk=yes
247 fi
248
249 if test -z $with_vtk ; then
250   with_vtk=""
251 fi
252 case "x$with_vtk" in
253   xyes)
254     dnl in case user wrote --with-vtk=yes
255     with_vtk=""
256     ;;
257   xno)
258     dnl in case user wrote --with-vtk=no
259     with_vtk=""
260     AC_MSG_WARN(Value "no", specified for option --with-vtk, is not supported)
261     ;;
262   x)
263     ;;
264   *)
265     try_regular_vtk=yes
266     ;;
267 esac
268
269 if test "$try_regular_vtk" = "yes"; then
270
271   dnl Check regular VTK installation
272   AC_CHECKING(for regular VTK)
273   
274   dnl VTK install dir
275
276   if test "x$with_vtk" != "x" ; then
277     VTKHOME="$with_vtk"
278   else
279     if test -z $VTKHOME ; then
280       AC_MSG_WARN(undefined VTKHOME variable which specify where vtk was compiled)
281       for d in /usr/local /usr ; do
282         if test -f ${d}/include/vtk${VTKSUFFIX}/vtkPlane.h ; then
283           AC_MSG_RESULT(trying ${d})
284           VTKHOME="${d}"
285           break
286         fi
287         if test -f ${d}/include/vtk-5.0/vtkPlane.h ; then
288           AC_MSG_RESULT(trying ${d})
289           VTKHOME="${d}"
290           VTKSUFFIX="-5.0"
291           break
292         fi
293         if test -f ${d}/include/vtk-5.2/vtkPlane.h ; then
294           AC_MSG_RESULT(trying ${d})
295           VTKHOME="${d}"
296           VTKSUFFIX="-5.2"
297           break
298         fi
299         if test -f ${d}/include/vtk/vtkPlane.h ; then
300           AC_MSG_RESULT(trying ${d})
301           VTKHOME="${d}"
302           VTKSUFFIX=""
303           break
304         fi
305       done
306     fi
307   fi
308   
309   VTK_LOCAL_INCLUDES="-I$VTKHOME/include/vtk${VTKSUFFIX} $LOCAL_INCLUDES"
310   VTK_LOCAL_LIBS="-L$VTKHOME/lib${LIB_LOCATION_SUFFIX}/vtk${VTKSUFFIX} $LOCAL_LIBS"
311   VTK_TRY_LINK_LIBS="-L$VTKHOME/lib${LIB_LOCATION_SUFFIX} -L$VTKHOME/lib${LIB_LOCATION_SUFFIX}/vtk${VTKSUFFIX} $TRY_LINK_LIBS"
312   if test "x$VTKHOME" != "x/usr" ; then
313     VTK_LOCAL_LIBS="-L$VTKHOME/lib${LIB_LOCATION_SUFFIX}/vtk${VTKSUFFIX} $LOCAL_LIBS"
314   fi
315   
316   dnl vtk headers
317   CPPFLAGS_old="$CPPFLAGS"
318   CPPFLAGS="$CPPFLAGS $VTK_LOCAL_INCLUDES"
319   
320   AC_CHECK_HEADER(vtkPlane.h,vtk_ok="yes",vtk_ok="no")
321   
322   CPPFLAGS="$CPPFLAGS_old"
323   
324   if test "x$vtk_ok" = "xyes"; then
325   
326   #   VTK_INCLUDES="$LOCAL_INCLUDES"
327   
328      dnl vtk libraries
329   
330      AC_MSG_CHECKING(linking regular VTK library)
331   
332      LIBS_old="$LIBS"
333      LIBS="$LIBS $VTK_TRY_LINK_LIBS"
334      CPPFLAGS_old="$CPPFLAGS"
335      CPPFLAGS="$CPPFLAGS $VTK_LOCAL_INCLUDES"
336   
337      dnl VTKPY_MODULES="$VTKHOME/python"
338   
339      AC_CACHE_VAL(salome_cv_lib_vtk,[
340        AC_TRY_LINK([#include "vtkPlane.h"
341                    ],
342                  [vtkPlane::New()],
343                  [salome_cv_lib_vtk=yes],
344                  [salome_cv_lib_vtk=no])
345      ])
346      vtk_ok="$salome_cv_lib_vtk"
347      LIBS="$LIBS_old"
348      CPPFLAGS="$CPPFLAGS_old"
349      AC_MSG_RESULT($vtk_ok)
350   fi
351   
352   VTKVERSION=" Undefined"
353   if test "x$vtk_ok" = "xyes"; then
354      AC_MSG_CHECKING(VTK version)
355      VTKVERSION=`grep VTK_VERSION $VTKHOME/include/vtk${VTKSUFFIX}/vtkConfigure.h`
356      AC_MSG_RESULT(${VTKVERSION:20:10})
357   fi
358 fi
359
360 dnl Select either of VTKs
361 if  test "x$pv_vtk_ok" = "xyes" ; then
362   if test "x$vtk_ok" = "xyes" ; then
363      if test "$VTKVERSION" \> "$PVVTKVERSION" ; then
364        AC_MSG_RESULT([VTK from ParaView is older, ignored])
365        pv_vtk_ok=no
366      else
367        AC_MSG_RESULT([regular VTK is older, ignored])
368        vtk_ok=no
369      fi
370   fi
371 fi  
372
373 if  test "x$pv_vtk_ok" = "xyes" ; then
374   AC_MSG_RESULT(for VTK: yes)
375   VTK_INCLUDES="$PV_LOCAL_INCLUDES -DVTK_EXCLUDE_STRSTREAM_HEADERS"
376   VTK_LIBS="$PV_LOCAL_LIBS"
377   VTK_MT_LIBS="$VTK_LIBS"
378   #VTKPY_MODULES=
379   vtk_ok=yes
380 else
381     if  test "x$vtk_ok" = "xyes" ; then
382       AC_MSG_RESULT(for VTK: yes)
383       VTK_INCLUDES="$VTK_LOCAL_INCLUDES -DVTK_EXCLUDE_STRSTREAM_HEADERS"
384       VTK_LIBS="$VTK_LOCAL_LIBS"
385       VTK_MT_LIBS="$VTK_LIBS"
386       #VTKPY_MODULES=
387     else
388       AC_MSG_RESULT(for VTK: no)
389       AC_MSG_WARN(unable to link with vtk library)
390     fi
391 fi
392
393 AC_LANG_RESTORE
394
395 # Save cache
396 AC_CACHE_SAVE
397
398 ])dnl