Dependency on OpenCL::OpenCL doesn't add library dependency
Suppose I have a program which uses OpenCL, in the file foo.c
, and I use the following CMakeLists.txt
:
cmake_minimum_required(VERSION 3.11)
project(foo C)
find_package(OpenCL REQUIRED)
add_executable(foo main.c)
add_dependencies(foo OpenCL::OpenCL)
This should work, assuming CMake can find an OpenCL installation - right?
Well, I'm using Devuan 3.0 (which is basically Debian 10 without systemd; cmake version: 3.13.4). When I configure the build, my cache has (among other lines):
OpenCL_INCLUDE_DIR:PATH=/usr/include
OpenCL_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libOpenCL.so
FIND_PACKAGE_MESSAGE_DETAILS_OpenCL:INTERNAL=[/usr/lib/x86_64-linux-gnu/libOpenCL.so][/usr/include][v2.2()]
OPENCL_VERSION_2_2:INTERNAL=1
OpenCL_INCLUDE_DIR-ADVANCED:INTERNAL=1
OpenCL_LIBRARY-ADVANCED:INTERNAL=1
Which seems alright.
So, make
'ing this issues the following commands:
/usr/bin/cc -o CMakeFiles/foo.dir/main.c.o -c /mnt/sdb3/home-eyalroz/src/mine/gpu_programming_ttt/opecl_link_test/main.c
/usr/bin/cc CMakeFiles/foo.dir/main.c.o -o foo
No -lOpenCL
! (and I can't tell whether it would have added a -I
had my OpenCL include files not been under /usr/include
.)
I'm also pretty sure the same thing happens with the master branch's FindOpenCL.cmake but because the changes since 3.13 are not that significant, but need to double-check.
PS - If you want my main.c, I can attach it.
Edited by Eyal Rozenberg