Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
376 lines (308 loc) · 11.4 KB
/
Copy pathCMakeLists.txt
File metadata and controls
376 lines (308 loc) · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
cmake_minimum_required(VERSION 3.16.3) # version on Ubuntu Focal
project(behaviortree_cpp VERSION 4.11.1 LANGUAGES C CXX)
# create compile_commands.json
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 17)
#---- project configuration ----
option(BTCPP_SHARED_LIBS "Build shared libraries" ON)
option(BTCPP_BUILD_TOOLS "Build commandline tools" ON)
option(BTCPP_EXAMPLES "Build tutorials and examples" ON)
option(BUILD_TESTING "Build the unit tests" ON)
option(BTCPP_GROOT_INTERFACE "Add Groot2 connection. Requires ZeroMQ" ON)
option(BTCPP_SQLITE_LOGGING "Add SQLite logging." ON)
option(BTCPP_ENABLE_ASAN "Enable Address Sanitizer" OFF)
option(BTCPP_ENABLE_UBSAN "Enable Undefined Behavior Sanitizer" OFF)
option(BTCPP_ENABLE_TSAN "Enable Thread Sanitizer" OFF)
option(USE_V3_COMPATIBLE_NAMES "Use some alias to compile more easily old 3.x code" OFF)
option(ENABLE_FUZZING "Enable fuzzing builds" OFF)
option(USE_AFLPLUSPLUS "Use AFL++ instead of libFuzzer" OFF)
option(ENABLE_DEBUG "Enable debug build with full symbols" OFF)
option(FORCE_STATIC_LINKING "Force static linking of all dependencies" OFF)
option(USE_VENDORED_CPPZMQ "Use the bundled version of cppzmq" ON)
option(USE_VENDORED_FLATBUFFERS "Use the bundled version of flatbuffers" ON)
option(USE_VENDORED_JSON "Use the bundled version of nlohmann/json" ON)
option(USE_VENDORED_MINICORO "Use the bundled version of minicoro" ON)
option(USE_VENDORED_MINITRACE "Use the bundled version of minitrace" ON)
include(GNUInstallDirs)
set(BTCPP_LIB_DESTINATION "${CMAKE_INSTALL_LIBDIR}" CACHE STRING "Library installation directory")
set(BTCPP_INCLUDE_DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" CACHE STRING "Header installation directory")
set(BTCPP_BIN_DESTINATION "${CMAKE_INSTALL_BINDIR}" CACHE STRING "Binary installation directory")
set(BASE_FLAGS "")
if(ENABLE_DEBUG)
list(APPEND BASE_FLAGS
-g3
-ggdb3
-O0
-fno-omit-frame-pointer
)
endif()
# Include fuzzing configuration if enabled
if(ENABLE_FUZZING)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/fuzzing_build.cmake)
else()
# Apply base flags for non-fuzzing builds
add_compile_options(${BASE_FLAGS})
add_link_options(${BASE_FLAGS})
endif()
set(CMAKE_CONFIG_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CONFIG_PATH}")
include(sanitizers)
set(BTCPP_LIBRARY ${PROJECT_NAME})
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -DWIN32_LEAN_AND_MEAN)
else()
add_definitions(-Wpedantic -fno-omit-frame-pointer)
endif()
if(USE_V3_COMPATIBLE_NAMES)
add_definitions(-DUSE_BTCPP3_OLD_NAMES)
endif()
# Update the policy setting to avoid an error when loading the ament_cmake package
# at the current cmake version level
if(POLICY CMP0057)
cmake_policy(SET CMP0057 NEW)
endif()
find_package(ament_cmake QUIET)
if ( ament_cmake_FOUND )
add_definitions( -DUSING_ROS2 )
message(STATUS "------------------------------------------")
message(STATUS "BehaviorTree is being built using AMENT.")
message(STATUS "------------------------------------------")
include(cmake/ament_build.cmake)
find_package(tinyxml2_vendor QUIET)
find_package(TinyXML2 REQUIRED)
else()
message(STATUS "------------------------------------------")
message(STATUS "BehaviorTree is being built without AMENT.")
message(STATUS "------------------------------------------")
include(cmake/conan_build.cmake)
option(USE_VENDORED_TINYXML2 "Use the bundled version of tinyxml2" ON)
if(USE_VENDORED_TINYXML2)
add_subdirectory(3rdparty/tinyxml2)
else()
find_package(tinyxml2 REQUIRED)
endif()
endif()
#############################################################
# Handle dependencies
find_package(Threads REQUIRED)
if(BTCPP_GROOT_INTERFACE)
if(USE_VENDORED_CPPZMQ)
add_subdirectory(3rdparty/cppzmq)
else()
find_package(cppzmq REQUIRED)
endif()
endif()
if(BTCPP_SQLITE_LOGGING)
find_package(SQLite3 REQUIRED)
endif()
if(USE_VENDORED_FLATBUFFERS)
add_subdirectory(3rdparty/flatbuffers)
else()
find_package(flatbuffers REQUIRED)
endif()
if(NOT USE_VENDORED_JSON)
find_package(nlohmann_json 3.10 REQUIRED)
endif()
if(USE_VENDORED_MINICORO)
add_subdirectory(3rdparty/minicoro)
else()
find_package(minicoro REQUIRED)
endif()
if(USE_VENDORED_MINITRACE)
add_subdirectory(3rdparty/minitrace)
else()
find_package(minitrace REQUIRED)
endif()
list(APPEND BT_SOURCE
src/action_node.cpp
src/basic_types.cpp
src/behavior_tree.cpp
src/blackboard.cpp
src/bt_factory.cpp
src/decorator_node.cpp
src/condition_node.cpp
src/control_node.cpp
src/shared_library.cpp
src/tree_node.cpp
src/script_parser.cpp
src/script_tokenizer.cpp
src/json_export.cpp
src/xml_parsing.cpp
src/actions/test_node.cpp
src/actions/sleep_node.cpp
src/actions/updated_action.cpp
src/decorators/delay_node.cpp
src/decorators/inverter_node.cpp
src/decorators/repeat_node.cpp
src/decorators/retry_node.cpp
src/decorators/subtree_node.cpp
src/decorators/timeout_node.cpp
src/decorators/updated_decorator.cpp
src/controls/if_then_else_node.cpp
src/controls/fallback_node.cpp
src/controls/parallel_node.cpp
src/controls/parallel_all_node.cpp
src/controls/reactive_sequence.cpp
src/controls/reactive_fallback.cpp
src/controls/sequence_node.cpp
src/controls/sequence_with_memory_node.cpp
src/controls/switch_node.cpp
src/controls/finally_node.cpp
src/controls/try_catch_node.cpp
src/controls/while_do_else_node.cpp
src/loggers/abstract_logger.cpp
src/loggers/bt_cout_logger.cpp
src/loggers/bt_file_logger_v2.cpp
src/loggers/bt_minitrace_logger.cpp
src/loggers/bt_observer.cpp
)
if(BTCPP_GROOT_INTERFACE)
# should be found already, at this stage
list(APPEND BT_SOURCE src/loggers/groot2_publisher.cpp )
endif()
if(BTCPP_SQLITE_LOGGING)
list(APPEND BT_SOURCE src/loggers/bt_sqlite_logger.cpp )
endif()
######################################################
if (UNIX)
list(APPEND BT_SOURCE src/shared_library_UNIX.cpp )
endif()
if (WIN32)
set(CMAKE_DEBUG_POSTFIX "d")
list(APPEND BT_SOURCE src/shared_library_WIN.cpp )
endif()
# Embed src/btcpp4_schematron.sch as a C++ string constant.
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/src/btcpp4_schematron.sch"
)
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/src/btcpp4_schematron.sch" BTCPP_SCHEMATRON_TEMPLATE)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/src/schematron_template.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/generated/schematron_template.gen.h"
@ONLY
)
if (BTCPP_SHARED_LIBS)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
add_library(${BTCPP_LIBRARY} SHARED ${BT_SOURCE})
else()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
add_library(${BTCPP_LIBRARY} STATIC ${BT_SOURCE})
endif()
message(STATUS "BTCPP_EXTRA_LIBRARIES: ${BTCPP_EXTRA_LIBRARIES}")
target_link_libraries(${BTCPP_LIBRARY}
PRIVATE
Threads::Threads
${CMAKE_DL_LIBS}
$<BUILD_INTERFACE:minitrace::minitrace>
$<BUILD_INTERFACE:tinyxml2::tinyxml2>
$<BUILD_INTERFACE:minicoro::minicoro>
$<BUILD_INTERFACE:flatbuffers::flatbuffers>
PUBLIC
${BTCPP_EXTRA_LIBRARIES}
)
if(BTCPP_GROOT_INTERFACE)
target_link_libraries(${BTCPP_LIBRARY}
PUBLIC
$<BUILD_INTERFACE:cppzmq>
)
endif()
if(BTCPP_SQLITE_LOGGING)
target_link_libraries(${BTCPP_LIBRARY}
PRIVATE
$<BUILD_INTERFACE:SQLite::SQLite3>
)
endif()
target_include_directories(${BTCPP_LIBRARY}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
${BTCPP_EXTRA_INCLUDE_DIRS}
${CMAKE_CURRENT_BINARY_DIR}/generated
)
target_compile_definitions(${BTCPP_LIBRARY} PUBLIC BTCPP_LIBRARY_VERSION="${PROJECT_VERSION}")
if(NOT USE_VENDORED_JSON)
# The public headers include <nlohmann/json.hpp> instead of the bundled copy
target_compile_definitions(${BTCPP_LIBRARY} PUBLIC BTCPP_SYSTEM_JSON)
target_link_libraries(${BTCPP_LIBRARY} PUBLIC nlohmann_json::nlohmann_json)
endif()
target_compile_features(${BTCPP_LIBRARY} PUBLIC cxx_std_17)
if(MSVC)
target_compile_options(${BTCPP_LIBRARY} PRIVATE "/source-charset:utf-8")
elseif(ENABLE_DEBUG)
target_compile_options(${BTCPP_LIBRARY} PRIVATE -g3 -ggdb3 -O0 -fno-omit-frame-pointer)
endif()
add_library(BT::${BTCPP_LIBRARY} ALIAS ${BTCPP_LIBRARY})
# Downstream projects (e.g. Nav2) compile our public headers with -Werror, so
# the library and every target below that instantiates them must be
# warning-free (issue #1288). -Wnull-dereference only fires with optimization.
# Set after the 3rdparty subdirectories, so vendored code is not affected.
if(MSVC)
# C4702 (unreachable code) is a code-generation warning that fires on
# instantiation-dependent `if constexpr` tails; GCC/Clang have no
# equivalent in -Wall -Wextra.
set(BTCPP_WARNING_FLAGS /W4 /WX /permissive- /wd4702)
else()
set(BTCPP_WARNING_FLAGS -Wall -Wextra -Wpedantic -Wnull-dereference -Werror)
endif()
target_compile_options(${BTCPP_LIBRARY} PRIVATE ${BTCPP_WARNING_FLAGS})
add_compile_options(${BTCPP_WARNING_FLAGS})
# Add fuzzing targets
if(ENABLE_FUZZING)
add_fuzzing_targets()
endif()
#############################################################
message( STATUS "BTCPP_LIB_DESTINATION: ${BTCPP_LIB_DESTINATION} " )
message( STATUS "BTCPP_INCLUDE_DESTINATION: ${BTCPP_INCLUDE_DESTINATION} " )
if (BUILD_TESTING OR BTCPP_EXAMPLES)
add_subdirectory(sample_nodes)
endif()
######################################################
include(CTest)
message( STATUS "BUILD_TESTING: ${BUILD_TESTING} " )
if (BUILD_TESTING)
add_subdirectory(tests)
endif()
if(BTCPP_BUILD_TOOLS)
add_subdirectory(tools)
endif()
if(BTCPP_EXAMPLES)
add_subdirectory(examples)
endif()
######################################################
# Generate .clangd configuration file for standalone header checking
file(WRITE ${PROJECT_SOURCE_DIR}/.clangd
"CompileFlags:
Add:
- -xc++
- -std=c++17
- -I${PROJECT_SOURCE_DIR}/include
- -I${PROJECT_SOURCE_DIR}/3rdparty
- -I${PROJECT_SOURCE_DIR}/3rdparty/minitrace
- -I${PROJECT_SOURCE_DIR}/3rdparty/tinyxml2
- -I${PROJECT_SOURCE_DIR}/3rdparty/minicoro
")
######################################################
# INSTALL
INSTALL(TARGETS ${BTCPP_LIBRARY}
EXPORT ${BTCPP_LIBRARY}Targets
ARCHIVE DESTINATION ${BTCPP_LIB_DESTINATION}
LIBRARY DESTINATION ${BTCPP_LIB_DESTINATION}
RUNTIME DESTINATION ${BTCPP_BIN_DESTINATION}
INCLUDES DESTINATION ${BTCPP_INCLUDE_DESTINATION}
)
if(NOT USE_VENDORED_JSON)
# Don't install the bundled copy: a user that doesn't get BTCPP_SYSTEM_JSON
# must fail to compile, rather than mix two versions of nlohmann::json
set(BTCPP_INSTALL_EXCLUDE REGEX "contrib/json\\.hpp$" EXCLUDE)
endif()
INSTALL( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
DESTINATION ${BTCPP_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.h*" ${BTCPP_INSTALL_EXCLUDE})
export_btcpp_package()