Skip to content

Commit

Permalink
Cmake fix. Address some of the concerns of microsoft#9 and microsoft#10
Browse files Browse the repository at this point in the history
… (microsoft#11)

* fix travis
* better installation with renamed directories
  • Loading branch information
facontidavide authored Nov 16, 2018
1 parent 3f04827 commit 15b43db
Show file tree
Hide file tree
Showing 106 changed files with 291 additions and 237 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ before_script:
- mkdir -p build

script:
- if [ "$ROS_DISTRO" = "none" ]; then (cd build; cmake .. ;cmake --build .; ./bin/behavior_tree_core_test); fi
- if [ "$ROS_DISTRO" = "none" ]; then (cd build; cmake .. ;cmake --build .; ./bin/behaviortree_cpp_test); fi
- if [ "$ROS_DISTRO" != "none" ]; then (.ci_config/travis.sh); fi


4 changes: 2 additions & 2 deletions 3rdparty/minitrace/minitrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ int64_t mtr_time_usec()
{
static int64_t prev = 0;
struct timeval tv;
gettimeofday(&tv, NULL);
gettimeofday(&tv, nullptr);
int64_t now = 1000000*tv.tv_sec + tv.tv_usec;
if( now <= prev) now = prev + 1;
prev = now;
return now;
}
#endif // !BLACKBERRY

static void termination_handler(int signum) {
static void termination_handler(int ) {
if (is_tracing) {
printf("Ctrl-C detected! Flushing trace and shutting down.\n\n");
mtr_flush();
Expand Down
9 changes: 5 additions & 4 deletions 3rdparty/tinyXML2/tinyxml2.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ distribution.
#endif

// Do NOT export. This version is meant to be linked statically only.
#define TINYXML2_LIB



#ifdef _WIN32
# define TINYXML2_LIB // TODO?
#else
# define TINYXML2_LIB __attribute__((visibility("hidden")))
#endif

#if defined(TINYXML2_DEBUG)
# if defined(_MSC_VER)
Expand Down
237 changes: 138 additions & 99 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,44 @@
cmake_minimum_required(VERSION 2.8)
project(behavior_tree_core)
cmake_minimum_required(VERSION 2.8.12) # version on Ubuntu Trusty
project(behaviortree_cpp)

if(NOT CMAKE_VERSION VERSION_LESS 3.1)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread -Werror=return-type -Wall -Wpedantic -Wattributes")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake")

set(CMAKE_CONFIG_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CONFIG_PATH}")

option(BUILD_EXAMPLES "Build tutorials and examples" ON)
option(BUILD_UNIT_TESTS "Build the unit tests" ON)

#############################################################
# http://answers.ros.org/question/230877/optionally-build-a-package-with-catkin/
#
# This variable MUST NOT be set manually by the user, it will be detected
# automatically if you compile using catkin
# Find packages
find_package(Threads REQUIRED)
find_package(ZMQ)
find_package(GTest)

list(APPEND BEHAVIOR_TREE_EXTERNAL_LIBRARIES ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS})

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)
else()
message(WARNING "ZeroMQ NOT found. Skipping the build of [PublisherZMQ] and [bt_recorder].")
endif()

if(NOT GTEST_FOUND)
message(WARNING " GTest not found!")
endif(NOT GTEST_FOUND)


if( CATKIN_DEVEL_PREFIX OR CATKIN_BUILD_BINARY_PACKAGE)
set(catkin_FOUND 1)
add_definitions( -DUSING_ROS )
Expand All @@ -26,119 +53,131 @@ if(catkin_FOUND)

catkin_package(
INCLUDE_DIRS include # do not include "3rdparty" here
LIBRARIES behavior_tree_core
LIBRARIES ${PROJECT_NAME}
)

else(catkin_FOUND)
else()

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

find_package(GTest)
include_directories(${GTEST_INCLUDE_DIRS})
if(NOT GTEST_FOUND)
message(WARNING " GTest not found!")
endif(NOT GTEST_FOUND)

endif(catkin_FOUND)


set(BT_Source
src/action_node.cpp
src/basic_types.cpp
src/decorator_node.cpp
src/condition_node.cpp
src/control_node.cpp
src/exceptions.cpp
src/leaf_node.cpp
src/tick_engine.cpp
src/tree_node.cpp
src/bt_factory.cpp
src/behavior_tree.cpp
src/xml_parsing.cpp
src/shared_library.cpp
src/shared_library_UNIX.cpp

src/decorators/inverter_node.cpp
src/decorators/repeat_node.cpp
src/decorators/retry_node.cpp
src/decorators/timeout_node.cpp

src/controls/parallel_node.cpp
src/controls/sequence_node.cpp
src/controls/sequence_star_node.cpp
src/controls/fallback_node.cpp
src/controls/fallback_star_node.cpp

src/loggers/bt_cout_logger.cpp
src/loggers/bt_file_logger.cpp
src/loggers/bt_minitrace_logger.cpp

3rdparty/tinyXML2/tinyxml2.cpp
3rdparty/minitrace/minitrace.cpp
)
include_directories(include 3rdparty/)

set(BEHAVIOR_TREE_LIBRARIES behavior_tree_core)
endif()

find_package(ZMQ)
#############################################################
# LIBRARY

if( ZMQ_FOUND )
message(STATUS "ZeroMQ found.")
add_definitions( -DZMQ_FOUND )
set(BT_Source ${BT_Source} src/loggers/bt_zmq_publisher.cpp )
list(APPEND BT_SOURCE
src/action_node.cpp
src/basic_types.cpp
src/decorator_node.cpp
src/condition_node.cpp
src/control_node.cpp
src/exceptions.cpp
src/leaf_node.cpp
src/tick_engine.cpp
src/tree_node.cpp
src/bt_factory.cpp
src/behavior_tree.cpp
src/xml_parsing.cpp
src/shared_library.cpp
src/shared_library_UNIX.cpp

src/decorators/inverter_node.cpp
src/decorators/repeat_node.cpp
src/decorators/retry_node.cpp
src/decorators/timeout_node.cpp

src/controls/parallel_node.cpp
src/controls/sequence_node.cpp
src/controls/sequence_star_node.cpp
src/controls/fallback_node.cpp
src/controls/fallback_star_node.cpp

src/loggers/bt_cout_logger.cpp
src/loggers/bt_file_logger.cpp
src/loggers/bt_minitrace_logger.cpp

3rdparty/tinyXML2/tinyxml2.cpp
3rdparty/minitrace/minitrace.cpp
)

set(BEHAVIOR_TREE_LIBRARY ${PROJECT_NAME})

set(BEHAVIOR_TREE_LIBRARIES ${BEHAVIOR_TREE_LIBRARIES} zmq)
add_library(${BEHAVIOR_TREE_LIBRARY} ${BT_SOURCE} )
target_link_libraries(${BEHAVIOR_TREE_LIBRARY} ${BEHAVIOR_TREE_EXTERNAL_LIBRARIES} ${catkin_LIBRARIES})
target_include_directories(${BEHAVIOR_TREE_LIBRARY} PUBLIC include 3rdparty ${catkin_INCLUDE_DIRS})

if(MSVC)
target_compile_options(${BEHAVIOR_TREE_LIBRARY} PRIVATE /W4 /WX)
else()
message(WARNING "ZeroMQ NOT found. Skipping the build of [PublisherZMQ] and [bt_recorder].")
target_compile_options(${BEHAVIOR_TREE_LIBRARY} PRIVATE -Wall -Wextra -Werror=return-type)
endif()

######################################################
# LIBRARY
# TESTS

list(APPEND BT_TESTS
gtest/src/action_test_node.cpp
gtest/src/condition_test_node.cpp
gtest/gtest_tree.cpp
gtest/gtest_sequence.cpp
gtest/gtest_parallel.cpp
gtest/gtest_fallback.cpp
gtest/gtest_factory.cpp
gtest/gtest_decorator.cpp
)

if(catkin_FOUND AND CATKIN_ENABLE_TESTING)

catkin_add_gtest(${BEHAVIOR_TREE_LIBRARY}_test ${BT_TESTS})
target_link_libraries(${BEHAVIOR_TREE_LIBRARY}_test ${BEHAVIOR_TREE_LIBRARY}
crossdoor_nodes
${catkin_LIBRARIES})
target_include_directories(${BEHAVIOR_TREE_LIBRARY}_test PRIVATE gtest/include)

elseif(GTEST_FOUND AND BUILD_UNIT_TESTS)

enable_testing()

add_executable(${BEHAVIOR_TREE_LIBRARY}_test ${BT_TESTS})
target_link_libraries(${PROJECT_NAME}_test ${BEHAVIOR_TREE_LIBRARY}
crossdoor_nodes
${GTEST_LIBRARIES}
${GTEST_MAIN_LIBRARIES})
target_include_directories(${BEHAVIOR_TREE_LIBRARY}_test PRIVATE gtest/include ${GTEST_INCLUDE_DIRS})

add_test(BehaviorTreeCoreTest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${BEHAVIOR_TREE_LIBRARY}_test)
endif()

######################################################
add_library(behavior_tree_core STATIC ${BT_Source} )
target_compile_options(behavior_tree_core PRIVATE "-fPIC")
target_link_libraries(behavior_tree_core dl)
# INSTALL
if(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_PACKAGE_BIN_DESTINATION} )
else()
set( BEHAVIOR_TREE_LIB_DESTINATION lib )
set( BEHAVIOR_TREE_INC_DESTINATION include )
set( BEHAVIOR_TREE_BIN_DESTINATION bin )
endif()

