fix linking against LLVM shared library

967280f140 broke linking against
libLLVM.so because it used the outdated way to link against LLVM from
CMake. This causes a compilation failure on systems that don't have the
LLVM static libraries, such as Arch Linux. On systems that have the
static libraries, it'll use them and increase binary sizes massively.

Switch to the newer llvm_config CMake macro from LLVM.
This commit is contained in:
Guilherme Janczak 2024-05-03 11:56:15 +00:00
parent 5817be7bd3
commit 68cbd2640d
No known key found for this signature in database
GPG Key ID: 9F1927DAAC7F9DCD

View File

@ -52,28 +52,22 @@ if(TARGET LibUSB::LibUSB)
endif()
if(ENABLE_LLVM)
find_package(LLVM CONFIG QUIET)
if(LLVM_FOUND AND TARGET LLVM)
find_package(LLVM CONFIG)
if(LLVM_FOUND)
message(STATUS "LLVM found, enabling LLVM support in disassembler")
# Minimal documentation about LLVM's CMake functions is available here:
# https://releases.llvm.org/16.0.0/docs/CMake.html#embedding-llvm-in-your-project
# https://groups.google.com/g/llvm-dev/c/YeEVe7HTasQ?pli=1
#
# However, you have to read the source code in any case.
# Look for LLVM-Config.cmake in your (Unix) system:
# $ find /usr -name LLVM-Config\\.cmake 2>/dev/null
separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
target_compile_definitions(uicommon
PRIVATE HAVE_LLVM ${LLVM_DEFINITIONS_LIST}
)
target_link_directories(uicommon PRIVATE ${LLVM_LIBRARY_DIRS})
llvm_expand_pseudo_components(LLVM_EXPAND_COMPONENTS
AllTargetsInfos AllTargetsDisassemblers AllTargetsCodeGens
)
llvm_map_components_to_libnames(LLVM_LIBRARIES
llvm_config(uicommon USE_SHARED
mcdisassembler target ${LLVM_EXPAND_COMPONENTS}
)
target_link_libraries(uicommon PRIVATE ${LLVM_LIBRARIES})
target_include_directories(uicommon PRIVATE ${LLVM_INCLUDE_DIRS})
endif()
endif()