Skip to content

Commit 4dbd081

Browse files
author
Alexander Batashev
authored
[SYCL] Add CMake macro for building targets with device code (#1966)
The `add_sycl_executable` can be used to create device code-enabled unit tests. Signed-off-by: Alexander Batashev <[email protected]>
1 parent ce2b59c commit 4dbd081

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

sycl/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ set(CMAKE_CXX_EXTENSIONS OFF)
88
option(SYCL_ENABLE_WERROR "Treat all warnings as errors in SYCL project" OFF)
99
option(SYCL_ADD_DEV_VERSION_POSTFIX "Adds -V postfix to version string" ON)
1010

11+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
12+
include(AddSYCLExecutable)
13+
1114
set(SYCL_MAJOR_VERSION 2)
1215
set(SYCL_MINOR_VERSION 1)
1316
set(SYCL_PATCH_VERSION 0)
@@ -372,3 +375,5 @@ add_custom_target(deploy-sycl-toolchain
372375

373376
# SYCL Runtime documentation
374377
add_subdirectory(doc)
378+
379+
add_subdirectory(examples)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
macro(add_sycl_executable ARG_TARGET_NAME)
2+
cmake_parse_arguments(ARG
3+
""
4+
"OPTIONS"
5+
"SOURCES"
6+
${ARGN})
7+
8+
set(CXX_COMPILER clang++)
9+
if(MSVC)
10+
set(CXX_COMPILER clang-cl.exe)
11+
endif()
12+
set(DEVICE_COMPILER_EXECUTABLE ${LLVM_RUNTIME_OUTPUT_INTDIR}/${CXX_COMPILER})
13+
14+
add_custom_target(${ARG_TARGET_NAME}_exec ALL
15+
COMMAND ${DEVICE_COMPILER_EXECUTABLE} -fsycl ${ARG_OPTIONS} ${ARG_SOURCES}
16+
-o ${CMAKE_CURRENT_BINARY_DIR}/${ARG_TARGET_NAME}
17+
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/${ARG_TARGET_NAME}
18+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
19+
add_dependencies(${ARG_TARGET_NAME}_exec sycl clang)
20+
21+
add_executable(${ARG_TARGET_NAME} IMPORTED GLOBAL)
22+
set_target_properties(${ARG_TARGET_NAME} PROPERTIES
23+
IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR})
24+
endmacro()

sycl/examples/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_sycl_executable(simple-dpcpp-app SOURCES simple-dpcpp-app.cpp)

0 commit comments

Comments
 (0)