blob: a646346be0caa6e382544cd181cb7d673f15b42f [file] [log] [blame]
cristy736173a2009-09-20 21:18:22 +00001# -*- mode: autoconf -*-
2#
cristy7141bca2010-01-21 16:51:24 +00003# AX_OPENCL
cristy736173a2009-09-20 21:18:22 +00004#
cristy7141bca2010-01-21 16:51:24 +00005# 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".
cristy736173a2009-09-20 21:18:22 +00009#
cristy7141bca2010-01-21 16:51:24 +000010# 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.
cristy736173a2009-09-20 21:18:22 +000013#
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#
cristy7141bca2010-01-21 16:51:24 +000037AC_DEFUN([AX_OPENCL],
cristy736173a2009-09-20 21:18:22 +000038[AC_REQUIRE([AC_CANONICAL_HOST])dnl
cristy736173a2009-09-20 21:18:22 +000039AC_REQUIRE([AC_PROG_SED])dnl
40AC_REQUIRE([ACX_PTHREAD])dnl
41
cristy43596fe2010-01-21 16:46:08 +000042AC_ARG_ENABLE([opencl],
cristy763f7ee2012-09-01 21:58:09 +000043 [AC_HELP_STRING([--enable-opencl],
44 [enable OpenCL support])],
45 [enable_opencl=$enableval],
46 [enable_opencl='no'])
cristy736173a2009-09-20 21:18:22 +000047
cristy763f7ee2012-09-01 21:58:09 +000048if test "$enable_opencl" = 'yes'; then
cristy43596fe2010-01-21 16:46:08 +000049 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
cristyfdc7d122013-08-17 20:46:45 +000055 ax_save_CL_CFLAGS=$CL_CFLAGS
56
57 found_opencl_header='no'
cristy43596fe2010-01-21 16:46:08 +000058 CPPFLAGS="$CL_CFLAGS $CPPFLAGS"
cristyfdc7d122013-08-17 20:46:45 +000059 AC_CHECK_HEADERS([CL/cl.h OpenCL/cl.h],
60 [found_opencl_header='yes'
61 break;],
62 [found_opencl_header='no'])
63
64 AS_IF([test X$found_opencl_header = Xno],
65 [AS_UNSET([ac_cv_header_CL_cl_h])
66 AS_UNSET([ac_cv_header_OpenCL_cl_h])
67 CL_CFLAGS="-I$AMDAPPSDKROOT/include"
68 CPPFLAGS="$ax_save_CPPFLAGS $CL_CFLAGS"
69 AC_CHECK_HEADERS([CL/cl.h OpenCL/cl.h],
70 [found_opencl_header='yes'
71 break;],
72 [found_opencl_header='no'])
73 ],
74 [])
75
76 CPPFLAGS="$ax_save_CPPFLAGS"
cristy43596fe2010-01-21 16:46:08 +000077
78 AC_CHECK_HEADERS([windows.h])
79
cristy7141bca2010-01-21 16:51:24 +000080 m4_define([AX_OPENCL_PROGRAM],
cristy43596fe2010-01-21 16:46:08 +000081 [AC_LANG_PROGRAM([[
82 # if defined(HAVE_WINDOWS_H) && defined(_WIN32)
83 # include <windows.h>
84 # endif
85 # ifdef HAVE_CL_CL_H
86 # include <CL/cl.h>
87 # elif defined(HAVE_OPENCL_CL_H)
88 # include <OpenCL/cl.h>
89 # else
90 # error no CL.h
91 # endif]],
92 [[clCreateContextFromType(0,0,0,0,0)]])])
93
94 AC_CACHE_CHECK([for OpenCL library], [ax_cv_check_cl_libcl],
95 [ax_cv_check_cl_libcl=no
96 case $host_cpu in
cristyfdc7d122013-08-17 20:46:45 +000097 x86_64) ax_check_cl_libdir=lib64
98 ax_check_cl_amd_libdir=x86_64
99 ;;
100 *) ax_check_cl_libdir=lib
101 ax_check_cl_amd_libdir=x86
102 ;;
cristy43596fe2010-01-21 16:46:08 +0000103 esac
104 ax_save_CPPFLAGS=$CPPFLAGS
105 CPPFLAGS="$CL_CFLAGS $CPPFLAGS"
106 ax_save_LIBS=$LIBS
107 LIBS=""
108 ax_check_libs="-lOpenCL -lCL -lclparser"
109 for ax_lib in $ax_check_libs; do
110 AS_IF([test X$ax_compiler_ms = Xyes],
111 [ax_try_lib=`echo $ax_lib | $SED -e 's/^-l//' -e 's/$/.lib/'`],
112 [ax_try_lib=$ax_lib])
113 LIBS="$ax_try_lib $CL_LIBS $ax_save_LIBS"
cristy7141bca2010-01-21 16:51:24 +0000114 AC_LINK_IFELSE([AX_OPENCL_PROGRAM],
cristy43596fe2010-01-21 16:46:08 +0000115 [ax_cv_check_cl_libcl=$ax_try_lib; break],
116 [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"
cristy7141bca2010-01-21 16:51:24 +0000117 AC_LINK_IFELSE([AX_OPENCL_PROGRAM],
cristy43596fe2010-01-21 16:46:08 +0000118 [ax_cv_check_cl_libcl="$ax_try_lib $ax_check_cl_nvidia_flags"; break],
cristy78c5a0c2010-12-04 20:00:59 +0000119 [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"
cristy7141bca2010-01-21 16:51:24 +0000120 AC_LINK_IFELSE([AX_OPENCL_PROGRAM],
cristyfdc7d122013-08-17 20:46:45 +0000121 [ax_cv_check_cl_libcl="$ax_try_lib $ax_check_cl_dylib_flag"; break],
122 [ax_check_cl_amd_flags="-L$AMDAPPSDKROOT/lib/$ax_check_cl_amd_libdir" LIBS="$ax_try_lib $ax_check_cl_amd_flags $CL_LIBS $ax_save_LIBS"
123 AC_LINK_IFELSE([AX_OPENCL_PROGRAM],
124 [ax_cv_check_cl_libcl="$ax_try_lib $ax_check_cl_amd_flags"; break]
125 )
126 ]
127 )])])
cristy43596fe2010-01-21 16:46:08 +0000128 done
129
cristyc3f8b8e2011-12-22 14:55:16 +0000130 AS_IF([test "X$ax_cv_check_cl_libcl" = Xno],
cristy78c5a0c2010-12-04 20:00:59 +0000131 [LIBS='-Wl,-framework,OpenCL'
cristy7141bca2010-01-21 16:51:24 +0000132 AC_LINK_IFELSE([AX_OPENCL_PROGRAM],
cristy43596fe2010-01-21 16:46:08 +0000133 [ax_cv_check_cl_libcl=$LIBS])])
134
135 LIBS=$ax_save_LIBS
136 CPPFLAGS=$ax_save_CPPFLAGS])
137
138 AS_IF([test "X$ax_cv_check_cl_libcl" = Xno],
139 [no_cl=yes; CL_CFLAGS=""; CL_LIBS=""],
140 [CL_LIBS="$ax_cv_check_cl_libcl $CL_LIBS"; AC_DEFINE([_OPENCL], [1],
141 [Define this for the OpenCL Accelerator])])
142 AC_LANG_POP([$1])
143fi
144
cristy736173a2009-09-20 21:18:22 +0000145AC_SUBST([CL_CFLAGS])
cristy0c832c62014-03-07 22:21:04 +0000146
147#remove static link on Linux
148CL_LIBS=`echo $CL_LIBS | $SED -e 's/-lOpenCL //'`
cristy736173a2009-09-20 21:18:22 +0000149AC_SUBST([CL_LIBS])
150])dnl