1
- # add_sycl_unittest(test_dirname SHARED|OBJECT file1.cpp, file2.cpp ...)
2
- #
3
- # Will compile the list of files together and link against SYCL.
4
- # Produces a binary names `basename(test_dirname)`.
5
- macro (add_sycl_unittest test_dirname link_variant )
1
+ # Internal function to create SYCL unit tests with code reuse
2
+ # add_sycl_unittest_internal(test_dirname SHARED|OBJECT is_preview file1.cpp, file2.cpp ...)
3
+ function (add_sycl_unittest_internal test_dirname link_variant is_preview )
6
4
# Enable exception handling for these unit tests
7
5
set (LLVM_REQUIRES_EH ON )
8
6
set (LLVM_REQUIRES_RTTI ON )
9
7
10
8
get_target_property (SYCL_BINARY_DIR sycl-toolchain BINARY_DIR )
11
9
12
10
string (TOLOWER "${CMAKE_BUILD_TYPE} " build_type_lower )
11
+
12
+ # Select which sycl libraries and object to link based
13
+ # on whether this is a preview build.
13
14
if (MSVC AND build_type_lower MATCHES "debug" )
14
- set (sycl_obj_target "sycld_object" )
15
- set (sycl_so_target "sycld" )
15
+ if (${is_preview} )
16
+ set (sycl_obj_target "sycl-previewd_object" )
17
+ set (sycl_so_target "sycl-previewd" )
18
+ else ()
19
+ set (sycl_obj_target "sycld_object" )
20
+ set (sycl_so_target "sycld" )
21
+ endif ()
16
22
else ()
17
- set (sycl_obj_target "sycl_object" )
18
- set (sycl_so_target "sycl" )
23
+ if (${is_preview} )
24
+ set (sycl_obj_target "sycl-preview_object" )
25
+ set (sycl_so_target "sycl-preview" )
26
+ else ()
27
+ set (sycl_obj_target "sycl_object" )
28
+ set (sycl_so_target "sycl" )
29
+ endif ()
30
+ endif ()
31
+
32
+ # This is done to ensure that preview tests are kept in a separate
33
+ # directory, so that they do not interfere with the non-preview tests.
34
+ # Chaning CMAKE_CURRENT_BINARY_DIR should not affect this variable in its
35
+ # parent scope.
36
+ if (${is_preview} )
37
+ set (CMAKE_CURRENT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR} /Preview" )
19
38
endif ()
20
39
21
40
if ("${link_variant} " MATCHES "SHARED" )
@@ -39,6 +58,13 @@ macro(add_sycl_unittest test_dirname link_variant)
39
58
)
40
59
endif ()
41
60
61
+ # Add preview-specific compile definition
62
+ if (${is_preview} )
63
+ target_compile_definitions (${test_dirname}
64
+ PRIVATE __INTEL_PREVIEW_BREAKING_CHANGES )
65
+ set (sycl_cache_suffix "_preview" )
66
+ endif ()
67
+
42
68
if (SYCL_ENABLE_XPTI_TRACING )
43
69
target_compile_definitions (${test_dirname}
44
70
PRIVATE XPTI_ENABLE_INSTRUMENTATION XPTI_STATIC_LIBRARY )
@@ -53,9 +79,10 @@ macro(add_sycl_unittest test_dirname link_variant)
53
79
LLVM_PROFILE_FILE= "${SYCL_COVERAGE_PATH} /${test_dirname} .profraw"
54
80
SYCL_CONFIG_FILE_NAME=null.cfg
55
81
SYCL_DEVICELIB_NO_FALLBACK=1
56
- SYCL_CACHE_DIR= "${CMAKE_BINARY_DIR} /sycl_cache"
82
+ SYCL_CACHE_DIR= "${CMAKE_BINARY_DIR} /sycl_cache${sycl_cache_suffix} "
57
83
"PATH=${CMAKE_BINARY_DIR} /bin;$ENV{PATH} "
58
84
${CMAKE_CURRENT_BINARY_DIR} /${test_dirname}
85
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
59
86
DEPENDS
60
87
${test_dirname}
61
88
)
@@ -65,9 +92,10 @@ macro(add_sycl_unittest test_dirname link_variant)
65
92
LLVM_PROFILE_FILE= "${SYCL_COVERAGE_PATH} /${test_dirname} .profraw"
66
93
SYCL_CONFIG_FILE_NAME=null.cfg
67
94
SYCL_DEVICELIB_NO_FALLBACK=1
68
- SYCL_CACHE_DIR= "${CMAKE_BINARY_DIR} /sycl_cache"
95
+ SYCL_CACHE_DIR= "${CMAKE_BINARY_DIR} /sycl_cache${sycl_cache_suffix} "
69
96
"LD_LIBRARY_PATH=${SYCL_BINARY_DIR} /unittests/lib:${CMAKE_BINARY_DIR} /lib:$ENV{LD_LIBRARY_PATH} "
70
97
${CMAKE_CURRENT_BINARY_DIR} /${test_dirname}
98
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
71
99
DEPENDS
72
100
${test_dirname}
73
101
)
@@ -79,6 +107,7 @@ macro(add_sycl_unittest test_dirname link_variant)
79
107
# Windows doesn't support LD_LIBRARY_PATH, so instead we copy the mock OpenCL binary next to the test and ensure
80
108
# that the test itself links to OpenCL (rather than through ur_adapter_opencl.dll)
81
109
set (mock_ocl ${CMAKE_CURRENT_BINARY_DIR} /OpenCL.dll )
110
+
82
111
add_custom_command (TARGET ${test_dirname} POST_BUILD
83
112
COMMAND ${CMAKE_COMMAND} -E copy $< TARGET_FILE:mockOpenCL> ${mock_ocl}
84
113
DEPENDS mockOpenCL
@@ -122,4 +151,14 @@ macro(add_sycl_unittest test_dirname link_variant)
122
151
endif ()
123
152
124
153
target_compile_definitions (${test_dirname} PRIVATE SYCL_DISABLE_FSYCL_SYCLHPP_WARNING )
154
+ endfunction ()
155
+
156
+ # add_sycl_unittest(test_name_prefix SHARED|OBJECT file1.cpp, file2.cpp ...)
157
+ #
158
+ # Will compile the list of files together to create two builds, with and without
159
+ # the SYCL preview features enabled.
160
+ # Produces two binaries, named `basename(test_name_prefix_non_preview)` and `basename(test_name_prefix_preview)`
161
+ macro (add_sycl_unittest test_name_prefix link_variant )
162
+ add_sycl_unittest_internal (${test_name_prefix} _non_preview ${link_variant} FALSE ${ARGN} )
163
+ add_sycl_unittest_internal (${test_name_prefix} _preview ${link_variant} TRUE ${ARGN} )
125
164
endmacro ()
0 commit comments