xref: /llvm-project/offload/src/CMakeLists.txt (revision 80525dfcde5bf8aae6ab6b0810124ba502de6096)
1message(STATUS "Building offloading runtime library libomptarget.")
2
3if(LIBOMP_STANDALONE)
4  set(LIBOMP ${LIBOMP_STANDALONE})
5else()
6  set(LIBOMP omp)
7endif()
8
9add_llvm_library(omptarget
10  SHARED
11
12  device.cpp
13  interface.cpp
14  omptarget.cpp
15  OffloadRTL.cpp
16  LegacyAPI.cpp
17  PluginManager.cpp
18  DeviceImage.cpp
19
20  OpenMP/API.cpp
21  OpenMP/Mapping.cpp
22  OpenMP/InteropAPI.cpp
23  OpenMP/OMPT/Callback.cpp
24
25  KernelLanguage/API.cpp
26
27  ADDITIONAL_HEADER_DIRS
28  ${LIBOMPTARGET_INCLUDE_DIR}
29  ${LIBOMPTARGET_BINARY_INCLUDE_DIR}
30
31  LINK_COMPONENTS
32  FrontendOpenMP
33  Support
34  Object
35
36  LINK_LIBS
37  PUBLIC
38  ${LIBOMP}
39
40  NO_INSTALL_RPATH
41  BUILDTREE_ONLY
42)
43target_include_directories(omptarget PRIVATE
44  ${LIBOMPTARGET_INCLUDE_DIR} ${LIBOMPTARGET_BINARY_INCLUDE_DIR}
45)
46
47if (LIBOMP_HAVE_VERSION_SCRIPT_FLAG)
48  target_link_libraries(omptarget PRIVATE
49    "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports")
50endif()
51
52# Define the TARGET_NAME and DEBUG_PREFIX.
53target_compile_definitions(omptarget PRIVATE
54  TARGET_NAME=omptarget
55  DEBUG_PREFIX="omptarget"
56)
57
58foreach(plugin IN LISTS LIBOMPTARGET_PLUGINS_TO_BUILD)
59  target_link_libraries(omptarget PRIVATE omptarget.rtl.${plugin})
60endforeach()
61
62target_compile_options(omptarget PRIVATE ${offload_compile_flags})
63target_link_options(omptarget PRIVATE ${offload_link_flags})
64
65# libomptarget.so needs to be aware of where the plugins live as they
66# are now separated in the build directory.
67set_target_properties(omptarget PROPERTIES
68                      POSITION_INDEPENDENT_CODE ON
69                      INSTALL_RPATH "$ORIGIN"
70                      BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/..")
71install(TARGETS omptarget LIBRARY COMPONENT omptarget DESTINATION "${OFFLOAD_INSTALL_LIBDIR}")
72