[docs] Fix build-docs.sh
[llvm-project.git] / compiler-rt / test / fuzzer / CMakeLists.txt
blob4ab04822447f28f074aafc7ffc38825ce06e7e68
1 set(LIBFUZZER_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
2 if (NOT COMPILER_RT_STANDALONE_BUILD)
3   list(APPEND LIBFUZZER_TEST_DEPS fuzzer asan ubsan)
4   if (COMPILER_RT_HAS_MSAN)
5     list(APPEND LIBFUZZER_TEST_DEPS msan)
6   endif()
7   if (COMPILER_RT_HAS_DFSAN)
8     list(APPEND LIBFUZZER_TEST_DEPS dfsan)
9   endif()
10   if(NOT APPLE AND COMPILER_RT_HAS_LLD AND "lld" IN_LIST LLVM_ENABLE_PROJECTS)
11     list(APPEND LIBFUZZER_TEST_DEPS lld)
12   endif()
13 endif()
15 set(FUZZER_TEST_ARCH ${FUZZER_SUPPORTED_ARCH})
16 if (APPLE)
17   darwin_filter_host_archs(FUZZER_SUPPORTED_ARCH FUZZER_TEST_ARCH)
18 endif()
20 if(COMPILER_RT_INCLUDE_TESTS)
21   list(APPEND LIBFUZZER_TEST_DEPS FuzzerUnitTests)
22   list(APPEND LIBFUZZER_TEST_DEPS FuzzedDataProviderUnitTests)
23 endif()
25 add_custom_target(check-fuzzer)
27 if(COMPILER_RT_INCLUDE_TESTS)
28   # libFuzzer unit tests.
29   configure_lit_site_cfg(
30     ${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.site.cfg.py.in
31     ${CMAKE_CURRENT_BINARY_DIR}/unit/lit.site.cfg.py)
32   add_lit_testsuite(check-fuzzer-unit "Running Fuzzer unit tests"
33     ${CMAKE_CURRENT_BINARY_DIR}/unit
34     DEPENDS ${LIBFUZZER_TEST_DEPS})
35   set_target_properties(check-fuzzer-unit PROPERTIES FOLDER "Compiler-RT Tests")
36   add_dependencies(check-fuzzer check-fuzzer-unit)
37 endif()
39 macro(test_fuzzer stdlib)
40   cmake_parse_arguments(TEST "" "" "DEPS" ${ARGN})
41   string(REPLACE "+" "x" stdlib_name ${stdlib})
42   string(REPLACE "-" ";" stdlib_list ${stdlib_name})
43   set(STDLIB_CAPITALIZED "")
44   foreach(part IN LISTS stdlib_list)
45     string(SUBSTRING ${part} 0 1 first_letter)
46     string(TOUPPER ${first_letter} first_letter)
47     string(REGEX REPLACE "^.(.*)" "${first_letter}\\1" part "${part}")
48     set(STDLIB_CAPITALIZED "${STDLIB_CAPITALIZED}${part}")
49   endforeach()
50   foreach(arch ${FUZZER_TEST_ARCH})
51     set(LIBFUZZER_TEST_COMPILER ${COMPILER_RT_TEST_COMPILER})
52     get_test_cc_for_arch(${arch} LIBFUZZER_TEST_COMPILER LIBFUZZER_TEST_FLAGS)
54     set(LIBFUZZER_TEST_TARGET_ARCH ${arch})
55     set(LIBFUZZER_TEST_APPLE_PLATFORM "osx")
56     set(LIBFUZZER_TEST_MIN_DEPLOYMENT_TARGET_FLAG "${DARWIN_osx_MIN_VER_FLAG}")
58     set(LIBFUZZER_TEST_STDLIB ${stdlib})
60     string(TOUPPER ${arch} ARCH_UPPER_CASE)
61     set(CONFIG_NAME ${ARCH_UPPER_CASE}${STDLIB_CAPITALIZED}${OS_NAME}Config)
63     # LIT-based libFuzzer tests.
64     configure_lit_site_cfg(
65       ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
66       ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py
67       )
69     add_lit_testsuite(check-fuzzer-${stdlib_name}-${arch}
70       "Running libFuzzer ${stdlib} tests for arch ${arch}"
71       ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
72       DEPENDS ${LIBFUZZER_TEST_DEPS})
73     if(TEST_DEPS)
74       add_dependencies(check-fuzzer-${stdlib_name}-${arch} ${TEST_DEPS})
75     endif()
76     set_target_properties(check-fuzzer-${stdlib_name}-${arch}
77         PROPERTIES FOLDER "Compiler-RT Tests")
78     add_dependencies(check-fuzzer check-fuzzer-${stdlib_name}-${arch})
79   endforeach()
80 endmacro()
82 test_fuzzer("default")
83 if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
84   if(TARGET cxx_shared)
85     test_fuzzer("libc++" DEPS cxx_shared)
86   endif()
87   if(TARGET cxx_static)
88     test_fuzzer("static-libc++" DEPS cxx_static)
89   endif()
90 endif()
92 if (APPLE)
93   set(LIBFUZZER_TEST_COMPILER ${COMPILER_RT_TEST_COMPILER})
94   set(FUZZER_APPLE_PLATFORMS ${FUZZER_SUPPORTED_OS})
95   foreach(platform ${FUZZER_APPLE_PLATFORMS})
96     if ("${platform}" STREQUAL "osx")
97       # Skip macOS because it's handled by the code above that builds tests for the host machine.
98       continue()
99     endif()
100     list_intersect(
101       FUZZER_TEST_${platform}_ARCHS
102       FUZZER_SUPPORTED_ARCH
103       DARWIN_${platform}_ARCHS
104     )
105     foreach(arch ${FUZZER_TEST_${platform}_ARCHS})
106       get_test_cflags_for_apple_platform(
107         "${platform}"
108         "${arch}"
109         LIBFUZZER_TEST_FLAGS
110         )
111       string(TOUPPER "${arch}" ARCH_UPPER_CASE)
112       get_capitalized_apple_platform("${platform}" PLATFORM_CAPITALIZED)
113       set(CONFIG_NAME "${PLATFORM_CAPITALIZED}${ARCH_UPPER_CASE}Config")
114       set(LIBFUZZER_TEST_CONFIG_SUFFIX "-${arch}-${platform}")
115       set(LIBFUZZER_TEST_APPLE_PLATFORM "${platform}")
116       set(LIBFUZZER_TEST_TARGET_ARCH "${arch}")
117       set(LIBFUZZER_TEST_MIN_DEPLOYMENT_TARGET_FLAG "${DARWIN_${platform}_MIN_VER_FLAG}")
118       configure_lit_site_cfg(
119         ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
120         ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py
121         )
122       add_lit_testsuite(check-fuzzer-${platform}-${arch} "libFuzzer ${platform} ${arch} tests"
123         EXCLUDE_FROM_CHECK_ALL
124         ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
125         DEPENDS ${LIBFUZZER_TEST_DEPS})
126     endforeach()
127   endforeach()
128 endif()