Skip to content

Commit 824692b

Browse files
authored
[SYCL][NativeCPU][CMake] Simplify OCK CMake handling (#19704)
I'm trying to make this repo more easily packaged by Linux distros, and OCK came up in some feedback from NixOS (see linked issue). Overall, the external dependency behavior should work as follows: 1) Use the user specified directory if given 2) If not, search the system for the dependency's install location and use that 3) If not found, fetch it OCK seems a bit special because installing OCK locally doesn't seem to install any CMake files nor does it install the files required to use it to build NativeCPU support. Seems we actually need the git tree, not the installed result of a built OCK. Strange but let's go with it. You can already provide a precreated clone to use to build with `FetchContent` using `FETCHCONTENT_SOURCE_DIR_<uppercaseName>`, so there is no need for variable to set the directory and a custom repo and tag. Remove variables that duplicate functionality that already exists in `FetchContent`, and add a simple search for the source directory on the system. Issue: #19635 --------- Signed-off-by: Sarnie, Nick <[email protected]>
1 parent 10af536 commit 824692b

File tree

1 file changed

+23
-27
lines changed

1 file changed

+23
-27
lines changed

llvm/lib/SYCLNativeCPUUtils/CMakeLists.txt

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ add_llvm_component_library(LLVMSYCLNativeCPUUtils
1919
ipo
2020
)
2121

22-
set(OCK_SOURCE_DIR "" CACHE PATH "Root of the local checkout of the oneAPI Construction Kit")
23-
set(OCK_GIT_REPO "" CACHE STRING "Git repository for the oneAPI Construction Kit FetchContent")
24-
set(OCK_GIT_TAG "" CACHE STRING "Git tag for the oneAPI Construction Kit FetchContent")
25-
option(NATIVECPU_OCK_USE_FETCHCONTENT "Use FetchContent to acquire oneAPI Construction Kit source code" On)
2622
option(NATIVECPU_USE_OCK "Use the oneAPI Construction Kit for Native CPU" ON)
2723

2824
# Don't fetch OCK if Native CPU is not enabled.
@@ -31,8 +27,16 @@ if(NOT "native_cpu" IN_LIST SYCL_ENABLE_BACKENDS)
3127
endif()
3228

3329
if(NATIVECPU_USE_OCK)
34-
if(NATIVECPU_OCK_USE_FETCHCONTENT)
35-
set(OCK_GIT_INTERNAL_REPO "https://github.com/uxlfoundation/oneapi-construction-kit.git")
30+
set(OCK_SEARCH_LOC "oneapi-construction-kit/compiler_passes")
31+
if(NOT FETCHCONTENT_SOURCE_DIR_ONEAPI-CK)
32+
find_path(OCK_SOURCE_DIR ${OCK_SEARCH_LOC} PATHS ${CMAKE_PREFIX_PATH})
33+
endif()
34+
if(OCK_SOURCE_DIR)
35+
message(STATUS "Found system source location of oneAPI Construction Kit in ${OCK_SOURCE_DIR}")
36+
set(OCK_SOURCE_DIR "${OCK_SOURCE_DIR}/${OCK_SEARCH_LOC}")
37+
set(OCK_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/oneapi-construction-kit")
38+
else()
39+
set(OCK_GIT_REPO "https://github.com/uxlfoundation/oneapi-construction-kit.git")
3640
# commit d0a32d701e34b3285de7ce776ea36abfec673df7
3741
# Merge: a9f848e0e8 56473a8c25
3842
# Author: Harald van Dijk <[email protected]>
@@ -41,39 +45,31 @@ if(NATIVECPU_USE_OCK)
4145
# Merge pull request #878 from hvdijk/specify-fuse-ld-lld
4246
#
4347
# [RefSi] Explicitly specify -fuse-ld=lld.
44-
set(OCK_GIT_INTERNAL_TAG d0a32d701e34b3285de7ce776ea36abfec673df7)
45-
46-
# Overwrite OCK_GIT_INTERNAL_REPO/OCK_GIT_INTERNAL_TAG if the corresponding options are set
47-
if(OCK_GIT_REPO)
48-
set(OCK_GIT_INTERNAL_REPO "${OCK_GIT_REPO}")
49-
endif()
50-
if(OCK_GIT_TAG)
51-
set(OCK_GIT_INTERNAL_TAG "${OCK_GIT_TAG}")
52-
endif()
48+
set(OCK_GIT_TAG d0a32d701e34b3285de7ce776ea36abfec673df7)
49+
5350
include(FetchContent)
5451
FetchContent_Declare(oneapi-ck
55-
GIT_REPOSITORY "${OCK_GIT_INTERNAL_REPO}"
56-
GIT_TAG "${OCK_GIT_INTERNAL_TAG}"
52+
GIT_REPOSITORY "${OCK_GIT_REPO}"
53+
GIT_TAG "${OCK_GIT_TAG}"
5754
)
5855
FetchContent_GetProperties(oneapi-ck)
5956
if(NOT oneapi-ck_POPULATED)
60-
message(STATUS "Cloning oneAPI Construction Kit from ${OCK_GIT_INTERNAL_REPO}, tag ${OCK_GIT_INTERNAL_TAG}")
57+
if(FETCHCONTENT_SOURCE_DIR_ONEAPI-CK)
58+
message(STATUS "Using specified oneAPI Construction Kit repo location at ${FETCHCONTENT_SOURCE_DIR_ONEAPI-CK}")
59+
else()
60+
message(STATUS "Cloning oneAPI Construction Kit from ${OCK_GIT_REPO}, tag ${OCK_GIT_TAG}")
61+
endif()
6162
FetchContent_Populate(oneapi-ck)
6263
message(STATUS "oneAPI Construction Kit cloned in ${oneapi-ck_SOURCE_DIR}")
63-
set(OCK_SOURCE_DIR_INTERNAL ${oneapi-ck_SOURCE_DIR}/compiler_passes)
64-
set(OCK_BINARY_DIR_INTERNAL ${oneapi-ck_BINARY_DIR})
64+
set(OCK_SOURCE_DIR ${oneapi-ck_SOURCE_DIR}/compiler_passes)
65+
set(OCK_BINARY_DIR ${oneapi-ck_BINARY_DIR})
6566
endif()
66-
elseif(OCK_SOURCE_DIR)
67-
set(OCK_SOURCE_DIR_INTERNAL "${OCK_SOURCE_DIR}/compiler_passes")
68-
set(OCK_BINARY_DIR_INTERNAL "${CMAKE_CURRENT_BINARY_DIR}/oneapi-construction-kit")
69-
else()
70-
message(FATAL_ERROR "NATIVECPU_OCK_USE_FETCHCONTENT is Off and OCK_SOURCE_DIR not set")
7167
endif()
7268

7369
set(CA_ENABLE_API "cl" CACHE STRING "" FORCE)
7470
add_subdirectory(
75-
${OCK_SOURCE_DIR_INTERNAL}
76-
${OCK_BINARY_DIR_INTERNAL} EXCLUDE_FROM_ALL)
71+
${OCK_SOURCE_DIR}
72+
${OCK_BINARY_DIR} EXCLUDE_FROM_ALL)
7773

7874
install(TARGETS compiler-pipeline
7975
EXPORT;LLVMExports

0 commit comments

Comments
 (0)