Cannot specify compile definitions for target "INTERFACE" which is not built by this project

Hello all,
forgive me as this is quite a noob question mainly about CMake Files. This is my first SYCL project and I am trying to include the computeCPP-SDK in my project as written in the guide on the website.
My CMakeLists.txt is as follows -

cmake_minimum_required(VERSION 3.17)
project(computecpp_test)

set(CMAKE_MODULE_PATH /home/atharva/computecpp-sdk/cmake/Modules/)
include(FindComputeCpp)

include_directories($(COMPUTECPP_INCLUDE_DIRECTORY))

add_executable(computecpp_test main.cpp)
add_sycl_to_target(computecpp_test main.cpp  ${CMAKE_CURRENT_BINARY_DIR})

However, I get the following error in the cmake, which is -

CMake Error at /home/atharva/computecpp-sdk/cmake/Modules/FindComputeCpp.cmake:457 (target_compile_definitions):
  Cannot specify compile definitions for target "INTERFACE" which is not
  built by this project.

Could anyone please tell what could be going wrong?
TIA

1 Like

Hello there,
Thanks for posting.
I think you are referring to the documentation that suggests using FindComputeCpp.cmake. This makes sense as it does some of the heavy lifting in setting things up and finding everything that is needed.

The best way to do it is to use some of the commands that are part of the computecpp-sdk cmake file.
In your example you should just be able to replace include(FindComputeCpp) with find_package(ComputeCpp) and you don’t need the include_directories($(COMPUTECPP_INCLUDE_DIRECTORY)) command as a note.

This CMake file would be most relevant as a reference if you want to replicate the same commands.

Hello @rod , Thanks a lot for replying. I did replace it with find_pacakge However the error is coming in the line add_sycl_to_target, could you please help with this.

Yes I am quite new to this and not that well versed withCMake` as well :sweat_smile:

You should also check this file for how to use add_sycl_to_target correctly. I don’t remember how long ago it was that you had to pass a directory to the command, but it was a while. The function add_sample shows correct usage of add_sycl_to_target.

Thanks for replying @duncan , I will try that out. On a side note, the find_package command should include all the headers into the project, However, if I replace include with find_package it Is not able to include the directories at least.

When you add_sycl_to_target it links the target to ComputeCpp::ComputeCpp. This CMake target has an interface include directory specified, so if you fix the add_sycl_to_target command you should not require the include_directories (you can see there are no explicit link or include commands in the CMake on the SDK).

Thanks a lot for your replies at @duncan @rod and your patience. I was not able to make add_sycl_to_target work but manually setting the compiler and passing appropriate compiler flags works. Here is the CMake files which makes it work at the moment(without using add_sycl_to_target).

cmake_minimum_required(VERSION 3.17)
project(computecpp_test)
set(CMAKE_CXX_COMPILER /home/atharva/ComputeCPP/computeCPP/bin/compute++)
set(CMAKE_CXX_FLAGS -sycl-driver)
set(CMAKE_MODULE_PATH /home/atharva/computecpp-sdk/cmake/Modules/)
#include(FindComputeCpp)
find_package(ComputeCpp)

include_directories($(COMPUTECPP_INCLUDE_DIRECTORY))

add_executable(computecpp_test main.cpp)
target_link_libraries(computecpp_test PUBLIC ComputeCpp::ComputeCpp)
#add_sycl_to_target(computecpp_test main.cpp ${CMAKE_CURRENT_BINARY_DIR})

I will try the add_sycl_to_target now. Thanks a lot once again.

Hey, I’ve recently started using ComputeCpp as well, and while setting up a project I faced the same problem. After looking at the SDK samples and my own file, the way I solved it was by explicitly adding the TARGET and SOURCES keywords to the add_sycl_to_target parameters, e.g.:

add_sycl_to_target(TARGET my_proj SOURCES "src/main.cpp" "src/main.h")

Also, I found out that you can pass flags to computecpp by setting the variables COMPUTECPP_BITCODE and COMPUTECPP_USER_FLAGS when invoking cmake, with the former being used to control which platform(s) should the compiler target and the latter being used to specify any additional flags, e.g.:

-DCOMPUTECPP_BITCODE=ptx64;spirv64 -DCOMPUTECPP_USER_FLAGS=-Wsycl-pedantic;-Wno-ignored-attributes

Hope this helps.

1 Like

Thanks a lot for sharing this @rsantos. This is indeed helpful