cristy | 736173a | 2009-09-20 21:18:22 +0000 | [diff] [blame] | 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 | # |
cristy | a03a085 | 2009-10-13 02:02:39 +0000 | [diff] [blame] | 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 |
cristy | 736173a | 2009-09-20 21:18:22 +0000 | [diff] [blame] | 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 | # |
| 37 | AC_DEFUN([AX_CHECK_CL], |
| 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 | |
| 42 | AC_LANG_PUSH([C]) |
| 43 | AX_LANG_COMPILER_MS |
| 44 | AS_IF([test X$ax_compiler_ms = Xno], |
| 45 | [CL_CFLAGS="${PTHREAD_CFLAGS}"; CL_LIBS="${PTHREAD_LIBS} -lm"]) |
| 46 | |
cristy | 736173a | 2009-09-20 21:18:22 +0000 | [diff] [blame] | 47 | ax_save_CPPFLAGS=$CPPFLAGS |
| 48 | CPPFLAGS="$CL_CFLAGS $CPPFLAGS" |
cristy | c7083c1 | 2009-10-14 03:16:55 +0000 | [diff] [blame^] | 49 | AC_CHECK_HEADERS([CL/opencl.h OpenCL/OpenCL.h]) |
cristy | 736173a | 2009-09-20 21:18:22 +0000 | [diff] [blame] | 50 | CPPFLAGS=$ax_save_CPPFLAGS |
| 51 | |
| 52 | AC_CHECK_HEADERS([windows.h]) |
| 53 | |
| 54 | m4_define([AX_CHECK_CL_PROGRAM], |
| 55 | [AC_LANG_PROGRAM([[ |
| 56 | # if defined(HAVE_WINDOWS_H) && defined(_WIN32) |
| 57 | # include <windows.h> |
| 58 | # endif |
cristy | a03a085 | 2009-10-13 02:02:39 +0000 | [diff] [blame] | 59 | # ifdef HAVE_CL_OPENCL_H |
cristy | c7083c1 | 2009-10-14 03:16:55 +0000 | [diff] [blame^] | 60 | # include <CL/opencl.h> |
cristy | a03a085 | 2009-10-13 02:02:39 +0000 | [diff] [blame] | 61 | # elif defined(HAVE_OPENCL_OPENCL_H) |
| 62 | # include <OpenCL/OpenCL.h> |
cristy | 736173a | 2009-09-20 21:18:22 +0000 | [diff] [blame] | 63 | # else |
cristy | a03a085 | 2009-10-13 02:02:39 +0000 | [diff] [blame] | 64 | # error no OpenCL.h |
cristy | 736173a | 2009-09-20 21:18:22 +0000 | [diff] [blame] | 65 | # endif]], |
cristy | df230b4 | 2009-10-13 11:36:27 +0000 | [diff] [blame] | 66 | [[clCreateContextFromType(0,0,0,0,0)]])]) |
cristy | 736173a | 2009-09-20 21:18:22 +0000 | [diff] [blame] | 67 | |
| 68 | AC_CACHE_CHECK([for OpenCL library], [ax_cv_check_cl_libcl], |
| 69 | [ax_cv_check_cl_libcl=no |
| 70 | case $host_cpu in |
| 71 | x86_64) ax_check_cl_libdir=lib64 ;; |
| 72 | *) ax_check_cl_libdir=lib ;; |
| 73 | esac |
| 74 | ax_save_CPPFLAGS=$CPPFLAGS |
| 75 | CPPFLAGS="$CL_CFLAGS $CPPFLAGS" |
| 76 | ax_save_LIBS=$LIBS |
| 77 | LIBS="" |
cristy | a49aa42 | 2009-09-20 23:40:10 +0000 | [diff] [blame] | 78 | ax_check_libs="-lOpenCL -lCL" |
cristy | 736173a | 2009-09-20 21:18:22 +0000 | [diff] [blame] | 79 | for 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" |
| 84 | AC_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])])]) |
| 92 | done |
| 93 | |
| 94 | AS_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 | |
| 99 | LIBS=$ax_save_LIBS |
| 100 | CPPFLAGS=$ax_save_CPPFLAGS]) |
| 101 | |
| 102 | AS_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"]) |
| 105 | AC_LANG_POP([C]) |
| 106 | |
| 107 | AC_SUBST([CL_CFLAGS]) |
| 108 | AC_SUBST([CL_LIBS]) |
| 109 | ])dnl |