-
Notifications
You must be signed in to change notification settings - Fork 19
/
CMakeLists.txt
347 lines (278 loc) · 11.6 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# Detects whether this is a top-level project
get_directory_property(HAS_PARENT PARENT_DIRECTORY)
if(HAS_PARENT)
set(RIGID_IPC_TOPLEVEL_PROJECT OFF)
else()
set(RIGID_IPC_TOPLEVEL_PROJECT ON)
endif()
# Check required CMake version
set(REQUIRED_CMAKE_VERSION "3.14.0")
if(RIGID_IPC_TOPLEVEL_PROJECT)
cmake_minimum_required(VERSION ${REQUIRED_CMAKE_VERSION})
else()
# Don't use cmake_minimum_required here to avoid implicitly overriding parent policies
if(${CMAKE_VERSION} VERSION_LESS ${REQUIRED_CMAKE_VERSION})
message(FATAL_ERROR "CMake required version to build Rigid IPC is ${REQUIRED_CMAKE_VERSION}")
endif()
endif()
# Include user-provided default options if available. We do that before the main
# `project()` so that we can define the C/C++ compilers from the option file.
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/RigidIPCOptions.cmake)
message(STATUS "Using local options file: ${CMAKE_CURRENT_SOURCE_DIR}/RigidIPCOptions.cmake")
include(${CMAKE_CURRENT_SOURCE_DIR}/RigidIPCOptions.cmake)
endif()
################################################################################
project(RigidIPC
DESCRIPTION "Robust, intersection-free, simulations of rigid bodies."
LANGUAGES CXX)
option(RIGID_IPC_WITH_UNIT_TESTS "Build unit-tests" ${RIGID_IPC_TOPLEVEL_PROJECT})
option(RIGID_IPC_WITH_OPENGL "Build GUI" ${RIGID_IPC_TOPLEVEL_PROJECT})
option(RIGID_IPC_WITH_TOOLS "Build tools" ${RIGID_IPC_TOPLEVEL_PROJECT})
option(RIGID_IPC_WITH_PROFILING "Profile functions" OFF)
option(RIGID_IPC_WITH_COMPARISONS "Build comparisons" OFF)
option(RIGID_IPC_WITH_SIMD "Enable SIMD" OFF)
option(RIGID_IPC_WITH_PYTHON "Build Python bindings" OFF)
option(RIGID_IPC_WITH_DERIVATIVE_CHECK "Check derivatives using finite differences" OFF)
# Set default minimum C++ standard
if(RIGID_IPC_TOPLEVEL_PROJECT)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
endif()
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/rigid_ipc/")
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/recipes/")
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/find/")
include(rigid_ipc_cpm_cache)
# Color output
include(rigid_ipc_use_colors)
include(rigid_ipc_autogen)
mark_as_advanced(CLEAR CMAKE_BUILD_TYPE)
################################################################################
# External project settings
################################################################################
# libigl options
option(LIBIGL_USE_STATIC_LIBRARY "Use libigl as static library" OFF)
option(LIBIGL_WITH_PREDICATES "Use exact predicates" ON)
set(LIBIGL_WITH_OPENGL_GLFW_IMGUI ${RIGID_IPC_WITH_OPENGL} CACHE BOOL "Use OpenGL" FORCE)
set(LIBIGL_WITH_OPENGL_GLFW ${RIGID_IPC_WITH_OPENGL} CACHE BOOL "Use GLFW" FORCE)
set(LIBIGL_WITH_OPENGL ${RIGID_IPC_WITH_OPENGL} CACHE BOOL "Use IMGUI" FORCE)
set(LIBIGL_WITH_PNG ${RIGID_IPC_WITH_OPENGL} CACHE BOOL "Use PNG" FORCE)
# PolySolve settings
option(POLYSOLVE_WITH_CHOLMOD "Enable Cholmod library" ON)
option(POLYSOLVE_WITH_UMFPACK "Enable UmfPack library" OFF)
option(POLYSOLVE_WITH_SUPERLU "Enable SuperLU library" OFF)
option(POLYSOLVE_WITH_MKL "Enable MKL library" OFF)
option(POLYSOLVE_WITH_PARDISO "Enable Pardiso library" OFF)
option(POLYSOLVE_WITH_HYPRE "Enable hypre" OFF)
option(POLYSOLVE_WITH_AMGCL "Use AMGCL" OFF)
option(POLYSOLVE_WITH_SPECTRA "Enable computing spectrum" OFF)
set(TIGHT_INCLUSION_WITH_NO_ZERO_TOI OFF CACHE BOOL "Enable refinement if CCD produces a zero ToI" FORCE)
################################################################################
# Rigid IPC Library
################################################################################
add_library(ipc_rigid
src/autodiff/autodiff.cpp
src/utils/sinc.cpp
src/ccd/impact.cpp
src/ccd/ccd.cpp
src/ccd/linear/broad_phase.cpp
src/ccd/piecewise_linear/time_of_impact.cpp
src/interval/filib_rounding.cpp
src/interval/interval_root_finder.cpp
src/ccd/rigid/broad_phase.cpp
src/ccd/rigid/rigid_body_hash_grid.cpp
src/ccd/rigid/rigid_body_bvh.cpp
src/ccd/rigid/time_of_impact.cpp
src/ccd/rigid/rigid_trajectory_aabb.cpp
src/ccd/redon/time_of_impact.cpp
src/ccd/save_queries.cpp
src/geometry/intersection.cpp
src/io/serialize_json.cpp
src/io/read_rb_scene.cpp
src/io/read_obj.cpp
src/io/write_obj.cpp
src/io/write_gltf.cpp
src/physics/mass.cpp
src/utils/mesh_selector.cpp
src/physics/rigid_body.cpp
src/physics/rigid_body_assembler.cpp
src/physics/rigid_body_problem.cpp
src/barrier/barrier.cpp
src/barrier/barrier_chorner.cpp
src/opt/distance_barrier_constraint.cpp
src/opt/collision_constraint.cpp
src/opt/optimization_problem.cpp
src/opt/optimization_results.cpp
src/problems/barrier_problem.cpp
src/solvers/newton_solver.cpp
src/solvers/ipc_solver.cpp
src/solvers/homotopy_solver.cpp
src/solvers/solver_factory.cpp
# src/solvers/line_search.cpp
src/problems/rigid_body_collision_constraint.cpp
src/problems/distance_barrier_rb_problem.cpp
src/problems/split_distance_barrier_rb_problem.cpp
src/problems/problem_factory.cpp
src/time_stepper/sympletic_euler_time_stepper.cpp
src/time_stepper/verlet_time_stepper.cpp
src/time_stepper/exponential_euler_time_stepper.cpp
src/time_stepper/dmv_time_stepper.cpp
src/time_stepper/time_stepper_factory.cpp
src/utils/tensor.cpp
src/utils/eigen_ext.cpp
src/utils/regular_2d_grid.cpp
src/utils/get_rss.cpp
src/SimState.cpp
src/logger.cpp
src/profiler.cpp
)
target_include_directories(ipc_rigid PUBLIC src)
add_library(ipc::rigid ALIAS ipc_rigid)
# Autogenerated files ----------------------------------------------------------
# project_autogen(ipc_rigid time_of_impact_coeff.py time_of_impact_coeff.tpp auto_time_of_impact_coeff .ipp)
################################################################################
# Optional Definitions
################################################################################
# Directory paths
set(RIGID_IPC_MESH_DIR ${CMAKE_CURRENT_SOURCE_DIR}/meshes)
target_compile_definitions(ipc_rigid PUBLIC RIGID_IPC_MESHES_DIR=\"${RIGID_IPC_MESH_DIR}\")
if(RIGID_IPC_WITH_DERIVATIVE_CHECK)
target_compile_definitions(ipc_rigid PUBLIC RIGID_IPC_WITH_DERIVATIVE_CHECK)
endif()
if(RIGID_IPC_WITH_PROFILING)
message(STATUS "Profiling Enabled")
target_compile_definitions(ipc_rigid PUBLIC RIGID_IPC_PROFILE_FUNCTIONS)
endif()
# For MSVC, do not use the min and max macros.
target_compile_definitions(ipc_rigid PUBLIC NOMINMAX)
################################################################################
# Required Libraries
################################################################################
# Extra warnings
include(rigid_ipc_warnings)
target_link_libraries(ipc_rigid PRIVATE ipc::rigid::warnings)
# libigl
include(eigen)
include(libigl)
target_link_libraries(ipc_rigid PUBLIC
Eigen3::Eigen
igl::core
igl::predicates
)
# JSON Parser
include(json)
target_link_libraries(ipc_rigid PUBLIC nlohmann::json)
# Logger
include(spdlog)
target_link_libraries(ipc_rigid PUBLIC spdlog::spdlog)
# Finite Differences
include(finite_diff)
target_link_libraries(ipc_rigid PUBLIC finitediff::finitediff)
# Boost
include(boost)
target_link_libraries(ipc_rigid PUBLIC Boost::boost)
# TBB
include(tbb)
target_link_libraries(ipc_rigid PUBLIC TBB::tbb)
# MSCCD
include(tight_inclusion)
target_link_libraries(ipc_rigid PUBLIC tight_inclusion::tight_inclusion)
# PolySolve for wrapping linear solvers
include(polysolve)
target_link_libraries(ipc_rigid PUBLIC PolyFEM::polysolve)
# IPC Toolkit
include(ipc_toolkit)
target_link_libraries(ipc_rigid PUBLIC ipc::toolkit)
# filib
include(filib)
target_link_libraries(ipc_rigid PUBLIC filib::filib)
# SimpleBVH
include(simple_bvh)
target_link_libraries(ipc_rigid PUBLIC simple_bvh::simple_bvh)
# tinygltf
include(tinygltf)
target_link_libraries(ipc_rigid PUBLIC tinygltf::tinygltf)
# Filesystem
include(filesystem)
target_link_libraries(ipc_rigid PUBLIC ghc::filesystem)
################################################################################
# Compiler options
################################################################################
## SIMD support
if(RIGID_IPC_WITH_SIMD)
# Figure out SSE level support
message(STATUS "Seaching for SSE...")
find_package(SSE)
# Apple broke AVX instructions with clang:
# https://gitlab.com/libeigen/eigen/-/commit/71aa53dd6dfdc497324d9e87f59c4ba820191856
if(NOT APPLE)
# Figure out AVX level support
message(STATUS "Searching for AVX...")
find_package(AVX)
# Figure out FMA level support
message(STATUS "Searching for FMA...")
find_package(FMA)
else()
message(WARNING "Disabling AVX support: clang compiler shipped with XCode 11.[012] generates broken assembly with -macosx-version-min=10.15 and AVX enabled.")
endif()
# Add SSE, AVX, and FMA flags to compiler flags
string(REPLACE " " ";" SIMD_FLAGS "${SSE_FLAGS} ${AVX_FLAGS} ${FMA_FLAGS}")
target_compile_options(ipc_rigid PUBLIC ${SIMD_FLAGS})
endif()
# Use C++17
target_compile_features(ipc_rigid PUBLIC cxx_std_17)
################################################################################
# Simulations Executable
################################################################################
add_executable(rigid_ipc_sim src/main.cpp)
if(RIGID_IPC_WITH_OPENGL)
target_sources(rigid_ipc_sim PUBLIC
src/viewer/imgui_ext.cpp
src/viewer/igl_viewer_ext.cpp
src/viewer/UISimState.cpp
src/viewer/UIMenu.cpp
)
endif()
target_link_libraries(rigid_ipc_sim PUBLIC ipc::rigid)
include(cli11)
target_link_libraries(rigid_ipc_sim PUBLIC CLI11::CLI11)
if(RIGID_IPC_WITH_OPENGL)
target_compile_definitions(rigid_ipc_sim PUBLIC RIGID_IPC_WITH_OPENGL)
include(libigl)
target_link_libraries(rigid_ipc_sim PUBLIC
igl::opengl igl::opengl_glfw igl::opengl_glfw_imgui igl::png)
# Charlie Tangora's gif-h library
include(gif_h)
target_link_libraries(rigid_ipc_sim PRIVATE gif_h::gif_h)
endif()
################################################################################
# Tools
################################################################################
if(RIGID_IPC_WITH_TOOLS)
add_subdirectory(src/tools)
endif()
################################################################################
# Tests
################################################################################
# Enable unit testing at the root level
if(RIGID_IPC_WITH_UNIT_TESTS)
include(CTest)
enable_testing()
# Include Catch2 and provide function `catch_discover_tests` to register tests.
include(catch2)
FetchContent_GetProperties(catch2)
include("${catch2_SOURCE_DIR}/contrib/Catch.cmake")
add_subdirectory(tests)
endif()
################################################################################
# Comparisons to other methods
################################################################################
if(RIGID_IPC_WITH_COMPARISONS)
add_subdirectory(comparisons)
endif()
################################################################################
# Python bindings
################################################################################
if(RIGID_IPC_WITH_PYTHON)
add_subdirectory(python)
endif()