Win32 support for ATI SDK by Salnikov Anton.
[findopencl:findopencl.git] / FindOpenCL.cmake
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 shoudl work, too.
4 #
5 # Once done this will define
6 #  OPENCL_FOUND        - system has OpenCL
7 #  OPENCL_INCLUDE_DIRS  - the OpenCL include directory
8 #  OPENCL_LIBRARIES    - link these to use OpenCL
9 #
10 # WIN32 should work, but is untested
11
12 FIND_PACKAGE( PackageHandleStandardArgs )
13
14 SET (OPENCL_VERSION_STRING "0.1.0")
15 SET (OPENCL_VERSION_MAJOR 0)
16 SET (OPENCL_VERSION_MINOR 1)
17 SET (OPENCL_VERSION_PATCH 0)
18
19 IF (APPLE)
20
21   FIND_LIBRARY(OPENCL_LIBRARIES OpenCL DOC "OpenCL lib for OSX")
22   FIND_PATH(OPENCL_INCLUDE_DIRS OpenCL/cl.h DOC "Include for OpenCL on OSX")
23   FIND_PATH(_OPENCL_CPP_INCLUDE_DIRS OpenCL/cl.hpp DOC "Include for OpenCL CPP bindings on OSX")
24
25 ELSE (APPLE)
26
27         IF (WIN32)
28         
29             FIND_PATH(OPENCL_INCLUDE_DIRS CL/cl.h)
30             FIND_PATH(_OPENCL_CPP_INCLUDE_DIRS CL/cl.hpp)
31         
32             # The AMD SDK currently installs both x86 and x86_64 libraries
33             # This is only a hack to find out architecture
34             IF( ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64" )
35                 SET(OPENCL_LIB_DIR "$ENV{ATISTREAMSDKROOT}/lib/x86_64")
36             ELSE (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
37                 SET(OPENCL_LIB_DIR "$ENV{ATISTREAMSDKROOT}/lib/x86")
38             ENDIF( ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64" )
39             FIND_LIBRARY(OPENCL_LIBRARIES OpenCL.lib ${OPENCL_LIB_DIR})
40             
41             GET_FILENAME_COMPONENT(_OPENCL_INC_CAND ${OPENCL_LIB_DIR}/../../include ABSOLUTE)
42             
43             # On Win32 search relative to the library
44             FIND_PATH(OPENCL_INCLUDE_DIRS CL/cl.h PATHS "${_OPENCL_INC_CAND}")
45             FIND_PATH(_OPENCL_CPP_INCLUDE_DIRS CL/cl.hpp PATHS "${_OPENCL_INC_CAND}")
46         
47         ELSE (WIN32)
48
49             # Unix style platforms
50             FIND_LIBRARY(OPENCL_LIBRARIES OpenCL
51               ENV LD_LIBRARY_PATH
52             )
53
54             GET_FILENAME_COMPONENT(OPENCL_LIB_DIR ${OPENCL_LIBRARIES} PATH)
55             GET_FILENAME_COMPONENT(_OPENCL_INC_CAND ${OPENCL_LIB_DIR}/../../include ABSOLUTE)
56
57             # The AMD SDK currently does not place its headers
58             # in /usr/include, therefore also search relative
59             # to the library
60             FIND_PATH(OPENCL_INCLUDE_DIRS CL/cl.h PATHS ${_OPENCL_INC_CAND})
61             FIND_PATH(_OPENCL_CPP_INCLUDE_DIRS CL/cl.hpp PATHS ${_OPENCL_INC_CAND})
62
63         ENDIF (WIN32)
64
65 ENDIF (APPLE)
66
67 FIND_PACKAGE_HANDLE_STANDARD_ARGS( OpenCL DEFAULT_MSG OPENCL_LIBRARIES OPENCL_INCLUDE_DIRS )
68
69 IF( _OPENCL_CPP_INCLUDE_DIRS )
70         SET( OPENCL_HAS_CPP_BINDINGS TRUE )
71         LIST( APPEND OPENCL_INCLUDE_DIRS ${_OPENCL_CPP_INCLUDE_DIRS} )
72         # This is often the same, so clean up
73         LIST( REMOVE_DUPLICATES OPENCL_INCLUDE_DIRS )
74 ENDIF( _OPENCL_CPP_INCLUDE_DIRS )
75
76 MARK_AS_ADVANCED(
77   OPENCL_INCLUDE_DIRS
78 )
79