diff options
-rw-r--r-- | CMakeLists.txt | 7 | ||||
-rw-r--r-- | cmake/modules/FindOpenCLHeaders.cmake | 32 |
2 files changed, 38 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a415d2..3179116 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,6 +75,11 @@ SET(CMAKE_VERBOSE_MAKEFILE TRUE) # Do not use system installed versions Find_Package(LLVM REQUIRED) Find_Package(Clang REQUIRED) +# Shamrock build requires headers in standard location, result of +# apt-get install opencl-headers (eg: on Ubuntu) +if (SHAMROCK_BUILD) + Find_Package(OpenCLHeaders 1.2 EXACT REQUIRED) +endif() # OpenCL requires boost headers. If boost is installed to some directory # other than /usr/include then define BOOST_INCLUDEDIR as below: @@ -141,8 +146,8 @@ ENDIF (BUILD_TESTS) endif() # install OCL builtin and extension headers in opencl-headers package installation directory. -# TODO: We should require that the Khronos OpenCL headers have already been installed there. if (SHAMROCK_BUILD) +# TODO: Android may not have a /usr/include directory. #install(DIRECTORY include DESTINATION /usr ${OCL_DPERMS}) #install(DIRECTORY include/CL DESTINATION /usr/include ${OCL_DPERMS}) install(FILES include/clc.h DESTINATION /usr/include/CL ) diff --git a/cmake/modules/FindOpenCLHeaders.cmake b/cmake/modules/FindOpenCLHeaders.cmake new file mode 100644 index 0000000..6fafc79 --- /dev/null +++ b/cmake/modules/FindOpenCLHeaders.cmake @@ -0,0 +1,32 @@ +# FindOCLHeaders +# +# If successful, will define:: +# +# OCL_INCLUDE_DIR - Set to where CL/cl.h was found +# OCL_VERSION_STRING - Version of the OpenCL Headers "[Major].[minor]" +# + +include(CheckSymbolExists) +find_path(OCL_INCLUDE_DIR NAMES CL/cl.h PATHS /usr/include ) + +set(REQUIRED_VERSION "1_2") +if (${OCL_INCLUDE_DIR} STREQUAL "OCL_INCLUDE_DIR-NOTFOUND") + message(STATUS "Please install opencl-headers package for version ${REQUIRED_VERSION}") + message(FATAL_ERROR "ERROR: Unable to find installed OpenCL Headers") +endif() + +set(CMAKE_REQUIRED_INCLUDES "${OpenCL_INCLUDE_DIR}") + +CHECK_SYMBOL_EXISTS(CL_VERSION_${REQUIRED_VERSION} "${OCL_INCLUDE_DIR}/CL/cl.h" + OPENCL_VERSION_${VERSION}) + +if(OPENCL_VERSION_${VERSION}) + string(REPLACE "_" "." REQUIRED_VERSION "${REQUIRED_VERSION}") + set(OCL_VERSION_STRING ${REQUIRED_VERSION} ) +endif() + +MESSAGE(STATUS "OpenCL Headers: Path: ${OCL_INCLUDE_DIR}; Version: ${OCL_VERSION_STRING}") + +if ("${OCL_VERSION_STRING}" STREQUAL "" OR NOT "${OCL_VERSION_STRING}" STREQUAL "${REQUIRED_VERSION}") + message(FATAL_ERROR "ERROR: expected OpenCL Headers version ${REQUIRED_VERSION}") +endif() |