From beade4c5ed6bb0b1fad4df0d7f9851cdc9e6630d Mon Sep 17 00:00:00 2001 From: Wenju He Date: Tue, 1 Sep 2026 04:31:29 +0200 Subject: [PATCH] [CMake] Deduplicate libclc-enabled runtime check sycl/CMakeLists.txt and sycl-jit/jit-compiler/CMakeLists.txt each independently looped over LLVM_RUNTIME_TARGETS to determine whether the "libclc" runtime is enabled. Factor that into a shared is_llvm_runtime_enabled(runtime result) function in a new llvm/cmake/modules/CheckEnabledLLVMRuntime.cmake so future callers (e.g. downstream libdevice/offload consumers that need this before runtimes/CMakeLists.txt creates the libclc/libspirv-builtins targets) can reuse it instead of reimplementing the loop or relying on if(TARGET libclc), which evaluates false before those targets exist. Co-Authored-By: Claude Sonnet 5 --- .../cmake/modules/CheckEnabledLLVMRuntime.cmake | 17 +++++++++++++++++ sycl-jit/jit-compiler/CMakeLists.txt | 9 ++------- sycl/CMakeLists.txt | 9 ++------- 3 files changed, 21 insertions(+), 14 deletions(-) create mode 100644 llvm/cmake/modules/CheckEnabledLLVMRuntime.cmake diff --git a/llvm/cmake/modules/CheckEnabledLLVMRuntime.cmake b/llvm/cmake/modules/CheckEnabledLLVMRuntime.cmake new file mode 100644 index 0000000000000..2ff6c9495ce2d --- /dev/null +++ b/llvm/cmake/modules/CheckEnabledLLVMRuntime.cmake @@ -0,0 +1,17 @@ +# is_llvm_runtime_enabled(runtime result) sets 'result' to TRUE if 'runtime' +# (e.g. libclc) is enabled for any configured runtime target, FALSE otherwise. +# +# Use this instead of if(TARGET ) because this runs before +# runtimes/CMakeLists.txt creates runtime targets, so a TARGET check would +# always be false. The enabled-runtimes lists aren't affected by that +# ordering. +function(is_llvm_runtime_enabled runtime result) + set(enabled FALSE) + foreach(runtime_target IN LISTS LLVM_RUNTIME_TARGETS) + if("${runtime}" IN_LIST RUNTIMES_${runtime_target}_LLVM_ENABLE_RUNTIMES) + set(enabled TRUE) + break() + endif() + endforeach() + set(${result} ${enabled} PARENT_SCOPE) +endfunction() diff --git a/sycl-jit/jit-compiler/CMakeLists.txt b/sycl-jit/jit-compiler/CMakeLists.txt index 4193e3c961a9c..6964941055ba3 100644 --- a/sycl-jit/jit-compiler/CMakeLists.txt +++ b/sycl-jit/jit-compiler/CMakeLists.txt @@ -29,13 +29,8 @@ set(SYCL_JIT_RESOURCE_INSTALL_COMPONENTS clang-resource-headers libsycldevice) -set(libclc_enabled FALSE) -foreach(target IN LISTS LLVM_RUNTIME_TARGETS) - if("libclc" IN_LIST RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES) - set(libclc_enabled TRUE) - break() - endif() -endforeach() +include(CheckEnabledLLVMRuntime) +is_llvm_runtime_enabled(libclc libclc_enabled) if (libclc_enabled) # If some targets required `libclc` then we should embed it for the diff --git a/sycl/CMakeLists.txt b/sycl/CMakeLists.txt index 5a2490d7ed554..a482a080cb910 100644 --- a/sycl/CMakeLists.txt +++ b/sycl/CMakeLists.txt @@ -584,13 +584,8 @@ if("lld" IN_LIST LLVM_ENABLE_PROJECTS) list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS lld) endif() -set(libclc_enabled FALSE) -foreach(target IN LISTS LLVM_RUNTIME_TARGETS) - if("libclc" IN_LIST RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES) - set(libclc_enabled TRUE) - break() - endif() -endforeach() +include(CheckEnabledLLVMRuntime) +is_llvm_runtime_enabled(libclc libclc_enabled) if(libclc_enabled) add_dependencies(sycl-toolchain libclc)