Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

behaviortree.cpp: add version 4.0.1, support conan v2 #14320

Merged
merged 5 commits into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions recipes/behaviortree.cpp/all/CMakeLists.txt

This file was deleted.

18 changes: 9 additions & 9 deletions recipes/behaviortree.cpp/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
sources:
"4.0.1":
url: "https://github.com/BehaviorTree/BehaviorTree.CPP/archive/refs/tags/4.0.1.tar.gz"
sha256: "71544f72abea8e8c246b016b7e8d87d96f731c8aa96698058d8e69d40e56f9b9"
"3.7.0":
url: "https://github.com/BehaviorTree/BehaviorTree.CPP/archive/refs/tags/3.7.0.tar.gz"
sha256: "ab0d8ac1a0df4dd43cf45da8a784bab7fdedf711bd0e227f7ed071f79b0c7b5c"
"3.5.6":
url: "https://github.com/BehaviorTree/BehaviorTree.CPP/archive/refs/tags/3.5.6.tar.gz"
sha256: "543c428602b5acb7c5666aee34feb532e18ce7200870a79b23ff9aed17ee84c4"
patches:
"4.0.1":
- patch_file: "patches/4.0.1-0001-remove-fpic.patch"
- patch_file: "patches/4.0.1-0002-find-zmq.patch"
- patch_file: "patches/4.0.1-0003-no-werror.patch"
- patch_file: "patches/3.5.6-0005-stdc-format.patch"
- patch_file: "patches/3.5.6-0005-stdc-format.patch"
"3.7.0":
- patch_file: "patches/3.7.0-0001-remove-fpic.patch"
base_path: "src"
- patch_file: "patches/3.7.0-0002-find-zmq.patch"
base_path: "src"
- patch_file: "patches/3.7.0-0003-no-werror.patch"
base_path: "src"
- patch_file: "patches/3.5.6-0005-stdc-format.patch"
base_path: "src"
"3.5.6":
- patch_file: "patches/3.5.6-0001-remove-fpic.patch"
base_path: "src"
- patch_file: "patches/3.5.6-0002-find-zmq.patch"
base_path: "src"
- patch_file: "patches/3.5.6-0003-no-werror.patch"
base_path: "src"
- patch_file: "patches/3.5.6-0004-win-sigaction.patch"
base_path: "src"
- patch_file: "patches/3.5.6-0005-stdc-format.patch"
base_path: "src"
167 changes: 98 additions & 69 deletions recipes/behaviortree.cpp/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
import os
import functools
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.microsoft import check_min_vs, is_msvc
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rmdir
from conan.tools.build import check_min_cppstd
from conan.tools.scm import Version
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout

conan_minimum_required = ">=1.43.0"
import os

required_conan_version = ">=1.53.0"

class BehaviorTreeCPPConan(ConanFile):
name = "behaviortree.cpp"
description = "This C++ library provides a framework to create BehaviorTrees"
license = "MIT"
homepage = "https://github.com/BehaviorTree/BehaviorTree.CPP"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/BehaviorTree/BehaviorTree.CPP"
topics = ("ai", "robotics", "games", "coordination")
settings = "os", "arch", "compiler", "build_type"
options = {
Expand All @@ -26,111 +30,136 @@ class BehaviorTreeCPPConan(ConanFile):
"with_tools": False,
"with_coroutines": False,
}
generators = "cmake", "cmake_find_package"

@property
def _source_subfolder(self):
return "src"

@property
def _build_subfolder(self):
return "bld"

@property
def _minimum_cppstd_required(self):
return 14
return 14 if Version(self.version) < "4.0" else 17

@property
def _minimum_compilers_version(self):
return {
"Visual Studio": "15",
"gcc": "5",
"clang": "5",
"apple-clang": "12",
}
if Version(self.version) < "4.0":
return {
"gcc": "5",
"clang": "5",
"apple-clang": "12",
}
else:
return {
"gcc": "8",
"clang": "7",
"apple-clang": "12",
}

def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC
self.options.rm_safe("fPIC")

def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
if self.options.with_coroutines:
self.requires("boost/1.79.0")
self.requires("boost/1.80.0")
self.requires("ncurses/6.3")
self.requires("zeromq/4.3.4")
self.requires("cppzmq/4.8.1")
self.requires("cppzmq/4.9.0")

