Skip to content

Commit 3653e58

Browse files
authored
[OpenCL] Allow upstream to manually set the OpenCL target (#969)
- Upstream CI is unable to use find_package() for OpenCL. This commit allows it to set the target manually and skip the call to find_package(). - This commit also changes UR to use the OpenCL::OpenCL target. It provides a simpler alternative to import the opencl library without having to use add_library().
1 parent f0de2f4 commit 3653e58

File tree

1 file changed

+6
-23
lines changed

1 file changed

+6
-23
lines changed

source/adapters/opencl/CMakeLists.txt

+6-23
Original file line numberDiff line numberDiff line change
@@ -43,41 +43,24 @@ set_target_properties(${TARGET_NAME} PROPERTIES
4343

4444
find_package(Threads REQUIRED)
4545

46-
if (NOT DEFINED OpenCL_LIBRARY OR NOT DEFINED OpenCL_INCLUDE_DIR)
47-
message(WARNING "OpenCL_LIBRARY and OpenCL_INCLUDE_DIR are not set. Using find_package() to find an OpenCL installation in the system.")
46+
# The OpenCL target can be set manually on upstream cmake to avoid using find_package().
47+
if (NOT UR_OPENCL_ICD_LOADER_LIBRARY)
4848
find_package(OpenCL REQUIRED)
49+
message(STATUS "OpenCL_LIBRARY: ${OpenCL_LIBRARY}")
50+
message(STATUS "OpenCL_INCLUDE_DIR: ${OpenCL_INCLUDE_DIR}")
51+
set(UR_OPENCL_ICD_LOADER_LIBRARY OpenCL::OpenCL)
4952
endif()
5053

51-
message(STATUS "OpenCL_LIBRARY: ${OpenCL_LIBRARY}")
52-
message(STATUS "OpenCL_INCLUDE_DIR: ${OpenCL_INCLUDE_DIR}")
53-
5454
# Suppress a compiler message about undefined CL_TARGET_OPENCL_VERSION.
5555
# Define all symbols up to OpenCL 3.0.
5656
target_compile_definitions(ur_adapter_opencl PRIVATE CL_TARGET_OPENCL_VERSION=300 CL_USE_DEPRECATED_OPENCL_1_2_APIS)
5757

58-
# Make imported library global to use it within the project.
59-
add_library(OpenCL-ICD SHARED IMPORTED GLOBAL)
60-
61-
if (WIN32)
62-
set_target_properties(
63-
OpenCL-ICD PROPERTIES
64-
IMPORTED_IMPLIB ${OpenCL_LIBRARY}
65-
INTERFACE_INCLUDE_DIRECTORIES ${OpenCL_INCLUDE_DIR}
66-
)
67-
else()
68-
set_target_properties(
69-
OpenCL-ICD PROPERTIES
70-
IMPORTED_LOCATION ${OpenCL_LIBRARY}
71-
INTERFACE_INCLUDE_DIRECTORIES ${OpenCL_INCLUDE_DIR}
72-
)
73-
endif()
74-
7558
target_link_libraries(${TARGET_NAME} PRIVATE
7659
${PROJECT_NAME}::headers
7760
${PROJECT_NAME}::common
7861
${PROJECT_NAME}::unified_malloc_framework
7962
Threads::Threads
80-
OpenCL-ICD
63+
${UR_OPENCL_ICD_LOADER_LIBRARY}
8164
)
8265

8366
target_include_directories(${TARGET_NAME} PRIVATE

0 commit comments

Comments
 (0)