From d6d5a9b2cdf8ea817bc8d5c8c2fd4b8a4bf15e9c Mon Sep 17 00:00:00 2001
From: Maneesh Gupta <maneesh.gupta@amd.com>
Date: Wed, 27 May 2015 15:29:45 +0530
Subject: [PATCH 1/1] configure: autodetect OpenCL headers and ICD loader.

Signed-off-by: Maneesh Gupta <maneesh.gupta@amd.com>
---
 configure | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/configure b/configure
index c21d475..9264455 100755
--- a/configure
+++ b/configure
@@ -270,7 +270,7 @@ External library support:
   --enable-mmal            enable decoding via MMAL [no]
   --enable-nvenc           enable NVIDIA NVENC support [no]
   --enable-openal          enable OpenAL 1.1 capture support [no]
-  --enable-opencl          enable OpenCL code
+  --disable-opencl         disable OpenCL code [autodetect]
   --enable-opengl          enable OpenGL rendering [no]
   --enable-openssl         enable openssl, needed for https support
                            if gnutls is not used [no]
@@ -5152,12 +5152,6 @@ enabled openal            && { { for al_libs in "${OPENAL_LIBS}" "-lopenal" "-lO
                                die "ERROR: openal not found"; } &&
                              { check_cpp_condition "AL/al.h" "defined(AL_VERSION_1_1)" ||
                                die "ERROR: openal must be installed and version must be 1.1 or compatible"; }
-enabled opencl            && { check_lib2 OpenCL/cl.h clEnqueueNDRangeKernel -Wl,-framework,OpenCL ||
-                               check_lib2 CL/cl.h clEnqueueNDRangeKernel -lOpenCL ||
-                               die "ERROR: opencl not found"; } &&
-                             { check_cpp_condition "OpenCL/cl.h" "defined(CL_VERSION_1_2)" ||
-                               check_cpp_condition "CL/cl.h" "defined(CL_VERSION_1_2)" ||
-                               die "ERROR: opencl must be installed and version must be 1.2 or compatible"; }
 enabled opengl            && { check_lib GL/glx.h glXGetProcAddress "-lGL" ||
                                check_lib2 windows.h wglGetProcAddress "-lopengl32 -lgdi32" ||
                                check_lib2 OpenGL/gl3.h glGetError "-Wl,-framework,OpenGL" ||
@@ -5206,6 +5200,22 @@ if ! disabled sdl; then
 fi
 enabled sdl && add_cflags $sdl_cflags && add_extralibs $sdl_libs
 
+if ! disabled opencl; then
+    if check_lib2 OpenCL/cl.h clEnqueueNDRangeKernel -Wl,-framework,OpenCL || check_lib2 CL/cl.h clEnqueueNDRangeKernel -lOpenCL ; then
+        if check_cpp_condition "OpenCL/cl.h" "defined(CL_VERSION_1_2)" || check_cpp_condition "CL/cl.h" "defined(CL_VERSION_1_2)" ; then
+            enable opencl
+        elif enabled opencl ; then
+            die "ERROR: opencl must be installed and version must be 1.2 or compatible";
+        else
+            disable opencl
+        fi
+    elif enabled opencl ; then
+        die "ERROR: opencl not found";
+    else
+        disable opencl
+    fi
+fi
+
 makeinfo --version > /dev/null 2>&1 && enable makeinfo  || disable makeinfo
 enabled makeinfo && (makeinfo --version | \
                      grep -q 'makeinfo (GNU texinfo) 5' > /dev/null 2>&1) \
-- 
1.9.5.msysgit.0

