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

Added a new cmake_build for generating a debian #855

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
17 changes: 16 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ option(BTCPP_EXAMPLES "Build tutorials and examples" ON)
option(BTCPP_UNIT_TESTS "Build the unit tests" ON)
option(BTCPP_GROOT_INTERFACE "Add Groot2 connection. Requires ZeroMQ" ON)
option(BTCPP_SQLITE_LOGGING "Add SQLite logging." ON)
option(CMAKE_BUILD "Build using CMAKE" OFF)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the purpose of adding this? Shouldn't it be the default ON?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intent is that the users would turn this ON only when they need standalone debians that do not depend on ROS (catkin/ament). That was my requirement for a project I have been working on where I am using BTCPP with a custom RTOS.
Maybe the variable could be named 'GENERATE_DEBS' instead of 'CMAKE_BUILD', if that makes it clearer?


option(USE_V3_COMPATIBLE_NAMES "Use some alias to compile more easily old 3.x code" OFF)

Expand Down Expand Up @@ -67,6 +68,14 @@ elseif( CATKIN_DEVEL_PREFIX OR CATKIN_BUILD_BINARY_PACKAGE)
message(STATUS "------------------------------------------")
include(cmake/catkin_build.cmake)
set(catkin_FOUND TRUE)

elseif( CMAKE_BUILD )

message(STATUS "------------------------------------------")
message(STATUS "BehaviourTree is being built using CMAKE.")
message(STATUS "------------------------------------------")
include(cmake/cmake_build.cmake)

else()
message(STATUS "------------------------------------------")
message(STATUS "BehaviourTree is being built with conan.")
Expand Down Expand Up @@ -216,6 +225,12 @@ if(BTCPP_EXAMPLES)
add_subdirectory(examples)
endif()

if( CMAKE_BUILD )
message(STATUS "Ensuring everything gets installed into '/usr/local/' as the Lord intended")
set(BTCPP_LIB_DESTINATION ${CMAKE_INSTALL_PREFIX}/${BTCPP_LIB_DESTINATION})
set(BTCPP_INCLUDE_DESTINATION ${CMAKE_INSTALL_PREFIX}/${BTCPP_INCLUDE_DESTINATION})
endif()

######################################################
# INSTALL

Expand All @@ -231,4 +246,4 @@ INSTALL( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
DESTINATION ${BTCPP_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.h*")

export_btcpp_package()
export_btcpp_package()
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ If you want to build in a [pixi](https://pixi.sh/) project (conda virtual enviro
```
pixi run build
```
If you want to generate a standalone behaviortree_cpp debian that you can install and link your project against,
- Clone the BehaviorTreee.CPP repo
- cd into the cloned repo
- run the following commands:
```
cmake -S . -B build -DCMAKE_BUILD=ON
cmake --build build/ -j{Number_of_cores} --target package
```
Replace {Number_of_cores} with how many cores you would like to use to build.

- If built succesfully, it should generate a ```.deb``` file inside the build folder.
- You can install this debian in any container or environment using ```apt install /path/to/.deb```

If you want to use BT.CPP in your application, please refer to the
example here: https://github.com/BehaviorTree/btcpp_sample .
Expand Down
64 changes: 64 additions & 0 deletions cmake/cmake_build.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@

if(BTCPP_GROOT_INTERFACE)
find_package(ZeroMQ REQUIRED)
list(APPEND BTCPP_EXTRA_LIBRARIES ${ZeroMQ_LIBRARIES})
list(APPEND BTCPP_EXTRA_INCLUDE_DIRS ${ZeroMQ_INCLUDE_DIRS})
message(STATUS "ZeroMQ_LIBRARIES: ${ZeroMQ_LIBRARIES}")
endif()

if(BTCPP_SQLITE_LOGGING)
find_package(SQLite3 REQUIRED)
list(APPEND BTCPP_EXTRA_LIBRARIES ${SQLite3_LIBRARIES})
message(STATUS "SQLite3_LIBRARIES: ${SQLite3_LIBRARIES}")
endif()


set( BTCPP_LIB_DESTINATION lib )
set( BTCPP_INCLUDE_DESTINATION include )
set( BTCPP_BIN_DESTINATION bin )
set( BTCPP_CMAKE_DESTINATION ${CMAKE_INSTALL_PREFIX}/share )

# CPack configuration
set( CPACK_GENERATOR "DEB" )
set( CPACK_PACKAGE_NAME "behaviortree-cpp" )
set( CPACK_PACKAGE_VERSION ${PROJECT_VERSION} )
set( CPACK_PACKAGE_DESCRIPTION "BehaviorTree.CPP library" )
set( CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/BehaviorTree/BehaviorTree.CPP" )
set( CPACK_DEBIAN_PACKAGE_DEPENDS "libstdc++6, libc6, libzmq3-dev, libsqlite3-dev" )
set( CPACK_DEBIAN_PACKAGE_SECTION "devel" )
set( CPACK_DEBIAN_PACKAGE_PRIORITY "optional" )
set( CPACK_PACKAGE_CONTACT "example <[email protected]>" )
set( CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON )

include(CPack)

mark_as_advanced(
BTCPP_EXTRA_LIBRARIES
BTCPP_LIB_DESTINATION
BTCPP_INCLUDE_DESTINATION
BTCPP_BIN_DESTINATION )

macro(export_btcpp_package)

install(EXPORT ${PROJECT_NAME}Targets
FILE "${PROJECT_NAME}Targets.cmake"
DESTINATION "${BTCPP_CMAKE_DESTINATION}/cmake/${PROJECT_NAME}"
NAMESPACE BT::
)
export(PACKAGE ${PROJECT_NAME})

include(CMakePackageConfigHelpers)

configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION "${BTCPP_CMAKE_DESTINATION}/cmake/${PROJECT_NAME}"
)

install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
DESTINATION "${BTCPP_CMAKE_DESTINATION}/cmake/${PROJECT_NAME}"
)
endmacro()