
#Minimal OpenCL CMakeLists.txt by StreamHPC cmake_minimum_required (VERSION 3.1) project(GreatProject) # Handle OpenCL find_package(OpenCL REQUIRED) include_directories(${OpenCL_INCLUDE_DIRS}) link_directories(${OpenCL_LIBRARY}) add_executable (main main.cpp) target_include_directories (main PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries (main ${OpenCL_LIBRARY})Then do the usual:
- make a build-directory
- cd build
- cmake .. (specifying the right Generator)
Cmake 3.7
CMake 3.7 makes it even easier! You can do the following:find_package(OpenCL REQUIRED) add_executable(test_tgt main.c) target_link_libraries(test_tgt OpenCL::OpenCL)This automatically sets up the include paths and target library to link against. No need to use the ${OpenCL_INCLUDE_DIRS} and ${OpenCL_LIBRARIES} any more. (Thanks Matthäus G. Chajdas for improving this!)
Getting CMake 3.1 or higher
- Ubuntu/Debian: Get the PPA.
- Other Linux: Get the latest tar.gz and compile.
- Windows/OSX: Download the latest exe/dmg from the CMake homepage.
Related Posts
Updated: OpenCL and CUDA programming training – now online
... or replaced if time is getting too limited. Day 1: OpenCL/CUDA Foundations This is close to our standard OpenCL crash ...