blob: e0829adaaf9d1edd552cd1399a90cb8951708780 [file] [log] [blame]
cristy736173a2009-09-20 21:18:22 +00001# -*- 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/cl.h" is found, "HAVE_CL_CL_H" is defined. If the header
11# "OpenCL/cl.h" is found, HAVE_OPENCL_CL_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_PATH_X])dnl
40AC_REQUIRE([AC_PROG_SED])dnl
41AC_REQUIRE([ACX_PTHREAD])dnl
42
43AC_LANG_PUSH([C])
44AX_LANG_COMPILER_MS
45AS_IF([test X$ax_compiler_ms = Xno],
46 [CL_CFLAGS="${PTHREAD_CFLAGS}"; CL_LIBS="${PTHREAD_LIBS} -lm"])
47
48#
49# Use x_includes and x_libraries if they have been set (presumably by
50# AC_PATH_X).
51#
52AS_IF([test X$no_x != Xyes],
53 [AS_IF([test -n "$x_includes"],
54 [CL_CFLAGS="-I$x_includes $CL_CFLAGS"])]
55 AS_IF([test -n "$x_libraries"],
56 [CL_LIBS="-L$x_libraries -lX11 $CL_LIBS"]))
57
58ax_save_CPPFLAGS=$CPPFLAGS
59CPPFLAGS="$CL_CFLAGS $CPPFLAGS"
60AC_CHECK_HEADERS([CL/cl.h OpenCL/cl.h])
61CPPFLAGS=$ax_save_CPPFLAGS
62
63AC_CHECK_HEADERS([windows.h])
64
65m4_define([AX_CHECK_CL_PROGRAM],
66 [AC_LANG_PROGRAM([[
67# if defined(HAVE_WINDOWS_H) && defined(_WIN32)
68# include <windows.h>
69# endif
70# ifdef HAVE_CL_CL_H
71# include <CL/cl.h>
72# elif defined(HAVE_OPENCL_CL_H)
73# include <OpenCL/cl.h>
74# else
75# error no cl.h
76# endif]],
77 [[clBegin(0)]])])
78
79AC_CACHE_CHECK([for OpenCL library], [ax_cv_check_cl_libcl],
80[ax_cv_check_cl_libcl=no
81case $host_cpu in
82 x86_64) ax_check_cl_libdir=lib64 ;;
83 *) ax_check_cl_libdir=lib ;;
84esac
85ax_save_CPPFLAGS=$CPPFLAGS
86CPPFLAGS="$CL_CFLAGS $CPPFLAGS"
87ax_save_LIBS=$LIBS
88LIBS=""
cristya49aa422009-09-20 23:40:10 +000089ax_check_libs="-lOpenCL -lCL"
cristy736173a2009-09-20 21:18:22 +000090for ax_lib in $ax_check_libs; do
91 AS_IF([test X$ax_compiler_ms = Xyes],
92 [ax_try_lib=`echo $ax_lib | $SED -e 's/^-l//' -e 's/$/.lib/'`],
93 [ax_try_lib=$ax_lib])
94 LIBS="$ax_try_lib $CL_LIBS $ax_save_LIBS"
95AC_LINK_IFELSE([AX_CHECK_CL_PROGRAM],
96 [ax_cv_check_cl_libcl=$ax_try_lib; break],
97 [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"
98 AC_LINK_IFELSE([AX_CHECK_CL_PROGRAM],
99 [ax_cv_check_cl_libcl="$ax_try_lib $ax_check_cl_nvidia_flags"; break],
100 [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"
101 AC_LINK_IFELSE([AX_CHECK_CL_PROGRAM],
102 [ax_cv_check_cl_libcl="$ax_try_lib $ax_check_cl_dylib_flag"; break])])])
103done
104
105AS_IF([test "X$ax_cv_check_cl_libcl" = Xno -a X$no_x = Xyes],
106 [LIBS='-framework OpenCL'
107 AC_LINK_IFELSE([AX_CHECK_CL_PROGRAM],
108 [ax_cv_check_cl_libcl=$LIBS])])
109
110LIBS=$ax_save_LIBS
111CPPFLAGS=$ax_save_CPPFLAGS])
112
113AS_IF([test "X$ax_cv_check_cl_libcl" = Xno],
114 [no_cl=yes; CL_CFLAGS=""; CL_LIBS=""],
115 [CL_LIBS="$ax_cv_check_cl_libcl $CL_LIBS"])
116AC_LANG_POP([C])
117
118AC_SUBST([CL_CFLAGS])
119AC_SUBST([CL_LIBS])
120])dnl