[llvm] [polly] [cmake] Don't install static extensions when linked into libLLVM (PR #88660)

via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 14 08:04:35 PDT 2024


https://github.com/xarblu created https://github.com/llvm/llvm-project/pull/88660

When extensions like polly are linked as part of `libLLVM` these don't need to be and likely shouldn't be installed.

Reason being that e.g. out-of-tree clang builds against `libLLVM` will try to statically link these extensions
when calling `process_llvm_pass_plugins`.

1. This is undesirable because the whole point is to have a shared library to link to
2.  It actually causes issues because `LLVMExports.cmake` will include e.g. `libPollyISL`, `LLVMPolly`, etc. as installed targets depending on on non-installed `LLVM*.a` targets which are available via `libLLVM.so` 

This is mainly intended to allow distributions to ship polly enabled `libLLVM` while still keeping e.g. clang independent and linked dynamically.

>From d63bdba3eddd0ab9f552aab059fd01447578234a Mon Sep 17 00:00:00 2001
From: Xarblu <xarblu at protonmail.com>
Date: Sun, 14 Apr 2024 16:32:57 +0200
Subject: [PATCH] [cmake] Don't install static extensions when linked into
 libLLVM

Allows building out-of-tree clang against libLLVM
built with ENABLE_PROJECTS=polly POLLY_LINK_INTO_TOOLS=ON
and LINK_LLVM_DYLIB=ON.
Previously clang/CMakeLists.txt would call process_llvm_pass_plugins
and try statically linking extensions that are unavailable if only
installed as part of libLLVM.
---
 llvm/cmake/modules/AddLLVM.cmake | 14 +++++++++++---
 polly/cmake/polly_macros.cmake   |  3 ++-
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 693fd5669f63f9..74d5ee2edb261a 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -1180,9 +1180,17 @@ function(process_llvm_pass_plugins)
       # LLVM_INSTALL_PACKAGE_DIR might be absolute, so don't reuse below.
       string(REPLACE "${CMAKE_CFG_INTDIR}" "." llvm_cmake_builddir "${LLVM_LIBRARY_DIR}")
       set(llvm_cmake_builddir "${llvm_cmake_builddir}/cmake/llvm")
-      file(WRITE
-          "${llvm_cmake_builddir}/LLVMConfigExtensions.cmake"
-          "set(LLVM_STATIC_EXTENSIONS ${LLVM_STATIC_EXTENSIONS})")
+      if(LLVM_LINK_LLVM_DYLIB)
+          # Install a dummy file. When the extensions are part of libLLVM other
+          # tools should link it instead of the static library.
+          file(WRITE
+              "${llvm_cmake_builddir}/LLVMConfigExtensions.cmake"
+              "set(LLVM_STATIC_EXTENSIONS )")
+      else()
+          file(WRITE
+              "${llvm_cmake_builddir}/LLVMConfigExtensions.cmake"
+              "set(LLVM_STATIC_EXTENSIONS ${LLVM_STATIC_EXTENSIONS})")
+      endif()
       install(FILES
           ${llvm_cmake_builddir}/LLVMConfigExtensions.cmake
           DESTINATION ${LLVM_INSTALL_PACKAGE_DIR}
diff --git a/polly/cmake/polly_macros.cmake b/polly/cmake/polly_macros.cmake
index df541eeccc4cb5..11c4c6b07e543e 100644
--- a/polly/cmake/polly_macros.cmake
+++ b/polly/cmake/polly_macros.cmake
@@ -41,7 +41,8 @@ macro(add_polly_library name)
   if( LLVM_LINK_COMPONENTS )
     llvm_config(${name} ${LLVM_LINK_COMPONENTS})
   endif( LLVM_LINK_COMPONENTS )
-  if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LLVMPolly")
+  if ((NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LLVMPolly")
+    AND NOT LLVM_LINK_LLVM_DYLIB)
     install(TARGETS ${name}
       COMPONENT ${name}
       EXPORT LLVMExports



More information about the llvm-commits mailing list