55
66set (OPENCL_DIR "${CMAKE_CURRENT_SOURCE_DIR} " CACHE PATH "OpenCL adapter directory" )
77
8- set (UR_OPENCL_INCLUDE_DIR "" CACHE PATH "Directory containing the OpenCL Headers" )
9- set (UR_OPENCL_ICD_LOADER_LIBRARY "" CACHE FILEPATH "Path of the OpenCL ICD Loader library" )
8+ if (UR_STANDALONE_BUILD)
9+ # This is pretty horrific, but UR is built in standlone mode with various older versions of DPC++, so even having SYCL install
10+ # this CMake file wouldn't work. UR is not a standalone project anymore and is not commonly used standalone,
11+ # so just manually download this file when doing a standalone build to be able to share OpenCL detection/fetching logic
12+ # with the larger project.
13+ file (DOWNLOAD https://raw.githubusercontent.com/intel/llvm/refs/heads/sarnex/opencl/sycl/cmake/modules/FetchOpenCL.cmake
14+ "${CMAKE_CURRENT_BINARY_DIR} /FetchOpenCL.cmake" )
15+
16+ if (NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR} /FetchOpenCL.cmake" )
17+ message (FATAL_ERROR "Failed to download SYCL CMake module" )
18+ endif ()
19+ list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_BINARY_DIR} " )
20+ endif ()
21+
22+ include (FetchOpenCL)
1023
1124find_package (Threads REQUIRED)
1225
@@ -53,52 +66,13 @@ set_target_properties(${TARGET_NAME} PROPERTIES
5366 SOVERSION "${PROJECT_VERSION_MAJOR} "
5467)
5568
56- if (UR_OPENCL_INCLUDE_DIR)
57- set (OpenCLIncludeDirectory ${UR_OPENCL_INCLUDE_DIR} )
58- else ()
59- FetchContent_Declare(OpenCL-Headers
60- GIT_REPOSITORY "https://github.com/KhronosGroup/OpenCL-Headers.git"
61- GIT_TAG 6eabe90aa7b6cff9c67800a2fe25a0cd88d8b749
62- )
63- FetchContent_MakeAvailable(OpenCL-Headers)
64- FetchContent_GetProperties(OpenCL-Headers
65- SOURCE_DIR OpenCLIncludeDirectory
66- )
67- endif ()
68-
69- # The OpenCL target can be set manually on upstream cmake to avoid using
70- # find_package().
71- if (UR_OPENCL_ICD_LOADER_LIBRARY)
72- set (OpenCLICDLoaderLibrary ${UR_OPENCL_ICD_LOADER_LIBRARY} )
73- else ()
74- find_package (OpenCL 3.0)
75- if (NOT OpenCL_FOUND)
76- FetchContent_Declare(OpenCL-ICD-Loader
77- GIT_REPOSITORY "https://github.com/KhronosGroup/OpenCL-ICD-Loader.git"
78- GIT_TAG main
79- )
80- FetchContent_MakeAvailable(OpenCL-ICD-Loader)
81- endif ()
82- set (OpenCLICDLoaderLibrary OpenCL::OpenCL)
69+ # https://github.com/intel/llvm/issues/19648
70+ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND LLVM_ENABLE_PEDANTIC)
71+ target_compile_options (ur_adapter_opencl PRIVATE -std=gnu++17)
8372endif ()
8473
85- # Make interface library use within the project.
86- add_library (OpenCLICDLoader INTERFACE )
87- target_link_libraries (OpenCLICDLoader INTERFACE "${OpenCLICDLoaderLibrary} " )
88- target_include_directories (OpenCLICDLoader INTERFACE ${OpenCLIncludeDirectory} )
89-
90- message (STATUS "OpenCL Include Directory: ${OpenCLIncludeDirectory} " )
91- message (STATUS "OpenCL ICD Loader Library: ${OpenCLICDLoaderLibrary} " )
92-
93- # Suppress a compiler message about undefined CL_TARGET_OPENCL_VERSION.
94- # Define all symbols up to OpenCL 3.0.
95- target_compile_definitions (ur_adapter_opencl PRIVATE
96- CL_TARGET_OPENCL_VERSION=300
97- CL_USE_DEPRECATED_OPENCL_1_2_APIS
98- )
99-
10074target_include_directories (${TARGET_NAME} PRIVATE
101- ${OpenCLIncludeDirectory }
75+ ${OpenCL_INCLUDE_DIRECTORY }
10276 "${CMAKE_CURRENT_SOURCE_DIR} /../../"
10377)
10478
@@ -107,5 +81,6 @@ target_link_libraries(${TARGET_NAME} PRIVATE
10781 ${PROJECT_NAME} ::common
10882 ${PROJECT_NAME} ::umf
10983 Threads::Threads
110- ${OpenCLICDLoaderLibrary}
84+ OpenCL-Headers
85+ ${OpenCL_LIBRARY}
11186)
0 commit comments