Skip to content

Commit

Permalink
Use Bullet cmake targets when available
Browse files Browse the repository at this point in the history
  • Loading branch information
johnwason committed Jan 9, 2025
1 parent 5b11d95 commit 78b5926
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 33 deletions.
3 changes: 1 addition & 2 deletions tesseract_common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
71 changes: 40 additions & 31 deletions tesseract_common/cmake/tesseract_macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()

0 comments on commit 78b5926

Please sign in to comment.