-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
159 lines (138 loc) · 4.06 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# The files in this repository are licensed under the zlib license.
cmake_minimum_required(VERSION 3.15)
unset(PROJECT_IS_TOPLEVEL)
project(libbullet3
VERSION 3.1.7
DESCRIPTION "C++ library portion of bullet"
LANGUAGES CXX
)
# PROJECT_IS_TOPLEVEL for older CMake versions
if(NOT DEFINED PROJECT_IS_TOPLEVEL)
set(PROJECT_IS_TOPLEVEL OFF)
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
set(PROJECT_IS_TOPLEVEL ON)
endif()
endif()
# Build options
option(LIBBULLET3_BUILD_TESTS "Build libbullet3 tests" ${PROJECT_IS_TOPLEVEL})
option(LIBBULLET3_BUILD_SHARED "Build libbullet3 as a shared library" ${BUILD_SHARED_LIBS})
# Grab the upstream Bullet source code
include(FetchContent)
FetchContent_Declare(bullet
GIT_REPOSITORY https://github.com/bulletphysics/bullet3.git
GIT_TAG ebe1916b90acae8b13cd8c6b637d8327cdc64e94 # 3.1.7
)
FetchContent_Populate(bullet)
# Bullet is broken into sub-"libraries"; we'll automate handling of these
set(BULLET_SUBMODULES
Bullet3Collision
Bullet3Common
Bullet3Dynamics
Bullet3Geometry
BulletDynamics
BulletCollision
BulletInverseDynamics
BulletSoftBody
LinearMath
)
# Find all relevant sources in upstream repo
# We don't use the bc*All.cpp files, as they
# fail to build, while the individual sources
# build correctly
set(BULLET3_SOURCES
"${bullet_SOURCE_DIR}/src/btBulletCollisionCommon.h"
"${bullet_SOURCE_DIR}/src/btBulletDynamicsCommon.h"
)
foreach(SUB ${BULLET_SUBMODULES})
file(GLOB_RECURSE SUBMODULE_SOURCES
"${bullet_SOURCE_DIR}/src/${SUB}/*.h"
"${bullet_SOURCE_DIR}/src/${SUB}/*.cpp"
)
list(APPEND BULLET3_SOURCES ${SUBMODULE_SOURCES})
endforeach()
# CPack support
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
include(CPack)
# Build the main libbullet3 library
set(BULLET3_LIBRARY_TYPE "STATIC")
if(LIBBULLET3_BUILD_SHARED)
set(BULLET3_LIBRARY_TYPE "SHARED")
endif()
add_library(libbullet3 ${BULLET3_LIBRARY_TYPE} ${BULLET3_SOURCES})
set_target_properties(libbullet3 PROPERTIES
WINDOWS_EXPORT_ALL_SYMBOLS 1
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION}
)
target_include_directories(libbullet3
SYSTEM INTERFACE
$<BUILD_INTERFACE:${bullet_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:include/Bullet3>
PRIVATE
${bullet_SOURCE_DIR}/src
)
# Silence the many warnings in the libbullet source code;
# we're not the maintainers of the code, so these warnings
# aren't meaningful to us; they just clog up build output
# when building Bullet as a subdirectory
target_compile_options(libbullet3 PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/w>
$<$<CXX_COMPILER_ID:GNU,Clang,Intel>:-w>
)
# Installation
install(
TARGETS libbullet3
DESTINATION lib
EXPORT Bullet3Targets
)
if(LIBBULLET3_BUILD_SHARED AND MSVC)
install(FILES $<TARGET_PDB_FILE:libbullet3> DESTINATION lib)
endif()
install(FILES
"${bullet_SOURCE_DIR}/src/btBulletCollisionCommon.h"
"${bullet_SOURCE_DIR}/src/btBulletDynamicsCommon.h"
DESTINATION "include/Bullet3"
)
foreach(SUB ${BULLET_SUBMODULES})
install(
DIRECTORY "${bullet_SOURCE_DIR}/src/${SUB}"
DESTINATION "include/Bullet3"
FILES_MATCHING PATTERN "*.h"
)
endforeach()
install(
EXPORT Bullet3Targets
FILE Bullet3Targets.cmake
DESTINATION "lib/cmake/Bullet3"
)
include(CMakePackageConfigHelpers)
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/Bullet3Config.cmake"
INSTALL_DESTINATION "lib/cmake/Bullet3"
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/Bullet3ConfigVersion.cmake"
VERSION "${libbullet3_VERSION_MAJOR}.${libbullet3_VERSION_MINOR}"
COMPATIBILITY AnyNewerVersion
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/Bullet3Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/Bullet3ConfigVersion.cmake"
DESTINATION lib/cmake/Bullet3
)
export(EXPORT Bullet3Targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/Bullet3Targets.cmake"
)
# Tests
if(LIBBULLET3_BUILD_TESTS)
enable_testing()
add_executable(test_libbullet3
"test_bullet3.cpp"
)
target_link_libraries(test_libbullet3 libbullet3)
add_test(NAME test_libbullet3 COMMAND test_libbullet3)
endif()