1 ##===----------------------------------------------------------------------===##
3 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 # See https://llvm.org/LICENSE.txt for license information.
5 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 ##===----------------------------------------------------------------------===##
9 # Common parts which can be used by all plugins
11 ##===----------------------------------------------------------------------===##
13 # NOTE: Don't try to build `PluginInterface` using `add_llvm_library` because we
14 # don't want to export `PluginInterface` while `add_llvm_library` requires that.
15 add_library(PluginInterface OBJECT
16 PluginInterface.cpp GlobalHandler.cpp JIT.cpp RPC.cpp)
18 # Only enable JIT for those targets that LLVM can support.
19 string(TOUPPER "${LLVM_TARGETS_TO_BUILD}" TargetsSupported)
20 foreach(Target ${TargetsSupported})
21 target_compile_definitions(PluginInterface PRIVATE "LIBOMPTARGET_JIT_${Target}")
24 # This is required when using LLVM libraries.
25 llvm_update_compile_flags(PluginInterface)
27 if (LLVM_LINK_LLVM_DYLIB)
30 llvm_map_components_to_libnames(llvm_libs
31 ${LLVM_TARGETS_TO_BUILD}
58 target_link_libraries(PluginInterface
65 # Include the RPC server from the `libc` project if availible.
66 if(TARGET llvmlibc_rpc_server AND ${LIBOMPTARGET_GPU_LIBC_SUPPORT})
67 target_link_libraries(PluginInterface PRIVATE llvmlibc_rpc_server)
68 target_compile_definitions(PluginInterface PRIVATE LIBOMPTARGET_RPC_SUPPORT)
69 elseif(${LIBOMPTARGET_GPU_LIBC_SUPPORT})
70 find_library(llvmlibc_rpc_server NAMES llvmlibc_rpc_server
71 PATHS ${LIBOMPTARGET_LLVM_LIBRARY_DIR} NO_DEFAULT_PATH)
72 if(llvmlibc_rpc_server)
73 target_link_libraries(PluginInterface PRIVATE llvmlibc_rpc_server)
74 target_compile_definitions(PluginInterface PRIVATE LIBOMPTARGET_RPC_SUPPORT)
78 if ((OMPT_TARGET_DEFAULT) AND (LIBOMPTARGET_OMPT_SUPPORT))
79 target_link_libraries(PluginInterface PUBLIC OMPT)
82 # Define the TARGET_NAME and DEBUG_PREFIX.
83 target_compile_definitions(PluginInterface PRIVATE
84 TARGET_NAME="PluginInterface"
85 DEBUG_PREFIX="PluginInterface"
88 target_include_directories(PluginInterface
89 INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
90 PRIVATE ${LIBOMPTARGET_INCLUDE_DIR}
93 set_target_properties(PluginInterface PROPERTIES
94 POSITION_INDEPENDENT_CODE ON
95 CXX_VISIBILITY_PRESET protected)