def validate(self):
if self.settings.os == "Windows" and self.options.shared:
raise ConanInvalidConfiguration("BehaviorTree.CPP can not be built as shared on Windows.")
if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, self._minimum_cppstd_required)
minimum_version = self._minimum_compilers_version.get(str(self.settings.compiler), False)
if not minimum_version:
self.output.warn("BehaviorTree.CPP requires C++{}. Your compiler is unknown. Assuming it supports C++14."
.format(self._minimum_cppstd_required))
elif tools.Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration("BehaviorTree.CPP requires C++{}, which your compiler does not support."
.format(self._minimum_cppstd_required))
if self.info.settings.os == "Windows" and self.info.options.shared:
raise ConanInvalidConfiguration(f"{self.ref} can not be built as shared on Windows.")
if self.info.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, self._minimum_cppstd_required)
check_min_vs(self, 191 if Version(self.version) < "4.0" else 192)
if not is_msvc(self):
minimum_version = self._minimum_compilers_version.get(str(self.info.settings.compiler), False)
if not minimum_version:
self.output.warn(f"{self.ref} requires C++{self._minimum_cppstd_required}. Your compiler is unknown. Assuming it supports C++{self._minimum_cppstd_required}.")
elif Version(self.info.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration("BehaviorTree.CPP requires C++{}, which your compiler does not support."
.format(self._minimum_cppstd_required))

if self.settings.compiler == "clang" and str(self.settings .compiler.libcxx) == "libstdc++":
raise ConanInvalidConfiguration(f"{self.ref} needs recent libstdc++ with charconv. please switch to gcc, or to libc++")

def source(self):
tools.get(**self.conan_data["sources"][self.version], strip_root=True,
destination=self._source_subfolder)

@functools.lru_cache(1)
def _configure_cmake(self):
cmake = CMake(self)
cmake.definitions["BUILD_EXAMPLES"] = False
cmake.definitions["BUILD_UNIT_TESTS"] = False
cmake.definitions["BUILD_TOOLS"] = self.options.with_tools
cmake.definitions["ENABLE_COROUTINES"] = self.options.with_coroutines
cmake.configure(build_folder=self._build_subfolder)
return cmake
get(self, **self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
if Version(self.version) < "4.0":
tc.variables["BUILD_EXAMPLES"] = False
tc.variables["BUILD_UNIT_TESTS"] = False
tc.variables["BUILD_TOOLS"] = self.options.with_tools
tc.variables["ENABLE_COROUTINES"] = self.options.with_coroutines
else:
tc.variables["BTCPP_SHARED_LIBS"] = self.options.shared
tc.variables["BTCPP_EXAMPLES"] = False
tc.variables["BTCPP_UNIT_TESTS"] = False
tc.variables["BTCPP_BUILD_TOOLS"] = self.options.with_tools
tc.variables["BTCPP_ENABLE_COROUTINES"] = self.options.with_coroutines
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0077"] = "NEW"
tc.generate()

deps = CMakeDeps(self)
deps.generate()

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
cmake = self._configure_cmake()
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
cmake = CMake(self)
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "BehaviorTreeV3"))
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))

