[Openmp-commits] [openmp] 59ae452 - [OpenMP] Refactor CMake files related to `PluginInterface` in `plugins-nextgen`

Shilei Tian via Openmp-commits openmp-commits at lists.llvm.org
Tue Dec 6 14:39:46 PST 2022


Author: Shilei Tian
Date: 2022-12-06T17:39:41-05:00
New Revision: 59ae4529838395da115293ac54d733fd91dbefc6

URL: https://github.com/llvm/llvm-project/commit/59ae4529838395da115293ac54d733fd91dbefc6
DIFF: https://github.com/llvm/llvm-project/commit/59ae4529838395da115293ac54d733fd91dbefc6.diff

LOG: [OpenMP] Refactor CMake files related to `PluginInterface` in `plugins-nextgen`

This patch uses refactors CMake files related to `PluginInterface` in `plugins-nextgen` to handle LLVM dependences in a better way.

Reviewed By: jhuber6

Differential Revision: https://reviews.llvm.org/D139371

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/plugins-nextgen/common/PluginInterface/CMakeLists.txt b/openmp/libomptarget/plugins-nextgen/common/PluginInterface/CMakeLists.txt
index 60aeff8796fc7..e8df5ff0eac82 100644
--- a/openmp/libomptarget/plugins-nextgen/common/PluginInterface/CMakeLists.txt
+++ b/openmp/libomptarget/plugins-nextgen/common/PluginInterface/CMakeLists.txt
@@ -10,25 +10,37 @@
 #
 ##===----------------------------------------------------------------------===##
 
-# Plugin Interface library.
+# NOTE: Don't try to build `PluginInterface` using `add_llvm_library` because we
+# don't want to export `PluginInterface` while `add_llvm_library` requires that.
 add_library(PluginInterface OBJECT PluginInterface.cpp GlobalHandler.cpp)
 
-# Define the TARGET_NAME.
-add_definitions("-DTARGET_NAME=PluginInterface")
+# This is required when using LLVM libraries.
+llvm_update_compile_flags(PluginInterface)
+
+if (LLVM_LINK_LLVM_DYLIB)
+  set(llvm_libs LLVM)
+else()
+  llvm_map_components_to_libnames(llvm_libs Support)
+endif()
+
+target_link_libraries(PluginInterface
+  PUBLIC
+    ${llvm_libs}
+    elf_common
+    MemoryManager
+)
 
-# Define the DEBUG_PREFIX.
-add_definitions(-DDEBUG_PREFIX="PluginInterface")
+# Define the TARGET_NAME and DEBUG_PREFIX.
+target_compile_definitions(PluginInterface PRIVATE
+  TARGET_NAME="PluginInterface"
+  DEBUG_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})

diff  --git a/openmp/libomptarget/plugins/common/elf_common/CMakeLists.txt b/openmp/libomptarget/plugins/common/elf_common/CMakeLists.txt
index f6aa809b46169..54d28bc66d634 100644
--- a/openmp/libomptarget/plugins/common/elf_common/CMakeLists.txt
+++ b/openmp/libomptarget/plugins/common/elf_common/CMakeLists.txt
@@ -10,21 +10,27 @@
 #
 ##===----------------------------------------------------------------------===##
 
+# NOTE: Don't try to build `elf_common` using `add_llvm_library`.
+# See openmp/libomptarget/plugins-nextgen/common/PluginInterface/CMakeLists.txt
+# for more explanation.
 add_library(elf_common OBJECT elf_common.cpp ELFSymbols.cpp)
 
-# Build elf_common with PIC to be able to link it with plugin shared libraries.
-set_property(TARGET elf_common PROPERTY POSITION_INDEPENDENT_CODE ON)
+# This is required when using LLVM libraries.
 llvm_update_compile_flags(elf_common)
-set(LINK_LLVM_LIBS LLVMBinaryFormat LLVMObject LLVMSupport)
+
 if (LLVM_LINK_LLVM_DYLIB)
-  set(LINK_LLVM_LIBS LLVM)
+  set(llvm_libs LLVM)
+else()
+  llvm_map_components_to_libnames(llvm_libs BinaryFormat Object Support)
 endif()
-target_link_libraries(elf_common INTERFACE ${LINK_LLVM_LIBS})
-add_dependencies(elf_common ${LINK_LLVM_LIBS})
 
-# The code uses Debug.h, which requires threads support.
-target_link_libraries(elf_common INTERFACE ${OPENMP_PTHREAD_LIB})
+target_link_libraries(elf_common PUBLIC ${llvm_libs} ${OPENMP_PTHREAD_LIB})
+
+# Build elf_common with PIC to be able to link it with plugin shared libraries.
+set_property(TARGET elf_common PROPERTY POSITION_INDEPENDENT_CODE ON)
 
 # Expose elf_common.h directory to the users of this library.
-target_include_directories(elf_common INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
-target_include_directories(elf_common PRIVATE ${LIBOMPTARGET_INCLUDE_DIR})
+target_include_directories(elf_common
+  INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
+  PRIVATE ${LIBOMPTARGET_INCLUDE_DIR}
+)


        


More information about the Openmp-commits mailing list