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