1add_subdirectory(memory_utils)
2
3add_entrypoint_object(
4  strcat
5  SRCS
6    strcat.cpp
7  HDRS
8    strcat.h
9  DEPENDS
10    .strcpy
11    .strlen
12    libc.include.string
13)
14
15add_entrypoint_object(
16  strcpy
17  SRCS
18    strcpy.cpp
19  HDRS
20    strcpy.h
21  DEPENDS
22    .memcpy
23    .strlen
24    libc.include.string
25)
26
27add_entrypoint_object(
28  strlen
29  SRCS
30    strlen.cpp
31  HDRS
32    strlen.h
33  DEPENDS
34    libc.include.string
35)
36
37# ------------------------------------------------------------------------------
38# memcpy
39# ------------------------------------------------------------------------------
40
41# include the relevant architecture specific implementations
42if(${LIBC_TARGET_MACHINE} STREQUAL "x86_64")
43  set(LIBC_MEMCPY_IMPL_FOLDER "x86")
44else()
45  set(LIBC_MEMCPY_IMPL_FOLDER ${LIBC_TARGET_MACHINE})
46endif()
47
48add_gen_header(
49  memcpy_arch_specific
50  DEF_FILE
51    memcpy_arch_specific.h.def
52  GEN_HDR
53    memcpy_arch_specific.h
54  PARAMS
55    memcpy_arch_specific=${LIBC_MEMCPY_IMPL_FOLDER}/memcpy_arch_specific.h.inc
56  DATA_FILES
57    ${LIBC_MEMCPY_IMPL_FOLDER}/memcpy_arch_specific.h.inc
58)
59
60# Helper to define an implementation of memcpy.
61# - Computes flags to satisfy required/rejected features and arch,
62# - Declares an entry point,
63# - Attach the REQUIRE_CPU_FEATURES property to the target,
64# - Add the target to `memcpy_implementations` global property for tests.
65function(add_memcpy memcpy_name)
66  cmake_parse_arguments(
67    "ADD_MEMCPY"
68    "" # Optional arguments
69    "MARCH" # Single value arguments
70    "REQUIRE;REJECT" # Multi value arguments
71    ${ARGN})
72  compute_flags(flags
73    MARCH ${ADD_MEMCPY_MARCH}
74    REQUIRE ${ADD_MEMCPY_REQUIRE}
75    REJECT ${ADD_MEMCPY_REJECT}
76  )
77  add_entrypoint_object(
78    ${memcpy_name}
79    SRCS ${LIBC_SOURCE_DIR}/src/string/memcpy.cpp
80    HDRS ${LIBC_SOURCE_DIR}/src/string/memcpy.h
81    DEPENDS
82      .memory_utils.memory_utils
83      .memcpy_arch_specific
84      libc.include.string
85    COMPILE_OPTIONS
86      -fno-builtin-memcpy
87      ${flags}
88  )
89  get_fq_target_name(${memcpy_name} fq_target_name)
90  set_target_properties(${fq_target_name} PROPERTIES REQUIRE_CPU_FEATURES "${ADD_MEMCPY_REQUIRE}")
91  get_property(all GLOBAL PROPERTY memcpy_implementations)
92  list(APPEND all ${memcpy_name})
93  set_property(GLOBAL PROPERTY memcpy_implementations "${all}")
94endfunction()
95
96include(${LIBC_MEMCPY_IMPL_FOLDER}/CMakeLists.txt)
97add_memcpy(memcpy MARCH native)
98