52 lines · plain
1#===============================================================================2# Define targets for linking against the selected C library3#4# After including this file, the following targets are defined:5# - runtimes-libc-headers: An interface target that allows getting access to the6# headers of the selected C library.7# - runtimes-libc-shared: A target representing the selected shared C library.8# - runtimes-libc-static: A target representing the selected static C library.9#===============================================================================10 11include_guard(GLOBAL)12 13set(RUNTIMES_SUPPORTED_C_LIBRARIES system llvm-libc picolibc newlib)14set(RUNTIMES_USE_LIBC "system" CACHE STRING "Specify C library to use. Supported values are ${RUNTIMES_SUPPORTED_C_LIBRARIES}.")15if (NOT "${RUNTIMES_USE_LIBC}" IN_LIST RUNTIMES_SUPPORTED_C_LIBRARIES)16 message(FATAL_ERROR "Unsupported C library: '${RUNTIMES_USE_LIBC}'. Supported values are ${RUNTIMES_SUPPORTED_C_LIBRARIES}.")17endif()18 19# Link against a system-provided libc20if (RUNTIMES_USE_LIBC STREQUAL "system")21 add_library(runtimes-libc-headers INTERFACE)22 23 add_library(runtimes-libc-static INTERFACE)24 add_library(runtimes-libc-shared INTERFACE)25 26# Link against the in-tree LLVM libc27elseif (RUNTIMES_USE_LIBC STREQUAL "llvm-libc")28 add_library(runtimes-libc-headers INTERFACE)29 target_link_libraries(runtimes-libc-headers INTERFACE libc-headers)30 check_cxx_compiler_flag(-nostdlibinc CXX_SUPPORTS_NOSTDLIBINC_FLAG)31 if(CXX_SUPPORTS_NOSTDLIBINC_FLAG)32 target_compile_options(runtimes-libc-headers INTERFACE "-nostdlibinc")33 if(LIBC_KERNEL_HEADERS)34 target_compile_options(runtimes-libc-headers INTERFACE "-idirafter${LIBC_KERNEL_HEADERS}")35 endif()36 endif()37 38 add_library(runtimes-libc-static INTERFACE)39 if (TARGET libc)40 target_link_libraries(runtimes-libc-static INTERFACE libc)41 endif()42 if (TARGET libm)43 target_link_libraries(runtimes-libc-static INTERFACE libm)44 endif()45 if (CXX_SUPPORTS_NOLIBC_FLAG)46 target_link_options(runtimes-libc-static INTERFACE "-nolibc")47 endif()48 49 # TODO: There's no support for building LLVM libc as a shared library yet.50 add_library(runtimes-libc-shared INTERFACE)51endif()52