https://github.com/Steelskin created https://github.com/llvm/llvm-project/pull/224624
The proper way to reference LLVM components is to pass them via the LLVM_LINK_COMPONENTS variable. This is needed when building LLVM as a dylib, so the proper dependency (the LLVM library) is passed. This does not apply to plain add_executable() targets, which should manually select to link against LLVM or individual LLVM components. The effort to build LLVM as a dylib is tracked in #109483. >From 8b19c980371db379cf16762c62b6161c1438f110 Mon Sep 17 00:00:00 2001 From: Fabrice de Gans <[email protected]> Date: Fri, 18 Sep 2026 14:40:22 +0200 Subject: [PATCH] [cmake] Properly link against LLVM components The proper way to reference LLVM components is to pass them via the LLVM_LINK_COMPONENTS variable. This is needed when building LLVM as a dylib, so the proper dependency (the LLVM library) is passed. This does not apply to plain add_executable() targets, which should manually select to link against LLVM or individual LLVM components. The effort to build LLVM as a dylib is tracked in #109483. --- clang-tools-extra/clangd/benchmarks/CMakeLists.txt | 5 ++++- .../clangd/benchmarks/CompletionModel/CMakeLists.txt | 5 ++++- cross-project-tests/CMakeLists.txt | 5 ++++- .../llvm-prettyprinters/lldb/CMakeLists.txt | 8 +++++++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/clang-tools-extra/clangd/benchmarks/CMakeLists.txt b/clang-tools-extra/clangd/benchmarks/CMakeLists.txt index 13ca21ad70d81..13beec4919ebf 100644 --- a/clang-tools-extra/clangd/benchmarks/CMakeLists.txt +++ b/clang-tools-extra/clangd/benchmarks/CMakeLists.txt @@ -2,10 +2,13 @@ if(CLANGD_DECISION_FOREST) add_subdirectory(CompletionModel) endif() +set(LLVM_LINK_COMPONENTS + Support + ) + add_benchmark(IndexBenchmark IndexBenchmark.cpp) target_link_libraries(IndexBenchmark PRIVATE clangDaemon - LLVMSupport ) diff --git a/clang-tools-extra/clangd/benchmarks/CompletionModel/CMakeLists.txt b/clang-tools-extra/clangd/benchmarks/CompletionModel/CMakeLists.txt index 4c7cd779eb3e7..81cf3cc0fca60 100644 --- a/clang-tools-extra/clangd/benchmarks/CompletionModel/CMakeLists.txt +++ b/clang-tools-extra/clangd/benchmarks/CompletionModel/CMakeLists.txt @@ -1,7 +1,10 @@ +set(LLVM_LINK_COMPONENTS + Support + ) + add_benchmark(DecisionForestBenchmark DecisionForestBenchmark.cpp) target_link_libraries(DecisionForestBenchmark PRIVATE clangDaemon - LLVMSupport ) diff --git a/cross-project-tests/CMakeLists.txt b/cross-project-tests/CMakeLists.txt index 85102065e79e6..8961958f6f16e 100644 --- a/cross-project-tests/CMakeLists.txt +++ b/cross-project-tests/CMakeLists.txt @@ -7,10 +7,13 @@ set(LLVM_SUBPROJECT_TITLE "Cross-Project") find_package(Python3 COMPONENTS Interpreter) +set(LLVM_LINK_COMPONENTS + Support + ) + add_llvm_executable(check-gdb-llvm-support debuginfo-tests/llvm-prettyprinters/gdb/llvm-support.cpp ) -target_link_libraries(check-gdb-llvm-support PRIVATE LLVMSupport) add_subdirectory(debuginfo-tests/llvm-prettyprinters/lldb) diff --git a/cross-project-tests/debuginfo-tests/llvm-prettyprinters/lldb/CMakeLists.txt b/cross-project-tests/debuginfo-tests/llvm-prettyprinters/lldb/CMakeLists.txt index e2a9a080fd4c7..ac3efaf641c24 100644 --- a/cross-project-tests/debuginfo-tests/llvm-prettyprinters/lldb/CMakeLists.txt +++ b/cross-project-tests/debuginfo-tests/llvm-prettyprinters/lldb/CMakeLists.txt @@ -1,6 +1,12 @@ add_library(lldb-formatter-test-settings INTERFACE) -target_link_libraries(lldb-formatter-test-settings INTERFACE LLVMSupport) +# Link the correct LLVM dependency, depending on the configuration. +if(LLVM_LINK_LLVM_DYLIB) + target_link_libraries(lldb-formatter-test-settings INTERFACE LLVM) +else() + target_link_libraries(lldb-formatter-test-settings INTERFACE LLVMSupport) +endif() + # Unset _FORTIFY_SOURCE since it's incompatible with -O0. target_compile_options(lldb-formatter-test-settings INTERFACE -g -O0 -U_FORTIFY_SOURCE) _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
