Skip to content

Commit 84b139e

Browse files
committed
add version string
1 parent 4c789ea commit 84b139e

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
cmake_minimum_required(VERSION 3.16.3) # version on Ubuntu Focal
2-
project(behaviortree_cpp)
2+
3+
project(behaviortree_cpp VERSION 4.1.1)
34

45
set(CMAKE_CONFIG_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake")
56
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CONFIG_PATH}")
@@ -175,6 +176,7 @@ target_include_directories(${BTCPP_LIBRARY}
175176
)
176177

177178
target_compile_definitions(${BTCPP_LIBRARY} PRIVATE $<$<CONFIG:Debug>:TINYXML2_DEBUG>)
179+
target_compile_definitions(${BTCPP_LIBRARY} PUBLIC BTCPP_LIBRARY_VERSION="${CMAKE_PROJECT_VERSION}")
178180

179181
if(MSVC)
180182
else()

include/behaviortree_cpp/behavior_tree.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,11 @@ inline NodeType getType()
9090
// clang-format on
9191
}
9292

93+
94+
inline const char* LibraryVersionString() {
95+
return BTCPP_LIBRARY_VERSION;
96+
}
97+
98+
int LibraryVersionNumber();
99+
93100
} // namespace BT

src/behavior_tree.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,15 @@ void buildSerializedStatusSnapshot(TreeNode* root_node,
111111
applyRecursiveVisitor(root_node, visitor);
112112
}
113113

114+
int LibraryVersionNumber() {
115+
static int number = -1;
116+
if(number == -1) {
117+
auto const parts = splitString(BTCPP_LIBRARY_VERSION, '.');
118+
number = std::stoi( std::string(parts[0]) ) * 10000 +
119+
std::stoi( std::string(parts[1]) ) * 100 +
120+
std::stoi( std::string(parts[2]));
121+
}
122+
return number;
123+
}
124+
114125
} // namespace BT

0 commit comments

Comments
 (0)