[llvm] 8df5841 - [CMake] Add option to link LLVM/subproject executables against LLVM libc
Aiden Grossman via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 7 00:28:49 PDT 2023
Author: Aiden Grossman
Date: 2023-06-07T07:27:53Z
New Revision: 8df5841c2574705def3d4a96ef5da4d32d64b39b
URL: https://github.com/llvm/llvm-project/commit/8df5841c2574705def3d4a96ef5da4d32d64b39b
DIFF: https://github.com/llvm/llvm-project/commit/8df5841c2574705def3d4a96ef5da4d32d64b39b.diff
LOG: [CMake] Add option to link LLVM/subproject executables against LLVM libc
This patch adds in CMake option LLVM_ENABLE_LLVM_LIBC which when set to
true automatically builds LLVM libc in overlay mode and links all
generated executables against the libc overlay. This is intended to
somewhat mirror the LLVM_ENABLE_LIBCXX flag.
Differential Revision: https://reviews.llvm.org/D151013
Added:
Modified:
llvm/CMakeLists.txt
llvm/cmake/modules/AddLLVM.cmake
llvm/cmake/modules/HandleLLVMOptions.cmake
llvm/docs/CMake.rst
Removed:
################################################################################
diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index dfe81ad0e2ee3..637b87552a625 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -558,6 +558,7 @@ else()
endif()
option(LLVM_ENABLE_LOCAL_SUBMODULE_VISIBILITY "Compile with -fmodules-local-submodule-visibility." ON)
option(LLVM_ENABLE_LIBCXX "Use libc++ if available." OFF)
+option(LLVM_ENABLE_LLVM_LIBC "Set to on to link all LLVM executables against LLVM libc, assuming it is accessible by the host compiler." OFF)
option(LLVM_STATIC_LINK_CXX_STDLIB "Statically link the standard library." OFF)
option(LLVM_ENABLE_LLD "Use lld as C and C++ linker." OFF)
option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 5dadac02bee81..bc3deef614458 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -1029,6 +1029,10 @@ macro(add_llvm_executable name)
target_link_libraries(${name} PRIVATE ${LLVM_PTHREAD_LIB})
endif()
+ if(HAVE_LLVM_LIBC)
+ target_link_libraries(${name} PRIVATE llvmlibc)
+ endif()
+
llvm_codesign(${name} ENTITLEMENTS ${ARG_ENTITLEMENTS} BUNDLE_PATH ${ARG_BUNDLE_PATH})
endmacro(add_llvm_executable name)
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 52cb2eaa3009a..1322a54ee6e99 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -1300,3 +1300,10 @@ endif()
set(LLVM_THIRD_PARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../third-party CACHE STRING
"Directory containing third party software used by LLVM (e.g. googletest)")
+
+if(LLVM_ENABLE_LLVM_LIBC)
+ check_library_exists(llvmlibc printf "" HAVE_LLVM_LIBC)
+ if(NOT HAVE_LLVM_LIBC)
+ message(WARNING "Unable to link against LLVM libc. LLVM will be built without linking against the LLVM libc overlay.")
+ endif()
+endif()
diff --git a/llvm/docs/CMake.rst b/llvm/docs/CMake.rst
index 30e0789da0392..67827bf46a512 100644
--- a/llvm/docs/CMake.rst
+++ b/llvm/docs/CMake.rst
@@ -514,6 +514,11 @@ enabled sub-projects. Nearly all of these variable names begin with
passed to invocations of both so that the project is built using libc++
instead of stdlibc++. Defaults to OFF.
+**LLVM_ENABLE_LLVM_LIBC**: BOOL
+ If the LLVM libc overlay is installed in a location where the host linker
+ can access it, all built executables will be linked against the LLVM libc
+ overlay before linking against the system libc. Defaults to OFF.
+
**LLVM_ENABLE_LIBPFM**:BOOL
Enable building with libpfm to support hardware counter measurements in LLVM
tools.
More information about the llvm-commits
mailing list