forked from ipc-sim/IPC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
294 lines (239 loc) · 10.5 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
cmake_minimum_required(VERSION 3.9)
project(IPC)
################################################################################
# libigl
option(LIBIGL_USE_STATIC_LIBRARY "Use libigl as static library" OFF)
option(LIBIGL_WITH_ANTTWEAKBAR "Use AntTweakBar" OFF)
option(LIBIGL_WITH_CGAL "Use CGAL" OFF)
option(LIBIGL_WITH_COMISO "Use CoMiso" OFF)
option(LIBIGL_WITH_CORK "Use Cork" OFF)
option(LIBIGL_WITH_EMBREE "Use Embree" OFF)
option(LIBIGL_WITH_LIM "Use LIM" OFF)
option(LIBIGL_WITH_MATLAB "Use Matlab" OFF)
option(LIBIGL_WITH_MOSEK "Use MOSEK" OFF)
option(LIBIGL_WITH_OPENGL "Use OpenGL" ON)
option(LIBIGL_WITH_OPENGL_GLFW "Use GLFW" ON)
option(LIBIGL_WITH_OPENGL_GLFW_IMGUI "Use ImGui" ON)
option(LIBIGL_WITH_PNG "Use PNG" ON)
option(LIBIGL_WITH_PYTHON "Use Python" OFF)
option(LIBIGL_WITH_TETGEN "Use Tetgen" ON)
option(LIBIGL_WITH_TRIANGLE "Use Triangle" ON)
option(LIBIGL_WITH_VIEWER "Use OpenGL viewer" ON)
option(LIBIGL_QUIET_VIEWER "Suppress viewer messages" ON)
option(LIBIGL_WITH_XML "Use XML" OFF)
option(LIBIGL_WITH_PREDICATES "Use exact predicates" ON)
# project-options
option(IPC_WITH_EXACT_CCD "Use exact CCD as a verification" ON)
option(IPC_WITH_TESTS "Build unit tests using Catch2" ON)
option(IPC_WITH_GUROBI "Enable Gurobi QP solver for SQP method" OFF)
option(IPC_WITH_OSQP_MKL "Use MKL Pardiso linear solver in OSQP if available" ON)
option(IPC_WITH_OPENGL "Use libgil viewer for preview and output" ON)
set(IPC_LINSYSSOLVER "CHOLMOD" CACHE STRING "Linear system solver to use (options: CHOLMOD, AMGCL, EIGEN)")
set_property(CACHE IPC_LINSYSSOLVER PROPERTY STRINGS "CHOLMOD" "AMGCL" "EIGEN")
option(IPC_EXIT_UPON_QP_FAIL "Exit if the QP/SQP intersects or blows-up" OFF)
if(NOT IPC_WITH_OPENGL)
set(LIBIGL_WITH_VIEWER OFF CACHE BOOL "" FORCE)
set(LIBIGL_WITH_OPENGL_GLFW_IMGUI OFF CACHE BOOL "" FORCE)
set(LIBIGL_WITH_OPENGL_GLFW OFF CACHE BOOL "" FORCE)
set(LIBIGL_WITH_OPENGL OFF CACHE BOOL "" FORCE)
set(LIBIGL_WITH_PNG OFF CACHE BOOL "" FORCE)
endif()
# debug-options
################################################################################
### Configuration
set(IPC_EXTERNAL "${CMAKE_CURRENT_SOURCE_DIR}/external")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# include(Warnings)
include(${PROJECT_NAME}Dependencies)
################################################################################
# IPC Library
################################################################################
# project source files
file(GLOB SRCFILES
"src/*.cpp"
"src/Energy/*.cpp"
"src/Energy/Physics_Elasticity/*.cpp"
"src/Energy/Geometry_Isometry/*.cpp"
"src/Energy/Connectivity/*.cpp"
"src/Energy/Collision/*.cpp"
"src/CollisionObject/*.cpp"
"src/CCD/*.cpp"
"src/Utils/*.cpp"
"src/LinSysSolver/EigenLibSolver.cpp"
"src/LinSysSolver/CHOLMODSolver.cpp"
"src/LinSysSolver/AMGCLSolver.cpp"
"src/TimeStepper/*.cpp"
)
FOREACH(item ${SRCFILES})
IF(${item} MATCHES "main.cpp")
LIST(REMOVE_ITEM SRCFILES ${item})
ENDIF(${item} MATCHES "main.cpp")
ENDFOREACH(item)
add_library(${PROJECT_NAME}_dev ${SRCFILES})
target_include_directories(${PROJECT_NAME}_dev PUBLIC
"src"
"src/Energy"
"src/Energy/Physics_Elasticity"
"src/Energy/Geometry_Isometry"
"src/Energy/Connectivity"
"src/Energy/Collision"
"src/CollisionObject/"
"src/CCD/"
"src/Utils"
"src/Utils/SVD"
"src/LinSysSolver"
"src/TimeStepper"
)
################################################################################
# Simulations Executable
################################################################################
add_executable(${PROJECT_NAME}_bin "src/main.cpp")
# Link against the library
target_link_libraries(${PROJECT_NAME}_bin PUBLIC ${PROJECT_NAME}_dev)
# CLI11
target_link_libraries(${PROJECT_NAME}_bin PUBLIC CLI11::CLI11)
################################################################################
# Etienne Vouga's CTCD Library
################################################################################
add_library(EVCTCD "src/CCD/EVCTCD/CTCD.cpp")
target_include_directories(EVCTCD PUBLIC "src/CCD/EVCTCD/")
# Link against Eigen in libigl
target_link_libraries(EVCTCD PUBLIC igl::core)
# Turn of floating point contraction for CCD robustness
target_compile_options(EVCTCD PUBLIC "-ffp-contract=off")
################################################################################
# Required Libraries
################################################################################
# EVCTCD
target_link_libraries(${PROJECT_NAME}_dev PUBLIC EVCTCD)
# SuiteSparse
target_link_libraries(${PROJECT_NAME}_dev PUBLIC ${SUITESPARSE_LIBRARIES})
target_include_directories(${PROJECT_NAME}_dev PUBLIC ${SUITESPARSE_INCLUDE_DIRS})
# OSQP
target_link_libraries(${PROJECT_NAME}_dev PUBLIC osqp::osqp)
# libigl
target_link_libraries(${PROJECT_NAME}_dev PUBLIC igl::core igl::triangle igl::tetgen)
if(IPC_WITH_OPENGL)
target_link_libraries(${PROJECT_NAME}_dev PUBLIC igl::opengl_glfw igl::opengl_glfw_imgui igl::png)
target_compile_definitions(${PROJECT_NAME}_dev PUBLIC USE_OPENGL)
endif()
if(LIBIGL_WITH_PREDICATES)
target_link_libraries(${PROJECT_NAME}_dev PUBLIC igl::predicates)
target_compile_definitions(${PROJECT_NAME}_dev PUBLIC USE_PREDICATES)
endif()
target_link_libraries(${PROJECT_NAME}_dev PUBLIC RationalCCD)
# tbb
target_link_libraries(${PROJECT_NAME}_dev PUBLIC TBB::tbb)
# exact-ccd
if(IPC_WITH_EXACT_CCD)
target_link_libraries(${PROJECT_NAME}_dev PUBLIC exact-ccd::exact-ccd)
target_compile_definitions(${PROJECT_NAME}_dev PUBLIC USE_EXACT_CCD)
endif()
# Logger
target_link_libraries(${PROJECT_NAME}_dev PUBLIC spdlog::spdlog)
# AMGCL
target_link_libraries(${PROJECT_NAME}_dev PUBLIC amgcl::amgcl)
# target_link_libraries(${PROJECT_NAME}_dev PUBLIC pardiso600-GNU720-X86-64 gfortran)
# find_package(Pardiso)
# if(PARDISO_FOUND)
# find_package(LAPACK)
# if(LAPACK_FOUND)
# target_link_libraries(${PROJECT_NAME}_dev PUBLIC ${LAPACK_LIBRARIES})
# else()
# message(FATAL_ERROR “unable to find lapack”)
# endif()
# # find_package(OpenMP)
# # if( OpenMP_CXX_FOUND )
# # target_link_libraries(polyfem PUBLIC ${OpenMP_CXX_LIBRARIES})
# # # target_compile_definitions(polyfem PUBLIC ${OpenMP_CXX_FLAGS})
# # else()
# # message(FATAL_ERROR “unable to find omp”)
# # endif()
# target_link_libraries(${PROJECT_NAME}_dev PUBLIC ${PARDISO_LIBRARIES})
# else()
# message(WARNING “Pardiso not found, solver will not be available.“)
# endif()
# target_link_libraries(${PROJECT_NAME}_dev PUBLIC gfortran)
if(IPC_WITH_GUROBI)
target_link_libraries(${PROJECT_NAME}_dev PUBLIC EigenGurobi::EigenGurobi)
target_compile_definitions(${PROJECT_NAME}_dev PUBLIC USE_GUROBI)
endif()
# Extra warnings
# target_link_libraries(${PROJECT_NAME}_dev PRIVATE warnings::all)
################################################################################
# Sub-Projects
################################################################################
add_subdirectory(src/Projects)
################################################################################
# Code Format Tool
################################################################################
find_program(CLANG_FORMAT_INSTALLED "clang-format")
if(CLANG_FORMAT_INSTALLED)
message(STATUS "Building code format tool")
add_subdirectory(Format)
else()
message(STATUS "clang-format not found: skipping Format subdirectory")
endif()
################################################################################
# Compiler options
################################################################################
# Set version of SVD to use
message(STATUS "Using scalar implmentation of SVD")
target_compile_definitions(${PROJECT_NAME}_dev PUBLIC -DUSE_SCALAR_IMPLEMENTATION)
# Figure out SSE level support
message(STATUS "Seaching for SSE...")
find_package(SSE)
# 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)
# Add SSE, AVX, and FMA flags to compiler flags
string(REPLACE " " ";" SIMD_FLAGS "${SSE_FLAGS} ${AVX_FLAGS} ${FMA_FLAGS}")
target_compile_options(${PROJECT_NAME}_dev PUBLIC ${SIMD_FLAGS})
# Add -pthread to compilation and linking
find_package(Threads)
target_link_libraries(${PROJECT_NAME}_dev PUBLIC ${CMAKE_THREAD_LIBS_INIT})
# Use C++17
target_compile_features(${PROJECT_NAME}_dev PUBLIC cxx_std_17)
# code only support 3D
message(STATUS "Building for three dimensions")
target_compile_definitions(${PROJECT_NAME}_dev PUBLIC DIM=3)
# Ensure that PRId64 is defined
target_compile_definitions(${PROJECT_NAME}_dev PUBLIC -D__STDC_FORMAT_MACROS)
# Unit tests
if(IPC_WITH_TESTS)
include(CTest)
enable_testing()
add_subdirectory(tests)
endif()
# MKL Pardiso OSQP linear system solver
if(IPC_WITH_OSQP_MKL)
find_library(MKL_RT_LIBRARY mkl_rt
PATHS $ENV{MKLROOT}/lib
$ENV{MKLROOT}/lib/intel64
$ENV{INTEL}/mkl/lib/intel64
/opt/intel/mkl/lib)
if(MKL_RT_LIBRARY)
message(STATUS "MKL found: enabling OSQP MKL Pardiso linear system solver")
target_compile_definitions(${PROJECT_NAME}_dev PUBLIC OSQP_USE_MKL_PARDISO)
else()
message(WARNING "MKL not found: disabling OSQP MKL Pardiso linear system solver")
endif()
endif()
# Set the selected linear system solver
if(IPC_LINSYSSOLVER STREQUAL "CHOLMOD")
target_compile_definitions(${PROJECT_NAME}_dev PUBLIC LINSYSSOLVER_USE_CHOLMOD)
elseif(IPC_LINSYSSOLVER STREQUAL "AMGCL")
target_compile_definitions(${PROJECT_NAME}_dev PUBLIC LINSYSSOLVER_USE_AMGCL)
elseif(NOT (IPC_LINSYSSOLVER STREQUAL "EIGEN"))
message(WARNING "Invalid linear system solver: ${IPC_LINSYSSOLVER}. Falling back to EIGEN.")
endif()
# Quiet the viewer
if(LIBIGL_QUIET_VIEWER)
target_compile_definitions(${PROJECT_NAME}_dev PUBLIC IGL_VIEWER_VIEWER_QUIET)
endif()
if(IPC_EXIT_UPON_QP_FAIL)
target_compile_definitions(${PROJECT_NAME}_dev PUBLIC EXIT_UPON_QP_FAIL)
endif()