From 78b592647873b57088ee2ae530db3382580811f6 Mon Sep 17 00:00:00 2001 From: John Wason Date: Thu, 9 Jan 2025 17:43:21 -0500 Subject: [PATCH] Use Bullet cmake targets when available --- tesseract_common/CMakeLists.txt | 3 +- tesseract_common/cmake/tesseract_macros.cmake | 71 +++++++++++-------- 2 files changed, 41 insertions(+), 33 deletions(-) diff --git a/tesseract_common/CMakeLists.txt b/tesseract_common/CMakeLists.txt index b2e61c964da..02dd304bd42 100644 --- a/tesseract_common/CMakeLists.txt +++ b/tesseract_common/CMakeLists.txt @@ -17,8 +17,7 @@ find_package( COMPONENTS system filesystem serialization - stacktrace_noop - OPTIONAL_COMPONENTS stacktrace_backtrace stacktrace_basic) + stacktrace_noop) find_package(Eigen3 REQUIRED) find_package(TinyXML2 REQUIRED) find_package(yaml-cpp REQUIRED) diff --git a/tesseract_common/cmake/tesseract_macros.cmake b/tesseract_common/cmake/tesseract_macros.cmake index ee929e8af8e..7b968a6bbaa 100644 --- a/tesseract_common/cmake/tesseract_macros.cmake +++ b/tesseract_common/cmake/tesseract_macros.cmake @@ -167,29 +167,6 @@ macro(find_bullet) WARNING "Bullet does not appear to be build with double precision, current definitions: ${BULLET_DEFINITIONS}") endif() - # Some Bullet installations (vcpkg) use absolute paths instead of relative to BULLET_ROOT_DIR in the CMake vars - set(BULLET_INCLUDE_DIRS_ABS "") - set(BULLET_LIBRARY_DIRS_ABS "") - if(NOT IS_ABSOLUTE "${BULLET_INCLUDE_DIR}") - foreach(dir IN LISTS BULLET_INCLUDE_DIRS) - list(APPEND BULLET_INCLUDE_DIRS_ABS "${BULLET_ROOT_DIR}/${dir}") - endforeach() - foreach(dir IN LISTS BULLET_LIBRARY_DIRS) - list(APPEND BULLET_LIBRARY_DIRS_ABS "${BULLET_ROOT_DIR}/${dir}") - endforeach() - else() - set(BULLET_INCLUDE_DIRS_ABS ${BULLET_INCLUDE_DIRS}) - set(BULLET_LIBRARY_DIRS_ABS ${BULLET_LIBRARY_DIRS}) - endif() - - set(BULLET_LIBRARIES_ABS "") - foreach(BULLET_LIB IN LISTS BULLET_LIBRARIES) - find_library(BULLET_LIB_ABS_${BULLET_LIB} ${BULLET_LIB} PATHS ${BULLET_LIBRARY_DIRS_ABS} NO_DEFAULT_PATH REQUIRED) - list(APPEND BULLET_LIBRARIES_ABS "${BULLET_LIB_ABS_${BULLET_LIB}}") - message(STATUS "BULLET_LIB=${BULLET_LIB} BULLET_LIB_ABS=${BULLET_LIB_ABS_${BULLET_LIB}}") - endforeach() - message(STATUS "BULLET_LIBRARIES_ABS=${BULLET_LIBRARIES_ABS}") - set(BULLET_DEFINITIONS_STRIPED "") foreach(DEF ${BULLET_DEFINITIONS}) string(STRIP ${DEF} DEF) @@ -207,16 +184,48 @@ macro(find_bullet) endif() endforeach() - if(NOT TARGET Bullet3::Bullet) + if(TARGET Bullet3Common) add_library(Bullet3::Bullet INTERFACE IMPORTED) - set_target_properties(Bullet3::Bullet PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${BULLET_INCLUDE_DIRS_ABS}") - set_target_properties(Bullet3::Bullet PROPERTIES INTERFACE_LINK_LIBRARIES "${BULLET_LIBRARIES_ABS}") + set_target_properties(Bullet3::Bullet PROPERTIES INTERFACE_LINK_LIBRARIES + "BulletCollision;Bullet3Geometry;Bullet3Common;LinearMath") set_target_properties(Bullet3::Bullet PROPERTIES INTERFACE_COMPILE_DEFINITIONS "${BULLET_DEFINITIONS_STRIPED}") - endif() + else() - find_library(HACD_LIBRARY HACD HINTS ${BULLET_LIBRARY_DIRS_ABS}) - if(NOT HACD_LIBRARY) - message( - WARNING "HACD not found! Convex decomposition library will not be built. Install libbullet-extras-dev on Linux.") + # Some Bullet installations (vcpkg) use absolute paths instead of relative to BULLET_ROOT_DIR in the CMake vars + set(BULLET_INCLUDE_DIRS_ABS "") + set(BULLET_LIBRARY_DIRS_ABS "") + if(NOT IS_ABSOLUTE "${BULLET_INCLUDE_DIR}") + foreach(dir IN LISTS BULLET_INCLUDE_DIRS) + list(APPEND BULLET_INCLUDE_DIRS_ABS "${BULLET_ROOT_DIR}/${dir}") + endforeach() + foreach(dir IN LISTS BULLET_LIBRARY_DIRS) + list(APPEND BULLET_LIBRARY_DIRS_ABS "${BULLET_ROOT_DIR}/${dir}") + endforeach() + else() + set(BULLET_INCLUDE_DIRS_ABS ${BULLET_INCLUDE_DIRS}) + set(BULLET_LIBRARY_DIRS_ABS ${BULLET_LIBRARY_DIRS}) + endif() + + set(BULLET_LIBRARIES_ABS "") + foreach(BULLET_LIB IN LISTS BULLET_LIBRARIES) + find_library(BULLET_LIB_ABS_${BULLET_LIB} ${BULLET_LIB} PATHS ${BULLET_LIBRARY_DIRS_ABS} NO_DEFAULT_PATH REQUIRED) + list(APPEND BULLET_LIBRARIES_ABS "${BULLET_LIB_ABS_${BULLET_LIB}}") + message(STATUS "BULLET_LIB=${BULLET_LIB} BULLET_LIB_ABS=${BULLET_LIB_ABS_${BULLET_LIB}}") + endforeach() + message(STATUS "BULLET_LIBRARIES_ABS=${BULLET_LIBRARIES_ABS}") + + if(NOT TARGET Bullet3::Bullet) + add_library(Bullet3::Bullet INTERFACE IMPORTED) + set_target_properties(Bullet3::Bullet PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${BULLET_INCLUDE_DIRS_ABS}") + set_target_properties(Bullet3::Bullet PROPERTIES INTERFACE_LINK_LIBRARIES "${BULLET_LIBRARIES_ABS}") + set_target_properties(Bullet3::Bullet PROPERTIES INTERFACE_COMPILE_DEFINITIONS "${BULLET_DEFINITIONS_STRIPED}") + endif() + + find_library(HACD_LIBRARY HACD HINTS ${BULLET_LIBRARY_DIRS_ABS}) + if(NOT HACD_LIBRARY) + message( + WARNING "HACD not found! Convex decomposition library will not be built. Install libbullet-extras-dev on Linux." + ) + endif() endif() endmacro()