cristy | 736173a | 2009-09-20 21:18:22 +0000 | [diff] [blame] | 1 | # -*- mode: autoconf -*- |
| 2 | # |
cristy | 7141bca | 2010-01-21 16:51:24 +0000 | [diff] [blame] | 3 | # AX_OPENCL |
cristy | 736173a | 2009-09-20 21:18:22 +0000 | [diff] [blame] | 4 | # |
cristy | 7141bca | 2010-01-21 16:51:24 +0000 | [diff] [blame] | 5 | # Check for an OpenCL implementation. If CL is found, _OPENCL is defined and |
| 6 | # the required compiler and linker flags are included in the output variables |
| 7 | # "CL_CFLAGS" and "CL_LIBS", respectively. If no usable CL implementation is |
| 8 | # found, "no_cl" is set to "yes". |
cristy | 736173a | 2009-09-20 21:18:22 +0000 | [diff] [blame] | 9 | # |
cristy | 7141bca | 2010-01-21 16:51:24 +0000 | [diff] [blame] | 10 | # If the header "CL/OpenCL.h" is found, "HAVE_CL_OPENCL_H" is defined. If the |
| 11 | # header "OpenCL/OpenCL.h" is found, HAVE_OPENCL_OPENCL_H is defined. These |
| 12 | # preprocessor definitions may not be mutually exclusive. |
cristy | 736173a | 2009-09-20 21:18:22 +0000 | [diff] [blame] | 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 | # |
cristy | 7141bca | 2010-01-21 16:51:24 +0000 | [diff] [blame] | 37 | AC_DEFUN([AX_OPENCL], |
cristy | 736173a | 2009-09-20 21:18:22 +0000 | [diff] [blame] | 38 | [AC_REQUIRE([AC_CANONICAL_HOST])dnl |
cristy | 736173a | 2009-09-20 21:18:22 +0000 | [diff] [blame] | 39 | AC_REQUIRE([AC_PROG_SED])dnl |
| 40 | AC_REQUIRE([ACX_PTHREAD])dnl |
| 41 | |
cristy | 43596fe | 2010-01-21 16:46:08 +0000 | [diff] [blame] | 42 | AC_ARG_ENABLE([opencl], |
| 43 | [AC_HELP_STRING([--disable-opencl], |
| 44 | [do not use OpenCL])], |
| 45 | [disable_opencl=$enableval], |
| 46 | [disable_opencl='yes']) |
cristy | 736173a | 2009-09-20 21:18:22 +0000 | [diff] [blame] | 47 | |
cristy | 43596fe | 2010-01-21 16:46:08 +0000 | [diff] [blame] | 48 | if test "$disable_opencl" = 'yes'; then |
| 49 | AC_LANG_PUSH([$1]) |
| 50 | AX_LANG_COMPILER_MS |
| 51 | AS_IF([test X$ax_compiler_ms = Xno], |
| 52 | [CL_CFLAGS="${PTHREAD_CFLAGS}"; CL_LIBS="${PTHREAD_LIBS} -lm"]) |
| 53 | |
| 54 | ax_save_CPPFLAGS=$CPPFLAGS |
| 55 | CPPFLAGS="$CL_CFLAGS $CPPFLAGS" |
| 56 | AC_CHECK_HEADERS([CL/cl.h OpenCL/cl.h]) |
| 57 | CPPFLAGS=$ax_save_CPPFLAGS |
| 58 | |
| 59 | AC_CHECK_HEADERS([windows.h]) |
| 60 | |
cristy | 7141bca | 2010-01-21 16:51:24 +0000 | [diff] [blame] | 61 | m4_define([AX_OPENCL_PROGRAM], |
cristy | 43596fe | 2010-01-21 16:46:08 +0000 | [diff] [blame] | 62 | [AC_LANG_PROGRAM([[ |
| 63 | # if defined(HAVE_WINDOWS_H) && defined(_WIN32) |
| 64 | # include <windows.h> |
| 65 | # endif |
| 66 | # ifdef HAVE_CL_CL_H |
| 67 | # include <CL/cl.h> |
| 68 | # elif defined(HAVE_OPENCL_CL_H) |
| 69 | # include <OpenCL/cl.h> |
| 70 | # else |
| 71 | # error no CL.h |
| 72 | # endif]], |
| 73 | [[clCreateContextFromType(0,0,0,0,0)]])]) |
| 74 | |
| 75 | AC_CACHE_CHECK([for OpenCL library], [ax_cv_check_cl_libcl], |
| 76 | [ax_cv_check_cl_libcl=no |
| 77 | case $host_cpu in |
| 78 | x86_64) ax_check_cl_libdir=lib64 ;; |
| 79 | *) ax_check_cl_libdir=lib ;; |
| 80 | esac |
| 81 | ax_save_CPPFLAGS=$CPPFLAGS |
| 82 | CPPFLAGS="$CL_CFLAGS $CPPFLAGS" |
| 83 | ax_save_LIBS=$LIBS |
| 84 | LIBS="" |
| 85 | ax_check_libs="-lOpenCL -lCL -lclparser" |
| 86 | for ax_lib in $ax_check_libs; do |
| 87 | AS_IF([test X$ax_compiler_ms = Xyes], |
| 88 | [ax_try_lib=`echo $ax_lib | $SED -e 's/^-l//' -e 's/$/.lib/'`], |
| 89 | [ax_try_lib=$ax_lib]) |
| 90 | LIBS="$ax_try_lib $CL_LIBS $ax_save_LIBS" |
cristy | 7141bca | 2010-01-21 16:51:24 +0000 | [diff] [blame] | 91 | AC_LINK_IFELSE([AX_OPENCL_PROGRAM], |
cristy | 43596fe | 2010-01-21 16:46:08 +0000 | [diff] [blame] | 92 | [ax_cv_check_cl_libcl=$ax_try_lib; break], |
| 93 | [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" |
cristy | 7141bca | 2010-01-21 16:51:24 +0000 | [diff] [blame] | 94 | AC_LINK_IFELSE([AX_OPENCL_PROGRAM], |
cristy | 43596fe | 2010-01-21 16:46:08 +0000 | [diff] [blame] | 95 | [ax_cv_check_cl_libcl="$ax_try_lib $ax_check_cl_nvidia_flags"; break], |
cristy | 78c5a0c | 2010-12-04 20:00:59 +0000 | [diff] [blame] | 96 | [ax_check_cl_dylib_flag='-Wl,-framework,OpenCL -L/System/Library/Frameworks/OpenCL.framework/Versions/A/Libraries' LIBS="$ax_try_lib $ax_check_cl_dylib_flag $CL_LIBS $ax_save_LIBS" |
cristy | 7141bca | 2010-01-21 16:51:24 +0000 | [diff] [blame] | 97 | AC_LINK_IFELSE([AX_OPENCL_PROGRAM], |
cristy | 43596fe | 2010-01-21 16:46:08 +0000 | [diff] [blame] | 98 | [ax_cv_check_cl_libcl="$ax_try_lib $ax_check_cl_dylib_flag"; break])])]) |
| 99 | done |
| 100 | |
cristy | c3f8b8e | 2011-12-22 14:55:16 +0000 | [diff] [blame] | 101 | AS_IF([test "X$ax_cv_check_cl_libcl" = Xno], |
cristy | 78c5a0c | 2010-12-04 20:00:59 +0000 | [diff] [blame] | 102 | [LIBS='-Wl,-framework,OpenCL' |
cristy | 7141bca | 2010-01-21 16:51:24 +0000 | [diff] [blame] | 103 | AC_LINK_IFELSE([AX_OPENCL_PROGRAM], |
cristy | 43596fe | 2010-01-21 16:46:08 +0000 | [diff] [blame] | 104 | [ax_cv_check_cl_libcl=$LIBS])]) |
| 105 | |
| 106 | LIBS=$ax_save_LIBS |
| 107 | CPPFLAGS=$ax_save_CPPFLAGS]) |
| 108 | |
| 109 | AS_IF([test "X$ax_cv_check_cl_libcl" = Xno], |
| 110 | [no_cl=yes; CL_CFLAGS=""; CL_LIBS=""], |
| 111 | [CL_LIBS="$ax_cv_check_cl_libcl $CL_LIBS"; AC_DEFINE([_OPENCL], [1], |
| 112 | [Define this for the OpenCL Accelerator])]) |
| 113 | AC_LANG_POP([$1]) |
| 114 | fi |
| 115 | |
cristy | 736173a | 2009-09-20 21:18:22 +0000 | [diff] [blame] | 116 | AC_SUBST([CL_CFLAGS]) |
| 117 | AC_SUBST([CL_LIBS]) |
| 118 | ])dnl |