root/ImageMagick/trunk/m4/ax_check_cl.m4

Revision 372, 4.1 KB (checked in by cristy, 6 weeks ago)
Line 
1# -*- mode: autoconf -*-
2#
3# AX_CHECK_CL
4#
5# Check for an OpenCL implementation.  If CL is found, the required compiler
6# and linker flags are included in the output variables "CL_CFLAGS" and
7# "CL_LIBS", respectively.  If no usable CL implementation is found, "no_cl"
8# is set to "yes".
9#
10# If the header "CL/OpenCL.h" is found, "HAVE_CL_OPENCL_H" is defined.  If the header
11# "OpenCL/OpenCL.h" is found, HAVE_OPENCL_OPENCL_H is defined.  These preprocessor
12# definitions may not be mutually exclusive.
13#
14# Based on AX_CHECK_GL, version: 2.4 author: Braden McDaniel
15# <braden@endoframe.com>
16#
17# This program is free software; you can redistribute it and/or modify
18# it under the terms of the GNU General Public License as published by
19# the Free Software Foundation; either version 2, or (at your option)
20# any later version.
21#
22# This program is distributed in the hope that it will be useful,
23# but WITHOUT ANY WARRANTY; without even the implied warranty of
24# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25# GNU General Public License for more details.
26#
27# You should have received a copy of the GNU General Public License
28# along with this program; if not, write to the Free Software
29# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
30# 02110-1301, USA.
31#
32# As a special exception, the you may copy, distribute and modify the
33# configure scripts that are the output of Autoconf when processing
34# the Macro.  You need not follow the terms of the GNU General Public
35# License when using or distributing such scripts.
36#
37AC_DEFUN([AX_CHECK_CL],
38[AC_REQUIRE([AC_CANONICAL_HOST])dnl
39AC_REQUIRE([AC_PROG_SED])dnl
40AC_REQUIRE([ACX_PTHREAD])dnl
41
42AC_LANG_PUSH([C])
43AX_LANG_COMPILER_MS
44AS_IF([test X$ax_compiler_ms = Xno],
45      [CL_CFLAGS="${PTHREAD_CFLAGS}"; CL_LIBS="${PTHREAD_LIBS} -lm"])
46
47ax_save_CPPFLAGS=$CPPFLAGS
48CPPFLAGS="$CL_CFLAGS $CPPFLAGS"
49AC_CHECK_HEADERS([CL/opencl.h OpenCL/OpenCL.h])
50CPPFLAGS=$ax_save_CPPFLAGS
51
52AC_CHECK_HEADERS([windows.h])
53
54m4_define([AX_CHECK_CL_PROGRAM],
55          [AC_LANG_PROGRAM([[
56# if defined(HAVE_WINDOWS_H) && defined(_WIN32)
57#   include <windows.h>
58# endif
59# ifdef HAVE_CL_OPENCL_H
60#   include <CL/opencl.h>
61# elif defined(HAVE_OPENCL_OPENCL_H)
62#   include <OpenCL/OpenCL.h>
63# else
64#   error no OpenCL.h
65# endif]],
66                           [[clCreateContextFromType(0,0,0,0,0)]])])
67
68AC_CACHE_CHECK([for OpenCL library], [ax_cv_check_cl_libcl],
69[ax_cv_check_cl_libcl=no
70case $host_cpu in
71  x86_64) ax_check_cl_libdir=lib64 ;;
72  *)      ax_check_cl_libdir=lib ;;
73esac
74ax_save_CPPFLAGS=$CPPFLAGS
75CPPFLAGS="$CL_CFLAGS $CPPFLAGS"
76ax_save_LIBS=$LIBS
77LIBS=""
78ax_check_libs="-lOpenCL -lCL"
79for ax_lib in $ax_check_libs; do
80  AS_IF([test X$ax_compiler_ms = Xyes],
81        [ax_try_lib=`echo $ax_lib | $SED -e 's/^-l//' -e 's/$/.lib/'`],
82        [ax_try_lib=$ax_lib])
83  LIBS="$ax_try_lib $CL_LIBS $ax_save_LIBS"
84AC_LINK_IFELSE([AX_CHECK_CL_PROGRAM],
85               [ax_cv_check_cl_libcl=$ax_try_lib; break],
86               [ax_check_cl_nvidia_flags="-L/usr/$ax_check_cl_libdir/nvidia" LIBS="$ax_try_lib $ax_check_cl_nvidia_flags $CL_LIBS $ax_save_LIBS"
87               AC_LINK_IFELSE([AX_CHECK_CL_PROGRAM],
88                              [ax_cv_check_cl_libcl="$ax_try_lib $ax_check_cl_nvidia_flags"; break],
89                              [ax_check_cl_dylib_flag='-dylib_file /System/Library/Frameworks/OpenCL.framework/Versions/A/Libraries/libCL.dylib:/System/Library/Frameworks/OpenCL.framework/Versions/A/Libraries/libCL.dylib' LIBS="$ax_try_lib $ax_check_cl_dylib_flag $CL_LIBS $ax_save_LIBS"
90                              AC_LINK_IFELSE([AX_CHECK_CL_PROGRAM],
91                                             [ax_cv_check_cl_libcl="$ax_try_lib $ax_check_cl_dylib_flag"; break])])])
92done
93
94AS_IF([test "X$ax_cv_check_cl_libcl" = Xno -a X$no_x = Xyes],
95      [LIBS='-framework OpenCL'
96      AC_LINK_IFELSE([AX_CHECK_CL_PROGRAM],
97                     [ax_cv_check_cl_libcl=$LIBS])])
98
99LIBS=$ax_save_LIBS
100CPPFLAGS=$ax_save_CPPFLAGS])
101
102AS_IF([test "X$ax_cv_check_cl_libcl" = Xno],
103      [no_cl=yes; CL_CFLAGS=""; CL_LIBS=""],
104      [CL_LIBS="$ax_cv_check_cl_libcl $CL_LIBS"])
105AC_LANG_POP([C])
106
107AC_SUBST([CL_CFLAGS])
108AC_SUBST([CL_LIBS])
109])dnl
Note: See TracBrowser for help on using the browser.