How to use BulletConfig.cmake and UseBullet.cmake in CMakeLists.txt #4670
-
Hello, I am new in CMake. I have installed Bullet 2.83.7 using CMake-GUI. I use this version because it is small and Ammo.js uses this version. But I have tied Bullet 3.25 too and it is the same. So, Bullet 2.83.7 was installed to the directory: E:\libs\bullet3-2.83.7-prefix\win I see two files here: BulletConfig.cmake # -*- cmake -*-
#
# BulletConfig.cmake(.in)
#
# Use the following variables to compile and link against Bullet:
# BULLET_FOUND - True if Bullet was found on your system
# BULLET_USE_FILE - The file making Bullet usable
# BULLET_DEFINITIONS - Definitions needed to build with Bullet
# BULLET_INCLUDE_DIR - Directory where Bullet-C-Api.h can be found
# BULLET_INCLUDE_DIRS - List of directories of Bullet and it's dependencies
# BULLET_LIBRARIES - List of libraries to link against Bullet library
# BULLET_LIBRARY_DIRS - List of directories containing Bullet' libraries
# BULLET_ROOT_DIR - The base directory of Bullet
# BULLET_VERSION_STRING - A human-readable string containing the version
set ( BULLET_FOUND 1 )
set ( BULLET_USE_FILE "lib/cmake/bullet/UseBullet.cmake" )
set ( BULLET_DEFINITIONS "" )
set ( BULLET_INCLUDE_DIR "include/bullet" )
set ( BULLET_INCLUDE_DIRS "include/bullet" )
set ( BULLET_LIBRARIES "LinearMath;BulletCollision;BulletDynamics;BulletSoftBody" )
set ( BULLET_LIBRARY_DIRS "lib" )
set ( BULLET_ROOT_DIR "E:/libs/bullet3-2.83.7-prefix/win" )
set ( BULLET_VERSION_STRING "2.83" ) UseBullet.cmake # -*- cmake -*-
#
# UseBullet.cmake
#
add_definitions ( ${BULLET_DEFINITIONS} )
include_directories ( ${BULLET_INCLUDE_DIRS} )
link_directories ( ${BULLET_LIBRARY_DIRS} ) My question is how to use these files in CMakeLists.txt? I have asked Google AI. This is the answer: https://g.co/gemini/share/c4b5e4cadd0a Understanding BulletConfig.cmake and UseBullet.cmake Before diving into their usage, let's briefly understand these files:
Integrating Bullet into Your CMake Project 1. Find the BulletConfig.cmake file:
2. Include the UseBullet.cmake script in your CMakeLists.txt: include(UseBullet) 3. Find and link the Bullet library: find_package(Bullet REQUIRED)
# Link your target to the Bullet library
target_link_libraries(your_target PRIVATE Bullet::BulletDynamics Bullet::BulletCollision) Replace Example CMakeLists.txt: cmake_minimum_required(VERSION 3.10)
project(MyBulletProject)
# Find and include Bullet
include(UseBullet)
find_package(Bullet REQUIRED)
# Add executable
add_executable(my_bullet_app main.cpp)
# Link to Bullet libraries
target_link_libraries(my_bullet_app PRIVATE Bullet::BulletDynamics Bullet::BulletCollision) Additional Considerations:
By following these steps and considering the additional points, you should be able to effectively integrate the Bullet Physics SDK into your CMake-based project. I try to use the guide above. This is my CMakeListst.txt: cmake_minimum_required(VERSION 3.20)
project(cmake-bullet-physics-opengles20-sdl3-cpp)
add_executable(app)
target_sources(app
PRIVATE
E:/libs/glad-2.0.6/src/glad.c
src/main.cpp
)
include(UseBullet)
find_package(Bullet REQUIRED)
message(${BULLET_FOUND})
find_package(SDL3)
# Link your target to the Bullet library
target_link_libraries(app PRIVATE Bullet::BulletDynamics Bullet::BulletCollision Bullet::BulletSoftBody Bullet::LinearMath SDL3::SDL3)
target_compile_definitions(app PRIVATE SDL_MAIN_USE_CALLBACKS) I use this command to config: config-win.bat set BULLET_ROOT=E:/libs/bullet3-2.83.7-prefix/win
cmake -G "MinGW Makefiles" -S . -B dist/win -DSDL3_DIR=E:/libs/sdl-3.1.3-prefix/win/lib/cmake/SDL3 Output:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
This works: target_include_directories(app PRIVATE ${BULLET_INCLUDE_DIR})
find_package(Bullet REQUIRED)
find_package(SDL3)
target_link_libraries(app PRIVATE ${BULLET_DYNAMICS_LIBRARY} ${BULLET_COLLISION_LIBRARY} ${BULLET_MATH_LIBRARY} SDL3::SDL3) config-win.bat set BULLET_ROOT=E:/libs/bullet3-2.83.7-prefix/win
cmake -G "MinGW Makefiles" -S . -B dist/win -DSDL3_DIR=E:/libs/sdl-3.1.3-prefix/win/lib/cmake/SDL3 build-win.bat cd dist\win
cmake --build . |
Beta Was this translation helpful? Give feedback.
This works:
config-win.bat
build-win.bat