INSTALL(TARGETS ${BEHAVIOR_TREE_LIBRARY}
ARCHIVE DESTINATION ${BEHAVIOR_TREE_LIB_DESTINATION}
LIBRARY DESTINATION ${BEHAVIOR_TREE_LIB_DESTINATION}
)

INSTALL( DIRECTORY ${CMAKE_SOURCE_DIR}/include/
DESTINATION ${BEHAVIOR_TREE_INC_DESTINATION}
FILES_MATCHING PATTERN "*.h*")

######################################################
# EXAMPLES and TOOLS
######################################################

if( BUILD_EXAMPLES )
add_subdirectory(tools)
add_subdirectory(sample_nodes)
add_subdirectory(examples)
endif()
######################################################
# TESTS
######################################################
set(BT_Tests
gtest/src/action_test_node.cpp
gtest/src/condition_test_node.cpp
gtest/gtest_tree.cpp
gtest/gtest_sequence.cpp
gtest/gtest_parallel.cpp
gtest/gtest_fallback.cpp
gtest/gtest_factory.cpp
gtest/gtest_decorator.cpp
)

if(catkin_FOUND AND CATKIN_ENABLE_TESTING)
include_directories(gtest/include)

catkin_add_gtest(behavior_tree_core_test ${BT_Tests} )
target_link_libraries(behavior_tree_core_test
${BEHAVIOR_TREE_LIBRARIES} crossdoor_nodes
${catkin_LIBRARIES} )

