Skip to content

Commit 8df5841

Browse files
[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
1 parent 57882fe commit 8df5841

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

llvm/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@ else()
558558
endif()
559559
option(LLVM_ENABLE_LOCAL_SUBMODULE_VISIBILITY "Compile with -fmodules-local-submodule-visibility." ON)
560560
option(LLVM_ENABLE_LIBCXX "Use libc++ if available." OFF)
561+
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)
561562
option(LLVM_STATIC_LINK_CXX_STDLIB "Statically link the standard library." OFF)
562563
option(LLVM_ENABLE_LLD "Use lld as C and C++ linker." OFF)
563564
option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)

llvm/cmake/modules/AddLLVM.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,10 @@ macro(add_llvm_executable name)
10291029
target_link_libraries(${name} PRIVATE ${LLVM_PTHREAD_LIB})
10301030
endif()
10311031

1032+
if(HAVE_LLVM_LIBC)
1033+
target_link_libraries(${name} PRIVATE llvmlibc)
1034+
endif()
1035+
10321036
llvm_codesign(${name} ENTITLEMENTS ${ARG_ENTITLEMENTS} BUNDLE_PATH ${ARG_BUNDLE_PATH})
10331037
endmacro(add_llvm_executable name)
10341038

llvm/cmake/modules/HandleLLVMOptions.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,3 +1300,10 @@ endif()
13001300

13011301
set(LLVM_THIRD_PARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../third-party CACHE STRING
13021302
"Directory containing third party software used by LLVM (e.g. googletest)")
1303+
1304+
if(LLVM_ENABLE_LLVM_LIBC)
1305+
check_library_exists(llvmlibc printf "" HAVE_LLVM_LIBC)
1306+
if(NOT HAVE_LLVM_LIBC)
1307+
message(WARNING "Unable to link against LLVM libc. LLVM will be built without linking against the LLVM libc overlay.")
1308+
endif()
1309+
endif()

llvm/docs/CMake.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,11 @@ enabled sub-projects. Nearly all of these variable names begin with
514514
passed to invocations of both so that the project is built using libc++
515515
instead of stdlibc++. Defaults to OFF.
516516

517+
**LLVM_ENABLE_LLVM_LIBC**: BOOL
518+
If the LLVM libc overlay is installed in a location where the host linker
519+
can access it, all built executables will be linked against the LLVM libc
520+
overlay before linking against the system libc. Defaults to OFF.
521+
517522
**LLVM_ENABLE_LIBPFM**:BOOL
518523
Enable building with libpfm to support hardware counter measurements in LLVM
519524
tools.

0 commit comments

Comments
 (0)