CMakeLists.txt 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. include_directories(${PROJECT_SOURCE_DIR}/include)
  2. include_directories(${PROJECT_SOURCE_DIR}/deps)
  3. include_directories(${PROJECT_SOURCE_DIR}/src)
  4. include_directories(${PROJECT_SOURCE_DIR}/src/server)
  5. include_directories(${PROJECT_SOURCE_DIR}/plugins)
  6. include_directories(${PROJECT_SOURCE_DIR}/tests)
  7. include_directories(${PROJECT_BINARY_DIR}/src_generated)
  8. remove_definitions(-std=c99 -Wmissing-prototypes -Wstrict-prototypes)
  9. set (CMAKE_CXX_STANDARD 11)
  10. if (NOT UA_BUILD_OSS_FUZZ)
  11. if(NOT "x${CMAKE_C_COMPILER_ID}" STREQUAL "xClang")
  12. MESSAGE(FATAL_ERROR "To build fuzzing, you need to use Clang as the compiler")
  13. endif()
  14. # oss-fuzz builds already include these flags
  15. if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
  16. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O1 -fsanitize=address")
  17. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1 -fsanitize=address")
  18. else()
  19. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer -gline-tables-only -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address -fsanitize-address-use-after-scope -fsanitize-coverage=trace-pc-guard,trace-cmp")
  20. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -gline-tables-only -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address -fsanitize-address-use-after-scope -fsanitize-coverage=trace-pc-guard,trace-cmp")
  21. endif()
  22. set(LIBS Fuzzer)
  23. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
  24. else()
  25. set(LIBS $ENV{LIB_FUZZING_ENGINE})
  26. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY $ENV{OUT})
  27. endif()
  28. list(APPEND LIBS "${open62541_LIBRARIES}")
  29. # Use different plugins for testing
  30. set(fuzzing_plugin_sources ${PROJECT_SOURCE_DIR}/plugins/ua_network_tcp.c
  31. ${PROJECT_SOURCE_DIR}/plugins/ua_clock.c
  32. ${PROJECT_SOURCE_DIR}/tests/testing_networklayers.c
  33. ${PROJECT_SOURCE_DIR}/plugins/ua_log_stdout.c
  34. ${PROJECT_SOURCE_DIR}/plugins/ua_config_standard.c
  35. ${PROJECT_SOURCE_DIR}/plugins/ua_accesscontrol_default.c)
  36. add_library(open62541-fuzzplugins OBJECT ${fuzzing_plugin_sources})
  37. add_dependencies(open62541-fuzzplugins open62541)
  38. # the fuzzer test are built directly on the open62541 object files. so they can
  39. # access symbols that are hidden/not exported to the shared library
  40. set(FUZZER_TARGETS)
  41. macro(add_fuzzer FUZZER_NAME FUZZER_SOURCE)
  42. add_executable(${FUZZER_NAME} $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-fuzzplugins> ${FUZZER_SOURCE} ${ARGN})
  43. target_link_libraries(${FUZZER_NAME} ${LIBS})
  44. target_include_directories(${FUZZER_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/src/server)
  45. assign_source_group(${FUZZER_SOURCE})
  46. list(APPEND FUZZER_TARGETS ${FUZZER_NAME})
  47. endmacro()
  48. # Add new fuzzers here
  49. add_fuzzer(fuzz_binary_message fuzz_binary_message.cc)
  50. add_fuzzer(fuzz_binary_decode fuzz_binary_decode.cc)
  51. add_custom_target(
  52. run_fuzzer
  53. COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/fuzz_binary_message ${CMAKE_CURRENT_SOURCE_DIR}/fuzz_binary_message_corpus/client_Browse.bin
  54. COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/fuzz_binary_message ${CMAKE_CURRENT_SOURCE_DIR}/fuzz_binary_message_corpus/client_CLO.bin
  55. COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/fuzz_binary_message ${CMAKE_CURRENT_SOURCE_DIR}/fuzz_binary_message_corpus/client_CreateActivateSession.bin
  56. COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/fuzz_binary_message ${CMAKE_CURRENT_SOURCE_DIR}/fuzz_binary_message_corpus/client_HELOPN.bin
  57. COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/fuzz_binary_message ${CMAKE_CURRENT_SOURCE_DIR}/fuzz_binary_message_corpus/client_Read.bin
  58. COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/fuzz_binary_message ${CMAKE_CURRENT_SOURCE_DIR}/fuzz_binary_message_corpus/client_Write.bin
  59. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  60. DEPENDS ${FUZZER_TARGETS}
  61. ${MAYBE_USES_TERMINAL})