[libc] Add a target "install-llvmlibc" to install LLVM libc static archive.
GitOrigin-RevId: b22f448c21e718a3b6219df89169f38d436189c6
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 95c3b6c..7054bfc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -5,14 +5,16 @@
cmake_policy(SET CMP0076 OLD)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
-# The top-level source directory of libc.
+# The top-level sourse and binary directories.
set(LIBC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+set(LIBC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
# The top-level directory in which libc is being built.
set(LIBC_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR})
# Path libc/scripts directory.
set(LIBC_BUILD_SCRIPTS_DIR "${LIBC_SOURCE_DIR}/utils/build_scripts")
+set(LIBC_INSTALL_PREFIX "" CACHE STRING "Define libc destination prefix.")
set(LIBC_TARGET_OS ${CMAKE_SYSTEM_NAME})
string(TOLOWER ${LIBC_TARGET_OS} LIBC_TARGET_OS)
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index b8ca13b..7d99bd9 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -3,3 +3,22 @@
DEPENDS
${TARGET_LLVMLIBC_ENTRYPOINTS}
)
+
+if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR)
+ set(LIBC_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE})
+else()
+ set(LIBC_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX})
+endif()
+
+install(
+ TARGETS llvmlibc
+ ARCHIVE DESTINATION ${LIBC_INSTALL_PREFIX}/${LIBC_INSTALL_LIBRARY_DIR}
+ COMPONENT llvmlibc
+)
+
+add_custom_target(
+ install-llvmlibc
+ DEPENDS llvmlibc
+ COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=llvmlibc
+ -P "${LIBC_BINARY_DIR}/cmake_install.cmake"
+)