[Lldb-commits] [lldb] [lldb] Add an option to build liblldb statically (PR #223210)

Anutosh Bhat via lldb-commits lldb-commits at lists.llvm.org
Wed Sep 16 00:31:21 PDT 2026


https://github.com/anutosh491 updated https://github.com/llvm/llvm-project/pull/223210

>From 7b89dde18f1dc5eda337388439bbd73d071729f1 Mon Sep 17 00:00:00 2001
From: anutosh491 <andersonbhat491 at gmail.com>
Date: Sun, 13 Sep 2026 11:40:33 +0530
Subject: [PATCH] [lldb] Add an option to build liblldb statically

---
 lldb/cmake/modules/LLDBConfig.cmake |  6 ++++++
 lldb/source/API/CMakeLists.txt      | 26 +++++++++++++++++++++++---
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/lldb/cmake/modules/LLDBConfig.cmake b/lldb/cmake/modules/LLDBConfig.cmake
index 4859609d4f5a9..dbd0dcedf4b0d 100644
--- a/lldb/cmake/modules/LLDBConfig.cmake
+++ b/lldb/cmake/modules/LLDBConfig.cmake
@@ -67,6 +67,12 @@ add_optional_dependency(LLDB_ENABLE_TREESITTER "Enable Tree-sitter syntax highli
 
 option(LLDB_USE_ENTITLEMENTS "When codesigning, use entitlements if available" ON)
 option(LLDB_BUILD_FRAMEWORK "Build LLDB.framework (Darwin only)" OFF)
+option(LLDB_BUILD_STATIC_LIBLLDB
+  "Build liblldb as a static library for Emscripten" OFF)
+if(LLDB_BUILD_STATIC_LIBLLDB AND
+   NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
+  message(FATAL_ERROR "LLDB_BUILD_STATIC_LIBLLDB is only supported for Emscripten")
+endif()
 option(LLDB_ENABLE_PROTOCOL_SERVERS "Enable protocol servers (e.g. MCP) in LLDB" ON)
 option(LLDB_NO_INSTALL_DEFAULT_RPATH "Disable default RPATH settings in binaries" OFF)
 option(LLDB_USE_SYSTEM_DEBUGSERVER "Use the system's debugserver for testing (Darwin only)." OFF)
diff --git a/lldb/source/API/CMakeLists.txt b/lldb/source/API/CMakeLists.txt
index 3dc272f7fe118..6bcd4d287c639 100644
--- a/lldb/source/API/CMakeLists.txt
+++ b/lldb/source/API/CMakeLists.txt
@@ -1,5 +1,11 @@
 get_property(LLDB_ALL_PLUGINS GLOBAL PROPERTY LLDB_PLUGINS)
 
+if(LLDB_BUILD_STATIC_LIBLLDB)
+  set(liblldb_library_type STATIC)
+else()
+  set(liblldb_library_type SHARED)
+endif()
+
 if(LLDB_BUILD_FRAMEWORK)
   set(option_install_prefix INSTALL_PREFIX ${LLDB_FRAMEWORK_INSTALL_DIR})
   set(option_framework FRAMEWORK)
@@ -33,7 +39,7 @@ add_custom_target(lldb-sbapi-dwarf-enums
   DEPENDS ${sb_languages_file})
 set_target_properties(lldb-sbapi-dwarf-enums PROPERTIES FOLDER "LLDB/Tablegenning")
 
-add_lldb_library(liblldb SHARED ${option_framework}
+add_lldb_library(liblldb ${liblldb_library_type} ${option_framework}
   SBAddress.cpp
   SBAddressRange.cpp
   SBAddressRangeList.cpp
@@ -160,7 +166,20 @@ set_target_properties(liblldb
 )
 
 target_compile_definitions(liblldb PRIVATE LLDB_IN_LIBLLDB)
-if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
+
+if(LLDB_BUILD_STATIC_LIBLLDB)
+  install(TARGETS liblldb
+    COMPONENT liblldb
+    ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
+  if(NOT CMAKE_CONFIGURATION_TYPES)
+    add_llvm_install_targets(install-liblldb
+      DEPENDS liblldb
+      COMPONENT liblldb)
+  endif()
+endif()
+
+if (NOT LLDB_BUILD_STATIC_LIBLLDB AND
+    NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
   if (LLDB_EXPORT_ALL_SYMBOLS)
     if (LLDB_EXPORT_ALL_SYMBOLS_EXPORTS_FILE)
       message(STATUS "Symbols (liblldb): exporting all symbols specified in the exports "
@@ -208,7 +227,8 @@ if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
     message(STATUS "Symbols (liblldb): exporting all symbols from the lldb namespace")
     add_llvm_symbol_exports(liblldb ${CMAKE_CURRENT_SOURCE_DIR}/liblldb.exports)
   endif()
-elseif (LLDB_EXPORT_ALL_SYMBOLS OR LLDB_ENABLE_DYNAMIC_SCRIPTINTERPRETERS)
+elseif (NOT LLDB_BUILD_STATIC_LIBLLDB AND
+        (LLDB_EXPORT_ALL_SYMBOLS OR LLDB_ENABLE_DYNAMIC_SCRIPTINTERPRETERS))
   # On Windows there is no per-plugin symbol extraction, so dynamically loaded
   # script interpreter plugins resolve their imports against the full set of
   # private symbols, same as LLDB_EXPORT_ALL_SYMBOLS.



More information about the lldb-commits mailing list