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

Anutosh Bhat via lldb-commits lldb-commits at lists.llvm.org
Mon Sep 14 21:49:50 PDT 2026


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

>From ff8c7b3709fa9a1fc81dd044a8c953a782d9b191 Mon Sep 17 00:00:00 2001
From: anutosh491 <andersonbhat491 at gmail.com>
Date: Sun, 13 Sep 2026 01:22:09 +0530
Subject: [PATCH 1/4] [lldb] Add HostInfoEmscripten

---
 lldb/include/lldb/Host/HostInfo.h             |  5 +++-
 .../lldb/Host/emscripten/HostInfoEmscripten.h | 29 +++++++++++++++++++
 lldb/source/Host/CMakeLists.txt               |  6 ++--
 .../Host/emscripten/HostInfoEmscripten.cpp    | 17 +++++++++++
 4 files changed, 54 insertions(+), 3 deletions(-)
 create mode 100644 lldb/include/lldb/Host/emscripten/HostInfoEmscripten.h
 create mode 100644 lldb/source/Host/emscripten/HostInfoEmscripten.cpp

diff --git a/lldb/include/lldb/Host/HostInfo.h b/lldb/include/lldb/Host/HostInfo.h
index 0f7ec0e0aa0d24..46973edaf8c75e 100644
--- a/lldb/include/lldb/Host/HostInfo.h
+++ b/lldb/include/lldb/Host/HostInfo.h
@@ -35,7 +35,10 @@
 #if defined(_WIN32)
 #include "lldb/Host/windows/HostInfoWindows.h"
 #define HOST_INFO_TYPE HostInfoWindows
-#elif defined(__linux__) || defined(__EMSCRIPTEN__)
+#elif defined(__EMSCRIPTEN__)
+#include "lldb/Host/emscripten/HostInfoEmscripten.h"
+#define HOST_INFO_TYPE HostInfoEmscripten
+#elif defined(__linux__)
 #if defined(__ANDROID__)
 #include "lldb/Host/android/HostInfoAndroid.h"
 #define HOST_INFO_TYPE HostInfoAndroid
diff --git a/lldb/include/lldb/Host/emscripten/HostInfoEmscripten.h b/lldb/include/lldb/Host/emscripten/HostInfoEmscripten.h
new file mode 100644
index 00000000000000..60c3168a0ff7f6
--- /dev/null
+++ b/lldb/include/lldb/Host/emscripten/HostInfoEmscripten.h
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_HOST_EMSCRIPTEN_HOSTINFOEMSCRIPTEN_H
+#define LLDB_HOST_EMSCRIPTEN_HOSTINFOEMSCRIPTEN_H
+
+#include "lldb/Host/posix/HostInfoPosix.h"
+#include "lldb/Utility/FileSpec.h"
+
+namespace lldb_private {
+
+class HostInfoEmscripten : public HostInfoPosix {
+  friend class HostInfoBase;
+
+public:
+  static void Initialize();
+  static void Terminate();
+
+  static FileSpec GetProgramFileSpec();
+};
+
+} // namespace lldb_private
+
+#endif // LLDB_HOST_EMSCRIPTEN_HOSTINFOEMSCRIPTEN_H
diff --git a/lldb/source/Host/CMakeLists.txt b/lldb/source/Host/CMakeLists.txt
index ebcad8f63e4f3d..ef99c79deab820 100644
--- a/lldb/source/Host/CMakeLists.txt
+++ b/lldb/source/Host/CMakeLists.txt
@@ -135,8 +135,10 @@ else()
       set_property(SOURCE macosx/Host.mm APPEND PROPERTY
                COMPILE_DEFINITIONS "NO_XPC_SERVICES=1")
     endif()