rmdir(self, os.path.join(self.package_folder, "lib", "BehaviorTreeV3"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "BehaviorTreeV3")
self.cpp_info.set_property("cmake_target_name", "BT::behaviortree_cpp_v3")
if Version(self.version) < "4.0":
self.cpp_info.set_property("cmake_file_name", "BehaviorTreeV3")
else:
self.cpp_info.set_property("cmake_file_name", "BehaviorTree")

libname = "behaviortree_cpp_v3" if Version(self.version) < "4.0" else "behaviortree_cpp"
self.cpp_info.set_property("cmake_target_name", f"BT::{libname}")

postfix = "d" if self.settings.os == "Windows" and self.settings.build_type == "Debug" else ""
# TODO: back to global scope in conan v2 once cmake_find_package* generators removed
self.cpp_info.components["behaviortree_cpp_v3"].libs = ["behaviortree_cpp_v3" + postfix]
self.cpp_info.components["behaviortree_cpp_v3"].requires = ["zeromq::zeromq", "cppzmq::cppzmq", "ncurses::ncurses"]
self.cpp_info.components[libname].libs = [f"{libname}{postfix}"]
self.cpp_info.components[libname].requires = ["zeromq::zeromq", "cppzmq::cppzmq", "ncurses::ncurses"]
if self.options.with_coroutines:
self.cpp_info.components["behaviortree_cpp_v3"].requires.append("boost::coroutine")
self.cpp_info.components[libname].requires.append("boost::coroutine")
if self.settings.os in ("Linux", "FreeBSD"):
self.cpp_info.components["behaviortree_cpp_v3"].system_libs.append("pthread")
self.cpp_info.components[libname].system_libs.append("pthread")
if Version(self.version) >= "4.0" and \
self.settings.compiler == "gcc" and Version(self.settings.compiler.version).major == "8":
self.cpp_info.components[libname].system_libs.append("stdc++fs")

if self.options.with_tools:
bin_path = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH env var with : {}".format(bin_path))
self.env_info.PATH.append(bin_path)

# TODO: to remove in conan v2 once cmake_find_package* generators removed
self.cpp_info.filenames["cmake_find_package"] = "BehaviorTreeV3"
self.cpp_info.filenames["cmake_find_package_multi"] = "BehaviorTreeV3"
if Version(self.version) < "4.0":
self.cpp_info.filenames["cmake_find_package"] = "BehaviorTreeV3"
self.cpp_info.filenames["cmake_find_package_multi"] = "BehaviorTreeV3"
else:
self.cpp_info.filenames["cmake_find_package"] = "BehaviorTree"
self.cpp_info.filenames["cmake_find_package_multi"] = "BehaviorTree"

self.cpp_info.names["cmake_find_package"] = "BT"
self.cpp_info.names["cmake_find_package_multi"] = "BT"
self.cpp_info.components["behaviortree_cpp_v3"].names["cmake_find_package"] = "behaviortree_cpp_v3"
self.cpp_info.components["behaviortree_cpp_v3"].names["cmake_find_package_multi"] = "behaviortree_cpp_v3"
self.cpp_info.components["behaviortree_cpp_v3"].set_property("cmake_target_name", "BT::behaviortree_cpp_v3")
self.cpp_info.components[libname].names["cmake_find_package"] = libname
self.cpp_info.components[libname].names["cmake_find_package_multi"] = libname
self.cpp_info.components[libname].set_property("cmake_target_name", f"BT::{libname}")
13 changes: 13 additions & 0 deletions recipes/behaviortree.cpp/all/patches/4.0.1-0001-remove-fpic.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d03b8a7..a2f23cf 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -15,8 +15,6 @@ else()
add_definitions(-Wpedantic)
endif()

-set(CMAKE_POSITION_INDEPENDENT_CODE ON)
-
#---- project configuration ----
option(BTCPP_SHARED_LIBS "Build shared libraries" ON)
option(BTCPP_ENABLE_COROUTINES "Enable boost coroutines" ON)
57 changes: 57 additions & 0 deletions recipes/behaviortree.cpp/all/patches/4.0.1-0002-find-zmq.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a2f23cf..d427d37 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -67,14 +67,14 @@ endif()

#---- Find other packages ----
find_package(Threads)
-find_package(ZMQ)
+find_package(ZeroMQ)

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

-if( ZMQ_FOUND )
+if( ZeroMQ_FOUND )
message(STATUS "ZeroMQ found.")
add_definitions( -DZMQ_FOUND )
list(APPEND BT_SOURCE src/loggers/bt_zmq_publisher.cpp)
@@ -221,7 +221,7 @@ target_link_libraries(${BEHAVIOR_TREE_LIBRARY}
${BEHAVIOR_TREE_PUBLIC_LIBRARIES}
PRIVATE
${Boost_LIBRARIES}
- ${ZMQ_LIBRARIES}
+ ${ZeroMQ_LIBRARIES}
$<BUILD_INTERFACE:foonathan::lexy>
)

@@ -243,8 +243,8 @@ target_include_directories(${BEHAVIOR_TREE_LIBRARY} PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/lexy/include>
)

-if( ZMQ_FOUND )
- target_compile_definitions(${BEHAVIOR_TREE_LIBRARY} PUBLIC ZMQ_FOUND)
+if( ZeroMQ_FOUND )
+ target_compile_definitions(${BEHAVIOR_TREE_LIBRARY} PUBLIC ZeroMQ_FOUND)
endif()

if(MSVC)
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
index 163e703..b98f525 100644
--- a/tools/CMakeLists.txt
+++ b/tools/CMakeLists.txt
@@ -7,9 +7,9 @@ target_link_libraries(bt3_log_cat ${BEHAVIOR_TREE_LIBRARY} )
install(TARGETS bt3_log_cat
DESTINATION ${BEHAVIOR_TREE_BIN_DESTINATION} )

-if( ZMQ_FOUND )
+if( ZeroMQ_FOUND )
add_executable(bt3_recorder bt_recorder.cpp )
- target_link_libraries(bt3_recorder ${BEHAVIOR_TREE_LIBRARY} ${ZMQ_LIBRARIES})
+ target_link_libraries(bt3_recorder ${BEHAVIOR_TREE_LIBRARY} ${ZeroMQ_LIBRARIES})
install(TARGETS bt3_recorder
DESTINATION ${BEHAVIOR_TREE_BIN_DESTINATION} )
endif()
13 changes: 13 additions & 0 deletions recipes/behaviortree.cpp/all/patches/4.0.1-0003-no-werror.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d427d37..0c10f52 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -250,7 +250,7 @@ endif()
if(MSVC)
else()
target_compile_options(${BEHAVIOR_TREE_LIBRARY} PRIVATE
- -Wall -Wextra -Werror=return-type)
+ -Wall -Wextra)
endif()

#############################################################
23 changes: 14 additions & 9 deletions recipes/behaviortree.cpp/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
cmake_minimum_required(VERSION 3.1)
project(test_package CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(BehaviorTreeV3 CONFIG REQUIRED)
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} BT::behaviortree_cpp_v3)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14)

find_package(BehaviorTreeV3 CONFIG)
if(TARGET BT::behaviortree_cpp_v3)
target_link_libraries(${PROJECT_NAME} PRIVATE BT::behaviortree_cpp_v3)
target_compile_definitions(${PROJECT_NAME} PRIVATE -DBEHAVIORTREE_CPP_VERSION=3)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
else()
find_package(BehaviorTree REQUIRED CONFIG)
target_link_libraries(${PROJECT_NAME} PRIVATE BT::behaviortree_cpp)
target_compile_definitions(${PROJECT_NAME} PRIVATE -DBEHAVIORTREE_CPP_VERSION=4)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
endif()
Loading