forked from BehaviorTree/BehaviorTree.CPP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
277 lines (220 loc) · 8.62 KB
/
CMakeLists.txt
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
cmake_minimum_required(VERSION 3.5.1) # version on Ubuntu Xenial
project(behaviortree_cpp_v3)
#---- Add the subdirectory cmake ----
set(CMAKE_CONFIG_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CONFIG_PATH}")
#---- Enable C++14 ----
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()
#---- Include boost to add coroutines ----
find_package(Boost COMPONENTS coroutine QUIET)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
string(REPLACE "." "0" Boost_VERSION_NODOT ${Boost_VERSION})
if(NOT Boost_VERSION_NODOT VERSION_LESS 105900)
message(STATUS "Found boost::coroutine2.")
add_definitions(-DBT_BOOST_COROUTINE2)
set(BT_COROUTINES true)
elseif(NOT Boost_VERSION_NODOT VERSION_LESS 105300)
message(STATUS "Found boost::coroutine.")
include_directories(${Boost_INCLUDE_DIRS})
add_definitions(-DBT_BOOST_COROUTINE)
set(BT_COROUTINES true)
endif()
endif()
if(NOT DEFINED BT_COROUTINES)
message(STATUS "Coroutines disabled. Install Boost to enable them (version 1.59+ recommended).")
add_definitions(-DBT_NO_COROUTINES)
endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
#---- project configuration ----
option(BUILD_EXAMPLES "Build tutorials and examples" ON)
option(BUILD_UNIT_TESTS "Build the unit tests" ON)
option(BUILD_TOOLS "Build commandline tools" ON)
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
#---- Find other packages ----
find_package(Threads)
find_package(ZMQ)
list(APPEND BEHAVIOR_TREE_EXTERNAL_LIBRARIES
${CMAKE_THREAD_LIBS_INIT}
${CMAKE_DL_LIBS}
${Boost_LIBRARIES} )
if( ZMQ_FOUND )
message(STATUS "ZeroMQ found.")
add_definitions( -DZMQ_FOUND )
list(APPEND BT_SOURCE src/loggers/bt_zmq_publisher.cpp)
list(APPEND BEHAVIOR_TREE_EXTERNAL_LIBRARIES ${ZMQ_LIBRARIES})
else()
message(WARNING "ZeroMQ NOT found. Skipping the build of [PublisherZMQ] and [bt_recorder].")
endif()
set(BEHAVIOR_TREE_LIBRARY ${PROJECT_NAME})
# 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 )
# Not adding -DUSING_ROS since xml_parsing.cpp hasn't been ported to ROS2
message(STATUS "------------------------------------------")
message(STATUS "BehaviourTree is being built using AMENT.")
message(STATUS "------------------------------------------")
set(BUILD_TOOL_INCLUDE_DIRS ${ament_INCLUDE_DIRS})
elseif( CATKIN_DEVEL_PREFIX OR CATKIN_BUILD_BINARY_PACKAGE)
set(catkin_FOUND 1)
add_definitions( -DUSING_ROS )
find_package(catkin REQUIRED COMPONENTS roslib)
find_package(GTest)
message(STATUS "------------------------------------------")
message(STATUS "BehaviourTree is being built using CATKIN.")
message(STATUS "------------------------------------------")
catkin_package(
INCLUDE_DIRS include # do not include "3rdparty" here
LIBRARIES ${BEHAVIOR_TREE_LIBRARY}
CATKIN_DEPENDS roslib
)
list(APPEND BEHAVIOR_TREE_EXTERNAL_LIBRARIES ${catkin_LIBRARIES})
set(BUILD_TOOL_INCLUDE_DIRS ${catkin_INCLUDE_DIRS})
elseif(BUILD_UNIT_TESTS)
find_package(GTest)
if(NOT GTEST_FOUND)
message(WARNING " GTest missing! You may want to follow these instructions:")
message(WARNING " https://gist.github.com/Cartexius/4c437c084d6e388288201aadf9c8cdd5")
endif()
endif()
#############################################################
if(ament_cmake_FOUND)
set( BEHAVIOR_TREE_LIB_DESTINATION lib )
set( BEHAVIOR_TREE_INC_DESTINATION include )
set( BEHAVIOR_TREE_BIN_DESTINATION bin )
ament_export_include_directories(include)
ament_export_libraries(${BEHAVIOR_TREE_LIBRARY})
ament_package()
elseif(catkin_FOUND)
set( BEHAVIOR_TREE_LIB_DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} )
set( BEHAVIOR_TREE_INC_DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION} )
set( BEHAVIOR_TREE_BIN_DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION} )
else()
set( BEHAVIOR_TREE_LIB_DESTINATION lib )
set( BEHAVIOR_TREE_INC_DESTINATION include )
set( BEHAVIOR_TREE_BIN_DESTINATION bin )
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${BEHAVIOR_TREE_BIN_DESTINATION}" )
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${BEHAVIOR_TREE_LIB_DESTINATION}" )
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${BEHAVIOR_TREE_BIN_DESTINATION}" )
endif()
message( STATUS "BEHAVIOR_TREE_LIB_DESTINATION: ${BEHAVIOR_TREE_LIB_DESTINATION} " )
message( STATUS "BEHAVIOR_TREE_BIN_DESTINATION: ${BEHAVIOR_TREE_BIN_DESTINATION} " )
message( STATUS "CMAKE_RUNTIME_OUTPUT_DIRECTORY: ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} " )
message( STATUS "CMAKE_LIBRARY_OUTPUT_DIRECTORY: ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} " )
message( STATUS "CMAKE_ARCHIVE_OUTPUT_DIRECTORY: ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY} " )
#############################################################
# LIBRARY
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/xml_parsing.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/controls/if_then_else_node.cpp
src/controls/fallback_node.cpp
src/controls/parallel_node.cpp
src/controls/reactive_sequence.cpp
src/controls/reactive_fallback.cpp
src/controls/sequence_node.cpp
src/controls/sequence_star_node.cpp
src/controls/switch_node.cpp
src/controls/while_do_else_node.cpp
src/loggers/bt_cout_logger.cpp
src/loggers/bt_file_logger.cpp
src/loggers/bt_minitrace_logger.cpp
src/private/tinyxml2.cpp
3rdparty/minitrace/minitrace.cpp
)
find_package(Curses QUIET)
if(CURSES_FOUND)
list(APPEND BT_SOURCE
src/controls/manual_node.cpp
)
list(APPEND BEHAVIOR_TREE_EXTERNAL_LIBRARIES ${CURSES_LIBRARIES})
add_definitions(-DNCURSES_FOUND)
endif()
######################################################
if (UNIX)
list(APPEND BT_SOURCE src/shared_library_UNIX.cpp )
if (BUILD_SHARED_LIBS)
add_library(${BEHAVIOR_TREE_LIBRARY} SHARED ${BT_SOURCE})
else()
add_library(${BEHAVIOR_TREE_LIBRARY} STATIC ${BT_SOURCE})
endif()
endif()
if (WIN32)
set(CMAKE_DEBUG_POSTFIX "d")
list(APPEND BT_SOURCE src/shared_library_WIN.cpp )
add_library(${BEHAVIOR_TREE_LIBRARY} STATIC ${BT_SOURCE} )
endif()
if( ZMQ_FOUND )
list(APPEND BUILD_TOOL_INCLUDE_DIRS ${ZMQ_INCLUDE_DIRS})
endif()
target_link_libraries(${BEHAVIOR_TREE_LIBRARY} PUBLIC
${BEHAVIOR_TREE_EXTERNAL_LIBRARIES})
target_compile_definitions(${BEHAVIOR_TREE_LIBRARY} PRIVATE $<$<CONFIG:Debug>:TINYXML2_DEBUG>)
target_include_directories(${BEHAVIOR_TREE_LIBRARY} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/3rdparty>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
${BUILD_TOOL_INCLUDE_DIRS})
if( ZMQ_FOUND )
target_compile_definitions(${BEHAVIOR_TREE_LIBRARY} PUBLIC ZMQ_FOUND)
endif()
if(MSVC)
target_compile_options(${BEHAVIOR_TREE_LIBRARY} PRIVATE /W4 /WX)
else()
target_compile_options(${BEHAVIOR_TREE_LIBRARY} PRIVATE
-Wall -Wextra -Werror=return-type)
endif()
######################################################
# Test
if (BUILD_UNIT_TESTS)
add_subdirectory(tests)
endif()
######################################################
# INSTALL
INSTALL(TARGETS ${BEHAVIOR_TREE_LIBRARY}
EXPORT BehaviorTreeV3Config
ARCHIVE DESTINATION ${BEHAVIOR_TREE_LIB_DESTINATION}
LIBRARY DESTINATION ${BEHAVIOR_TREE_LIB_DESTINATION}
RUNTIME DESTINATION ${BEHAVIOR_TREE_BIN_DESTINATION}
)
INSTALL( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
DESTINATION ${BEHAVIOR_TREE_INC_DESTINATION}
FILES_MATCHING PATTERN "*.h*")
install(EXPORT BehaviorTreeV3Config
DESTINATION "${BEHAVIOR_TREE_LIB_DESTINATION}/BehaviorTreeV3/cmake"
NAMESPACE BT::)
export(TARGETS ${PROJECT_NAME}
NAMESPACE BT::
FILE "${CMAKE_CURRENT_BINARY_DIR}/BehaviorTreeV3Config.cmake")
export(PACKAGE ${PROJECT_NAME})
######################################################
# EXAMPLES and TOOLS
if(BUILD_TOOLS)
add_subdirectory(tools)
endif()
if( BUILD_EXAMPLES )
add_subdirectory(sample_nodes)
add_subdirectory(examples)
endif()