-
-
+  elseif (CMAKE_SYSTEM_NAME MATCHES "Emscripten")
+    add_host_subdirectory(emscripten
+      emscripten/HostInfoEmscripten.cpp
+      )
   elseif (CMAKE_SYSTEM_NAME MATCHES "Linux|Android")
     add_host_subdirectory(linux
       linux/AbstractSocket.cpp
diff --git a/lldb/source/Host/emscripten/HostInfoEmscripten.cpp b/lldb/source/Host/emscripten/HostInfoEmscripten.cpp
new file mode 100644
index 00000000000000..10f0e2fc1dc4ab
--- /dev/null
+++ b/lldb/source/Host/emscripten/HostInfoEmscripten.cpp
@@ -0,0 +1,17 @@
+//===-- HostInfoEmscripten.cpp -------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Host/emscripten/HostInfoEmscripten.h"
+
+using namespace lldb_private;
+
+void HostInfoEmscripten::Initialize() { HostInfoPosix::Initialize(); }
+
+void HostInfoEmscripten::Terminate() { HostInfoBase::Terminate(); }
+
+FileSpec HostInfoEmscripten::GetProgramFileSpec() { return {}; }

>From 1136c62eabecf61ca49afed5a431a05c49eaf358 Mon Sep 17 00:00:00 2001
From: anutosh491 <andersonbhat491 at gmail.com>
Date: Sun, 13 Sep 2026 08:30:09 +0530
Subject: [PATCH 2/4] [lldb] Add PlatformEmscripten

---
 lldb/source/Plugins/Platform/CMakeLists.txt   |  1 +
 .../Platform/Emscripten/CMakeLists.txt        |  9 ++
 .../Emscripten/PlatformEmscripten.cpp         | 82 +++++++++++++++++++
 .../Platform/Emscripten/PlatformEmscripten.h  | 50 +++++++++++
 lldb/unittests/Platform/CMakeLists.txt        |  2 +
 .../Platform/PlatformEmscriptenTest.cpp       | 18 ++++
 6 files changed, 162 insertions(+)
 create mode 100644 lldb/source/Plugins/Platform/Emscripten/CMakeLists.txt
 create mode 100644 lldb/source/Plugins/Platform/Emscripten/PlatformEmscripten.cpp
 create mode 100644 lldb/source/Plugins/Platform/Emscripten/PlatformEmscripten.h
 create mode 100644 lldb/unittests/Platform/PlatformEmscriptenTest.cpp

diff --git a/lldb/source/Plugins/Platform/CMakeLists.txt b/lldb/source/Plugins/Platform/CMakeLists.txt
index cc1432aa4754be..8ad1c4ef31218b 100644
--- a/lldb/source/Plugins/Platform/CMakeLists.txt
+++ b/lldb/source/Plugins/Platform/CMakeLists.txt
@@ -7,6 +7,7 @@ set_property(DIRECTORY PROPERTY LLDB_TOLERATED_PLUGIN_DEPENDENCIES
 
 add_subdirectory(AIX)
 add_subdirectory(Android)
+add_subdirectory(Emscripten)
 add_subdirectory(FreeBSD)
 add_subdirectory(gdb-server)
 add_subdirectory(Linux)
diff --git a/lldb/source/Plugins/Platform/Emscripten/CMakeLists.txt b/lldb/source/Plugins/Platform/Emscripten/CMakeLists.txt
new file mode 100644
index 00000000000000..3022c7692441a6
--- /dev/null
+++ b/lldb/source/Plugins/Platform/Emscripten/CMakeLists.txt
@@ -0,0 +1,9 @@
+add_lldb_library(lldbPluginPlatformEmscripten PLUGIN
+  PlatformEmscripten.cpp
+
+  LINK_LIBS
+    lldbCore
+    lldbHost
+    lldbPluginPlatformPOSIX
+    lldbTarget
+  )
diff --git a/lldb/source/Plugins/Platform/Emscripten/PlatformEmscripten.cpp b/lldb/source/Plugins/Platform/Emscripten/PlatformEmscripten.cpp
new file mode 100644
index 00000000000000..01659e5556df41
--- /dev/null
+++ b/lldb/source/Plugins/Platform/Emscripten/PlatformEmscripten.cpp
@@ -0,0 +1,82 @@
+//===-- PlatformEmscripten.cpp -------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "PlatformEmscripten.h"
+
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::platform_emscripten;
+
+LLDB_PLUGIN_DEFINE(PlatformEmscripten)
+
+static uint32_t g_initialize_count = 0;
+
+PlatformSP PlatformEmscripten::CreateInstance(bool force,
+                                              const ArchSpec *arch) {
+  Log *log = GetLog(LLDBLog::Platform);
+  LLDB_LOG(log, "force = {0}, arch=({1}, {2})", force,
+           arch ? arch->GetArchitectureName() : "<null>",
+           arch ? arch->GetTriple().getTriple() : "<null>");
+
+  bool create =
+      force || (arch && arch->IsValid() && arch->GetTriple().isOSEmscripten());
+  LLDB_LOG(log, "create = {0}", create);
+  return create ? PlatformSP(new PlatformEmscripten(false)) : PlatformSP();
+}
+
+llvm::StringRef PlatformEmscripten::GetPluginDescriptionStatic(bool is_host) {
+  if (is_host)
+    return "Local Emscripten user platform plug-in.";
+  return "Remote Emscripten user platform plug-in.";
+}
+
+void PlatformEmscripten::Initialize() {
+  PlatformPOSIX::Initialize();
+
+  if (g_initialize_count++ == 0) {
+#if defined(__EMSCRIPTEN__)
+    PlatformSP platform_sp(new PlatformEmscripten(true));
+    platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture());
+    Platform::SetHostPlatform(platform_sp);
+#endif
+    PluginManager::RegisterPlugin(GetPluginNameStatic(false),
+                                  GetPluginDescriptionStatic(false),
+                                  PlatformEmscripten::CreateInstance, nullptr);
+  }
+}
+
+void PlatformEmscripten::Terminate() {
+  if (g_initialize_count > 0 && --g_initialize_count == 0)
+    PluginManager::UnregisterPlugin(PlatformEmscripten::CreateInstance);
+
+  PlatformPOSIX::Terminate();
+}
+
+PlatformEmscripten::PlatformEmscripten(bool is_host) : PlatformPOSIX(is_host) {
+  if (is_host)
+    m_supported_architectures.push_back(HostInfo::GetArchitecture());
+  else
+    m_supported_architectures = CreateArchList(
+        {llvm::Triple::wasm32, llvm::Triple::wasm64}, llvm::Triple::Emscripten);
+}
+
+std::vector<ArchSpec> PlatformEmscripten::GetSupportedArchitectures(
+    const ArchSpec &process_host_arch) {
+  if (m_remote_platform_sp)
+    return m_remote_platform_sp->GetSupportedArchitectures(process_host_arch);
+  return m_supported_architectures;
+}
+
+bool PlatformEmscripten::CanDebugProcess() {
+  return !IsHost() && IsConnected();
+}
diff --git a/lldb/source/Plugins/Platform/Emscripten/PlatformEmscripten.h b/lldb/source/Plugins/Platform/Emscripten/PlatformEmscripten.h
new file mode 100644
index 00000000000000..cce6d6efa1d415
--- /dev/null
+++ b/lldb/source/Plugins/Platform/Emscripten/PlatformEmscripten.h
@@ -0,0 +1,50 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_SOURCE_PLUGINS_PLATFORM_EMSCRIPTEN_PLATFORMEMSCRIPTEN_H
+#define LLDB_SOURCE_PLUGINS_PLATFORM_EMSCRIPTEN_PLATFORMEMSCRIPTEN_H
+
+#include "Plugins/Platform/POSIX/PlatformPOSIX.h"
+
+namespace lldb_private::platform_emscripten {
+
+class PlatformEmscripten : public PlatformPOSIX {
+public:
+  explicit PlatformEmscripten(bool is_host);
+
+  static void Initialize();
+  static void Terminate();
+
+  static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
+
+  static llvm::StringRef GetPluginNameStatic(bool is_host) {
+    return is_host ? Platform::GetHostPlatformName() : "remote-emscripten";
+  }
+
+  static llvm::StringRef GetPluginDescriptionStatic(bool is_host);
+
+  llvm::StringRef GetPluginName() override {
+    return GetPluginNameStatic(IsHost());
+  }
+
+  llvm::StringRef GetDescription() override {
+    return GetPluginDescriptionStatic(IsHost());
+  }
+
+  std::vector<ArchSpec>
+  GetSupportedArchitectures(const ArchSpec &process_host_arch) override;
+
+  bool CanDebugProcess() override;
+
+private:
+  std::vector<ArchSpec> m_supported_architectures;
+};
+
+} // namespace lldb_private::platform_emscripten
+
+#endif // LLDB_SOURCE_PLUGINS_PLATFORM_EMSCRIPTEN_PLATFORMEMSCRIPTEN_H
diff --git a/lldb/unittests/Platform/CMakeLists.txt b/lldb/unittests/Platform/CMakeLists.txt
index 693faa07e53f89..f08d48ddfc203d 100644
--- a/lldb/unittests/Platform/CMakeLists.txt
+++ b/lldb/unittests/Platform/CMakeLists.txt
@@ -2,6 +2,7 @@ add_lldb_unittest(LLDBPlatformTests
   TestUtils.cpp
   PlatformAppleSimulatorTest.cpp
   PlatformDarwinTest.cpp
+  PlatformEmscriptenTest.cpp
   PlatformMacOSXTest.cpp
   PlatformSiginfoTest.cpp
   PlatformTest.cpp
@@ -10,6 +11,7 @@ add_lldb_unittest(LLDBPlatformTests
   LINK_COMPONENTS
     Support
   LINK_LIBS
+    lldbPluginPlatformEmscripten
     lldbPluginPlatformFreeBSD
     lldbPluginPlatformLinux
     lldbPluginPlatformMacOSX
diff --git a/lldb/unittests/Platform/PlatformEmscriptenTest.cpp b/lldb/unittests/Platform/PlatformEmscriptenTest.cpp
new file mode 100644
index 00000000000000..e9c75ea9d4a97a
--- /dev/null
+++ b/lldb/unittests/Platform/PlatformEmscriptenTest.cpp
@@ -0,0 +1,18 @@
+//===-- PlatformEmscriptenTest.cpp ---------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "Plugins/Platform/Emscripten/PlatformEmscripten.h"
+#include "gtest/gtest.h"
+
+using namespace lldb_private;
+using namespace lldb_private::platform_emscripten;
+
+TEST(PlatformEmscriptenTest, RecognizesEmscriptenTriple) {
+  ArchSpec emscripten_arch("wasm32-unknown-emscripten");
+  EXPECT_TRUE(PlatformEmscripten::CreateInstance(false, &emscripten_arch));
+}

>From 2d1e7689d6d620cc734eda6482db19f87f7c1459 Mon Sep 17 00:00:00 2001
From: anutosh491 <andersonbhat491 at gmail.com>
Date: Sun, 13 Sep 2026 10:42:26 +0530
Subject: [PATCH 3/4] [lldb] Support building lldbHost under Emscripten

---
 lldb/source/Host/CMakeLists.txt      |  8 +++++++-
 lldb/source/Host/common/Host.cpp     |  6 +++---
 lldb/source/Host/emscripten/Host.cpp | 29 ++++++++++++++++++++++++++++
 3 files changed, 39 insertions(+), 4 deletions(-)
 create mode 100644 lldb/source/Host/emscripten/Host.cpp

diff --git a/lldb/source/Host/CMakeLists.txt b/lldb/source/Host/CMakeLists.txt
index ef99c79deab820..45821aa4109129 100644
--- a/lldb/source/Host/CMakeLists.txt
+++ b/lldb/source/Host/CMakeLists.txt
@@ -111,10 +111,15 @@ else()
     posix/LockFilePosix.cpp
     posix/MainLoopPosix.cpp
     posix/PipePosix.cpp
-    posix/ProcessLauncherPosixFork.cpp
     posix/Support.cpp
     )
 
+  if (NOT EMSCRIPTEN)
+    add_host_subdirectory(posix
+      posix/ProcessLauncherPosixFork.cpp
+      )
+  endif()
+
   if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
     add_subdirectory(macosx/objcxx)
     set(LLDBObjCLibs lldbHostMacOSXObjCXX)
@@ -137,6 +142,7 @@ else()
     endif()
   elseif (CMAKE_SYSTEM_NAME MATCHES "Emscripten")
     add_host_subdirectory(emscripten
+      emscripten/Host.cpp
       emscripten/HostInfoEmscripten.cpp
       )
   elseif (CMAKE_SYSTEM_NAME MATCHES "Linux|Android")
diff --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp
index c4e1500fe68ab1..fdf17db53ec3e2 100644
--- a/lldb/source/Host/common/Host.cpp
+++ b/lldb/source/Host/common/Host.cpp
@@ -67,7 +67,7 @@
 #if defined(_WIN32)
 #include "lldb/Host/windows/ConnectionGenericFileWindows.h"
 #include "lldb/Host/windows/ProcessLauncherWindows.h"
-#else
+#elif !defined(__EMSCRIPTEN__)
 #include "lldb/Host/posix/ProcessLauncherPosixFork.h"
 #endif
 
@@ -581,7 +581,7 @@ Status Host::RunShellCommand(llvm::StringRef shell_path, const Args &args,
 
 // The functions below implement process launching for non-Apple-based
 // platforms
-#if !defined(__APPLE__)
+#if !defined(__APPLE__) && !defined(__EMSCRIPTEN__)
 Status Host::LaunchProcess(ProcessLaunchInfo &launch_info) {
   std::unique_ptr<ProcessLauncher> delegate_launcher;
 #if defined(_WIN32)
@@ -600,7 +600,7 @@ Status Host::LaunchProcess(ProcessLaunchInfo &launch_info) {
 
   return error;
 }
-#endif // !defined(__APPLE__)
+#endif // !defined(__APPLE__) && !defined(__EMSCRIPTEN__)
 
 #ifndef _WIN32
 void Host::Kill(lldb::pid_t pid, int signo) { ::kill(pid, signo); }
diff --git a/lldb/source/Host/emscripten/Host.cpp b/lldb/source/Host/emscripten/Host.cpp
new file mode 100644
index 00000000000000..005a2f83f4ec7f
--- /dev/null
+++ b/lldb/source/Host/emscripten/Host.cpp
@@ -0,0 +1,29 @@
+//===-- Host.cpp ---------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Host/Host.h"
+#include "lldb/Utility/Status.h"
+
+using namespace lldb_private;
+
+uint32_t Host::FindProcessesImpl(const ProcessInstanceInfoMatch &,
+                                 ProcessInstanceInfoList &) {
+  return 0;
+}
+
+bool Host::GetProcessInfo(lldb::pid_t, ProcessInstanceInfo &) { return false; }
+
+Status Host::LaunchProcess(ProcessLaunchInfo &) {
+  return Status::FromErrorString(
+      "launching a host process is not supported under Emscripten");
+}
+
+Status Host::ShellExpandArguments(ProcessLaunchInfo &) {
+  return Status::FromErrorString(
+      "shell expansion is not supported under Emscripten");
+}

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

---
 lldb/cmake/modules/LLDBConfig.cmake |  6 +++++
 lldb/include/lldb/API/SBDefines.h   |  2 +-
 lldb/source/API/CMakeLists.txt      | 36 ++++++++++++++++++++++-------
 3 files changed, 35 insertions(+), 9 deletions(-)

diff --git a/lldb/cmake/modules/LLDBConfig.cmake b/lldb/cmake/modules/LLDBConfig.cmake
index 4859609d4f5a9e..f7475e7879c492 100644
--- a/lldb/cmake/modules/LLDBConfig.cmake
+++ b/lldb/cmake/modules/LLDBConfig.cmake
@@ -67,6 +67,8 @@ 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 instead of a shared library" OFF)
 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)
@@ -94,6 +96,10 @@ if (LLDB_USE_SYSTEM_DEBUGSERVER)
 endif()
 
 if(LLDB_BUILD_FRAMEWORK)
+  if(LLDB_BUILD_STATIC_LIBLLDB)
+    message(FATAL_ERROR "LLDB_BUILD_STATIC_LIBLLDB is incompatible with LLDB_BUILD_FRAMEWORK")
+  endif()
+
   if(NOT APPLE)
     message(FATAL_ERROR "LLDB.framework can only be generated when targeting Apple platforms")
   endif()
diff --git a/lldb/include/lldb/API/SBDefines.h b/lldb/include/lldb/API/SBDefines.h
index 951a656c050166..6214997797d9cc 100644
--- a/lldb/include/lldb/API/SBDefines.h
+++ b/lldb/include/lldb/API/SBDefines.h
@@ -18,7 +18,7 @@
 #include <cstdio> // For FILE *
 
 #ifndef LLDB_API
-#if defined(_WIN32)
+#if defined(_WIN32) && !defined(LLDB_STATIC)
 #if defined(LLDB_IN_LIBLLDB)
 #define LLDB_API __declspec(dllexport)
 #else
diff --git a/lldb/source/API/CMakeLists.txt b/lldb/source/API/CMakeLists.txt
index 3dc272f7fe118c..058328c1ef82f1 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
@@ -154,13 +160,26 @@ if (NOT LLDB_ENABLE_DYNAMIC_SCRIPTINTERPRETERS)
   endif()
 endif()
 
-set_target_properties(liblldb
-  PROPERTIES
-  VERSION ${LLDB_VERSION}
-)
+if(LLDB_BUILD_STATIC_LIBLLDB)
+  target_compile_definitions(liblldb PUBLIC LLDB_STATIC)
+  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()
+else()
+  set_target_properties(liblldb
+    PROPERTIES
+    VERSION ${LLDB_VERSION}
+  )
+  target_compile_definitions(liblldb PRIVATE LLDB_IN_LIBLLDB)
+endif()
 
-target_compile_definitions(liblldb PRIVATE LLDB_IN_LIBLLDB)
-if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
+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