11#
2- # Modifications, Copyright (c) 2023-2025 Intel Corporation
2+ # Modifications, Copyright (C) 2024 Intel Corporation
33#
44# This software and the related documents are Intel copyrighted materials, and
55# your use of them is governed by the express license under which they were
@@ -28,10 +28,16 @@ This will define the following variables:
2828
2929``IntelSYCL_FOUND``
3030 True if the system has the SYCL library.
31+ ``SYCL_COMPILER``
32+ The resolved SYCL compiler.
3133``SYCL_LANGUAGE_VERSION``
3234 The SYCL language spec version by Compiler.
35+ ``SYCL_COMPILER_VERSION``
36+ The SYCL version of the supported Compiler.
3337``SYCL_INCLUDE_DIR``
3438 Include directories needed to use SYCL.
39+ ``SYCL_INCLUDE_SYCL_DIR``
40+ Include directories needed to use SYCL.
3541``SYCL_IMPLEMENTATION_ID``
3642 The SYCL compiler variant.
3743``SYCL_FLAGS``
@@ -50,6 +56,11 @@ The following cache variable may also be set:
5056``SYCL_LANGUAGE_VERSION``
5157 The SYCL language spec version by Compiler.
5258
59+ ``SYCL_COMPILER_VERSION``
60+ The SYCL version of the supported Compiler.
61+
62+ ``SYCL_COMPILER``
63+ The supported SYCL Compiler.
5364
5465.. Note::
5566
@@ -73,6 +84,11 @@ The following cache variable may also be set:
7384
7485#]=======================================================================]
7586
87+ if (__INTEL_SYCL_CONFIG)
88+ return ()
89+ endif ()
90+ set (__INTEL_SYCL_CONFIG 1)
91+
7692include (${CMAKE_ROOT} /Modules/FindPackageHandleStandardArgs.cmake)
7793
7894find_package (PkgConfig QUIET )
@@ -88,10 +104,18 @@ endif()
88104string (COMPARE EQUAL "${CMAKE_CXX_COMPILER} " "" nocmplr)
89105if (nocmplr)
90106 set (IntelSYCL_FOUND False )
91- set (SYCL_REASON_FAILURE "SYCL: CMAKE_CXX_COMPILER not set!!" )
107+ set (SYCL_REASON_FAILURE "CMAKE_CXX_COMPILER not set!!" )
92108 set (IntelSYCL_NOT_FOUND_MESSAGE "${SYCL_REASON_FAILURE} " )
93109endif ()
94110
111+ if (NOT "x${SYCL_HOST_COMPILER} " STREQUAL "x" )
112+ set (sycl_host_compiler "-fsycl-host-compiler=${SYCL_HOST_COMPILER} " )
113+ else ()
114+ set (sycl_host_compiler "" )
115+ endif ()
116+
117+ message (VERBOSE "SYCL_HOST_COMPILER = ${SYCL_HOST_COMPILER} " )
118+
95119# Check if a Compiler ID is being set. project() should be set prior to find_package()
96120
97121if ("x${CMAKE_CXX_COMPILER_ID} " STREQUAL "x" )
@@ -106,15 +130,68 @@ endif()
106130if ( NOT "x${CMAKE_CXX_COMPILER_ID} " STREQUAL "xClang" AND
107131 NOT "x${CMAKE_CXX_COMPILER_ID} " STREQUAL "xIntelLLVM" )
108132 set (IntelSYCL_FOUND False )
109- set (SYCL_REASON_FAILURE "Unsupported compiler family ${CMAKE_CXX_COMPILER_ID} and compiler ${CMAKE_CXX_COMPILER} !!" )
110- set (IntelSYCL_NOT_FOUND_MESSAGE "${SYCL_REASON_FAILURE} " )
111- return ()
133+ set (SYCL_REASON_FAILURE "Unsupported compiler family ${CMAKE_CXX_COMPILER_ID} and compiler ${CMAKE_CXX_COMPILER} . Also default Intel SYCL compiler not found in the environment!!" )
134+
135+ #find_program(INTEL_SYCL_COMPILER NAMES icpx icx icx-cc icx-cl)
136+ if (WIN32 AND
137+ (NOT CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "GNU" ))
138+ find_program (INTEL_SYCL_COMPILER NAMES icx icx-cl)
139+ else ()
140+ find_program (INTEL_SYCL_COMPILER icpx)
141+ endif ()
142+
143+ if (NOT INTEL_SYCL_COMPILER)
144+ message (FATAL_ERROR "Intel SYCL Compiler not found." )
145+ set (IntelSYCL_NOT_FOUND_MESSAGE "${SYCL_REASON_FAILURE} " )
146+ return ()
147+ else ()
148+ # Remove trailing semicolon if present
149+ string (STRIP "${INTEL_SYCL_COMPILER} ;" INTEL_SYCL_COMPILER)
150+ message (STATUS "Setting SYCL Compiler to default ${INTEL_SYCL_COMPILER} ." )
151+ set (SYCL_COMPILER ${INTEL_SYCL_COMPILER} )
152+ set (IntelSYCL_FOUND True )
153+ endif ()
154+ else ()
155+ # Assume that CXX Compiler supports SYCL and then test to verify.
156+ set (SYCL_COMPILER ${CMAKE_CXX_COMPILER} )
112157endif ()
113158
114- # Assume that CXX Compiler supports SYCL and then test to verify.
115- set (SYCL_COMPILER ${CMAKE_CXX_COMPILER} )
116-
117159# Function to write a test case to verify SYCL features.
160+ function (parse_compiler_version compiler_name version_number)
161+ execute_process (
162+ COMMAND ${compiler_name} --version
163+ OUTPUT_VARIABLE COMPILER_VERSION_STRING
164+ OUTPUT_STRIP_TRAILING_WHITESPACE
165+ )
166+
167+ # Intel Compiler Regex
168+ string (REGEX MATCH "Intel\\ (R\\ ) (.*) Compiler ([0-9]+\\ .[0-9]+\\ .[0-9]+) (.*)"
169+ INTEL_VERSION_STRING ${COMPILER_VERSION_STRING} )
170+
171+ if (INTEL_VERSION_STRING)
172+ # Parse Intel Compiler Version
173+ string (REGEX REPLACE "Intel\\ (R\\ ) (.*) Compiler ([0-9]+\\ .[0-9]+\\ .[0-9]+) (.*)" "\\ 2"
174+ SYCL_VERSION_STRING_MATCH ${INTEL_VERSION_STRING} )
175+ string (REPLACE "." ";" SYCL_VERSION_LIST ${SYCL_VERSION_STRING_MATCH} )
176+ list (GET SYCL_VERSION_LIST 0 VERSION_MAJOR)
177+ list (GET SYCL_VERSION_LIST 1 VERSION_MINOR)
178+ list (GET SYCL_VERSION_LIST 2 VERSION_PATCH)
179+ math (EXPR VERSION_NUMBER_MATCH "${VERSION_MAJOR} * 10000 + ${VERSION_MINOR} * 100 + ${VERSION_PATCH} " )
180+ endif ()
181+ set (${version_number} "${VERSION_NUMBER_MATCH} " PARENT_SCOPE)
182+ endfunction ()
183+
184+ parse_compiler_version(${SYCL_COMPILER} SYCL_COMPILER_VERSION)
185+
186+ if (NOT SYCL_COMPILER_VERSION)
187+ set (SYCL_FOUND False )
188+ set (SYCL_REASON_FAILURE "Cannot parse sycl compiler version to get SYCL_COMPILER_VERSION!" )
189+ set (SYCL_NOT_FOUND_MESSAGE "${SYCL_REASON_FAILURE} " )
190+ return ()
191+ endif ()
192+
193+ #set(SYCL_COMPILER_VERSION ${COMPILER_VERSION})
194+ message (STATUS "SYCL Compiler version: ${SYCL_COMPILER_VERSION} " )
118195
119196function (SYCL_FEATURE_TEST_WRITE src)
120197
@@ -143,7 +220,7 @@ function(SYCL_FEATURE_TEST_BUILD TEST_SRC_FILE TEST_EXE)
143220
144221 # Convert CXX Flag string to list
145222 set (SYCL_CXX_FLAGS_LIST "${SYCL_CXX_FLAGS} " )
146- separate_arguments (SYCL_CXX_FLAGS_LIST)
223+ separate_arguments (SYCL_CXX_FLAGS_LIST NATIVE_COMMAND ${SYCL_CXX_FLAGS_LIST} )
147224
148225 # Spawn a process to build the test case.
149226 execute_process (
@@ -157,6 +234,7 @@ function(SYCL_FEATURE_TEST_BUILD TEST_SRC_FILE TEST_EXE)
157234 OUTPUT_FILE ${SYCL_TEST_DIR} /Compile.log
158235 RESULT_VARIABLE result
159236 TIMEOUT 60
237+ #COMMAND_ECHO STDOUT
160238 )
161239
162240 # Verify if test case build properly.
@@ -230,6 +308,17 @@ if(SYCL_COMPILER)
230308 NO_DEFAULT_PATH
231309 )
232310
311+ # Find include/sycl path from include path.
312+ find_file (
313+ SYCL_INCLUDE_SYCL_DIR
314+ NAMES sycl
315+ HINTS
316+ ${SYCL_PACKAGE_DIR} $ENV{SYCL_INCLUDE_DIR_HINT}
317+ PATH_SUFFIXES include
318+ NO_DEFAULT_PATH
319+ )
320+ message (STATUS "SYCL_INCLUDE_DIR: ${SYCL_INCLUDE_DIR} " )
321+
233322 # Find Library directory
234323 find_file (SYCL_LIBRARY_DIR
235324 NAMES
@@ -238,7 +327,22 @@ if(SYCL_COMPILER)
238327 ${SYCL_PACKAGE_DIR} $ENV{SYCL_LIBRARY_DIR_HINT}
239328 NO_DEFAULT_PATH
240329 )
241-
330+ #TODO Make an input file to configure and update the lib current version
331+ if (WIN32 )
332+ set (sycl_lib_suffix "8" )
333+ else ()
334+ set (sycl_lib_suffix "" )
335+ endif ()
336+ if (NOT "x${SYCL_LIB_SUFFIX} " STREQUAL "x" )
337+ set (sycl_lib_suffix "${SYCL_LIB_SUFFIX} " )
338+ endif ()
339+ find_library (
340+ SYCL_LIBRARY
341+ NAMES "sycl${sycl_lib_suffix} "
342+ HINTS ${SYCL_LIBRARY_DIR}
343+ NO_DEFAULT_PATH
344+ )
345+ message (STATUS "SYCL_LIBRARY=${SYCL_LIBRARY} " )
242346endif ()
243347
244348
@@ -247,7 +351,7 @@ set(SYCL_LINK_FLAGS "")
247351
248352# Based on Compiler ID, add support for SYCL
249353if ( "x${CMAKE_CXX_COMPILER_ID} " STREQUAL "xClang" OR
250- "x${CMAKE_CXX_COMPILER_ID} " STREQUAL "xIntelLLVM" )
354+ "x${CMAKE_CXX_COMPILER_ID} " STREQUAL "xIntelLLVM" OR IntelSYCL_FOUND )
251355 list (APPEND SYCL_FLAGS "-fsycl" )
252356 list (APPEND SYCL_LINK_FLAGS "-fsycl" )
253357endif ()
@@ -258,7 +362,9 @@ if(WIN32)
258362 list (APPEND SYCL_FLAGS "/EHsc" )
259363endif ()
260364
261- set (SYCL_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SYCL_FLAGS} " )
365+ list (JOIN SYCL_FLAGS " " SYCL_FLAGS_STRING)
366+ message (DEBUG "SYCL_FLAGS_STRING: ${SYCL_FLAGS_STRING} " )
367+ set (SYCL_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SYCL_FLAGS_STRING} " )
262368
263369# And now test the assumptions.
264370
@@ -286,10 +392,15 @@ SYCL_FEATURE_TEST_EXTRACT(${test_output})
286392string (COMPARE EQUAL "${SYCL_LANGUAGE_VERSION} " "" nosycllang)
287393if (nosycllang)
288394 set (IntelSYCL_FOUND False )
289- set (SYCL_REASON_FAILURE "SYCL: It appears that the ${CMAKE_CXX_COMPILER } does not support SYCL" )
395+ set (SYCL_REASON_FAILURE "SYCL: It appears that the ${SYCL_COMPILER } does not support SYCL" )
290396 set (IntelSYCL_NOT_FOUND_MESSAGE "${SYCL_REASON_FAILURE} " )
291397endif ()
292398
399+ if (NOT "x${sycl_host_compiler} " STREQUAL "x" )
400+ list (APPEND SYCL_FLAGS ${sycl_host_compiler} )
401+ list (APPEND SYCL_CXX_FLAGS ${sycl_host_compiler} )
402+ endif ()
403+
293404# Placeholder for identifying various implementations of SYCL compilers.
294405# for now, set to the CMAKE_CXX_COMPILER_ID
295406set (SYCL_IMPLEMENTATION_ID "${CMAKE_CXX_COMPILER_ID} " )
@@ -307,16 +418,24 @@ set_property(TARGET IntelSYCL::SYCL_CXX PROPERTY
307418 INTERFACE_INCLUDE_DIRECTORIES ${SYCL_INCLUDE_DIR} )
308419set_property (TARGET IntelSYCL::SYCL_CXX PROPERTY
309420 INTERFACE_LINK_DIRECTORIES ${SYCL_LIBRARY_DIR} )
421+ set_property (TARGET IntelSYCL::SYCL_CXX PROPERTY
422+ INTERFACE_LINK_LIBRARIES ${SYCL_LIBRARY} )
310423
311424find_package_handle_standard_args(
312425 IntelSYCL
313426 FOUND_VAR IntelSYCL_FOUND
314- REQUIRED_VARS SYCL_INCLUDE_DIR SYCL_LIBRARY_DIR SYCL_FLAGS
427+ REQUIRED_VARS SYCL_INCLUDE_DIR SYCL_LIBRARY_DIR SYCL_FLAGS SYCL_COMPILER_VERSION SYCL_COMPILER SYCL_LIBRARY
315428 VERSION_VAR SYCL_LANGUAGE_VERSION
316429 REASON_FAILURE_MESSAGE "${SYCL_REASON_FAILURE} " )
317430
318431# Include in Cache
319432set (SYCL_LANGUAGE_VERSION "${SYCL_LANGUAGE_VERSION} " CACHE STRING "SYCL Language version" )
433+ set (SYCL_COMPILER_VERSION "${SYCL_COMPILER_VERSION} " CACHE STRING "SYCL Compiler version" )
434+ set (SYCL_COMPILER "${SYCL_COMPILER} " CACHE STRING "SYCL Compiler" )
435+ set (SYCL_INCLUDE_DIR "${SYCL_INCLUDE_DIR} " CACHE STRING "SYCL Include Dir " )
436+ set (SYCL_INCLUDE_SYCL_DIR "${SYCL_INCLUDE_SYCL_DIR} " CACHE STRING "SYCL Include SYCL Dir " )
437+ set (SYCL_LIBRARY_DIR "${SYCL_LIBRARY_DIR} " CACHE STRING "SYCL Library Dir" )
438+ set (SYCL_LIBRARY "${SYCL_LIBRARY} " CACHE STRING "SYCL Library" )
320439
321440function (add_sycl_to_target)
322441
@@ -340,6 +459,10 @@ Adding sycl to all sources but that may effect compilation times")
340459 set (SYCL_TARGET ${ARGV} )
341460 endif ()
342461
462+ if (NOT SYCL_TARGET)
463+ message (FATAL_ERROR "add_sycl_to_target() requires a TARGET argument, but none was passed." )
464+ endif ()
465+
343466 if (NOT SYCL_SOURCES)
344467 message (WARNING "add_sycl_to_target() does not have sources specified.. Adding sycl to all sources but that may effect compilation times" )
345468 target_compile_options (${SYCL_TARGET} PUBLIC ${__sycl_cxx_options} )
@@ -353,7 +476,7 @@ Adding sycl to all sources but that may effect compilation times")
353476
354477 get_target_property (__sycl_link_options
355478 IntelSYCL::SYCL_CXX INTERFACE_LINK_OPTIONS)
356- target_link_options (${SYCL_TARGET} PRIVATE "${__sycl_link_options} " )
479+ target_link_options (${SYCL_TARGET} PUBLIC "${__sycl_link_options} " )
357480 get_target_property (__sycl_link_directories
358481 IntelSYCL::SYCL_CXX INTERFACE_LINK_DIRECTORIES)
359482 target_link_directories (${SYCL_TARGET} PUBLIC "${__sycl_link_directories} " )
0 commit comments