[PATCH] D145351: [cmake] Export component info needed to determine which libraries are in libLLVM.so.

Stella Laurenzo via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 5 21:25:02 PST 2023


stellaraccident created this revision.
Herald added subscribers: bzcheeseman, rriddle.
Herald added a project: All.
stellaraccident requested review of this revision.
Herald added subscribers: llvm-commits, stephenneuendorffer.
Herald added a project: LLVM.



- Export the GLOBAL property LLVM_COMPONENT_LIBS (this is used by by AddMLIR as a sanity check and the check seems invalid when built standalone without this).
- Export the per-target LLVM_COMPONENT boolean (can be used to implement a similar check as AddMLIR is doing in unified builds and makes things the same between unified and installed).
- Define a new GLOBAL property LLVM_DYLIB_INCLUDED_LIBNAMES and export it so that downstreams can reliably query precisely which libraries were included in libLLVM.so and link only what they need without ambiguity. This helps downstreams but will also give us some flexibility in a follow-on to rework the in-tree libLLVM redirect to be more precise (and getting us closer to a semantic that will work for Windows).

With the LLVM_COMPONENT_LIBS exported, it becomes possible for standalone LLVM dependants to call llvm_map_components_to_libnames() and approximate LLVM_DYLIB_INCLUDED_LIBNAMES, but as I was reading through that helper and the related code, I realized there are several special cases such that we really only know this precisely when we build the dylib. So I opted to export that decision for followon work.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145351

Files:
  llvm/cmake/modules/AddLLVM.cmake
  llvm/cmake/modules/CMakeLists.txt
  llvm/cmake/modules/LLVMConfig.cmake.in
  llvm/tools/llvm-shlib/CMakeLists.txt


Index: llvm/tools/llvm-shlib/CMakeLists.txt
===================================================================
--- llvm/tools/llvm-shlib/CMakeLists.txt
+++ llvm/tools/llvm-shlib/CMakeLists.txt
@@ -33,6 +33,11 @@
   add_llvm_library(LLVM SHARED DISABLE_LLVM_LINK_LLVM_DYLIB SONAME ${INSTALL_WITH_TOOLCHAIN} ${SOURCES})
 
   list(REMOVE_DUPLICATES LIB_NAMES)
+
+  # Set a global property for the library names that are included in libLLVM
+  # so that everyone has a precise list to determine when to redirect.
+  set_property(GLOBAL PROPERTY LLVM_DYLIB_INCLUDED_LIBNAMES ${LIB_NAMES})
+
   if(("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") OR (MINGW) OR (HAIKU)
      OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
      OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "GNU")
@@ -192,5 +197,5 @@
     # Make sure we search LLVMSupport first, before the CRT libs
     set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -INCLUDE:malloc")
   endif()
-  
+
 endif()
Index: llvm/cmake/modules/LLVMConfig.cmake.in
===================================================================
--- llvm/cmake/modules/LLVMConfig.cmake.in
+++ llvm/cmake/modules/LLVMConfig.cmake.in
@@ -29,6 +29,10 @@
 
 set(LLVM_DYLIB_COMPONENTS @LLVM_DYLIB_COMPONENTS@)
 
+set_property(GLOBAL PROPERTY LLVM_COMPONENT_LIBS @LLVM_CONFIG_COMPONENT_LIBS@)
+
+set_property(GLOBAL PROPERTY LLVM_DYLIB_INCLUDED_LIBNAMES @LLVM_CONFIG_DYLIB_INCLUDED_LIBNAMES@)
+
 set(LLVM_ALL_TARGETS @LLVM_ALL_TARGETS@)
 
 set(LLVM_TARGETS_TO_BUILD @LLVM_TARGETS_TO_BUILD@)
Index: llvm/cmake/modules/CMakeLists.txt
===================================================================
--- llvm/cmake/modules/CMakeLists.txt
+++ llvm/cmake/modules/CMakeLists.txt
@@ -82,6 +82,11 @@
       "set(LLVM_LINK_LLVM_DYLIB ${LLVM_LINK_LLVM_DYLIB})")
 endif()
 
+# Some global properties needed to make llvm_map_components_to_libnames()
+# work.
+get_property(LLVM_CONFIG_COMPONENT_LIBS GLOBAL PROPERTY LLVM_COMPONENT_LIBS)
+get_property(LLVM_CONFIG_DYLIB_INCLUDED_LIBNAMES GLOBAL PROPERTY LLVM_DYLIB_INCLUDED_LIBNAMES)
+
 # We need to use the full path to the LLVM Exports file to make sure we get the
 # one from the build tree. This is due to our cmake files being split between
 # this source dir and the binary dir in the build tree configuration and the
Index: llvm/cmake/modules/AddLLVM.cmake
===================================================================
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -590,6 +590,7 @@
 
   if(ARG_COMPONENT_LIB)
     set_target_properties(${name} PROPERTIES LLVM_COMPONENT TRUE)
+    set_property(TARGET ${name} APPEND PROPERTY EXPORT_PROPERTIES LLVM_COMPONENT)
     set_property(GLOBAL APPEND PROPERTY LLVM_COMPONENT_LIBS ${name})
   endif()
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145351.502515.patch
Type: text/x-patch
Size: 2742 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230306/9fe3ab3b/attachment.bin>


More information about the llvm-commits mailing list