elseif(GTEST_FOUND AND BUILD_UNIT_TESTS)
include_directories(gtest/include)

add_executable(behavior_tree_core_test ${BT_Tests} )
target_link_libraries(behavior_tree_core_test
${BEHAVIOR_TREE_LIBRARIES} crossdoor_nodes
${GTEST_LIBRARIES}
${GTEST_MAIN_LIBRARIES}
)

endif()
2 changes: 1 addition & 1 deletion docs/tutorial_A_create_trees.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ The attribute "name" represents the name of the instance and it is optional.


``` c++
#include "behavior_tree_core/xml_parsing.h"
#include "behaviortree_cpp/xml_parsing.h"
#include "Blackboard/blackboard_local.h"
#include "dummy_nodes.h"

Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial_E_plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ The [first tutorial](tutorial_A_create_trees.md) becomes, as a result, much simp


```c++ hl_lines="3 25"
#include "behavior_tree_core/xml_parsing.h"
#include "behaviortree_cpp/xml_parsing.h"
#include "Blackboard/blackboard_local.h"
// #include "dummy_nodes.h" YOU DON'T NEED THIS ANYMORE

Expand Down
10 changes: 5 additions & 5 deletions docs/tutorial_F_loggers.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ We can attach multiple loggers to a tree.
To do this, we pass the root of the tree.

