This is a small CMake module I hacked to build my own OpenCL examples using CMake. I only tested it on Linux (no Windows + NVidia for me currently) and I am pretty new to CMake, so feel free to comment or improve. Use it as you wish, but share alike. I will be happy about any feedback.
Sadly the forum won’t let me upload the file, therefore I put it here as code. Save as FindOpenCL.cmake to use it.
# - Try to find OpenCL
# Once done this will define
#
# OPENCL_FOUND - system has OpenCL
# OPENCL_INCLUDE_DIR - the OpenCL include directory
# OPENCL_LIBRARIES - link these to use OpenCL
#
# WIN32 should work, but is untested
IF (WIN32)
FIND_PATH(OPENCL_INCLUDE_DIR CL/cl.h )
# TODO this is only a hack assuming the 64 bit library will
# not be found on 32 bit system
FIND_LIBRARY(OPENCL_LIBRARIES opencl64 )
IF( OPENCL_LIBRARIES )
FIND_LIBRARY(OPENCL_LIBRARIES opencl32 )
ENDIF( OPENCL_LIBRARIES )
ELSE (WIN32)
# Unix style platforms
# We also search for OpenCL in the NVIDIA SDK default location
FIND_PATH(OPENCL_INCLUDE_DIR CL/cl.h ~/NVIDIA_GPU_Computing_SDK/OpenCL/common/inc/ )
FIND_LIBRARY(OPENCL_LIBRARIES OpenCL
ENV LD_LIBRARY_PATH
)
ENDIF (WIN32)
SET( OPENCL_FOUND "NO" )
IF(OPENCL_LIBRARIES )
SET( OPENCL_FOUND "YES" )
ENDIF(OPENCL_LIBRARIES)
MARK_AS_ADVANCED(
OPENCL_INCLUDE_DIR
)
Usage could look like this:
# This is an example project to show and test the usage of the FindOpenCL
# module.
cmake_minimum_required( VERSION 2.6 )
project( Example )
find_package( OpenCL REQUIRED )
include_directories( ${OPENCL_INCLUDE_DIR} )
add_executable( example example.cpp )
target_link_libraries( example ${OPENCL_LIBRARIES} )