Files
clang-p2996/libc/test/src/string/CMakeLists.txt
Tue Ly 800051487f [libc] Implement FLAGS option for generating all combinations for targets.
Add FLAGS option for add_header_library, add_object_library,
add_entrypoint_object, and add_libc_unittest.

In general, a flag is a string provided for supported functions under the
multi-valued option `FLAGS`.  It should be one of the following forms:
  FLAG_NAME
  FLAG_NAME__NO
  FLAG_NAME__ONLY
A target will inherit all the flags of its upstream dependency.

When we create a target `TARGET_NAME` with a flag using (add_header_library,
add_object_library, ...), its behavior will depend on the flag form as follow:
- FLAG_NAME: The following 2 targets will be generated:
    `TARGET_NAME` that has `FLAG_NAME` in its `FLAGS` property.
    `TARGET_NAME.__NO_FLAG_NAME` that depends on `DEP.__NO_FLAG_NAME` if
       `TARGET_NAME` depends on `DEP` and `DEP` has `FLAG_NAME` in its `FLAGS`
       property.
- FLAG_NAME__ONLY: Only generate 1 target `TARGET_NAME` that has `FLAG_NAME`
    in its `FLAGS` property.
- FLAG_NAME__NO: Only generate 1 target `TARGET_NAME.__NO_FLAG_NAME` that
    depends on `DEP.__NO_FLAG_NAME` if `DEP` is in its DEPENDS list and `DEP`
    has `FLAG_NAME` in its `FLAGS` property.

To show all the targets generated, pass SHOW_INTERMEDIATE_OBJECTS=ON to cmake.
To show all the targets' dependency and flags, pass
`SHOW_INTERMEDIATE_OBJECTS=DEPS` to cmake.

To completely disable a flag FLAG_NAME expansion, set the variable
`SKIP_FLAG_EXPANSION_FLAG_NAME=TRUE`.

Reviewed By: michaelrj, sivachandra

Differential Revision: https://reviews.llvm.org/D125174
2022-06-01 00:54:07 -04:00

299 lines
4.8 KiB
CMake

