Skip to content

Commit

Permalink
Fix Bullet linking on MacOS (#1101)
Browse files Browse the repository at this point in the history
* Use Bullet cmake targets when available

* Guard creation of Bullet3::Bullet target

* Windows does not have Bullet3Geometry.lib

* Restore boost-stacktrace changes
  • Loading branch information
johnwason authored Jan 10, 2025
1 parent 5b11d95 commit c0162ef
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 40 deletions.
23 changes: 16 additions & 7 deletions tesseract_common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@ endif()
include(cmake/tesseract_macros.cmake)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/")

find_package(
Boost REQUIRED
COMPONENTS system
filesystem
serialization
stacktrace_noop
OPTIONAL_COMPONENTS stacktrace_backtrace stacktrace_basic)
if(NOT APPLE)
find_package(
Boost REQUIRED
COMPONENTS system
filesystem
serialization
stacktrace_noop
OPTIONAL_COMPONENTS stacktrace_backtrace stacktrace_basic)
else()
find_package(
Boost REQUIRED
COMPONENTS system
filesystem
serialization
stacktrace_noop)
endif()
find_package(Eigen3 REQUIRED)
find_package(TinyXML2 REQUIRED)
find_package(yaml-cpp REQUIRED)
Expand Down
83 changes: 50 additions & 33 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,56 @@ macro(find_bullet)
endif()
endforeach()

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()
if(TARGET Bullet3Common)
if(NOT TARGET Bullet3::Bullet)
add_library(Bullet3::Bullet INTERFACE IMPORTED)
if(NOT WIN32)
set_target_properties(Bullet3::Bullet PROPERTIES INTERFACE_LINK_LIBRARIES
"BulletCollision;Bullet3Geometry;Bullet3Common;LinearMath")
else()
set_target_properties(Bullet3::Bullet PROPERTIES INTERFACE_LINK_LIBRARIES
"BulletCollision;Bullet3Common;LinearMath")
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.")
set_target_properties(Bullet3::Bullet PROPERTIES INTERFACE_COMPILE_DEFINITIONS "${BULLET_DEFINITIONS_STRIPED}")
endif()
else()

# 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 c0162ef

Please sign in to comment.