Skip to content
This repository has been archived by the owner on Jan 31, 2025. It is now read-only.

Commit

Permalink
Use shared library of LLVM if static libraries not available.
Browse files Browse the repository at this point in the history
- In some distributions of LLVM, like in ArchLinux, static libraries
  are not included.
  • Loading branch information
Thelta committed Sep 21, 2023
1 parent da573bc commit aa61f65
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
21 changes: 21 additions & 0 deletions cmake/FindLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,24 @@ endif()

add_library(LLVMHeaders INTERFACE IMPORTED)
target_include_directories(LLVMHeaders INTERFACE ${LLVM_INCLUDE_DIRS})

function(find_llvm_libs REQUIRED_LLVM_LIBS)
find_library(LLVM_SHARED_LIB LLVM NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH PATHS ${LLVM_LIBRARY_DIR})
set(LLVM_LIBS_TMP "" PARENT_SCOPE)
foreach(LIB IN LISTS REQUIRED_LLVM_LIBS)
find_library(LLVM_LIB ${LIB} NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH PATHS ${LLVM_LIBRARY_DIR})
if(LLVM_LIB)
message(VERBOSE "Adding ${LIB}")
list(APPEND LLVM_LIBS_TMP ${LIB})
elseif(LLVM_SHARED_LIB)
set(LLVM_LIBS ${LLVM_SHARED_LIB} PARENT_SCOPE)
message(STATUS "Using shared LLVM library.")
return()
else()
message(FATAL_ERROR "Can't find necessary LLVM libraries")
endif()
endforeach()

set(LLVM_LIBS ${LLVM_LIBS_TMP} PARENT_SCOPE)
message(STATUS "Using static LLVM libraries.")
endfunction()
15 changes: 10 additions & 5 deletions src/ObjectUtils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@

cmake_minimum_required(VERSION 3.15)

set(REQUIRED_LLVM_LIBS LLVMDebugInfoCodeView
LLVMDebugInfoDWARF
LLVMDebugInfoPDB
LLVMObject
LLVMSymbolize)

find_llvm_libs("${REQUIRED_LLVM_LIBS}")

project(ObjectUtils)
add_library(ObjectUtils STATIC)

Expand Down Expand Up @@ -55,12 +63,9 @@ target_link_libraries(
absl::synchronization
absl::time
absl::span
LLVMDebugInfoCodeView
LLVMDebugInfoDWARF
LLVMDebugInfoPDB
LLVMHeaders
LLVMObject
LLVMSymbolize)
${LLVM_LIBS}
)

if (WIN32)
target_link_libraries(ObjectUtils PUBLIC DIASDK::DIASDK)
Expand Down

0 comments on commit aa61f65

Please sign in to comment.