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)
64 # Enable exception handling for these unit tests
75 set (LLVM_REQUIRES_EH ON )
86 set (LLVM_REQUIRES_RTTI ON )
97
108 get_target_property (SYCL_BINARY_DIR sycl-toolchain BINARY_DIR)
119
1210 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.
1314 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 ()
1622 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" )
1938 endif ()
2039
2140 if ("${link_variant} " MATCHES "SHARED" )
@@ -39,6 +58,13 @@ macro(add_sycl_unittest test_dirname link_variant)
3958 )
4059 endif ()
4160
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+
4268 if (SYCL_ENABLE_XPTI_TRACING)
4369 target_compile_definitions (${test_dirname}
4470 PRIVATE XPTI_ENABLE_INSTRUMENTATION XPTI_STATIC_LIBRARY)
@@ -53,9 +79,10 @@ macro(add_sycl_unittest test_dirname link_variant)
5379 LLVM_PROFILE_FILE="${SYCL_COVERAGE_PATH} /${test_dirname} .profraw"
5480 SYCL_CONFIG_FILE_NAME=null.cfg
5581 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} "
5783 "PATH=${CMAKE_BINARY_DIR} /bin;$ENV{PATH} "
5884 ${CMAKE_CURRENT_BINARY_DIR} /${test_dirname}
85+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
5986 DEPENDS
6087 ${test_dirname}
6188 )
@@ -65,9 +92,10 @@ macro(add_sycl_unittest test_dirname link_variant)
6592 LLVM_PROFILE_FILE="${SYCL_COVERAGE_PATH} /${test_dirname} .profraw"
6693 SYCL_CONFIG_FILE_NAME=null.cfg
6794 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} "
6996 "LD_LIBRARY_PATH=${SYCL_BINARY_DIR} /unittests/lib:${CMAKE_BINARY_DIR} /lib:$ENV{LD_LIBRARY_PATH} "
7097 ${CMAKE_CURRENT_BINARY_DIR} /${test_dirname}
98+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
7199 DEPENDS
72100 ${test_dirname}
73101 )
@@ -79,6 +107,7 @@ macro(add_sycl_unittest test_dirname link_variant)
79107 # Windows doesn't support LD_LIBRARY_PATH, so instead we copy the mock OpenCL binary next to the test and ensure
80108 # that the test itself links to OpenCL (rather than through ur_adapter_opencl.dll)
81109 set (mock_ocl ${CMAKE_CURRENT_BINARY_DIR} /OpenCL.dll)
110+
82111 add_custom_command (TARGET ${test_dirname} POST_BUILD
83112 COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:mockOpenCL> ${mock_ocl}
84113 DEPENDS mockOpenCL
@@ -122,4 +151,14 @@ macro(add_sycl_unittest test_dirname link_variant)
122151 endif ()
123152
124153 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} )
125164endmacro ()
0 commit comments