Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
FindOpenCL.cmake
Go to the documentation of this file.
1 # - Try to find OpenCL
2 # This module tries to find an OpenCL implementation on your system. It supports
3 # AMD / ATI, Apple and NVIDIA implementations, but should work, too.
4 #
5 # To set manually the paths, define these environment variables:
6 # OpenCL_INCPATH - Include path (e.g. OpenCL_INCPATH=/opt/cuda/4.0/cuda/include)
7 # OpenCL_LIBPATH - Library path (e.h. OpenCL_LIBPATH=/usr/lib64/nvidia)
8 #
9 # Once done this will define
10 # OPENCL_FOUND - system has OpenCL
11 # OPENCL_INCLUDE_DIRS - the OpenCL include directory
12 # OPENCL_LIBRARIES - link these to use OpenCL
13 #
14 # WIN32 should work, but is untested
15 
16 FIND_PACKAGE(PackageHandleStandardArgs)
17 
18 SET (OPENCL_VERSION_STRING "0.1.0")
19 SET(OPENCL_VERSION_MAJOR 0)
20 SET(OPENCL_VERSION_MINOR 1)
21 SET(OPENCL_VERSION_PATCH 0)
22 
23 IF(APPLE)
24 
25  FIND_LIBRARY(OPENCL_LIBRARIES OpenCL DOC "OpenCL lib for OSX")
26  FIND_PATH(OPENCL_INCLUDE_DIRS OpenCL/cl.h DOC "Include for OpenCL on OSX")
27  FIND_PATH(_OPENCL_CPP_INCLUDE_DIRS OpenCL/cl.hpp DOC "Include for OpenCL CPP bindings on OSX")
28 
29 ELSE()
30  IF (WIN32)
31 
32  FIND_PATH(OPENCL_INCLUDE_DIRS CL/cl.h)
33  FIND_PATH(_OPENCL_CPP_INCLUDE_DIRS CL/cl.hpp)
34 
35  IF(CMAKE_SIZEOF_VOID_P MATCHES "8")
36  SET(OPENCL_LIB_DIR "$ENV{ATISTREAMSDKROOT}/lib/x86_64")
37  if(NOT IS_DIRECTORY ${OPENCL_LIB_DIR})
38  SET(OPENCL_LIB_DIR "$ENV{CUDA_PATH}/lib/x64")
39  endif()
40  ELSE()
41  SET(OPENCL_LIB_DIR "$ENV{ATISTREAMSDKROOT}/lib/x86")
42  if(NOT IS_DIRECTORY ${OPENCL_LIB_DIR}) # need to convert path in the cmake style ?
43  SET(OPENCL_LIB_DIR "$ENV{CUDA_PATH}/lib/Win32")
44  endif()
45  ENDIF()
46  file(TO_CMAKE_PATH ${OPENCL_LIB_DIR} OPENCL_LIB_DIR)
47  GET_FILENAME_COMPONENT(OPENCL_LIB_DIR ${OPENCL_LIB_DIR} ABSOLUTE)
48 
49  FIND_LIBRARY(OPENCL_LIBRARIES OpenCL.lib PATHS ${OPENCL_LIB_DIR} ENV OpenCL_LIBPATH)
50 
51  GET_FILENAME_COMPONENT(_OPENCL_INC_CAND ${OPENCL_LIB_DIR}/../../include ABSOLUTE)
52 
53  # On Win32 search relative to the library
54  FIND_PATH(OPENCL_INCLUDE_DIRS CL/cl.h PATHS "${_OPENCL_INC_CAND}" ENV OpenCL_INCPATH)
55  FIND_PATH(_OPENCL_CPP_INCLUDE_DIRS CL/cl.hpp PATHS "${_OPENCL_INC_CAND}" ENV OpenCL_INCPATH)
56 
57  ELSE (WIN32)
58 
59  # Unix style platforms
60  FIND_LIBRARY(OPENCL_LIBRARIES OpenCL
61  PATHS ENV LD_LIBRARY_PATH ENV OpenCL_LIBPATH
62  )
63 
64  GET_FILENAME_COMPONENT(OPENCL_LIB_DIR ${OPENCL_LIBRARIES} PATH)
65  GET_FILENAME_COMPONENT(_OPENCL_INC_CAND ${OPENCL_LIB_DIR}/../../include ABSOLUTE)
66 
67  # The AMD SDK currently does not place its headers
68  # in /usr/include, therefore also search relative
69  # to the library
70  FIND_PATH(OPENCL_INCLUDE_DIRS CL/cl.h PATHS ${_OPENCL_INC_CAND} "/usr/local/cuda/include" "/opt/AMDAPP/include" ENV OpenCL_INCPATH)
71  FIND_PATH(_OPENCL_CPP_INCLUDE_DIRS CL/cl.hpp PATHS ${_OPENCL_INC_CAND} "/usr/local/cuda/include" "/opt/AMDAPP/include" ENV OpenCL_INCPATH)
72 
73  ENDIF (WIN32)
74 
75 ENDIF (APPLE)
76 
77 FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenCL DEFAULT_MSG OPENCL_LIBRARIES OPENCL_INCLUDE_DIRS)
78 
79 IF(_OPENCL_CPP_INCLUDE_DIRS)
80  SET( OPENCL_HAS_CPP_BINDINGS TRUE )
81  LIST( APPEND OPENCL_INCLUDE_DIRS ${_OPENCL_CPP_INCLUDE_DIRS} )
82  # This is often the same, so clean up
83  LIST( REMOVE_DUPLICATES OPENCL_INCLUDE_DIRS )
84 ENDIF(_OPENCL_CPP_INCLUDE_DIRS)
85 
86 MARK_AS_ADVANCED(
87  OPENCL_INCLUDE_DIRS
88  )
89