```c++ hl_lines="21 22 23 25"
#include "behavior_tree_core/xml_parsing.h"
#include "behavior_tree_logger/bt_cout_logger.h"
#include "behavior_tree_logger/bt_minitrace_logger.h"
#include "behavior_tree_logger/bt_file_logger.h"
#include "behaviortree_cpp/xml_parsing.h"
#include "behaviortree_cpp/loggers/bt_cout_logger.h"
#include "behaviortree_cpp/loggers/bt_minitrace_logger.h"
#include "behaviortree_cpp/loggers/bt_file_logger.h"

#ifdef ZMQ_FOUND
#include "behavior_tree_logger/bt_zmq_publisher.h"
#include "behaviortree_cpp/loggers/bt_zmq_publisher.h"
#endif

using namespace BT;
Expand Down
14 changes: 6 additions & 8 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
cmake_minimum_required(VERSION 2.8)


include_directories( ../include ../sample_nodes )

# This tutorial demonstrates how to compile statically a tree (no factory)
add_executable(t01_programmatic_tree t01_programmatic_tree.cpp )
target_link_libraries(t01_programmatic_tree dummy_nodes ${BEHAVIOR_TREE_LIBRARIES} )
target_link_libraries(t01_programmatic_tree dummy_nodes ${BEHAVIOR_TREE_LIBRARY} )

# The plugin libdummy_nodes.so can be linked statically or
# loaded dynamically at run-time.
add_executable(t02_factory_static t02_factory_tree.cpp )
target_compile_definitions(t02_factory_static PRIVATE "MANUAL_STATIC_LINKING")
target_link_libraries(t02_factory_static ${BEHAVIOR_TREE_LIBRARIES} dummy_nodes )
target_link_libraries(t02_factory_static ${BEHAVIOR_TREE_LIBRARY} dummy_nodes )

add_executable(t02_factory_dynamic t02_factory_tree.cpp )
target_link_libraries(t02_factory_dynamic ${BEHAVIOR_TREE_LIBRARIES} )
target_link_libraries(t02_factory_dynamic ${BEHAVIOR_TREE_LIBRARY} )


# This tutorial shows how the difference between Sequence and SequenceStar
add_executable(t03_sequence_star t03_sequence_star.cpp )
target_link_libraries(t03_sequence_star movebase_node dummy_nodes ${BEHAVIOR_TREE_LIBRARIES} )
target_link_libraries(t03_sequence_star movebase_node dummy_nodes ${BEHAVIOR_TREE_LIBRARY} )

# This tutorial demonstrates how to use blackboards and NodeParameters
add_executable(t04_blackboard t04_blackboard.cpp )
target_link_libraries(t04_blackboard movebase_node ${BEHAVIOR_TREE_LIBRARIES} )
target_link_libraries(t04_blackboard movebase_node ${BEHAVIOR_TREE_LIBRARY} )

add_executable(t05_crossdoor t05_crossdoor.cpp )
target_link_libraries(t05_crossdoor crossdoor_nodes ${BEHAVIOR_TREE_LIBRARIES} )
target_link_libraries(t05_crossdoor crossdoor_nodes ${BEHAVIOR_TREE_LIBRARY} )
Loading

0 comments on commit 15b43db

Please sign in to comment.