-
Notifications
You must be signed in to change notification settings - Fork 73
/
CMakeLists.txt
318 lines (264 loc) · 10.9 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
# Detects whether this is a top-level project
get_directory_property(HAS_PARENT PARENT_DIRECTORY)
if(HAS_PARENT)
set(IPC_TOPLEVEL_PROJECT OFF)
else()
set(IPC_TOPLEVEL_PROJECT ON)
endif()
# Check required CMake version
set(REQUIRED_CMAKE_VERSION "3.14.0")
if(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 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}/IPCOptions.cmake)
message(STATUS "Using local options file: ${CMAKE_CURRENT_SOURCE_DIR}/IPCOptions.cmake")
include(${CMAKE_CURRENT_SOURCE_DIR}/IPCOptions.cmake)
endif()
################################################################################
project(IPC DESCRIPTION "Incremental Potential Contact (IPC)" LANGUAGES CXX)
################################################################################
# Project options
option(IPC_WITH_OPENGL "Use libgil viewer for preview and output" ON)
option(IPC_WITH_AMGCL "Enable AMGCL linear system solver" ON)
option(IPC_WITH_CHOLMOD "Enable CHOLMOD linear system solver" ON)
set(IPC_DEFAULT_LINSYSSOLVER "CHOLMOD" CACHE STRING "Linear system solver to use (options: CHOLMOD, AMGCL, EIGEN)")
set_property(CACHE IPC_DEFAULT_LINSYSSOLVER PROPERTY STRINGS "CHOLMOD" "AMGCL" "EIGEN")
## SQP and QP options
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_EXIT_UPON_QP_FAIL "Exit if the QP/SQP intersects or blows-up" OFF)
## CCD options
option(IPC_WITH_EXACT_CCD "Use exact CCD as a verification" OFF)
## Top level options
option(IPC_WITH_TESTS "Build unit tests using Catch2" ${IPC_TOPLEVEL_PROJECT})
# project-options
option(IPC_BUILD_DIAGNOSTIC_PROJECT "Build the Diagnostic sub-project" ${IPC_TOPLEVEL_PROJECT})
option(IPC_BUILD_MESH_PROCESSING_PROJECT "Build the MeshProcessing sub-project" ${IPC_TOPLEVEL_PROJECT})
################################################################################
### Configuration
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/ipc)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/find)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/recipes)
include(ipc_cpm_cache)
################################################################################
# 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/*.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"
)
################################################################################
# Required Libraries
################################################################################
# Extra warnings
include(ipc_warnings)
target_link_libraries(${PROJECT_NAME}_dev PRIVATE IPC::warnings)
# tbb
include(onetbb)
target_link_libraries(${PROJECT_NAME}_dev PUBLIC TBB::tbb)
# SuiteSparse
if(IPC_WITH_CHOLMOD)
set(SUITESPARSE_INCLUDE_DIR_HINTS $ENV{SUITESPARSE_INC})
set(SUITESPARSE_LIBRARY_DIR_HINTS $ENV{SUITESPARSE_LIB})
find_package(SuiteSparse REQUIRED)
target_link_libraries(${PROJECT_NAME}_dev PUBLIC ${SUITESPARSE_LIBRARIES})
target_include_directories(${PROJECT_NAME}_dev PUBLIC ${SUITESPARSE_INCLUDE_DIRS})
endif()
# OSQP
include(osqp)
target_link_libraries(${PROJECT_NAME}_dev PUBLIC osqp::osqp)
# libigl
include(eigen)
include(libigl)
target_link_libraries(${PROJECT_NAME}_dev PUBLIC igl::core)
if(IPC_WITH_OPENGL)
target_link_libraries(${PROJECT_NAME}_dev PUBLIC igl::glfw igl::imgui igl::stb)
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()
# CCD
include(ccd_wrapper)
target_link_libraries(${PROJECT_NAME}_dev PUBLIC ccd_wrapper::ccd_wrapper)
if(IPC_WITH_EXACT_CCD)
message(WARNING "The exact CCD methods RootParity and BSC miss some collisions! Please use TightInclusion instead.")
target_compile_definitions(${PROJECT_NAME}_dev PUBLIC USE_EXACT_CCD)
endif()
if(CCD_WRAPPER_WITH_FPRP)
target_compile_definitions(${PROJECT_NAME}_dev PUBLIC IPC_WITH_FPRP_CCD)
endif()
if(CCD_WRAPPER_WITH_TIGHT_INCLUSION)
target_compile_definitions(${PROJECT_NAME}_dev PUBLIC IPC_WITH_TIGHT_INCLUSION)
endif()
# Logger
include(spdlog)
target_link_libraries(${PROJECT_NAME}_dev PUBLIC spdlog::spdlog)
# AMGCL
if(IPC_WITH_AMGCL)
include(amgcl)
target_link_libraries(${PROJECT_NAME}_dev PUBLIC amgcl::amgcl)
endif()
if(IPC_WITH_GUROBI)
include(eigen_gurobi)
target_link_libraries(${PROJECT_NAME}_dev PUBLIC EigenGurobi::EigenGurobi)
target_compile_definitions(${PROJECT_NAME}_dev PUBLIC USE_GUROBI)
endif()
# MshIO
include(mshio)
target_link_libraries(${PROJECT_NAME}_dev PUBLIC mshio::mshio)
# Filesystem
include(filesystem)
target_link_libraries(${PROJECT_NAME}_dev PUBLIC ghc::filesystem)
# 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)
################################################################################
# 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
include(cli11)
target_link_libraries(${PROJECT_NAME}_bin PUBLIC CLI11::CLI11)
################################################################################
# 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_DEFAULT_LINSYSSOLVER STREQUAL "CHOLMOD" AND NOT IPC_WITH_CHOLMOD)
message(FATAL_ERROR "CHOLMOD selected as IPC_DEFAULT_LINSYSSOLVER, but CHOLMOD is disabled (IPC_WITH_CHOLMOD=OFF)!")
endif()
if(IPC_DEFAULT_LINSYSSOLVER STREQUAL "AMGCL" AND NOT IPC_WITH_AMGCL)
message(FATAL_ERROR "AMGCL selected as IPC_DEFAULT_LINSYSSOLVER, but AMGCL is disabled (IPC_WITH_AMGCL=OFF)!")
endif()
string(TOUPPER "${IPC_DEFAULT_LINSYSSOLVER}" IPC_DEFAULT_LINSYSSOLVER)
target_compile_definitions(${PROJECT_NAME}_dev PUBLIC "IPC_DEFAULT_LINSYSSOLVER=LinSysSolverType::${IPC_DEFAULT_LINSYSSOLVER}")
if(IPC_WITH_AMGCL)
target_compile_definitions(${PROJECT_NAME}_dev PUBLIC IPC_WITH_AMGCL)
endif()
if(IPC_WITH_CHOLMOD)
target_compile_definitions(${PROJECT_NAME}_dev PUBLIC IPC_WITH_CHOLMOD)
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()