[llvm] [CMake] Only export the LLVM_LINK_LLVM_DYLIB setting if not yet set (PR #135570)

Jonas Rembser via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 13 15:07:04 PDT 2025


https://github.com/guitargeek created https://github.com/llvm/llvm-project/pull/135570

Follows up on these two commits:

  * 3b8b3c2a2cd3 [CMake] Export the LLVM_LINK_LLVM_DYLIB setting
  * 5fed24a39698 [CMake] Followup for r337366: Only export LLVM_LINK_LLVM_DYLIB if it's set to ON

Commit 3b8b3c2a2cd3 introduced the export of the `LLVM_LINK_LLVM_DYLIB` setting, so that clients can check whether the option of dynamic linking is available. However, it left no way for the client to actually set `LLVM_LINK_LLVM_DYLIB` themselves.

Commit 5fed24a39698 addressed the problem that out-of-tree clients lost the ability to link against the dylib, even if in-tree tools did not.

There is one remaining problem: if LLVM_LINK_LLVM_DYLIB is supported there is no way to configure clients to not link against llvm dynamically anymore. Naively, one would be able to do this for Clang e.g. with `-DLLVM_LINK_LLVM_DYLIB=OFF`.

This commit suggests to fix this problem by only setting the DYLIB option if it was not already set before.

>From db384b5fe3656487cd870ed47376f8892b14f970 Mon Sep 17 00:00:00 2001
From: Jonas Rembser <jonas.rembser at cern.ch>
Date: Sun, 13 Apr 2025 23:45:45 +0200
Subject: [PATCH] [CMake] Only export the LLVM_LINK_LLVM_DYLIB setting if not
 yet set

Follows up on these two commits:

  * 3b8b3c2a2cd3 [CMake] Export the LLVM_LINK_LLVM_DYLIB setting
  * 5fed24a39698 [CMake] Followup for r337366:
                 Only export LLVM_LINK_LLVM_DYLIB if it's set to ON

Commit 3b8b3c2a2cd3 introduced the export of the `LLVM_LINK_LLVM_DYLIB`
setting, so that clients can check whether the option of dynamic linking
is available. However, it left no way for the client to actually set
`LLVM_LINK_LLVM_DYLIB` themselves.

Commit 5fed24a39698 addressed the problem that out-of-tree clients lost
the ability to link against the dylib, even if in-tree tools did not.

There is one remaining problem: if LLVM_LINK_LLVM_DYLIB is supported
there is no way to configure clients to not link against llvm
dynamically anymore. Naively, one would be able to do this for Clang
e.g. with `-DLLVM_LINK_LLVM_DYLIB=OFF`.

This commit suggests to fix this problem by only setting the DYLIB
option if it was not already set before.
---
 llvm/cmake/modules/CMakeLists.txt      | 5 -----
 llvm/cmake/modules/LLVMConfig.cmake.in | 6 +++++-
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/llvm/cmake/modules/CMakeLists.txt b/llvm/cmake/modules/CMakeLists.txt
index ef4cfa3acdb59..c64bf3e90fcd4 100644
--- a/llvm/cmake/modules/CMakeLists.txt
+++ b/llvm/cmake/modules/CMakeLists.txt
@@ -80,11 +80,6 @@ if (LLVM_BUILD_UTILS)
   endif()
 endif()
 
-if (LLVM_LINK_LLVM_DYLIB)
-  set(LLVM_CONFIG_LINK_LLVM_DYLIB
-      "set(LLVM_LINK_LLVM_DYLIB ${LLVM_LINK_LLVM_DYLIB})")
-endif()
-
 # 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
diff --git a/llvm/cmake/modules/LLVMConfig.cmake.in b/llvm/cmake/modules/LLVMConfig.cmake.in
index 5ccc66b8039bf..1fe78238644c4 100644
--- a/llvm/cmake/modules/LLVMConfig.cmake.in
+++ b/llvm/cmake/modules/LLVMConfig.cmake.in
@@ -22,7 +22,11 @@ set(LLVM_COMMON_DEPENDS @LLVM_COMMON_DEPENDS@)
 
 set(LLVM_AVAILABLE_LIBS @LLVM_AVAILABLE_LIBS@)
 
- at LLVM_CONFIG_LINK_LLVM_DYLIB@
+# By only exporting the setting if it was not yet defined, out-of-tree
+# clients get the correct default, but may still choose if they can.
+if(@LLVM_LINK_LLVM_DYLIB@ AND NOT DEFINED LLVM_LINK_LLVM_DYLIB)
+  set(LLVM_LINK_LLVM_DYLIB @LLVM_LINK_LLVM_DYLIB@)
+endif()
 
 set(LLVM_DYLIB_COMPONENTS @LLVM_DYLIB_COMPONENTS@)
 



More information about the llvm-commits mailing list