From 966d401c4d9c50a9c06967da518fbab2baba5b64 Mon Sep 17 00:00:00 2001
From: Tarun Chintalapati <tchintalapati@dekaresearch.com>
Date: Mon, 5 Aug 2024 18:09:55 -0400
Subject: [PATCH 1/3] feat: added a new cmake_build for generating a debian

---
 cmake/cmake_build.cmake | 64 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)
 create mode 100644 cmake/cmake_build.cmake

diff --git a/cmake/cmake_build.cmake b/cmake/cmake_build.cmake
new file mode 100644
index 000000000..ee9410a22
--- /dev/null
+++ b/cmake/cmake_build.cmake
@@ -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 <example@example.com>" )
+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()
+    
\ No newline at end of file

From 2674caa80f8da57796c13695d427ecc9aecc21f4 Mon Sep 17 00:00:00 2001
From: Tarun Chintalapati <tchintalapati@dekaresearch.com>
Date: Mon, 5 Aug 2024 18:13:24 -0400
Subject: [PATCH 2/3] feat: updated documentation for creating and installing a
 debian

---
 README.md | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/README.md b/README.md
index cd8e3371a..15a296598 100644
--- a/README.md
+++ b/README.md
@@ -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 .

From db4b472fc5df5444070b78fe37ce99fa7e181d29 Mon Sep 17 00:00:00 2001
From: Tarun Chintalapati <tchintalapati@dekaresearch.com>
Date: Mon, 5 Aug 2024 18:14:32 -0400
Subject: [PATCH 3/3] feat: Added CMake build as an option when building

---
 CMakeLists.txt | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9b6d1ebaa..bb9bd722e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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)
 
 option(USE_V3_COMPATIBLE_NAMES  "Use some alias to compile more easily old 3.x code" OFF)
 
@@ -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.")
@@ -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
 
@@ -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()
\ No newline at end of file