Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/gui.git] / adm_local / unix / config_files / check_opengl.m4
1 dnl  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 dnl  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
3 dnl 
4 dnl  This library is free software; you can redistribute it and/or 
5 dnl  modify it under the terms of the GNU Lesser General Public 
6 dnl  License as published by the Free Software Foundation; either 
7 dnl  version 2.1 of the License. 
8 dnl 
9 dnl  This library is distributed in the hope that it will be useful, 
10 dnl  but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 dnl  Lesser General Public License for more details. 
13 dnl 
14 dnl  You should have received a copy of the GNU Lesser General Public 
15 dnl  License along with this library; if not, write to the Free Software 
16 dnl  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
17 dnl 
18 dnl  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
19 dnl
20 dnl
21 dnl
22 AC_DEFUN([CHECK_OPENGL],[
23 AC_REQUIRE([AC_PROG_CC])dnl
24 AC_REQUIRE([AC_PROG_CPP])dnl
25 AC_REQUIRE([AC_LINKER_OPTIONS])dnl
26
27 AC_LANG_SAVE
28 AC_LANG_CPLUSPLUS
29
30 AC_ARG_WITH(opengl,
31   [AC_HELP_STRING([--with-opengl=DIR],[root directory path of OpenGL installation])],
32   [opengl_dir="$withval"], 
33   [dirs="/usr/lib${LIB_LOCATION_SUFFIX} /usr/local/lib${LIB_LOCATION_SUFFIX} /opt/graphics/OpenGL/lib${LIB_LOCATION_SUFFIX} /usr/openwin/lib${LIB_LOCATION_SUFFIX} /usr/X11R6/lib${LIB_LOCATION_SUFFIX}"])dnl
34
35 AC_CHECKING(for OpenGL)
36 AC_CHECKING(for OpenGL headers)
37
38 OGL_INCLUDES=""
39 OGL_LIBS=""
40
41 GL_LIB_PATH=""
42 GLU_LIB_PATH=""
43
44 OpenGL_ok=no
45 OpenGL_libs_ok=no
46 OpenGL_headers_ok=no
47
48 dnl openGL headers
49 # by default
50 if test "x${opengl_dir}" != "x" ; then
51   AC_MSG_RESULT(for opengl_dir: $opengl_dir)
52   AC_CHECK_HEADER([${opengl_dir}/include/GL/gl.h],
53                   [OpenGL_headers_ok=yes; OGL_INCLUDES="-I${opengl_dir}/include"],
54                   [OpenGL_headers_ok=no])
55   if test "x${OpenGL_headers_ok}" = "xyes" ; then
56     AC_CHECKING(for default OpenGL library)
57     if test "x${opengl_dir}" = "x/usr" ; then
58       OGL_LIBS=""
59     else
60       OGL_LIBS="-L${opengl_dir}/lib"
61     fi
62     LDFLAGS_old="$LDFLAGS"
63     LDFLAGS="$LDFLAGS $OGL_LIBS"
64     AC_CHECK_LIB([GL],
65                  [glBegin],
66                  [OpenGL_libs_ok=yes],
67                  [OpenGL_libs_ok=no])
68     if test "x${OpenGL_libs_ok}" = "xyes" ; then
69       AC_TRY_LINK([],
70                   [],
71                   [OpenGL_libs_ok=yes ; OpenGL_ok=yes; OGL_LIBS="$OGL_LIBS -lGL"],
72                   [OpenGL_libs_ok=no])
73     fi
74     LDFLAGS="$LDFLAGS_old"
75   fi
76 fi
77
78 if test "x${OpenGL_headers_ok}" = "xno" ; then
79   AC_CHECK_HEADER(GL/gl.h,
80                   [OpenGL_headers_ok=yes],
81                   [OpenGL_headers_ok=no])
82 fi
83
84 # under SunOS ?
85 if test "x${OpenGL_headers_ok}" = "xno" ; then
86   AC_CHECK_HEADERS(/usr/openwin/share/include/GL/glxmd.h,
87                   [OpenGL_headers_ok=yes; OGL_INCLUDES="-I/usr/openwin/share/include/"],
88                   [OpenGL_headers_ok=no])
89 fi
90
91 # under IRIX ?
92 if test "x${OpenGL_headers_ok}" = "xno" ; then
93   AC_CHECK_HEADERS(/opt/graphics/OpenGL/include/GL/glxmd.h,
94                   [OpenGL_headers_ok=yes; OGL_INCLUDES="-I/opt/graphics/OpenGL/include"],
95                   [OpenGL_headers_ok=no])
96 fi
97
98 # some linux OpenGL servers hide the includes in /usr/X11R6/include/GL
99 if test "x${OpenGL_headers_ok}" = "xno" ; then
100   AC_CHECK_HEADERS(/usr/X11R6/include/GL/gl.h,
101                   [OpenGL_headers_ok=yes; OGL_INCLUDES="-I/usr/X11R6/include"],
102                   [OpenGL_headers_ok=no])
103 fi
104
105 if test "x${OpenGL_headers_ok}" = "xyes" ; then
106   AC_CHECKING(for OpenGL library)
107   for idir in $dirs; do
108     if test -r "${idir}/libGL.so"; then
109       AC_MSG_RESULT(in ${idir})
110       if test "x${idir}" = "x/usr/lib${LIB_LOCATION_SUFFIX}" ; then
111         GL_LIB_PATH=""
112       else
113         GL_LIB_PATH="-L${idir}"
114       fi
115       break
116     fi
117     # under IRIX ?
118     if test -r "${idir}/libGL.sl"; then
119       AC_MSG_RESULT(in ${idir})
120       if test "x${idir}" = "x/usr/lib${LIB_LOCATION_SUFFIX}" ; then
121         GL_LIB_PATH=""
122       else
123         GL_LIB_PATH="-L${idir}"
124       fi
125       break
126     fi
127   done
128   LDFLAGS_old="${LDFLAGS}"
129   LDFLAGS="${LDFLAGS} ${GL_LIB_PATH}"
130   AC_CHECK_LIB([GL],
131                [glBegin],
132                [OpenGL_libs_ok=yes],
133                [OpenGL_libs_ok=no])
134   if test "x${OpenGL_libs_ok}" = "xyes" ; then
135     AC_TRY_LINK([],
136                 [],
137                 [OpenGL_libs_ok=yes ; OGL_LIBS="${OGL_LIBS} ${GL_LIB_PATH} -lGL"],
138                 [OpenGL_libs_ok=no])
139   fi
140   LDFLAGS="$LDFLAGS_old"
141 fi
142
143 if test "x${OpenGL_libs_ok}" = "xyes" ; then
144   for idir in $dirs; do
145     if test -r "${idir}/libGLU.so"; then
146       AC_MSG_RESULT(in ${idir})
147       if test "x${idir}" = "x/usr/lib${LIB_LOCATION_SUFFIX}" ; then
148         GLU_LIB_PATH=""
149       else
150         GLU_LIB_PATH="-L${idir}"
151       fi
152       break
153     fi
154     # under IRIX ?
155     if test -r "${idir}/libGLU.sl"; then
156       AC_MSG_RESULT(in ${idir})
157       if test "x${idir}" = "x/usr/lib${LIB_LOCATION_SUFFIX}" ; then
158         GLU_LIB_PATH=""
159       else
160         GLU_LIB_PATH="-L${idir}"
161       fi
162       break
163     fi
164   done
165
166   # workaround a problem with libGL library location
167   for idir in $dirs; do
168     if test -r "${idir}/libGLU.la"; then
169       GLU_LA_PATH="${idir}/libGLU.la"
170       GL_LA_PATH_TO_CHECK=`cat ${GLU_LA_PATH} | awk '{ for(i=1;i<NF;i++){ if(gsub("libGL.la","&",$i)>0) print $i } }'`
171       if test -z ${GL_LA_PATH_TO_CHECK} || test -r ${GL_LA_PATH_TO_CHECK}; then
172         # nothing to do
173         break
174       fi
175       for jdir in $dirs; do
176         if test -r "${jdir}/libGL.la"; then
177           GL_LA_PATH="${jdir}/libGL.la"
178           # copy the libGLU.la file and set correct libGL.la path in it
179           NEW_GLU_LA_PATH=${ROOT_BUILDDIR}
180           NEW_GLU_LA_FILE="${NEW_GLU_LA_PATH}/libGLU.la"
181           sed -e "s%${GL_LA_PATH_TO_CHECK}%${GL_LA_PATH}%" ${GLU_LA_PATH} > "${NEW_GLU_LA_FILE}"
182           chmod -f --reference=${GLU_LA_PATH} "${NEW_GLU_LA_FILE}"
183           # set a new libGLU.la path
184           GLU_LIB_PATH="-L${NEW_GLU_LA_PATH}"
185           # create a simbolic link to libGLU.so
186           for kdir in $dirs; do
187             if test -r "${kdir}/libGLU.so"; then
188               cp -fs "${kdir}/libGLU.so" "${NEW_GLU_LA_PATH}/libGLU.so"
189               break
190             fi
191           done
192           break
193         fi
194       done
195       break
196     fi
197   done
198
199   LDFLAGS_old="${LDFLAGS}"
200   LDFLAGS="${LDFLAGS} ${OGL_LIBS} ${GLU_LIB_PATH}"
201   AC_CHECK_LIB([GLU],
202                [gluBeginSurface],
203                [OpenGL_libs_ok=yes],
204                [OpenGL_libs_ok=no])
205   if test "x${OpenGL_libs_ok}" = "xyes" ; then
206     AC_TRY_LINK([],
207                 [],
208                 [OpenGL_libs_ok=yes ; OGL_LIBS="${OGL_LIBS} ${GLU_LIB_PATH} -lGLU"],
209                 [OpenGL_libs_ok=no])
210   fi
211   LDFLAGS="$LDFLAGS_old"
212 fi
213
214 if test "x${OpenGL_headers_ok}" = "xyes" ; then
215   if test "x${OpenGL_libs_ok}" = "xyes" ; then
216     OpenGL_ok=yes
217   fi
218 fi
219
220 AC_MSG_RESULT(for OpenGL_headers_ok: $OpenGL_headers_ok)
221 AC_MSG_RESULT(for OpenGL_libs_ok: $OpenGL_libs_ok)
222 AC_MSG_RESULT(for OpenGL_ok: $OpenGL_ok)
223
224 AC_SUBST(OGL_INCLUDES)
225 AC_SUBST(OGL_LIBS)
226
227 AC_LANG_RESTORE
228
229 ])dnl
230