From 1cde56c6cf1feaeb8f21b62f811c5c5d3c78da41 Mon Sep 17 00:00:00 2001 From: Wenju He Date: Wed, 27 Sep 2023 10:17:01 +0800 Subject: [PATCH] Fix link error if llvm is pre-built locally static or shared This fixes link error in Ubuntu 22.04 container. --- CMakeLists.txt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 98836f3..35eda42 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -298,8 +298,17 @@ else() ) endif() +if(USE_PREBUILT_LLVM AND UNIX) + # llvm_map_components_to_libnames(... all) returns empty string if llvm is + # pre-built locally in either static or shared type in Ubuntu 22.04 container. + execute_process(COMMAND llvm-config --libs all OUTPUT_VARIABLE ALL_LIBS) + string(STRIP ${ALL_LIBS} ALL_LIBS_STRIP) + string(REGEX REPLACE "[ ]*-l" ";" ALL_LLVM_LIBS ${ALL_LIBS_STRIP}) + set(ALL_LLVM_LIBS "${ALL_LLVM_LIBS};LLVMSPIRVLib") +else() + llvm_map_components_to_libnames(ALL_LLVM_LIBS all) +endif() set(OPENCL_CLANG_EXCLUDE_LIBS_FROM_ALL "" CACHE STRING "Space-separated list of LLVM libraries to exclude from all") -llvm_map_components_to_libnames(ALL_LLVM_LIBS all) if (NOT "${OPENCL_CLANG_EXCLUDE_LIBS_FROM_ALL}" STREQUAL "") list(REMOVE_ITEM ALL_LLVM_LIBS ${OPENCL_CLANG_EXCLUDE_LIBS_FROM_ALL}) endif()