add_libc_testsuite(libc_string_unittests)
add_subdirectory(memory_utils)
add_libc_unittest(
memccpy_test
SUITE
libc_string_unittests
SRCS
memccpy_test.cpp
DEPENDS
libc.src.string.memccpy
)
add_libc_unittest(
mempcpy_test
SUITE
libc_string_unittests
SRCS
mempcpy_test.cpp
DEPENDS
libc.src.string.mempcpy
)
add_libc_unittest(
memchr_test
SUITE
libc_string_unittests
SRCS
memchr_test.cpp
DEPENDS
libc.src.string.memchr
)
add_libc_unittest(
memrchr_test
SUITE
libc_string_unittests
SRCS
memrchr_test.cpp
DEPENDS
libc.src.string.memrchr
)
add_libc_unittest(
stpcpy_test
SUITE
libc_string_unittests
SRCS
stpcpy_test.cpp
DEPENDS
libc.src.string.stpcpy
)
add_libc_unittest(
stpncpy_test
SUITE
libc_string_unittests
SRCS
stpncpy_test.cpp
DEPENDS
libc.src.string.stpncpy
)
add_libc_unittest(
strcat_test
SUITE
libc_string_unittests
SRCS
strcat_test.cpp
DEPENDS
libc.src.string.strcat
)
add_libc_unittest(
strchr_test
SUITE
libc_string_unittests
SRCS
strchr_test.cpp
DEPENDS
libc.src.string.strchr
)
add_libc_unittest(
strcmp_test
SUITE
libc_string_unittests
SRCS
strcmp_test.cpp
DEPENDS
libc.src.string.strcmp
)
add_libc_unittest(
strcpy_test
SUITE
libc_string_unittests
SRCS
strcpy_test.cpp
DEPENDS
libc.src.string.strcpy
)
add_libc_unittest(
strcspn_test
SUITE
libc_string_unittests
SRCS
strcspn_test.cpp
DEPENDS
libc.src.string.strcspn
)
add_libc_unittest(
strdup_test
SUITE
libc_string_unittests
SRCS
strdup_test.cpp
DEPENDS
libc.include.stdlib
libc.src.string.strdup
)
add_libc_unittest(
strlcat_test
SUITE
libc_string_unittests
SRCS
strlcat_test.cpp
DEPENDS
libc.src.string.strlcat
)
add_libc_unittest(
strlcpy_test
SUITE
libc_string_unittests
SRCS
strlcpy_test.cpp
DEPENDS
libc.src.string.strlcpy
)
add_libc_unittest(
strlen_test
SUITE
libc_string_unittests
SRCS
strlen_test.cpp
DEPENDS
libc.src.string.strlen
)
add_libc_unittest(
strncat_test
SUITE
libc_string_unittests
SRCS
strncat_test.cpp
DEPENDS
libc.src.string.strncat
)
add_libc_unittest(
strncmp_test
SUITE
libc_string_unittests
SRCS
strncmp_test.cpp
DEPENDS
libc.src.string.strncmp
)
add_libc_unittest(
strncpy_test
SUITE
libc_string_unittests
SRCS
strncpy_test.cpp
DEPENDS
libc.src.string.strncpy
)
add_libc_unittest(
strndup_test
SUITE
libc_string_unittests
SRCS
strndup_test.cpp
DEPENDS
libc.include.stdlib
libc.src.string.strndup
)
add_libc_unittest(
strnlen_test
SUITE
libc_string_unittests
SRCS
strnlen_test.cpp
DEPENDS
libc.src.string.strnlen
)
add_libc_unittest(
strpbrk_test
SUITE
libc_string_unittests
SRCS
strpbrk_test.cpp
DEPENDS
libc.src.string.strpbrk
)
add_libc_unittest(
strrchr_test
SUITE
libc_string_unittests
SRCS
strrchr_test.cpp
DEPENDS
libc.src.string.strrchr
)
add_libc_unittest(
strspn_test
SUITE
libc_string_unittests
SRCS
strspn_test.cpp
DEPENDS
libc.src.string.strspn
)
add_libc_unittest(
strstr_test
SUITE
libc_string_unittests
SRCS
strstr_test.cpp
DEPENDS
libc.src.string.strstr
)
add_libc_unittest(
strtok_test
SUITE
libc_string_unittests
SRCS
strtok_test.cpp
DEPENDS
libc.src.string.strtok
)
add_libc_unittest(
strtok_r_test
SUITE
libc_string_unittests
SRCS
strtok_r_test.cpp
DEPENDS
libc.src.string.strtok_r
)
# Tests all implementations that can run on the target CPU.
function(add_libc_multi_impl_test name)
get_property(fq_implementations GLOBAL PROPERTY ${name}_implementations)
foreach(fq_config_name IN LISTS fq_implementations)
get_target_property(required_cpu_features ${fq_config_name} REQUIRE_CPU_FEATURES)
cpu_supports(can_run "${required_cpu_features}")
if(can_run)
add_libc_unittest(
${fq_config_name}_test
SUITE
libc_string_unittests
COMPILE_OPTIONS
${LIBC_COMPILE_OPTIONS_NATIVE}
LINK_LIBRARIES
LibcMemoryHelpers
${ARGN}
DEPENDS
${fq_config_name}
)
get_fq_target_name(${fq_config_name}_test fq_target_name)
else()
message(STATUS "Skipping test for '${fq_config_name}' insufficient host cpu features '${required_cpu_features}'")
endif()
endforeach()
endfunction()
add_libc_multi_impl_test(bcmp SRCS bcmp_test.cpp)
add_libc_multi_impl_test(bzero SRCS bzero_test.cpp)
add_libc_multi_impl_test(memcmp SRCS memcmp_test.cpp)
add_libc_multi_impl_test(memcpy SRCS memcpy_test.cpp)
add_libc_multi_impl_test(memmove SRCS memmove_test.cpp)
add_libc_multi_impl_test(memset SRCS memset_test.cpp)