[Libomptarget] Make libomptarget an LLVM library

This patch makes libomptarget depend on LLVM libraries to be built. The
reason for this is because we already have an implicit dependency on
LLVM headers for ELF identification and extraction as well as an
optional dependenly on the LLVMSupport library for time tracing
information. Furthermore, there are changes in the future that require
using more LLVM libraries, and will heavily simplify some future code as
well as open up the large amount of useful LLVM libraries to
libomptarget.

This will make "standalone" builds of `libomptarget' more difficult for
vendors wishing to ship their own. This will require a sufficiently new
version of LLVM to be installed on the system that should be picked up
by the existing handling for the implicit headers.

The things this patch changes are as follows:
  - `libomptarget.so` links against LLVMSupport and LLVMObject
  - `libomptarget.so` is a symbolic link to `libomptarget.so.15`
  - If using a shared library build, user applications will depend on LLVM
    libraries as well
  - We can now use LLVM resources in Libomptarget.

Note that this patch only changes this to apply to libomptarget itself,
not the plugins. Additional patches will be necessary for that.

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D129875
This commit is contained in:
Joseph Huber 2022-07-15 12:10:18 -04:00
parent 000e426449
commit 643dfd97d5
2 changed files with 25 additions and 30 deletions

View File

@ -26,7 +26,7 @@ include (FindPackageHandleStandardArgs)
if (OPENMP_STANDALONE_BUILD)
# Complete LLVM package is required for building libomptarget
# in an out-of-tree mode.
find_package(LLVM REQUIRED)
find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVM in: ${LLVM_DIR}")
list(APPEND LIBOMPTARGET_LLVM_INCLUDE_DIRS ${LLVM_INCLUDE_DIRS})

View File

@ -12,35 +12,30 @@
libomptarget_say("Building offloading runtime library libomptarget.")
set(LIBOMPTARGET_SRC_FILES
${CMAKE_CURRENT_SOURCE_DIR}/api.cpp
${CMAKE_CURRENT_SOURCE_DIR}/device.cpp
${CMAKE_CURRENT_SOURCE_DIR}/interface.cpp
${CMAKE_CURRENT_SOURCE_DIR}/interop.cpp
${CMAKE_CURRENT_SOURCE_DIR}/omptarget.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rtl.cpp
${CMAKE_CURRENT_SOURCE_DIR}/LegacyAPI.cpp
add_llvm_library(omptarget
SHARED
api.cpp
device.cpp
interface.cpp
interop.cpp
omptarget.cpp
rtl.cpp
LegacyAPI.cpp
ADDITIONAL_HEADER_DIRS
${LIBOMPTARGET_INCLUDE_DIR}
LINK_COMPONENTS
Support
Object
LINK_LIBS
${CMAKE_DL_LIBS}
"-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports"
)
set(LIBOMPTARGET_SRC_FILES ${LIBOMPTARGET_SRC_FILES} PARENT_SCOPE)
target_include_directories(omptarget PRIVATE ${LIBOMPTARGET_INCLUDE_DIR})
# Build libomptarget library with libdl dependency.
add_library(omptarget SHARED ${LIBOMPTARGET_SRC_FILES})
set_target_properties(omptarget PROPERTIES INSTALL_RPATH "$ORIGIN" BUILD_RPATH "$ORIGIN")
if (OPENMP_ENABLE_LIBOMPTARGET_PROFILING)
# Add LLVMSupport dependency if profiling is enabled.
# Linking with LLVM component libraries also requires
# aligning the compile flags.
llvm_update_compile_flags(omptarget)
target_compile_definitions(omptarget PUBLIC OMPTARGET_PROFILE_ENABLED)
target_link_libraries(omptarget PRIVATE LLVMSupport)
endif()
target_include_directories(omptarget PRIVATE
${LIBOMPTARGET_INCLUDE_DIR})
target_link_libraries(omptarget PRIVATE
${CMAKE_DL_LIBS}
"-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports")
# Install libomptarget under the lib destination folder.
install(TARGETS omptarget LIBRARY COMPONENT omptarget
DESTINATION "${OPENMP_INSTALL_LIBDIR}")
# Also install plugin under the standard lib destination folder.
install(TARGETS omptarget LIBRARY DESTINATION "${OPENMP_INSTALL_LIBDIR}")