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 |
| 39 | AC_REQUIRE([AC_PATH_X])dnl |
| 40 | AC_REQUIRE([AC_PROG_SED])dnl |
| 41 | AC_REQUIRE([ACX_PTHREAD])dnl |
| 42 | |
| 43 | AC_LANG_PUSH([C]) |
| 44 | AX_LANG_COMPILER_MS |
| 45 | AS_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 | # |
| 52 | AS_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 | |
| 58 | ax_save_CPPFLAGS=$CPPFLAGS |
| 59 | CPPFLAGS="$CL_CFLAGS $CPPFLAGS" |
cristy | a03a085 | 2009-10-13 02:02:39 +0000 | [diff] [blame^] | 60 | AC_CHECK_HEADERS([CL/OpenCL.h OpenCL/OpenCL.h]) |
cristy | 736173a | 2009-09-20 21:18:22 +0000 | [diff] [blame] | 61 | CPPFLAGS=$ax_save_CPPFLAGS |
| 62 | |
| 63 | AC_CHECK_HEADERS([windows.h]) |
| 64 | |
| 65 | m4_define([AX_CHECK_CL_PROGRAM], |
| 66 | [AC_LANG_PROGRAM([[ |
| 67 | # if defined(HAVE_WINDOWS_H) && defined(_WIN32) |
| 68 | # include <windows.h> |
| 69 | # endif |
cristy | a03a085 | 2009-10-13 02:02:39 +0000 | [diff] [blame^] | 70 | # ifdef HAVE_CL_OPENCL_H |
cristy | 736173a | 2009-09-20 21:18:22 +0000 | [diff] [blame] | 71 | # include <CL/cl.h> |
cristy | a03a085 | 2009-10-13 02:02:39 +0000 | [diff] [blame^] | 72 | # elif defined(HAVE_OPENCL_OPENCL_H) |
| 73 | # include <OpenCL/OpenCL.h> |
cristy | 736173a | 2009-09-20 21:18:22 +0000 | [diff] [blame] | 74 | # else |
cristy | a03a085 | 2009-10-13 02:02:39 +0000 | [diff] [blame^] | 75 | # error no OpenCL.h |
cristy | 736173a | 2009-09-20 21:18:22 +0000 | [diff] [blame] | 76 | # endif]], |
cristy | a03a085 | 2009-10-13 02:02:39 +0000 | [diff] [blame^] | 77 | [[clCreateContext(0)]])]) |
cristy | 736173a | 2009-09-20 21:18:22 +0000 | [diff] [blame] | 78 | |
| 79 | AC_CACHE_CHECK([for OpenCL library], [ax_cv_check_cl_libcl], |
| 80 | [ax_cv_check_cl_libcl=no |
| 81 | case $host_cpu in |
| 82 | x86_64) ax_check_cl_libdir=lib64 ;; |
| 83 | *) ax_check_cl_libdir=lib ;; |
| 84 | esac |
| 85 | ax_save_CPPFLAGS=$CPPFLAGS |
| 86 | CPPFLAGS="$CL_CFLAGS $CPPFLAGS" |
| 87 | ax_save_LIBS=$LIBS |
| 88 | LIBS="" |
cristy | a49aa42 | 2009-09-20 23:40:10 +0000 | [diff] [blame] | 89 | ax_check_libs="-lOpenCL -lCL" |
cristy | 736173a | 2009-09-20 21:18:22 +0000 | [diff] [blame] | 90 | for 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" |
| 95 | AC_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])])]) |
| 103 | done |
| 104 | |
| 105 | AS_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 | |
| 110 | LIBS=$ax_save_LIBS |
| 111 | CPPFLAGS=$ax_save_CPPFLAGS]) |
| 112 | |
| 113 | AS_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"]) |
| 116 | AC_LANG_POP([C]) |
| 117 | |
| 118 | AC_SUBST([CL_CFLAGS]) |
| 119 | AC_SUBST([CL_LIBS]) |
| 120 | ])dnl |