11cmake_minimum_required (VERSION 3.13 )
22project (Http)
33
4+ # Policies
5+ if (POLICY CMP0127)
6+ cmake_policy (SET CMP0127 NEW )
7+ endif ()
8+ if (POLICY CMP0135)
9+ cmake_policy (SET CMP0135 OLD )
10+ endif ()
11+
412# Deps
513include (FetchContent )
14+ include (CMakeDependentOption )
615find_package (Threads REQUIRED )
716find_package (OpenSSL REQUIRED )
817
9- if (POLICY CMP0135)
10- cmake_policy (SET CMP0135 OLD )
11- endif ()
1218set (BOOST_INCLUDE_LIBRARIES compat asio)
1319set (BOOST_ENABLE_CMAKE ON )
1420FetchContent_Declare (
@@ -17,30 +23,32 @@ FetchContent_Declare(
1723 URL_HASH MD5=3edffaacd2cfe63c240ef1b99497c74f)
1824FetchContent_MakeAvailable (Boost)
1925
26+ # Options
27+ cmake_dependent_option (HTTP_BUILD_FUZZERS "Builds Fuzz tests" OFF "CMAKE_CXX_COMPILER_ID STREQUAL \" Clang\" " OFF )
28+
2029# Lib
2130add_library (http ${CMAKE_CURRENT_SOURCE_DIR} /../src/http.cpp )
2231target_compile_features (http PUBLIC cxx_std_17 )
2332target_include_directories (http PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} /../src )
2433target_link_libraries (http PUBLIC OpenSSL::SSL OpenSSL::Crypto Boost::asio )
34+ target_compile_options (http PRIVATE $<$<BOOL :${HTTP_BUILD_FUZZERS} >:-fprofile -instr -generate -fcoverage -mapping >)
2535
2636# Examples
27- function (add_executable_20 target_name )
28- add_executable (${target_name} ${ARGN} )
29- target_compile_features (${target_name} PUBLIC cxx_std_20 )
30- target_link_options (${target_name} PUBLIC $<$<CONFIG :Release >:-s >)
31- target_link_libraries (${target_name} PUBLIC Threads::Threads http )
32- endfunction ()
33-
34- function (add_executable_coro target_name )
37+ function (add_example target_name )
3538 add_executable (${target_name} ${ARGN} )
3639 target_link_options (${target_name} PRIVATE $<$<CONFIG :Release >:-s >)
3740 target_link_libraries (${target_name} PRIVATE Threads::Threads Boost::compat http )
3841endfunction ()
3942
40- add_executable_20 (server ${CMAKE_CURRENT_SOURCE_DIR} /server.cpp )
41- add_executable_20 (client_http ${CMAKE_CURRENT_SOURCE_DIR} /client_http.cpp ${CMAKE_CURRENT_SOURCE_DIR} /extra/yyjson.c )
42- add_executable_20 (client_ws_awaitable ${CMAKE_CURRENT_SOURCE_DIR} /client_ws_awaitable.cpp )
43- add_executable_coro (client_ws_coro ${CMAKE_CURRENT_SOURCE_DIR} /client_ws_coro.cpp )
43+ function (add_example_20 target_name )
44+ add_example (${target_name} ${ARGN} )
45+ target_compile_features (${target_name} PUBLIC cxx_std_20 )
46+ endfunction ()
47+
48+ add_example_20 (server ${CMAKE_CURRENT_SOURCE_DIR} /server.cpp )
49+ add_example_20 (client_http ${CMAKE_CURRENT_SOURCE_DIR} /client_http.cpp ${CMAKE_CURRENT_SOURCE_DIR} /extra/yyjson.c )
50+ add_example_20 (client_ws_awaitable ${CMAKE_CURRENT_SOURCE_DIR} /client_ws_awaitable.cpp )
51+ add_example (client_ws_coro ${CMAKE_CURRENT_SOURCE_DIR} /client_ws_coro.cpp )
4452
4553# Unit tests
4654add_executable (tests
@@ -54,4 +62,20 @@ add_executable(tests
5462target_compile_features (tests PUBLIC cxx_std_20 )
5563target_link_options (tests PRIVATE $<$<CONFIG :Release >:-s >)
5664target_include_directories (tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} /extra )
57- target_link_libraries (tests PRIVATE http )
65+ target_link_libraries (tests PRIVATE http )
66+
67+ # Fuzz tests
68+ if (HTTP_BUILD_FUZZERS)
69+ function (add_fuzz target_name )
70+ add_executable (${target_name} ${ARGN} )
71+ target_link_libraries (${target_name} PRIVATE http )
72+ target_compile_options (${target_name} PRIVATE -fprofile-instr-generate -fcoverage-mapping )
73+ target_link_options (${target_name} PRIVATE -fsanitize=fuzzer -fprofile-instr-generate -fcoverage-mapping )
74+ endfunction ()
75+
76+ add_fuzz (request_parser fuzz/request_parser.cpp )
77+ add_fuzz (response_parser fuzz/response_parser.cpp )
78+ add_fuzz (websocket_parser fuzz/websocket_parser.cpp )
79+ add_fuzz (sha1 fuzz/sha1.cpp )
80+ add_fuzz (base64 fuzz/base64.cpp )
81+ endif ()
0 commit comments