Salome HOME
08e0adb3a31798ab2f33a78bf7cde491c6d4559f
[modules/gui.git] / adm_local / unix / config_files / check_opengl.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 AC_DEFUN([CHECK_OPENGL],[
24 AC_REQUIRE([AC_PROG_CC])dnl
25 AC_REQUIRE([AC_PROG_CPP])dnl
26 AC_REQUIRE([AC_LINKER_OPTIONS])dnl
27
28 AC_LANG_SAVE
29 AC_LANG_CPLUSPLUS
30
31 AC_ARG_WITH(opengl,
32   [AC_HELP_STRING([--with-opengl=DIR],[root directory path of OpenGL installation])],
33   [opengl_dir="$withval"], 
34   [dirs="/usr/lib64 /usr/lib /usr/local/lib64 /usr/local/lib /opt/graphics/OpenGL/lib64 /opt/graphics/OpenGL/lib /usr/openwin/lib64 /usr/openwin/lib /usr/X11R6/lib64 /usr/X11R6/lib"])dnl
35
36 AC_CHECKING(for OpenGL)
37 AC_CHECKING(for OpenGL headers)
38
39 OGL_INCLUDES=""
40 OGL_LIBS=""
41
42 GL_LIB_PATH=""
43 GLU_LIB_PATH=""
44
45 OpenGL_ok=no
46 OpenGL_libs_ok=no
47 OpenGL_headers_ok=no
48
49 dnl openGL headers
50 # by default
51 if test "x${opengl_dir}" != "x" ; then
52   AC_MSG_RESULT(for opengl_dir: $opengl_dir)
53   AC_CHECK_HEADER([${opengl_dir}/include/GL/gl.h],
54                   [OpenGL_headers_ok=yes; OGL_INCLUDES="-I${opengl_dir}/include"],
55                   [OpenGL_headers_ok=no])
56   if test "x${OpenGL_headers_ok}" = "xyes" ; then
57     AC_CHECKING(for default OpenGL library)
58     if test "x${opengl_dir}" = "x/usr" ; then
59       OGL_LIBS=""
60     else
61       OGL_LIBS="-L${opengl_dir}/lib"
62     fi
63     LDFLAGS_old="$LDFLAGS"
64     LDFLAGS="$LDFLAGS $OGL_LIBS"
65     AC_CHECK_LIB([GL],
66                  [glBegin],
67                  [OpenGL_libs_ok=yes],
68                  [OpenGL_libs_ok=no])
69     if test "x${OpenGL_libs_ok}" = "xyes" ; then
70       AC_TRY_LINK([],
71                   [],
72                   [OpenGL_libs_ok=yes ; OpenGL_ok=yes; OGL_LIBS="$OGL_LIBS -lGL"],
73                   [OpenGL_libs_ok=no])
74     fi
75     LDFLAGS="$LDFLAGS_old"
76   fi
77 fi
78
79 if test "x${OpenGL_headers_ok}" = "xno" ; then
80   AC_CHECK_HEADER(GL/gl.h,
81                   [OpenGL_headers_ok=yes],
82                   [OpenGL_headers_ok=no])
83 fi
84
85 # under SunOS ?
86 if test "x${OpenGL_headers_ok}" = "xno" ; then
87   AC_CHECK_HEADERS(/usr/openwin/share/include/GL/glxmd.h,
88                   [OpenGL_headers_ok=yes; OGL_INCLUDES="-I/usr/openwin/share/include/"],
89                   [OpenGL_headers_ok=no])
90 fi
91
92 # under IRIX ?
93 if test "x${OpenGL_headers_ok}" = "xno" ; then
94   AC_CHECK_HEADERS(/opt/graphics/OpenGL/include/GL/glxmd.h,
95                   [OpenGL_headers_ok=yes; OGL_INCLUDES="-I/opt/graphics/OpenGL/include"],
96                   [OpenGL_headers_ok=no])
97 fi
98
99 # some linux OpenGL servers hide the includes in /usr/X11R6/include/GL
100 if test "x${OpenGL_headers_ok}" = "xno" ; then
101   AC_CHECK_HEADERS(/usr/X11R6/include/GL/gl.h,
102                   [OpenGL_headers_ok=yes; OGL_INCLUDES="-I/usr/X11R6/include"],
103                   [OpenGL_headers_ok=no])
104 fi
105
106 if test "x${OpenGL_headers_ok}" = "xyes" ; then
107   AC_CHECKING(for OpenGL library)
108   for idir in $dirs; do
109     if test -r "${idir}/libGL.so"; then
110       AC_MSG_RESULT(in ${idir})
111       if test "x${idir}" = "x/usr/lib64" -o "x${idir}" = "x/usr/lib" ; then
112         GL_LIB_PATH=""
113       else
114         GL_LIB_PATH="-L${idir}"
115       fi
116       break
117     fi
118     # under IRIX ?
119     if test -r "${idir}/libGL.sl"; then
120       AC_MSG_RESULT(in ${idir})
121       if test "x${idir}" = "x/usr/lib64" -o "x${idir}" = "x/usr/lib" ; then
122         GL_LIB_PATH=""
123       else
124         GL_LIB_PATH="-L${idir}"
125       fi
126       break
127     fi
128   done
129   LDFLAGS_old="${LDFLAGS}"
130   LDFLAGS="${LDFLAGS} ${GL_LIB_PATH}"
131   AC_CHECK_LIB([GL],
132                [glBegin],
133                [OpenGL_libs_ok=yes],
134                [OpenGL_libs_ok=no])
135   if test "x${OpenGL_libs_ok}" = "xyes" ; then
136     AC_TRY_LINK([],
137                 [],
138                 [OpenGL_libs_ok=yes ; OGL_LIBS="${OGL_LIBS} ${GL_LIB_PATH} -lGL"],
139                 [OpenGL_libs_ok=no])
140   fi
141   LDFLAGS="$LDFLAGS_old"
142 fi
143
144 if test "x${OpenGL_libs_ok}" = "xyes" ; then
145   for idir in $dirs; do
146     if test -r "${idir}/libGLU.so"; then
147       AC_MSG_RESULT(in ${idir})
148       if test "x${idir}" = "x/usr/lib64" -o "x${idir}" = "x/usr/lib" ; then
149         GLU_LIB_PATH=""
150       else
151         GLU_LIB_PATH="-L${idir}"
152       fi
153       break
154     fi
155     # under IRIX ?
156     if test -r "${idir}/libGLU.sl"; then
157       AC_MSG_RESULT(in ${idir})
158       if test "x${idir}" = "x/usr/lib64" -o "x${idir}" = "x/usr/lib" ; then
159         GLU_LIB_PATH=""
160       else
161         GLU_LIB_PATH="-L${idir}"
162       fi
163       break
164     fi
165   done
166
167   # workaround a problem with libGL library location
168   for idir in $dirs; do
169     if test -r "${idir}/libGLU.la"; then
170       GLU_LA_PATH="${idir}/libGLU.la"
171       GL_LA_PATH_TO_CHECK=`cat ${GLU_LA_PATH} | awk '{ for(i=1;i<NF;i++){ if(gsub("libGL.la","&",$i)>0) print $i } }'`
172       if test -z ${GL_LA_PATH_TO_CHECK} || test -r ${GL_LA_PATH_TO_CHECK}; then
173         # nothing to do
174         break
175       fi
176       for jdir in $dirs; do
177         if test -r "${jdir}/libGL.la"; then
178           GL_LA_PATH="${jdir}/libGL.la"
179           # copy the libGLU.la file and set correct libGL.la path in it
180           NEW_GLU_LA_PATH=${ROOT_BUILDDIR}
181           NEW_GLU_LA_FILE="${NEW_GLU_LA_PATH}/libGLU.la"
182           sed -e "s%${GL_LA_PATH_TO_CHECK}%${GL_LA_PATH}%" ${GLU_LA_PATH} > "${NEW_GLU_LA_FILE}"
183           chmod -f --reference=${GLU_LA_PATH} "${NEW_GLU_LA_FILE}"
184           # set a new libGLU.la path
185           GLU_LIB_PATH="-L${NEW_GLU_LA_PATH}"
186           # create a simbolic link to libGLU.so
187           for kdir in $dirs; do
188             if test -r "${kdir}/libGLU.so"; then
189               cp -fs "${kdir}/libGLU.so" "${NEW_GLU_LA_PATH}/libGLU.so"
190               break
191             fi
192           done
193           break
194         fi
195       done
196       break
197     fi
198   done
199
200   LDFLAGS_old="${LDFLAGS}"
201   LDFLAGS="${LDFLAGS} ${OGL_LIBS} ${GLU_LIB_PATH}"
202   AC_CHECK_LIB([GLU],
203                [gluBeginSurface],
204                [OpenGL_libs_ok=yes],
205                [OpenGL_libs_ok=no])
206   if test "x${OpenGL_libs_ok}" = "xyes" ; then
207     AC_TRY_LINK([],
208                 [],
209                 [OpenGL_libs_ok=yes ; OGL_LIBS="${OGL_LIBS} ${GLU_LIB_PATH} -lGLU"],
210                 [OpenGL_libs_ok=no])
211   fi
212   LDFLAGS="$LDFLAGS_old"
213 fi
214
215 if test "x${OpenGL_headers_ok}" = "xyes" ; then
216   if test "x${OpenGL_libs_ok}" = "xyes" ; then
217     OpenGL_ok=yes
218   fi
219 fi
220
221 AC_MSG_RESULT(for OpenGL_headers_ok: $OpenGL_headers_ok)
222 AC_MSG_RESULT(for OpenGL_libs_ok: $OpenGL_libs_ok)
223 AC_MSG_RESULT(for OpenGL_ok: $OpenGL_ok)
224
225 AC_SUBST(OGL_INCLUDES)
226 AC_SUBST(OGL_LIBS)
227
228 AC_LANG_RESTORE
229
230 ])dnl
231