Skip to content

Commit edb2472

Browse files
authored
[UR][CMake] Fix OpenCL target error on rebuild (#19740)
The problem was `OpenCL_FOUND` was getting set to `TRUE` on the second invocation of the module because `find_package` was finding the `FetchContent` clone in `SOURCE_TREE/build/__deps`. We use `OpenCL_FOUND` to specifically refer to external system-wide installs, so use `NO_CMAKE_PACKAGE_REGISTRY` to make sure we don't find FetchContent clones. Also not related to the fix here but re-order `FetchContent_Declare` `FetchContent_GetProperties`, the `Declare` should come first and we `MakeAvailable` should not be inside the `if`, we only check if it's populated to print the message. Closes: #19737 Signed-off-by: Sarnie, Nick <[email protected]>
1 parent dc8068f commit edb2472

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

unified-runtime/cmake/FetchOpenCL.cmake

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ set(OCL_LOADER_REPO
1717
set(OCL_HEADERS_TAG 6eabe90aa7b6cff9c67800a2fe25a0cd88d8b749)
1818
set(OCL_LOADER_TAG ddf6c70230a79cdb8fcccfd3c775b09e6820f42e)
1919

20-
find_package(OpenCL 3.0 QUIET)
20+
# Set NO_CMAKE_PACKAGE_REGISTRY so only system-wide installs are
21+
# detected.
22+
find_package(OpenCL 3.0 QUIET NO_CMAKE_PACKAGE_REGISTRY)
23+
2124
if(OpenCL_FOUND)
2225
# The OpenCL-Headers CMake files don't provide granular info
2326
# on what is and isn't supposed, just the overall OpenCL version.
@@ -48,16 +51,16 @@ endif()
4851

4952
# OpenCL Headers
5053
if(NOT OpenCL_FOUND)
54+
FetchContent_Declare(ocl-headers
55+
GIT_REPOSITORY ${OCL_HEADERS_REPO}
56+
GIT_TAG ${OCL_HEADERS_TAG}
57+
)
5158
FetchContent_GetProperties(ocl-headers)
5259

5360
if(NOT ocl-headers_POPULATED)
5461
message(STATUS "Will fetch OpenCL headers from ${OCL_HEADERS_REPO}")
55-
FetchContent_Declare(ocl-headers
56-
GIT_REPOSITORY ${OCL_HEADERS_REPO}
57-
GIT_TAG ${OCL_HEADERS_TAG}
58-
)
59-
FetchContent_MakeAvailable(ocl-headers)
6062
endif()
63+
FetchContent_MakeAvailable(ocl-headers)
6164
set(OpenCL_INCLUDE_DIR ${ocl-headers_SOURCE_DIR} CACHE PATH "" FORCE)
6265
else()
6366
message(STATUS "Using OpenCL headers at ${OpenCL_INCLUDE_DIR}")
@@ -68,17 +71,15 @@ endif()
6871
set(BUILD_SHARED_LIBS ON)
6972

7073
if(NOT OpenCL_FOUND)
71-
74+
FetchContent_Declare(ocl-icd
75+
GIT_REPOSITORY ${OCL_LOADER_REPO}
76+
GIT_TAG ${OCL_LOADER_TAG}
77+
)
7278
FetchContent_GetProperties(ocl-icd)
7379
if(NOT ocl-icd_POPULATED)
7480
message(STATUS "Will fetch OpenCL ICD Loader from ${OCL_LOADER_REPO}")
75-
FetchContent_Declare(ocl-icd
76-
GIT_REPOSITORY ${OCL_LOADER_REPO}
77-
GIT_TAG ${OCL_LOADER_TAG}
78-
)
79-
80-
FetchContent_MakeAvailable(ocl-icd)
8181
endif()
82+
FetchContent_MakeAvailable(ocl-icd)
8283
set(OpenCL_LIBRARY OpenCL::OpenCL CACHE PATH "" FORCE)
8384
else()
8485
message(STATUS

0 commit comments

Comments
 (0)