xref: /llvm-project/libc/src/stdio/printf_core/CMakeLists.txt (revision 9cfe3028ca7977fb582fa3b15b875e8772fc8fc0)
1if(LIBC_CONF_PRINTF_DISABLE_FLOAT)
2  list(APPEND printf_config_copts "-DLIBC_COPT_PRINTF_DISABLE_FLOAT")
3endif()
4if(LIBC_CONF_PRINTF_DISABLE_INDEX_MODE)
5  list(APPEND printf_config_copts "-DLIBC_COPT_PRINTF_DISABLE_INDEX_MODE")
6endif()
7if(LIBC_CONF_PRINTF_DISABLE_WRITE_INT)
8  list(APPEND printf_config_copts "-DLIBC_COPT_PRINTF_DISABLE_WRITE_INT")
9endif()
10if(LIBC_CONF_PRINTF_FLOAT_TO_STR_USE_MEGA_LONG_DOUBLE_TABLE)
11  list(APPEND printf_config_copts "-DLIBC_COPT_FLOAT_TO_STR_USE_MEGA_LONG_DOUBLE_TABLE")
12endif()
13if(LIBC_CONF_PRINTF_FLOAT_TO_STR_USE_DYADIC_FLOAT)
14  list(APPEND printf_config_copts "-DLIBC_COPT_FLOAT_TO_STR_USE_DYADIC_FLOAT")
15endif()
16if(LIBC_CONF_PRINTF_FLOAT_TO_STR_NO_SPECIALIZE_LD)
17  list(APPEND printf_config_copts "-DLIBC_COPT_FLOAT_TO_STR_NO_SPECIALIZE_LD")
18endif()
19if(LIBC_CONF_PRINTF_DISABLE_FIXED_POINT)
20  list(APPEND printf_config_copts "-DLIBC_COPT_PRINTF_DISABLE_FIXED_POINT")
21endif()
22if(LIBC_CONF_PRINTF_DISABLE_STRERROR)
23  list(APPEND printf_config_copts "-DLIBC_COPT_PRINTF_DISABLE_STRERROR")
24endif()
25if(printf_config_copts)
26  list(PREPEND printf_config_copts "COMPILE_OPTIONS")
27endif()
28
29add_header_library(
30  printf_config
31  HDRS
32    printf_config.h
33  ${printf_config_copts}
34)
35
36add_header_library(
37  core_structs
38  HDRS
39    core_structs.h
40  DEPENDS
41    libc.src.__support.CPP.string_view
42    libc.src.__support.FPUtil.fp_bits
43)
44
45add_header_library(
46  parser
47  HDRS
48    parser.h
49  DEPENDS
50    .core_structs
51    libc.src.__support.arg_list
52    libc.src.__support.ctype_utils
53    libc.src.__support.str_to_integer
54    libc.src.__support.CPP.algorithm
55    libc.src.__support.CPP.bit
56    libc.src.__support.CPP.optional
57    libc.src.__support.CPP.string_view
58    libc.src.__support.CPP.type_traits
59    libc.src.__support.common
60)
61
62add_object_library(
63  writer
64  SRCS
65    writer.cpp
66  HDRS
67    writer.h
68  DEPENDS
69    .core_structs
70    libc.src.__support.CPP.string_view
71    libc.src.__support.macros.optimization
72    libc.src.string.memory_utils.inline_memcpy
73    libc.src.string.memory_utils.inline_memset
74)
75
76add_object_library(
77  converter
78  SRCS
79    converter.cpp
80  HDRS
81    converter.h
82    converter_atlas.h
83    converter_utils.h
84    string_converter.h
85    char_converter.h
86    int_converter.h
87    ptr_converter.h
88    write_int_converter.h
89    float_inf_nan_converter.h
90    float_hex_converter.h
91    float_dec_converter.h
92    fixed_converter.h #TODO: Check if this should be disabled when fixed unavail
93    strerror_converter.h
94  DEPENDS
95    .core_structs
96    .printf_config
97    .writer
98    libc.src.__support.big_int
99    libc.src.__support.common
100    libc.src.__support.CPP.limits
101    libc.src.__support.CPP.span
102    libc.src.__support.CPP.string_view
103    libc.src.__support.float_to_string
104    libc.src.__support.FPUtil.fenv_impl
105    libc.src.__support.FPUtil.fp_bits
106    libc.src.__support.FPUtil.rounding_mode
107    libc.src.__support.integer_to_string
108    libc.src.__support.libc_assert
109    libc.src.__support.uint128
110    libc.src.__support.StringUtil.error_to_string
111)
112
113add_object_library(
114  printf_main
115  SRCS
116    printf_main.cpp
117  HDRS
118    printf_main.h
119  DEPENDS
120    .parser
121    .converter
122    .writer
123    .core_structs
124    libc.src.__support.arg_list
125)
126
127add_header_library(
128  vasprintf_internal
129  HDRS
130    vasprintf_internal.h
131  DEPENDS
132    libc.hdr.func.malloc
133    libc.hdr.func.free
134    libc.hdr.func.realloc
135    libc.src.__support.arg_list
136    libc.src.stdio.printf_core.printf_main
137    libc.src.stdio.printf_core.writer
138)
139
140if(NOT (TARGET libc.src.__support.File.file) AND LLVM_LIBC_FULL_BUILD)
141  # Not all platforms have a file implementation. If file is unvailable, and a
142  # full build is requested, then we must skip all file based printf sections.
143  return()
144endif()
145
146add_header_library(
147  vfprintf_internal
148  HDRS
149    vfprintf_internal.h
150  DEPENDS
151    libc.src.__support.File.file
152    libc.src.__support.arg_list
153    libc.src.stdio.printf_core.printf_main
154    libc.src.stdio.printf_core.writer
155  ${use_system_file}
156)
157