xref: /llvm-project/libcxx/cmake/Modules/HandleLibC.cmake (revision 3b78dfa10c4b77581cc29c4510aefe919ae660ba)
1*3b78dfa1SPetr Hosek#===============================================================================
2*3b78dfa1SPetr Hosek# Define targets for linking against the selected C library
3*3b78dfa1SPetr Hosek#
4*3b78dfa1SPetr Hosek# After including this file, the following targets are defined:
5*3b78dfa1SPetr Hosek# - libcxx-libc-headers: An interface target that allows getting access to the
6*3b78dfa1SPetr Hosek#                        headers of the selected C library.
7*3b78dfa1SPetr Hosek# - libcxx-libc-shared: A target representing the selected shared C library.
8*3b78dfa1SPetr Hosek# - libcxx-libc-static: A target representing the selected static C library.
9*3b78dfa1SPetr Hosek#===============================================================================
10*3b78dfa1SPetr Hosek
11*3b78dfa1SPetr Hosek# Link against a system-provided libc
12*3b78dfa1SPetr Hosekif (LIBCXX_LIBC STREQUAL "system")
13*3b78dfa1SPetr Hosek  add_library(libcxx-libc-headers INTERFACE)
14*3b78dfa1SPetr Hosek
15*3b78dfa1SPetr Hosek  add_library(libcxx-libc-static INTERFACE)
16*3b78dfa1SPetr Hosek  add_library(libcxx-libc-shared INTERFACE)
17*3b78dfa1SPetr Hosek
18*3b78dfa1SPetr Hosek# Link against the in-tree LLVM libc
19*3b78dfa1SPetr Hosekelseif (LIBCXX_LIBC STREQUAL "llvm-libc")
20*3b78dfa1SPetr Hosek  add_library(libcxx-libc-headers INTERFACE)
21*3b78dfa1SPetr Hosek  target_link_libraries(libcxx-libc-headers INTERFACE libc-headers)
22*3b78dfa1SPetr Hosek  if(CXX_SUPPORTS_NOSTDLIBINC_FLAG)
23*3b78dfa1SPetr Hosek    target_compile_options(libcxx-libc-headers INTERFACE "-nostdlibinc")
24*3b78dfa1SPetr Hosek  endif()
25*3b78dfa1SPetr Hosek
26*3b78dfa1SPetr Hosek  add_library(libcxx-libc-static INTERFACE)
27*3b78dfa1SPetr Hosek  if (TARGET libc)
28*3b78dfa1SPetr Hosek    target_link_libraries(libcxx-libc-static INTERFACE libc)
29*3b78dfa1SPetr Hosek  endif()
30*3b78dfa1SPetr Hosek  if (TARGET libm)
31*3b78dfa1SPetr Hosek    target_link_libraries(libcxx-libc-static INTERFACE libm)
32*3b78dfa1SPetr Hosek  endif()
33*3b78dfa1SPetr Hosek  if (CXX_SUPPORTS_NOLIBC_FLAG)
34*3b78dfa1SPetr Hosek    target_link_options(libcxx-libc-static INTERFACE "-nolibc")
35*3b78dfa1SPetr Hosek  endif()
36*3b78dfa1SPetr Hosek
37*3b78dfa1SPetr Hosek  # TODO: There's no support for building LLVM libc as a shared library yet.
38*3b78dfa1SPetr Hosek  add_library(libcxx-libc-shared INTERFACE)
39*3b78dfa1SPetr Hosekendif()
40