@@ -2,18 +2,95 @@ cmake_minimum_required(VERSION 3.16.3) # version on Ubuntu Focal
2
2
3
3
project (behaviortree_cpp VERSION 4.6.2 LANGUAGES C CXX )
4
4
5
- set (CMAKE_CONFIG_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR} /cmake" )
5
+ # Build configuration options
6
+ option (ENABLE_FUZZING "Enable fuzzing builds" OFF )
7
+ option (USE_AFLPLUSPLUS "Use AFL++ instead of libFuzzer" OFF )
8
+ option (ENABLE_DEBUG "Enable debug build with full symbols" OFF )
9
+
10
+ set (BASE_FLAGS "" )
11
+
12
+ # Debug build configuration
13
+ if (ENABLE_DEBUG )
14
+ list (APPEND BASE_FLAGS
15
+ -g3
16
+ -ggdb3
17
+ -O0
18
+ -fno-omit-frame-pointer
19
+ )
20
+ endif ()
21
+
22
+ # Fuzzing configuration
23
+ if (ENABLE_FUZZING )
24
+ if (USE_AFLPLUSPLUS )
25
+ list (APPEND BASE_FLAGS -O3 )
26
+ else ()
27
+ list (APPEND BASE_FLAGS -O2 )
28
+ endif ()
29
+
30
+ if (USE_AFLPLUSPLUS )
31
+ set (SANITIZER_FLAGS
32
+ -fsanitize=address,undefined
33
+ )
34
+ else ()
35
+ # For libFuzzer, use fuzzer-no-link for the library
36
+ set (SANITIZER_FLAGS
37
+ -fsanitize=address,undefined,fuzzer-no-link
38
+ )
39
+ endif ()
40
+
41
+ # Apply sanitizer flags to the base library
42
+ list (APPEND BASE_FLAGS ${SANITIZER_FLAGS} )
43
+
44
+ # Apply base flags globally
45
+ add_compile_options (${BASE_FLAGS} )
46
+ add_link_options (${BASE_FLAGS} )
47
+
48
+ function (apply_fuzzing_flags target )
49
+ if (USE_AFLPLUSPLUS )
50
+ # AFL++ specific flags
51
+ target_compile_options (${target} PRIVATE
52
+ ${BASE_FLAGS}
53
+ ${SANITIZER_FLAGS}
54
+ )
55
+ target_link_options (${target} PRIVATE
56
+ ${BASE_FLAGS}
57
+ -fsanitize=fuzzer,address,undefined
58
+ )
59
+ else ()
60
+ # libFuzzer specific flags
61
+ target_compile_options (${target} PRIVATE
62
+ ${BASE_FLAGS}
63
+ -fsanitize=fuzzer
64
+ ${SANITIZER_FLAGS}
65
+ )
66
+ target_link_options (${target} PRIVATE
67
+ ${BASE_FLAGS}
68
+ -fsanitize=fuzzer
69
+ ${SANITIZER_FLAGS}
70
+ )
71
+ endif ()
72
+ endfunction ()
73
+
74
+ set (BTCPP_EXAMPLES OFF CACHE BOOL "Disable examples during fuzzing" FORCE )
75
+ set (BTCPP_BUILD_TOOLS OFF CACHE BOOL "Disable tools during fuzzing" FORCE )
76
+ set (BTCPP_UNIT_TESTS OFF CACHE BOOL "Disable tests during fuzzing" FORCE )
77
+ set (BTCPP_SHARED_LIBS OFF CACHE BOOL "Build static library for fuzzing" FORCE )
78
+ else ()
79
+ # Apply base flags for non-fuzzing builds
80
+ add_compile_options (${BASE_FLAGS} )
81
+ add_link_options (${BASE_FLAGS} )
82
+ endif ()
83
+
84
+ set (CMAKE_CONFIG_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR} /cmake" )
6
85
list (APPEND CMAKE_MODULE_PATH "${CMAKE_CONFIG_PATH} " )
7
86
8
87
set (BTCPP_LIBRARY ${PROJECT_NAME} )
9
88
10
89
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES )
11
- message (STATUS "Setting build type to 'Release' as none was specified." )
12
- set (CMAKE_BUILD_TYPE "Release" CACHE
13
- STRING "Choose the type of build." FORCE )
14
- # Set the possible values of build type for cmake-gui
15
- set_property (CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
16
- "Debug" "Release" "MinSizeRel" "RelWithDebInfo" )
90
+ message (STATUS "Setting build type to 'Release' as none was specified." )
91
+ set (CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE )
92
+ set_property (CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
93
+ "Debug" "Release" "MinSizeRel" "RelWithDebInfo" )
17
94
endif ()
18
95
19
96
if (MSVC )
@@ -186,20 +263,59 @@ target_compile_definitions(${BTCPP_LIBRARY} PUBLIC BTCPP_LIBRARY_VERSION="${CMAK
186
263
target_compile_features (${BTCPP_LIBRARY} PUBLIC cxx_std_17 )
187
264
188
265
if (MSVC )
189
- target_compile_options (${BTCPP_LIBRARY} PRIVATE "/source-charset:utf-8" )
266
+ target_compile_options (${BTCPP_LIBRARY} PRIVATE "/source-charset:utf-8" )
190
267
else ()
191
- target_compile_options (${BTCPP_LIBRARY} PRIVATE -Wall -Wextra )
268
+ if (ENABLE_DEBUG )
269
+ target_compile_options (${BTCPP_LIBRARY} PRIVATE -Wall -Wextra -g3 -ggdb3 -O0 -fno-omit-frame-pointer )
270
+ else ()
271
+ target_compile_options (${BTCPP_LIBRARY} PRIVATE -Wall -Wextra )
272
+ endif ()
192
273
endif ()
193
274
194
275
add_library (BT::${BTCPP_LIBRARY} ALIAS ${BTCPP_LIBRARY} )
195
276
277
+
278
+ # Add fuzzing targets
279
+ if (ENABLE_FUZZING )
280
+ add_executable (bt_fuzzer fuzzing/bt_fuzzer.cpp )
281
+ apply_fuzzing_flags (bt_fuzzer )
282
+ target_link_libraries (bt_fuzzer PRIVATE ${BTCPP_LIBRARY} ${BTCPP_EXTRA_LIBRARIES} )
283
+
284
+ add_executable (script_fuzzer fuzzing/script_fuzzer.cpp )
285
+ apply_fuzzing_flags (script_fuzzer )
286
+ target_link_libraries (script_fuzzer PRIVATE ${BTCPP_LIBRARY} ${BTCPP_EXTRA_LIBRARIES} )
287
+
288
+ add_executable (bb_fuzzer fuzzing/bb_fuzzer.cpp )
289
+ apply_fuzzing_flags (bb_fuzzer )
290
+ target_link_libraries (bb_fuzzer PRIVATE ${BTCPP_LIBRARY} ${BTCPP_EXTRA_LIBRARIES} )
291
+
292
+ foreach (fuzzer bt_fuzzer script_fuzzer bb_fuzzer )
293
+ set (CORPUS_DIR ${CMAKE_BINARY_DIR} /corpus/${fuzzer} )
294
+ file (MAKE_DIRECTORY ${CORPUS_DIR} )
295
+ endforeach ()
296
+
297
+ file (GLOB BT_CORPUS_FILES "fuzzing/corpus/bt_fuzzer/*" )
298
+ file (GLOB SCRIPT_CORPUS_FILES "fuzzing/corpus/script_fuzzer/*" )
299
+ file (GLOB BB_CORPUS_FILES "fuzzing/corpus/bb_fuzzer/*" )
300
+
301
+ if (BT_CORPUS_FILES )
302
+ file (COPY ${BT_CORPUS_FILES} DESTINATION ${CMAKE_BINARY_DIR} /corpus/bt_fuzzer )
303
+ endif ()
304
+ if (SCRIPT_CORPUS_FILES )
305
+ file (COPY ${SCRIPT_CORPUS_FILES} DESTINATION ${CMAKE_BINARY_DIR} /corpus/script_fuzzer )
306
+ endif ()
307
+ if (BB_CORPUS_FILES )
308
+ file (COPY ${BB_CORPUS_FILES} DESTINATION ${CMAKE_BINARY_DIR} /corpus/bb_fuzzer )
309
+ endif ()
310
+ endif ()
311
+
196
312
#############################################################
197
313
message ( STATUS "BTCPP_LIB_DESTINATION: ${BTCPP_LIB_DESTINATION} " )
198
314
message ( STATUS "BTCPP_INCLUDE_DESTINATION: ${BTCPP_INCLUDE_DESTINATION} " )
199
315
message ( STATUS "BTCPP_UNIT_TESTS: ${BTCPP_UNIT_TESTS} " )
200
316
201
317
if (BTCPP_UNIT_TESTS OR BTCPP_EXAMPLES )
202
- add_subdirectory (sample_nodes )
318
+ add_subdirectory (sample_nodes )
203
319
endif ()
204
320
205
321
######################################################
0 commit comments