[compiler-rt] [compiler-rt][cmake] Add option to control shared library builds (PR #139042)

Yuta Saito via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 16 18:50:52 PDT 2025


https://github.com/kateinoigakukun updated https://github.com/llvm/llvm-project/pull/139042

>From a9f0e23e669ca0b0f53b1258e8d1256e420a0bfb Mon Sep 17 00:00:00 2001
From: Yuta Saito <kateinoigakukun at gmail.com>
Date: Tue, 17 Jun 2025 08:40:27 +0900
Subject: [PATCH] [compiler-rt][cmake] Add option to control shared library
 builds

This patch introduces a new option `COMPILER_RT_BUILD_SHARED_LIBS` to
control whether shared libraries should be built for runtime libraries
in compiler-rt. By default, this option is set to ON, allowing shared
libraries to be built. If set to OFF, shared libraries will not be
built, which can be useful for projects that do not require them
or when building for environments where shared libraries are still
not yet matured, such as WebAssembly/WASI.
---
 compiler-rt/CMakeLists.txt                    | 3 +++
 compiler-rt/cmake/Modules/AddCompilerRT.cmake | 4 ++++
 2 files changed, 7 insertions(+)

diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index 9f8e8334d75ba..885670bd88a8c 100644
--- a/compiler-rt/CMakeLists.txt
+++ b/compiler-rt/CMakeLists.txt
@@ -91,6 +91,9 @@ mark_as_advanced(COMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED)
 option(COMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC "Build SCUDO standalone with LLVM's libc headers" OFF)
 mark_as_advanced(COMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC)
 
+option(COMPILER_RT_BUILD_SHARED_LIBS "Build all libraries as shared libraries in addition to static libraries" ON)
+mark_as_advanced(COMPILER_RT_BUILD_SHARED_LIBS)
+
 if(FUCHSIA)
   set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS_DEFAULT OFF)
 else()
diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
index d346b0ec01b03..06822d79019db 100644
--- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake
+++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
@@ -169,6 +169,10 @@ function(add_compiler_rt_runtime name type)
             "type argument must be OBJECT, STATIC, SHARED or MODULE")
     return()
   endif()
+  if(type STREQUAL "SHARED" AND NOT COMPILER_RT_BUILD_SHARED_LIBS)
+    message(STATUS "Skipping shared library ${name} because COMPILER_RT_BUILD_SHARED_LIBS is OFF")
+    return()
+  endif()
   cmake_parse_arguments(LIB
     ""
     "PARENT_TARGET"



More information about the llvm-commits mailing list