[AA] Pass query info.
[llvm-project.git] / libc / src / string / CMakeLists.txt
blob8a2adbe08e0b069a339364d6013c95abd2553d7d
1 add_subdirectory(memory_utils)
3 add_header_library(
4   string_utils
5   HDRS
6     string_utils.h
7   DEPENDS
8     libc.utils.CPP.standalone_cpp
11 add_entrypoint_object(
12   strcat
13   SRCS
14     strcat.cpp
15   HDRS
16     strcat.h
17   DEPENDS
18     .strcpy
19     .string_utils
22 add_entrypoint_object(
23   strcpy
24   SRCS
25     strcpy.cpp
26   HDRS
27     strcpy.h
28   DEPENDS
29     .memcpy
30     .string_utils
33 add_entrypoint_object(
34   strlen
35   SRCS
36     strlen.cpp
37   HDRS
38     strlen.h
39   DEPENDS
40     libc.include.string
43 add_entrypoint_object(
44   strcmp
45   SRCS
46     strcmp.cpp
47   HDRS
48     strcmp.h
51 add_entrypoint_object(
52   memchr
53   SRCS
54     memchr.cpp
55   HDRS
56     memchr.h
57   DEPENDS
58     .string_utils
61 add_entrypoint_object(
62   strchr
63   SRCS
64     strchr.cpp
65   HDRS
66     strchr.h
69 add_entrypoint_object(
70   strstr
71   SRCS
72     strstr.cpp
73   HDRS
74     strstr.h
77 add_entrypoint_object(
78   strnlen
79   SRCS
80     strnlen.cpp
81   HDRS
82     strnlen.h
83   DEPENDS
84     .string_utils
87 add_entrypoint_object(
88   memrchr
89   SRCS
90     memrchr.cpp
91   HDRS
92     memrchr.h
95 add_entrypoint_object(
96   strrchr
97   SRCS
98     strrchr.cpp
99   HDRS
100     strrchr.h
103 add_entrypoint_object(
104   strcspn
105   SRCS
106     strcspn.cpp
107   HDRS
108     strcspn.h
109   DEPENDS
110     .string_utils
113 add_entrypoint_object(
114   strspn
115   SRCS
116     strspn.cpp
117   HDRS
118     strspn.h
119   DEPENDS
120     libc.utils.CPP.standalone_cpp
123 add_entrypoint_object(
124   strpbrk
125   SRCS
126     strpbrk.cpp
127   HDRS
128     strpbrk.h
129   DEPENDS
130     .string_utils
133 add_entrypoint_object(
134   strtok
135   SRCS
136     strtok.cpp
137   HDRS
138     strtok.h
139   DEPENDS
140     .string_utils
143 add_entrypoint_object(
144   strtok_r
145   SRCS
146     strtok_r.cpp
147   HDRS
148     strtok_r.h
149   DEPENDS
150     .string_utils
153 # Helper to define a function with multiple implementations
154 # - Computes flags to satisfy required/rejected features and arch,
155 # - Declares an entry point,
156 # - Attach the REQUIRE_CPU_FEATURES property to the target,
157 # - Add the fully qualified target to `${name}_implementations` global property for tests.
158 function(add_implementation name impl_name)
159   cmake_parse_arguments(
160     "ADD_IMPL"
161     "" # Optional arguments
162     "MARCH" # Single value arguments
163     "REQUIRE;REJECT;SRCS;HDRS;DEPENDS;COMPILE_OPTIONS" # Multi value arguments
164     ${ARGN})
165   compute_flags(flags
166     MARCH ${ADD_IMPL_MARCH}
167     REQUIRE ${ADD_IMPL_REQUIRE}
168     REJECT ${ADD_IMPL_REJECT}
169   )
170   add_entrypoint_object(${impl_name}
171     NAME ${name}
172     SRCS ${ADD_IMPL_SRCS}
173     HDRS ${ADD_IMPL_HDRS}
174     DEPENDS ${ADD_IMPL_DEPENDS}
175     COMPILE_OPTIONS ${ADD_IMPL_COMPILE_OPTIONS} ${flags} -O2
176   )
177   get_fq_target_name(${impl_name} fq_target_name)
178   set_target_properties(${fq_target_name} PROPERTIES REQUIRE_CPU_FEATURES "${ADD_IMPL_REQUIRE}")
179   set_property(GLOBAL APPEND PROPERTY "${name}_implementations" "${fq_target_name}")
180 endfunction()
182 # ------------------------------------------------------------------------------
183 # memcpy
184 # ------------------------------------------------------------------------------
186 # include the relevant architecture specific implementations
187 if(${LIBC_TARGET_MACHINE} STREQUAL "x86_64")
188   set(LIBC_STRING_TARGET_ARCH "x86")
189   set(MEMCPY_SRC ${LIBC_SOURCE_DIR}/src/string/x86/memcpy.cpp)
190 else()
191   set(LIBC_STRING_TARGET_ARCH ${LIBC_TARGET_MACHINE})
192   set(MEMCPY_SRC ${LIBC_SOURCE_DIR}/src/string/memcpy.cpp)
193 endif()
195 function(add_memcpy memcpy_name)
196   add_implementation(memcpy ${memcpy_name}
197     SRCS ${MEMCPY_SRC}
198     HDRS ${LIBC_SOURCE_DIR}/src/string/memcpy.h
199     DEPENDS
200       .memory_utils.memory_utils
201       libc.include.string
202     COMPILE_OPTIONS
203       -fno-builtin-memcpy
204     ${ARGN}
205   )
206 endfunction()
208 if(${LIBC_STRING_TARGET_ARCH} STREQUAL "x86")
209   add_memcpy(memcpy MARCH native)
210 else()
211   add_memcpy(memcpy)
212 endif()
214 # ------------------------------------------------------------------------------
215 # memset
216 # ------------------------------------------------------------------------------
218 function(add_memset memset_name)
219   add_implementation(memset ${memset_name}
220     SRCS ${LIBC_SOURCE_DIR}/src/string/memset.cpp
221     HDRS ${LIBC_SOURCE_DIR}/src/string/memset.h
222     DEPENDS
223       .memory_utils.memory_utils
224       libc.include.string
225     COMPILE_OPTIONS
226       -fno-builtin-memset
227     ${ARGN}
228   )
229 endfunction()
231 if(${LIBC_STRING_TARGET_ARCH} STREQUAL "x86")
232   add_memset(memset MARCH native)
233 else()
234   add_memset(memset)
235 endif()
237 # ------------------------------------------------------------------------------
238 # bzero
239 # ------------------------------------------------------------------------------
241 function(add_bzero bzero_name)
242   add_implementation(bzero ${bzero_name}
243     SRCS ${LIBC_SOURCE_DIR}/src/string/bzero.cpp
244     HDRS ${LIBC_SOURCE_DIR}/src/string/bzero.h
245     DEPENDS
246       .memory_utils.memory_utils
247       libc.include.string
248     COMPILE_OPTIONS
249       -fno-builtin-memset
250       -fno-builtin-bzero
251     ${ARGN}
252   )
253 endfunction()
255 if(${LIBC_STRING_TARGET_ARCH} STREQUAL "x86")
256   add_bzero(bzero MARCH native)
257 else()
258   add_bzero(bzero)
259 endif()
261 # ------------------------------------------------------------------------------
262 # Add all other relevant implementations for the native target.
263 # ------------------------------------------------------------------------------
265 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_STRING_TARGET_ARCH})
266   include(${LIBC_STRING_TARGET_ARCH}/CMakeLists.txt)
267 endif()