Salome HOME
Copyright update 2022
[tools/configuration.git] / autotools / m4 / check_vtk.m4
1 dnl Copyright (C) 2007-2022  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, or (at your option) any later version.
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(VTK_SUFFIX)
59
60 VTK_INCLUDES=""
61 VTK_LIBS=""
62 VTK_SUFFIX=""
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 dnl VTK version suffix
89 if test -z $vtk_suffix ; then
90   vtk_suffix="yes"
91 fi
92 if test "x$vtk_suffix" = "xno" ; then
93   dnl in case user wrote --with-vtk-version=no, use empty suffix
94   vtk_suffix=""
95 fi
96 if test "x$vtk_suffix" != "xyes" ; then
97   VTKSUFFIX="$vtk_suffix"
98 else
99   dnl in case user wrote --with-vtk-version=yes, get the suffix from env
100   if test -z $VTKSUFFIX ; then
101     VTKSUFFIX="-6.0"
102   fi
103 fi
104
105 dnl
106 dnl Use VTK from ParaView unless --with-paraview=no is given
107 dnl
108
109 pv_vtk_ok=no
110
111 case "x$with_paraview" in
112
113   xno )
114     PVHOME=""
115     ;;
116
117   xyes | x )
118   
119     if test -z $PVHOME ; then
120       AC_PATH_PROG(para_path, paraview)
121       if test "x$para_path" != "x" ; then
122          para_path=`dirname $para_path`
123          PVHOME=`dirname $para_path`
124       else
125         for d in /usr/local /usr ; do
126           if test -f ${d}/include/paraview${PVVERSION}/pqDialog.h ; then
127             AC_MSG_RESULT(trying ${d})
128             PVHOME="${d}"
129             break
130           fi
131           for suffix in 3.98 4.0; do
132             if test -f ${d}/include/paraview-${suffix}/pqDialog.h ; then
133               AC_MSG_RESULT(trying ${d})
134               PVHOME="${d}"
135               PVVERSION="-${suffix}"
136               break
137             fi
138           done
139           if test "x${PVHOME}" != "x" ; then break ; fi
140           if test -f ${d}/include/paraview/pqDialog.h ; then
141             AC_MSG_RESULT(trying ${d})
142             PVHOME="${d}"
143             PVVERSION=""
144             break
145           fi
146         done
147       fi
148     fi
149     ;;
150
151   * )
152     PVHOME=${with_paraview}
153     ;;
154 esac
155
156 dnl Check VTK from ParaView.
157
158 if test "x$PVHOME" != "x" ; then
159
160   if test "x$PVVERSION" = "x" ; then
161     for suffix in 3.98 4.0; do
162       if test -f $PVHOME/include/paraview-$suffix/vtkPVConfig.h ; then
163         PVVERSION=$suffix
164         break;
165       fi
166     done
167   fi    
168   if test "x$PVVERSION" = "x" ; then
169     ls -1d $PVHOME/include/paraview-* > /dev/null 2>&1
170     if test $? = 0 ; then
171       nb=$(ls -1d $PVHOME/include/paraview-* | wc -l)
172       if test $nb = 1 ; then
173         d=$(ls -1d $PVHOME/include/paraview-*)
174         PVVERSION=$(echo $d | awk -F "-" '{print $(NF)}')
175       fi
176     fi
177   fi
178   if test "x$PVVERSION" = "x" ; then
179     PVVERSION=`basename $PVHOME | sed -e "s,[[^-]]*,,"`
180   else
181     if test "${PVVERSION:0:1}" != "-" ; then
182       PVVERSION="-$PVVERSION"
183     fi
184   fi
185
186   AC_CHECKING(for VTK from ParaView)
187
188   PV_LOCAL_INCLUDES="-I$PVHOME/include/paraview$PVVERSION $OGL_INCLUDES"
189
190   dnl vtk headers
191   CPPFLAGS_old="$CPPFLAGS"
192   CPPFLAGS="$CPPFLAGS $PV_LOCAL_INCLUDES"
193   
194   AC_CHECK_HEADER(vtkPoints.h,pv_vtk_ok="yes",pv_vtk_ok="no")
195   
196   CPPFLAGS="$CPPFLAGS_old"
197   
198   if test "x$pv_vtk_ok" = "xyes"; then
199
200      dnl vtk libraries
201   
202      AC_MSG_CHECKING(linking VTK library from ParaView)
203   
204      LIBS_old="$LIBS"
205      CPPFLAGS_old="$CPPFLAGS"
206
207      CPPFLAGS="$CPPFLAGS $PV_LOCAL_INCLUDES"
208
209      dnl - try libs without suffix
210
211      PV_LOCAL_LIBS="-L$PVHOME/lib/paraview$PVVERSION -lvtksys -lvtkmetaio -lvtkverdict -lvtkNetCDF -lvtkDICOMParser -lvtkftgl -lvtkexoIIc -lvtkCommonCore -lvtkCommonDataModel -lvtkCommonExecutionModel -lvtkFiltersFlowPaths -lvtkFiltersParallel -lvtkFiltersVerdict -lvtkInteractionStyle -lvtkInteractionWidgets -lvtkIOExport -lvtkIOXML -lvtkRenderingAnnotation -lvtkRenderingCore -lvtkRenderingFreeType -lvtkRenderingFreeTypeOpenGL -lvtkRenderingLabel -lvtkRenderingLOD -lvtkRenderingOpenGL -lvtkRenderingMatplotlib $LXLIB -lX11 -lXt"
212      PV_TRY_LINK_LIBS="-L$PVHOME/lib/paraview$PVVERSION -lvtksys -lvtkCommonCore $LXLIB -lX11 -lXt"
213
214      LIBS="${LIBS_old} $PV_TRY_LINK_LIBS"
215   
216 #     AC_CACHE_VAL(salome_cv_lib_pvvtk,[
217        AC_TRY_LINK([#include "vtkPoints.h"
218                    ],
219                  [vtkPoints::New()],
220                  [salome_cv_lib_pvvtk=yes],
221                  [salome_cv_lib_pvvtk=no])
222 #     ])
223
224      if test "x$salome_cv_lib_pvvtk" != "yes" -a "x$PVVERSION" != "x" ; then
225          dnl - try libs with suffix
226          VTK_SUFFIX="-pv${PVVERSION:1:10}"
227          PV_LOCAL_LIBS="-L$PVHOME/lib/paraview$PVVERSION -lvtksys${VTK_SUFFIX} -lvtkmetaio${VTK_SUFFIX} -lvtkverdict${VTK_SUFFIX} -lvtkNetCDF${VTK_SUFFIX} -lvtkDICOMParser${VTK_SUFFIX} -lvtkftgl${VTK_SUFFIX} -lvtkexoIIc${VTK_SUFFIX} -lvtkCommonCore${VTK_SUFFIX} -lvtkCommonDataModel${VTK_SUFFIX} -lvtkCommonExecutionModel${VTK_SUFFIX} -lvtkFiltersFlowPaths${VTK_SUFFIX} -lvtkFiltersParallel${VTK_SUFFIX} -lvtkFiltersVerdict${VTK_SUFFIX} -lvtkInteractionStyle${VTK_SUFFIX} -lvtkInteractionWidgets${VTK_SUFFIX} -lvtkIOExport${VTK_SUFFIX} -lvtkIOXML${VTK_SUFFIX} -lvtkRenderingAnnotation${VTK_SUFFIX} -lvtkRenderingCore${VTK_SUFFIX} -lvtkRenderingFreeType${VTK_SUFFIX} -lvtkRenderingFreeTypeOpenGL${VTK_SUFFIX} -lvtkRenderingLabel${VTK_SUFFIX} -lvtkRenderingLOD${VTK_SUFFIX} -lvtkRenderingOpenGL${VTK_SUFFIX} -lvtkRenderingMatplotlib${VTK_SUFFIX} $LXLIB -lX11 -lXt"
228          PV_TRY_LINK_LIBS="-L$PVHOME/lib/paraview$PVVERSION -lvtksys${VTK_SUFFIX} -lvtkCommonCore${VTK_SUFFIX} $LXLIB -lX11 -lXt"
229
230          LIBS="${LIBS_old} $PV_TRY_LINK_LIBS"
231   
232 #         AC_CACHE_VAL(salome_cv_lib_pvvtk,[
233            AC_TRY_LINK([#include "vtkPoints.h"
234                        ],
235                      [vtkPoints::New()],
236                      [salome_cv_lib_pvvtk=yes],
237                      [salome_cv_lib_pvvtk=no])
238 #         ])
239      fi
240
241      pv_vtk_ok="$salome_cv_lib_pvvtk"
242
243      LIBS="$LIBS_old"
244      CPPFLAGS="$CPPFLAGS_old"
245      AC_MSG_RESULT($pv_vtk_ok)
246   fi
247
248   dnl Find out version of VTK from ParaView
249   PVVTKVERSION=" Undefined"
250   if test "x$pv_vtk_ok" = "xyes"; then
251      AC_MSG_CHECKING(VTK version)
252      PVVTKVERSION=`grep VTK_VERSION $PVHOME/include/paraview$PVVERSION/vtkConfigure.h`
253      AC_MSG_RESULT(${PVVTKVERSION:20:10})
254   fi
255 fi
256
257 dnl
258 dnl Use regular VTK if no ParaView found or a newer version is provided via --with-vtk
259 dnl 
260
261 try_regular_vtk=no
262 if test "$pv_vtk_ok" = "no"; then
263   try_regular_vtk=yes
264 fi
265
266 if test -z $with_vtk ; then
267   with_vtk=""
268 fi
269 case "x$with_vtk" in
270   xyes)
271     dnl in case user wrote --with-vtk=yes
272     with_vtk=""
273     ;;
274   xno)
275     dnl in case user wrote --with-vtk=no
276     with_vtk=""
277     AC_MSG_WARN(Value "no", specified for option --with-vtk, is not supported)
278     ;;
279   x)
280     ;;
281   *)
282     try_regular_vtk=yes
283     ;;
284 esac
285
286 if test "$try_regular_vtk" = "yes"; then
287
288   dnl Check regular VTK installation
289   AC_CHECKING(for regular VTK)
290   
291   dnl VTK install dir
292
293   if test "x$with_vtk" != "x" ; then
294     VTKHOME="$with_vtk"
295   else
296     if test -z $VTKHOME ; then
297       AC_MSG_WARN(undefined VTKHOME variable which specify where vtk was compiled)
298       for d in /usr/local /usr ; do
299         if test -f ${d}/include/vtk${VTKSUFFIX}/vtkPlane.h ; then
300           AC_MSG_RESULT(trying ${d})
301           VTKHOME="${d}"
302           break
303         fi
304         for suffix in 5.8 5.9 6.0 ; do
305           if test -f ${d}/include/vtk-${suffix}/vtkPlane.h ; then
306             AC_MSG_RESULT(trying ${d})
307             VTKHOME="${d}"
308             VTKSUFFIX="-${suffix}"
309             break
310           fi
311         done
312         if test "x${VTKHOME}" != "x" ; then break ; fi
313         if test -f ${d}/include/vtk/vtkPlane.h ; then
314           AC_MSG_RESULT(trying ${d})
315           VTKHOME="${d}"
316           VTKSUFFIX=""
317           break
318         fi
319       done
320     fi
321   fi
322   
323   # VSR: is it necessary to check with suffix as for ParaView?
324   
325   VTK_LOCAL_INCLUDES="-I$VTKHOME/include/vtk${VTKSUFFIX} $OGL_INCLUDES"
326   VTK_LOCAL_LIBS="-L$VTKHOME/lib${LIB_LOCATION_SUFFIX}/vtk${VTKSUFFIX} -lvtkCommonCore -lvtkCommonDataModel -lvtkCommonExecutionModel -lvtkFiltersFlowPaths -lvtkFiltersParallel -lvtkFiltersVerdict -lvtkInteractionStyle -lvtkInteractionWidgets -lvtkIOExport -lvtkIOXML -lvtkRenderingAnnotation -lvtkRenderingCore -lvtkRenderingFreeType -lvtkRenderingFreeTypeOpenGL -lvtkRenderingLabel -lvtkRenderingLOD -lvtkRenderingOpenGL -lvtkRenderingMatplotlib $LXLIB -lX11 -lXt"
327   VTK_TRY_LINK_LIBS="-L$VTKHOME/lib${LIB_LOCATION_SUFFIX} -L$VTKHOME/lib${LIB_LOCATION_SUFFIX}/vtk${VTKSUFFIX} -lvtkCommonCore $LXLIB -lX11 -lXt"
328   
329   dnl vtk headers
330   CPPFLAGS_old="$CPPFLAGS"
331   CPPFLAGS="$CPPFLAGS $VTK_LOCAL_INCLUDES"
332   
333   AC_CHECK_HEADER(vtkPlane.h,vtk_ok="yes",vtk_ok="no")
334   
335   CPPFLAGS="$CPPFLAGS_old"
336   
337   if test "x$vtk_ok" = "xyes"; then
338   
339   #   VTK_INCLUDES="$OGL_INCLUDES"
340   
341      dnl vtk libraries
342   
343      AC_MSG_CHECKING(linking regular VTK library)
344   
345      LIBS_old="$LIBS"
346      LIBS="$LIBS $VTK_TRY_LINK_LIBS"
347      CPPFLAGS_old="$CPPFLAGS"
348      CPPFLAGS="$CPPFLAGS $VTK_LOCAL_INCLUDES"
349   
350      AC_CACHE_VAL(salome_cv_lib_vtk,[
351        AC_TRY_LINK([#include "vtkPlane.h"
352                    ],
353                  [vtkPlane::New()],
354                  [salome_cv_lib_vtk=yes],
355                  [salome_cv_lib_vtk=no])
356      ])
357      vtk_ok="$salome_cv_lib_vtk"
358      LIBS="$LIBS_old"
359      CPPFLAGS="$CPPFLAGS_old"
360      AC_MSG_RESULT($vtk_ok)
361   fi
362   
363   VTKVERSION=" Undefined"
364   if test "x$vtk_ok" = "xyes"; then
365      AC_MSG_CHECKING(VTK version)
366      VTKVERSION=`grep VTK_VERSION $VTKHOME/include/vtk${VTKSUFFIX}/vtkConfigure.h`
367      AC_MSG_RESULT(${VTKVERSION:20:10})
368   fi
369 fi
370
371 dnl Select either of VTKs
372 if  test "x$pv_vtk_ok" = "xyes" ; then
373   if test "x$vtk_ok" = "xyes" ; then
374      if test "$VTKVERSION" \> "$PVVTKVERSION" ; then
375        AC_MSG_RESULT([VTK from ParaView is older, ignored])
376        pv_vtk_ok=no
377      else
378        AC_MSG_RESULT([regular VTK is older, ignored])
379        vtk_ok=no
380      fi
381   fi
382 fi  
383
384 if  test "x$pv_vtk_ok" = "xyes" ; then
385   AC_MSG_RESULT(for VTK: yes)
386   VTK_INCLUDES="$PV_LOCAL_INCLUDES -DVTK_EXCLUDE_STRSTREAM_HEADERS"
387   VTK_LIBS="$PV_LOCAL_LIBS"
388   vtk_ok=yes
389 else
390     if  test "x$vtk_ok" = "xyes" ; then
391       AC_MSG_RESULT(for VTK: yes)
392       VTK_INCLUDES="$VTK_LOCAL_INCLUDES -DVTK_EXCLUDE_STRSTREAM_HEADERS"
393       VTK_LIBS="$VTK_LOCAL_LIBS"
394     else
395       AC_MSG_RESULT(for VTK: no)
396       AC_MSG_WARN(unable to link with vtk library)
397     fi
398 fi
399
400 AC_LANG_RESTORE
401
402 # Save cache
403 AC_CACHE_SAVE
404
405 ])dnl
406
407
408 dnl
409 dnl  CHECK_PYVTK (Python wrappings for VTK)
410 dnl  ------------------------------------------------------------------------
411 dnl
412 AC_DEFUN([CHECK_PYVTK], [
413 AC_REQUIRE([AC_PROG_CC])dnl
414 AC_REQUIRE([AC_PROG_CXX])dnl
415 AC_REQUIRE([AC_PROG_CPP])dnl
416 AC_REQUIRE([AC_PROG_CXXCPP])dnl
417 AC_REQUIRE([AC_LINKER_OPTIONS])dnl
418 AC_REQUIRE([CHECK_VTK])dnl
419 AC_REQUIRE([CHECK_PYTHON])dnl
420
421 AC_LANG_SAVE
422 AC_LANG_CPLUSPLUS
423
424 AC_SUBST(VTK_PYLIBS)
425 VTK_PYLIBS=""
426
427 if test "x$vtk_ok" != "x" ; then
428     PYVERSION=`echo ${PYTHON_VERSION} | sed -e "s%\.%%g"`
429     VTK_PYLIBS="-lvtkWrappingPython${PYVERSION}${VTK_SUFFIX}"
430 fi
431
432 AC_LANG_RESTORE
433
434 # Save cache
435 AC_CACHE_SAVE
436
437 ])dnl
438