From e82053fc509d79e3a45678f70417b245b1426968 Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Sun, 5 Oct 2025 20:20:47 +0200 Subject: [PATCH] CMake: prefer system tinyxml2, fix #1014 --- 3rdparty/tinyxml2/{ => include}/tinyxml2.h | 0 3rdparty/tinyxml2/{ => src}/tinyxml2.cpp | 0 CMakeLists.txt | 15 +++++++++++++-- src/xml_parsing.cpp | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) rename 3rdparty/tinyxml2/{ => include}/tinyxml2.h (100%) rename 3rdparty/tinyxml2/{ => src}/tinyxml2.cpp (100%) diff --git a/3rdparty/tinyxml2/tinyxml2.h b/3rdparty/tinyxml2/include/tinyxml2.h similarity index 100% rename from 3rdparty/tinyxml2/tinyxml2.h rename to 3rdparty/tinyxml2/include/tinyxml2.h diff --git a/3rdparty/tinyxml2/tinyxml2.cpp b/3rdparty/tinyxml2/src/tinyxml2.cpp similarity index 100% rename from 3rdparty/tinyxml2/tinyxml2.cpp rename to 3rdparty/tinyxml2/src/tinyxml2.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 81ac107b3..9a105d813 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,6 +64,7 @@ endif() #---- Find other packages ---- find_package(Threads REQUIRED) +find_package(tinyxml2 CONFIG) set(BEHAVIOR_TREE_LIBRARY ${PROJECT_NAME}) @@ -141,10 +142,11 @@ list(APPEND BT_SOURCE src/loggers/bt_file_logger_v2.cpp src/loggers/bt_minitrace_logger.cpp src/loggers/bt_observer.cpp - - 3rdparty/tinyxml2/tinyxml2.cpp ) +if(NOT TARGET tinyxml2::tinyxml2) + list(APPEND BT_SOURCE 3rdparty/tinyxml2/src/tinyxml2.cpp) +endif() if(BTCPP_GROOT_INTERFACE) # should be found already, at this stage @@ -186,6 +188,15 @@ target_link_libraries(${BTCPP_LIBRARY} ${BTCPP_EXTRA_LIBRARIES} ) +if(TARGET tinyxml2::tinyxml2) + target_link_libraries(${BTCPP_LIBRARY} PRIVATE tinyxml2::tinyxml2) +else() + target_include_directories(${BTCPP_LIBRARY} PRIVATE + $ + ) +endif() + + target_include_directories(${BTCPP_LIBRARY} PUBLIC $ diff --git a/src/xml_parsing.cpp b/src/xml_parsing.cpp index 8ab66b1fc..da68be99a 100644 --- a/src/xml_parsing.cpp +++ b/src/xml_parsing.cpp @@ -33,7 +33,7 @@ #include #include "behaviortree_cpp/xml_parsing.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" #include #ifdef USING_ROS2