Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add header file path in CMake file

Tags:

cmake

opencl

I am new to OpenCL. I have written a vector addition code in OpenCL with help from Internet. I have included one header file i.e. CL/cl.h using #include.

I am using NVIDIA graphic card and the OpenCL implementation is NVIDIA_GPU_Computing_SDK. My OpenCL header files are residing at this path /opt/NVIDIA_GPU_Computing_SDK/OpenCL/common/inc. I can run OpenCL programs through linux terminal by adding this path when compiling my code. But now I want to write CMake file for this code. CMake files are working fine for C programs, but not OpenCL programs because of this Path problem. In terminal, I used to enter $cmake ., after this $make, it will search for a Makefile which is created by cmake, now my error is after entering command make

fatal error: CL/cl.h: No such file or directory!

Now tell me how can I include this header file into CMake file?

like image 966
Fakruddeen Avatar asked Oct 12 '12 10:10

Fakruddeen


2 Answers

You will need to put these lines into CMakeLists.txt:

include_directories(/opt/NVIDIA_GPU_Computing_SDK/OpenCL/common/inc)
link_directories(/opt/NVIDIA_GPU_Computing_SDK/OpenCL/common/<lib or something similar>)

add_executable(yourexe src1.c ...)
target_link_libraries(yourexe OpenCL)

But beware that this is not portable, because OpenCL SDK can be somewhere else on another machine. The proper way to do this is to use FindOpenCL.cmake module.

like image 64
arrowd Avatar answered Oct 05 '22 03:10

arrowd


Maybe you can use a CMake "find" script like:

  • http://gitorious.org/findopencl/findopencl/blobs/master/FindOpenCL.cmake
  • http://code.google.com/p/opencl-book-samples/source/browse/trunk/cmake/FindOpenCL.cmake?r=14

CMake file example from OpenCL Programming Guide Book: http://code.google.com/p/opencl-book-samples/source/browse/trunk/CMakeLists.txt?r=14

like image 37
Alex Placet Avatar answered Oct 05 '22 03:10

Alex Placet