CMakeLists.txt 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 -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 -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_default.c
  35. ${PROJECT_SOURCE_DIR}/plugins/ua_nodestore_default.c
  36. ${PROJECT_SOURCE_DIR}/plugins/ua_accesscontrol_default.c
  37. ${PROJECT_SOURCE_DIR}/plugins/ua_securitypolicy_none.c)
  38. add_library(open62541-fuzzplugins OBJECT ${fuzzing_plugin_sources})
  39. add_dependencies(open62541-fuzzplugins open62541)
  40. # the fuzzer test are built directly on the open62541 object files. so they can
  41. # access symbols that are hidden/not exported to the shared library
  42. set(FUZZER_TARGETS)
  43. macro(add_fuzzer FUZZER_NAME FUZZER_SOURCE)
  44. add_executable(${FUZZER_NAME} $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-fuzzplugins> ${FUZZER_SOURCE} ${ARGN})
  45. target_link_libraries(${FUZZER_NAME} ${LIBS})
  46. target_include_directories(${FUZZER_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/src/server)
  47. assign_source_group(${FUZZER_SOURCE})
  48. list(APPEND FUZZER_TARGETS ${FUZZER_NAME})
  49. endmacro()
  50. # Add new fuzzers here
  51. add_fuzzer(fuzz_binary_message fuzz_binary_message.cc)
  52. add_fuzzer(fuzz_binary_decode fuzz_binary_decode.cc)
  53. add_custom_target(
  54. run_fuzzer
  55. COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/fuzz_binary_message ${CMAKE_CURRENT_SOURCE_DIR}/fuzz_binary_message_corpus/client_Browse.bin
  56. COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/fuzz_binary_message ${CMAKE_CURRENT_SOURCE_DIR}/fuzz_binary_message_corpus/client_CLO.bin
  57. COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/fuzz_binary_message ${CMAKE_CURRENT_SOURCE_DIR}/fuzz_binary_message_corpus/client_CreateActivateSession.bin
  58. COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/fuzz_binary_message ${CMAKE_CURRENT_SOURCE_DIR}/fuzz_binary_message_corpus/client_HELOPN.bin
  59. COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/fuzz_binary_message ${CMAKE_CURRENT_SOURCE_DIR}/fuzz_binary_message_corpus/client_Read.bin
  60. COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/fuzz_binary_message ${CMAKE_CURRENT_SOURCE_DIR}/fuzz_binary_message_corpus/client_Write.bin
  61. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  62. DEPENDS ${FUZZER_TARGETS}
  63. ${MAYBE_USES_TERMINAL})