forked from polyfem/polyfem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
executable file
·414 lines (324 loc) · 14.3 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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
################################################################################
cmake_minimum_required(VERSION 3.13)
project(PolyFEM)
################################################################################
cmake_policy(SET CMP0079 NEW)
# cmake_policy(SET CMP0063 NEW)
# set(CMAKE_CXX_VISIBILITY_PRESET hidden)
# Detects whether this is a top-level project
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(POLYFEM_TOPLEVEL_PROJECT ON)
else()
set(POLYFEM_TOPLEVEL_PROJECT OFF)
endif()
if(INPUT_THIRD_PARTY_DIR)
set(THIRD_PARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/${INPUT_THIRD_PARTY_DIR}/)
else()
set(THIRD_PARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/)
endif()
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
if(${POLYFEM_TOPLEVEL_PROJECT})
list(APPEND CMAKE_MODULE_PATH ${THIRD_PARTY_DIR}/Catch2/contrib)
endif()
# Color output
include(UseColors)
# Prepend function
include(PrependCurrentPath)
# Polyfem utils
include(PolyfemUtils)
# Extra warnings
include(Warnings)
# Use C++11/14
include(CXXFeatures)
# Sort projects inside the solution
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Generate position independent code by default
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
################################################################################
# if(${CMAKE_VERSION} VERSION_LESS "3.15.0")
# if(MSVC OR MSYS)
# foreach(config ${CMAKE_CONFIGURATION_TYPES})
# string(TOUPPER ${config} config)
# string(REPLACE /MD /MT CMAKE_C_FLAGS_${config} "${CMAKE_C_FLAGS_${config}}")
# string(REPLACE /MD /MT CMAKE_CXX_FLAGS_${config} "${CMAKE_CXX_FLAGS_${config}}")
# endforeach()
# endif()
# else()
# set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
# endif()
################################################################################
# Polyfem options
option(POLYFEM_WITH_SANITIZERS "Enable sanitizers in compilation targets" OFF)
set(POLYFEM_SMALL_N 80 CACHE STRING "Maximum length for stack-allocated vectors (gradient + Hessian).")
set(POLYFEM_BIG_N 1000 CACHE STRING "Maximum length for stack-allocated vectors (gradient only).")
option(POLYFEM_NO_UI "Disables the user interface" OFF)
# Polyfem options for enabling/disabling optional libraries
option(POLYFEM_WITH_MMG "Enable MMG library" OFF)
option(POLYFEM_WITH_OPENCL "Enable OpenCL" OFF)
option(POLYFEM_REGENERATE_AUTOGEN "Generate the python autogen files" OFF)
set(POLYFEM_THREADING "TBB" CACHE STRING "Multithreading library to use (options: CPP, TBB, NONE)")
set_property(CACHE POLYFEM_THREADING PROPERTY STRINGS "CPP" "TBB" "NONE")
option(POLYFEM_WITH_APPS "Build the apps" ON)
option(POLYFEM_WITH_MISC "Build misc targes" ON)
# Sanitizer options
option(POLYFEM_SANITIZE_ADDRESS "Sanitize Address" OFF)
option(POLYFEM_SANITIZE_MEMORY "Sanitize Memory" OFF)
option(POLYFEM_SANITIZE_THREAD "Sanitize Thread" OFF)
option(POLYFEM_SANITIZE_UNDEFINED "Sanitize Undefined" OFF)
#Solver
option(POLYSOLVE_WITH_CHOLMOD "Enable Cholmod library" ON)
option(POLYSOLVE_WITH_UMFPACK "Enable UmfPack library" ON)
option(POLYSOLVE_WITH_SUPERLU "Enable SuperLU library" ON)
option(POLYSOLVE_WITH_MKL "Enable MKL library" ON)
option(POLYSOLVE_WITH_PARDISO "Enable Pardiso library" OFF)
option(POLYSOLVE_WITH_HYPRE "Enable hypre" ON)
option(POLYSOLVE_WITH_AMGCL "Use AMGCL" ON)
option(POLYSOLVE_WITH_SPECTRA "Enable computing spectrum" OFF)
option(POLYSOLVE_LARGE_INDEX "Build for large indices" OFF)
# Options for libigl modules
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" OFF)
option(LIBIGL_WITH_PYTHON "Use Python" OFF)
option(LIBIGL_WITH_TRIANGLE "Use Triangle" OFF)
option(LIBIGL_WITH_VIEWER "Use OpenGL viewer" ON)
option(LIBIGL_WITH_XML "Use XML" OFF)
if(POLYFEM_TOPLEVEL_PROJECT AND POLYFEM_WITH_APPS)
option(LIBIGL_WITH_TETGEN "Use Tetgen" ON)
else()
option(LIBIGL_WITH_TETGEN "Use Tetgen" OFF)
endif()
if(POLYFEM_NO_UI)
set(LIBIGL_WITH_OPENGL OFF CACHE BOOL "" FORCE)
set(LIBIGL_WITH_OPENGL_GLFW OFF CACHE BOOL "" FORCE)
set(LIBIGL_WITH_OPENGL_GLFW_IMGUI OFF CACHE BOOL "" FORCE)
set(LIBIGL_WITH_VIEWER OFF CACHE BOOL "" FORCE)
endif()
################################################################################
# set(POLYFEM_SMALL_N 105 CACHE STRING "" FORCE)
################################################################################
# Dependencies
################################################################################
# Sanitizers
if(POLYFEM_WITH_SANITIZERS)
list(APPEND CMAKE_MODULE_PATH ${THIRD_PARTY_DIR}/sanitizers-cmake/cmake)
endif()
# Setup dependencies
include(PolyfemDependencies)
################################################################################
# Polyfem library
################################################################################
# add_library() can only be called without any source since CMake 3.11 ...
add_library(polyfem src/State.cpp)
# Must be call in the same "CMakeLists.txt" where add_library(polyfem ...) is called
polyfem_autogen(polyfem eigs.py auto_eigs)
polyfem_autogen(polyfem p_bases.py auto_p_bases)
polyfem_autogen(polyfem q_bases.py auto_q_bases)
polyfem_autogen(polyfem elasticity_rhs.py auto_elasticity_rhs)
# Public include directory for polyfem
target_include_directories(polyfem PUBLIC ${PROJECT_BINARY_DIR}/include)
set(MESH_PATH "${CMAKE_CURRENT_SOURCE_DIR}/tests/")
target_compile_definitions(polyfem PUBLIC -DPOLYFEM_MESH_PATH=\"${MESH_PATH}\")
# Dependencies
target_link_libraries(polyfem PUBLIC clipper::clipper)
# Extra warnings
target_link_libraries(polyfem PRIVATE warnings::all)
if(POLYFEM_THREADING STREQUAL "CPP")
# Use C++17
target_compile_features(polyfem PUBLIC ${CXX17_FEATURES})
else()
# Use C++14
target_compile_features(polyfem PUBLIC ${CXX14_FEATURES})
endif()
# No limit yay
target_compile_definitions(polyfem PUBLIC -DEIGEN_STACK_ALLOCATION_LIMIT=0)
# 8MB
# target_compile_definitions(polyfem PUBLIC -DEIGEN_STACK_ALLOCATION_LIMIT=8388608)
# Max stack-size small vectors (for gradient and Hessian)
target_compile_definitions(polyfem PUBLIC -DPOLYFEM_SMALL_N=${POLYFEM_SMALL_N})
target_compile_definitions(polyfem PUBLIC -DPOLYFEM_BIG_N=${POLYFEM_BIG_N})
if("$ENV{CLUSTER}" STREQUAL "PRINCE")
target_compile_definitions(polyfem PUBLIC -DPOLYFEM_ON_HPC)
endif()
if(POLYFEM_WITH_SANITIZERS)
add_sanitizers(polyfem)
endif()
################################################################################
# Required libraries
################################################################################
# Eigen
# Uncomment to use the system's version of Eigen (e.g. to use Eigen 3.3)
# find_package(Eigen3 REQUIRED)
# target_link_libraries(polyfem PUBLIC Eigen3::Eigen)
polyfem_download_solvers()
add_subdirectory(${THIRD_PARTY_DIR}/solvers)
target_link_libraries(polyfem PUBLIC polysolve)
# TBB
if(POLYFEM_THREADING STREQUAL "CPP")
target_compile_definitions(polyfem PUBLIC POLYFEM_WITH_CPP_THREADS)
elseif(POLYFEM_THREADING STREQUAL "TBB")
polyfem_download_tbb()
set(TBB_BUILD_STATIC ON CACHE BOOL " " FORCE)
set(TBB_BUILD_SHARED OFF CACHE BOOL " " FORCE)
set(TBB_BUILD_TBBMALLOC OFF CACHE BOOL " " FORCE)
set(TBB_BUILD_TBBMALLOC_PROXY OFF CACHE BOOL " " FORCE)
set(TBB_BUILD_TESTS OFF CACHE BOOL " " FORCE)
add_subdirectory(${THIRD_PARTY_DIR}/tbb tbb)
set_property(TARGET tbb_static tbb_def_files PROPERTY FOLDER "dependencies")
target_compile_definitions(tbb_static PUBLIC -DPOLYFEM_WITH_TBB)
target_include_directories(polyfem SYSTEM PUBLIC ${THIRD_PARTY_DIR}/tbb/include)
add_library(TBB::tbb ALIAS tbb_static)
target_link_libraries(polyfem PUBLIC TBB::tbb)
endif()
# IPC
option(IPC_TOOLKIT_BUILD_UNIT_TESTS "Build unit-tests" OFF)
polyfem_download_ipc()
add_subdirectory(${THIRD_PARTY_DIR}/ipc)
target_link_libraries(polyfem PUBLIC IPCToolkit)
# libigl
if(NOT TARGET igl::core)
polyfem_download_libigl()
find_package(LIBIGL REQUIRED)
endif()
target_link_libraries(polyfem PUBLIC igl::core)
# BVH
polyfem_download_BVH()
add_subdirectory(${THIRD_PARTY_DIR}/BVH)
target_link_libraries(polyfem PUBLIC BVH_lib)
# MSHIO
polyfem_download_mshio()
add_subdirectory(${THIRD_PARTY_DIR}/mshio)
target_link_libraries(polyfem PUBLIC mshio)
# Geogram
polyfem_download_geogram()
include(geogram)
target_link_libraries(polyfem PUBLIC geogram)
#spdlog
target_link_libraries(polyfem PUBLIC spdlog::spdlog)
# CppNumericalSolvers
polyfem_download_CppNumericalSolvers()
add_library(cppoptlib INTERFACE)
target_include_directories(cppoptlib SYSTEM INTERFACE ${THIRD_PARTY_DIR}/CppNumericalSolvers/include)
target_link_libraries(polyfem PUBLIC cppoptlib)
# TinyExpr library
if(NOT TARGET tinyexpr::tinyexpr)
polyfem_download_tinyexpr()
add_library(tinyexpr_tinyexpr ${THIRD_PARTY_DIR}/tinyexpr/tinyexpr.c)
target_include_directories(tinyexpr_tinyexpr SYSTEM PUBLIC ${THIRD_PARTY_DIR}/tinyexpr)
add_library(tinyexpr::tinyexpr ALIAS tinyexpr_tinyexpr)
endif()
target_link_libraries(polyfem PUBLIC tinyexpr::tinyexpr)
# TinyXML library
if(NOT TARGET tinyxml2)
polyfem_download_tinyxml()
SET(BUILD_SHARED_LIBS OFF)
SET(BUILD_STATIC_LIBS ON)
SET(BUILD_TESTING OFF)
add_subdirectory(${THIRD_PARTY_DIR}/tinyxml)
endif()
target_link_libraries(polyfem PUBLIC tinyxml2)
# Catch2
if(${POLYFEM_TOPLEVEL_PROJECT})
polyfem_download_catch2()
add_library(catch INTERFACE)
target_include_directories(catch SYSTEM INTERFACE ${THIRD_PARTY_DIR}/Catch2/single_include/catch2)
endif()
# Filesystem
target_link_libraries(polyfem PUBLIC ghc::filesystem)
################################################################################
# Optional libraries
################################################################################
# MMG wrapper
if(POLYFEM_WITH_MMG)
include(ExternalProject)
set(MMG_DIR "${THIRD_PARTY_DIR}/mmg")
ExternalProject_Add(MMG_Project
PREFIX "${MMG_DIR}"
GIT_REPOSITORY https://github.com/MmgTools/mmg.git
GIT_TAG "v5.3.8"
UPDATE_COMMAND ""
PATCH_COMMAND ""
CMAKE_ARGS
-DCMAKE_PREFIX_PATH=${MMG_DIR}/bin
-DBUILD_SHARED_LIBS=OFF
"-DCMAKE_INSTALL_PREFIX=${MMG_DIR}/"
TEST_COMMAND "")
set(MMG_PATH "${THIRD_PARTY_DIR}/mmg/bin/mmg3d_O3")
target_compile_definitions(polyfem PUBLIC -DPOLYFEM_MMG_PATH=\"${MMG_PATH}\")
target_compile_definitions(polyfem PUBLIC -DPOLYFEM_WITH_MMG)
# Boost
find_package(Boost 1.61 QUIET REQUIRED COMPONENTS filesystem system)
target_include_directories(polyfem PUBLIC ${Boost_INCLUDE_DIRS})
target_link_libraries(polyfem PUBLIC ${Boost_LIBRARIES})
endif()
################################################################################
# Polyfem binary
################################################################################
# Main executable
if(POLYFEM_TOPLEVEL_PROJECT)
add_executable(${PROJECT_NAME}_bin src/main.cpp)
source_group("gui" FILES src/main.cpp)
if(NOT POLYFEM_NO_UI)
source_group("gui" FILES src/viewer/UIState.cpp)
source_group("gui" FILES src/viewer/UIState.hpp)
source_group("gui" FILES src/viewer/UIMenu.cpp)
target_include_directories(${PROJECT_NAME}_bin PUBLIC src/viewer)
else()
target_compile_definitions(${PROJECT_NAME}_bin PUBLIC -DPOLYFEM_NO_UI)
endif()
target_compile_features(${PROJECT_NAME}_bin PUBLIC ${CXX14_FEATURES})
target_link_libraries(${PROJECT_NAME}_bin
PUBLIC
polyfem
warnings::all
CLI11::CLI11
)
if(NOT POLYFEM_NO_UI)
target_link_libraries(${PROJECT_NAME}_bin PUBLIC igl::opengl_glfw_imgui)
# igl::png
# tinyfiledialogs::tinyfiledialogs
endif()
if(POLYFEM_WITH_SANITIZERS)
add_sanitizers(${PROJECT_NAME}_bin)
endif()
if(NOT (${CMAKE_VERSION} VERSION_LESS "3.6.0"))
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME}_bin)
endif()
endif()
################################################################################
# Clutter management
################################################################################
if(TARGET igl_tetgen)
set_target_properties(tetgen PROPERTIES FOLDER 3rdparty/other)
endif()
set_target_properties(geogram PROPERTIES FOLDER 3rdparty/other)
set_target_properties(clipper_clipper PROPERTIES FOLDER 3rdparty/other)
################################################################################
# Subdirectories
################################################################################
# Other sources
add_subdirectory(src)
# Compile extras only if this is a top-level project
if(POLYFEM_TOPLEVEL_PROJECT)
# Auxiliary binaries
if(POLYFEM_WITH_APPS)
add_subdirectory(apps)
endif()
if(POLYFEM_WITH_MISC)
add_subdirectory(misc)
endif()
# Unit tests
include(CTest)
enable_testing()
add_subdirectory(tests)
endif()