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)