[Openmp-commits] [PATCH] D139371: [OpenMP] Use `add_llvm_library` to build the target `PluginInterface` in `plugins-nextgen`

Shilei Tian via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Mon Dec 5 14:20:44 PST 2022


tianshilei1992 created this revision.
tianshilei1992 added reviewers: jdoerfert, jhuber6.
Herald added subscribers: guansong, yaxunl.
Herald added a project: All.
tianshilei1992 requested review of this revision.
Herald added subscribers: openmp-commits, sstefan1.
Herald added a project: OpenMP.

This patch uses `add_llvm_library` to build the target `PluginInterface` since it can handle LLVM dependences much better. One temporary drawback of using this is that it doesn't support object libraries very well. After switching to that, `CXX_VISIBILITY_PRESET` can not be set correctly, which can cause runtime error that a function call from one plugin could go to another. As a consequence, `PluginInterface` is built as a static library for now. I have asked the question in CMake community (https://discourse.cmake.org/t/set-target-properties-doesnt-work-properly/7016). Once that issue is solved, I'll switch it back to object library. It is not necessarily too bad to use static library, especially `BUILDTREE_ONLY` is already set such that `PluginInterface.a` will not be installed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139371

Files:
  openmp/libomptarget/plugins-nextgen/common/PluginInterface/CMakeLists.txt


Index: openmp/libomptarget/plugins-nextgen/common/PluginInterface/CMakeLists.txt
===================================================================
--- openmp/libomptarget/plugins-nextgen/common/PluginInterface/CMakeLists.txt
+++ openmp/libomptarget/plugins-nextgen/common/PluginInterface/CMakeLists.txt
@@ -10,25 +10,30 @@
 #
 ##===----------------------------------------------------------------------===##
 
+# Define the TARGET_NAME and DEBUG_PREFIX.
+add_compile_definitions(
+  TARGET_NAME="PluginInterface"
+  DEBUG_PREFIX="PluginInterface"
+)
+
 # Plugin Interface library.
-add_library(PluginInterface OBJECT PluginInterface.cpp GlobalHandler.cpp)
+add_llvm_library(PluginInterface PluginInterface.cpp GlobalHandler.cpp
+  BUILDTREE_ONLY
+
+  LINK_COMPONENTS
+    Support
 
-# Define the TARGET_NAME.
-add_definitions("-DTARGET_NAME=PluginInterface")
+  LINK_LIBS
+  PRIVATE
+    elf_common
+    MemoryManager
+)
 
-# Define the DEBUG_PREFIX.
-add_definitions(-DDEBUG_PREFIX="PluginInterface")
+target_include_directories(PluginInterface
+  INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
+  PRIVATE ${LIBOMPTARGET_INCLUDE_DIR}
+)
 
 set_target_properties(PluginInterface PROPERTIES
   POSITION_INDEPENDENT_CODE ON
   CXX_VISIBILITY_PRESET protected)
-llvm_update_compile_flags(PluginInterface)
-set(LINK_LLVM_LIBS LLVMSupport)
-if (LLVM_LINK_LLVM_DYLIB)
-  set(LINK_LLVM_LIBS LLVM)
-endif()
-target_link_libraries(PluginInterface INTERFACE ${LINK_LLVM_LIBS} PRIVATE elf_common MemoryManager)
-add_dependencies(PluginInterface ${LINK_LLVM_LIBS})
-
-target_include_directories(PluginInterface INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
-target_include_directories(PluginInterface PRIVATE ${LIBOMPTARGET_INCLUDE_DIR})


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139371.480245.patch
Type: text/x-patch
Size: 1712 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20221205/291dcf7f/attachment.bin>


More information about the Openmp-commits mailing list