OSDN Git Service

Try to deflake fuzzer-oom.test on Windows
[android-x86/external-llvm.git] / lib / Fuzzer / CMakeLists.txt
1 include(CheckCXXSourceCompiles)
2
3 if( APPLE )
4   CHECK_CXX_SOURCE_COMPILES("
5       static thread_local int blah;
6       int main() {
7         return 0;
8       }
9       " HAS_THREAD_LOCAL)
10
11   if( NOT HAS_THREAD_LOCAL )
12     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Dthread_local=__thread")
13   endif()
14 endif()
15
16 set(LIBFUZZER_FLAGS_BASE "${CMAKE_CXX_FLAGS}")
17 if( LLVM_USE_SANITIZE_COVERAGE )
18   if(NOT "${LLVM_USE_SANITIZER}" STREQUAL "Address")
19     message(FATAL_ERROR
20       "LibFuzzer and its tests require LLVM_USE_SANITIZER=Address and "
21       "LLVM_USE_SANITIZE_COVERAGE=YES to be set."
22       )
23   endif()
24
25   # Disable the coverage and sanitizer instrumentation for the fuzzer itself.
26   set(CMAKE_CXX_FLAGS "${LIBFUZZER_FLAGS_BASE} -fno-sanitize-coverage=trace-pc-guard,edge,trace-cmp,indirect-calls,8bit-counters -Werror")
27 endif()
28
29 # Compile libFuzzer if the compilation is specifically requested, OR
30 # if the platform is known to be working.
31 if ( LLVM_USE_SANITIZE_COVERAGE OR CMAKE_SYSTEM_NAME MATCHES "Darwin|Linux" )
32   add_library(LLVMFuzzerNoMainObjects OBJECT
33       FuzzerCrossOver.cpp
34       FuzzerDriver.cpp
35       FuzzerExtFunctionsDlsym.cpp
36       FuzzerExtFunctionsDlsymWin.cpp
37       FuzzerExtFunctionsWeak.cpp
38       FuzzerExtraCounters.cpp
39       FuzzerIO.cpp
40       FuzzerIOPosix.cpp
41       FuzzerIOWindows.cpp
42       FuzzerLoop.cpp
43       FuzzerMerge.cpp
44       FuzzerMutate.cpp
45       FuzzerSHA1.cpp
46       FuzzerShmemPosix.cpp
47       FuzzerShmemWindows.cpp
48       FuzzerTracePC.cpp
49       FuzzerUtil.cpp
50       FuzzerUtilDarwin.cpp
51       FuzzerUtilLinux.cpp
52       FuzzerUtilPosix.cpp
53       FuzzerUtilWindows.cpp
54       )
55   add_library(LLVMFuzzerNoMain STATIC
56       $<TARGET_OBJECTS:LLVMFuzzerNoMainObjects>
57       )
58   target_link_libraries(LLVMFuzzerNoMain ${LLVM_PTHREAD_LIB})
59   add_library(LLVMFuzzer STATIC
60       FuzzerMain.cpp
61       $<TARGET_OBJECTS:LLVMFuzzerNoMainObjects>
62       )
63   target_link_libraries(LLVMFuzzer ${LLVM_PTHREAD_LIB})
64 endif()
65
66 if( LLVM_USE_SANITIZE_COVERAGE AND LLVM_INCLUDE_TESTS )
67   add_subdirectory(test)
68 endif()