FindOpenCL.cmake 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #.rst:
  2. # FindOpenCL
  3. # ----------
  4. #
  5. # Try to find OpenCL
  6. #
  7. # Once done this will define::
  8. #
  9. # OpenCL_FOUND - True if OpenCL was found
  10. # OpenCL_INCLUDE_DIRS - include directories for OpenCL
  11. # OpenCL_LIBRARIES - link against this library to use OpenCL
  12. # OpenCL_VERSION_STRING - Highest supported OpenCL version (eg. 1.2)
  13. # OpenCL_VERSION_MAJOR - The major version of the OpenCL implementation
  14. # OpenCL_VERSION_MINOR - The minor version of the OpenCL implementation
  15. #
  16. # The module will also define two cache variables::
  17. #
  18. # OpenCL_INCLUDE_DIR - the OpenCL include directory
  19. # OpenCL_LIBRARY - the path to the OpenCL library
  20. #
  21. #=============================================================================
  22. # Copyright 2014 Matthaeus G. Chajdas
  23. #
  24. # Distributed under the OSI-approved BSD License (the "License");
  25. # see accompanying file Copyright.txt for details.
  26. #
  27. # This software is distributed WITHOUT ANY WARRANTY; without even the
  28. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  29. # See the License for more information.
  30. #=============================================================================
  31. # (To distribute this file outside of CMake, substitute the full
  32. # License text for the above reference.)
  33. function(_FIND_OPENCL_VERSION)
  34. include(CheckSymbolExists)
  35. include(CMakePushCheckState)
  36. set(CMAKE_REQUIRED_QUIET ${OpenCL_FIND_QUIETLY})
  37. CMAKE_PUSH_CHECK_STATE()
  38. foreach(VERSION "2_0" "1_2" "1_1" "1_0")
  39. set(CMAKE_REQUIRED_INCLUDES "${OpenCL_INCLUDE_DIR}")
  40. if(APPLE)
  41. CHECK_SYMBOL_EXISTS(
  42. CL_VERSION_${VERSION}
  43. "${OpenCL_INCLUDE_DIR}/OpenCL/cl.h"
  44. OPENCL_VERSION_${VERSION})
  45. else()
  46. CHECK_SYMBOL_EXISTS(
  47. CL_VERSION_${VERSION}
  48. "${OpenCL_INCLUDE_DIR}/CL/cl.h"
  49. OPENCL_VERSION_${VERSION})
  50. endif()
  51. if(OPENCL_VERSION_${VERSION})
  52. string(REPLACE "_" "." VERSION "${VERSION}")
  53. set(OpenCL_VERSION_STRING ${VERSION} PARENT_SCOPE)
  54. string(REGEX MATCHALL "[0-9]+" version_components "${VERSION}")
  55. list(GET version_components 0 major_version)
  56. list(GET version_components 1 minor_version)
  57. set(OpenCL_VERSION_MAJOR ${major_version} PARENT_SCOPE)
  58. set(OpenCL_VERSION_MINOR ${minor_version} PARENT_SCOPE)
  59. break()
  60. endif()
  61. endforeach()
  62. CMAKE_POP_CHECK_STATE()
  63. endfunction()
  64. find_path(OpenCL_INCLUDE_DIR
  65. NAMES
  66. CL/cl.h OpenCL/cl.h
  67. PATHS
  68. ENV "PROGRAMFILES(X86)"
  69. ENV AMDAPPSDKROOT
  70. ENV INTELOCLSDKROOT
  71. ENV NVSDKCOMPUTE_ROOT
  72. ENV CUDA_PATH
  73. ENV ATISTREAMSDKROOT
  74. PATH_SUFFIXES
  75. include
  76. OpenCL/common/inc
  77. "AMD APP/include")
  78. _FIND_OPENCL_VERSION()
  79. if(WIN32)
  80. if(CMAKE_SIZEOF_VOID_P EQUAL 4)
  81. find_library(OpenCL_LIBRARY
  82. NAMES OpenCL
  83. PATHS
  84. ENV "PROGRAMFILES(X86)"
  85. ENV AMDAPPSDKROOT
  86. ENV INTELOCLSDKROOT
  87. ENV CUDA_PATH
  88. ENV NVSDKCOMPUTE_ROOT
  89. ENV ATISTREAMSDKROOT
  90. PATH_SUFFIXES
  91. "AMD APP/lib/x86"
  92. lib/x86
  93. lib/Win32
  94. OpenCL/common/lib/Win32)
  95. elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
  96. find_library(OpenCL_LIBRARY
  97. NAMES OpenCL
  98. PATHS
  99. ENV "PROGRAMFILES(X86)"
  100. ENV AMDAPPSDKROOT
  101. ENV INTELOCLSDKROOT
  102. ENV CUDA_PATH
  103. ENV NVSDKCOMPUTE_ROOT
  104. ENV ATISTREAMSDKROOT
  105. PATH_SUFFIXES
  106. "AMD APP/lib/x86_64"
  107. lib/x86_64
  108. lib/x64
  109. OpenCL/common/lib/x64)
  110. endif()
  111. else()
  112. find_library(OpenCL_LIBRARY
  113. NAMES OpenCL libOpenCL.so.1)
  114. endif()
  115. set(OpenCL_LIBRARIES ${OpenCL_LIBRARY})
  116. set(OpenCL_INCLUDE_DIRS ${OpenCL_INCLUDE_DIR})
  117. if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
  118. # prepare dlls
  119. string(REPLACE ".lib" ".dll" OpenCL_DLL "${OpenCL_LIBRARY}")
  120. string(REPLACE "/lib/" "/bin/" OpenCL_DLL "${OpenCL_DLL}")
  121. set(OpenCL_DLLS optimized ${OpenCL_DLL} debug "${OpenCL_DLL}")
  122. endif()
  123. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  124. find_package_handle_standard_args(
  125. OpenCL
  126. FOUND_VAR OpenCL_FOUND
  127. REQUIRED_VARS OpenCL_LIBRARY OpenCL_INCLUDE_DIR
  128. VERSION_VAR OpenCL_VERSION_STRING)
  129. mark_as_advanced(
  130. OpenCL_INCLUDE_DIR
  131. OpenCL_LIBRARY)