-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
261 lines (213 loc) · 7.42 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
cmake_minimum_required(VERSION 3.11)
project(dismech-rods)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "-O3 -DNDEBUG -Wno-deprecated-declarations")
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE)
if (COMPILER_SUPPORTS_MARCH_NATIVE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
endif ()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "../")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
set(MAGNUM_WITH_SDL2APPLICATION ON)
set(THREADS_PREFER_PTHREAD_FLAG ON)
# Per https://eigen.tuxfamily.org/dox/TopicUsingIntelMKL.html eigen should be used
# with MKL LAPACK only with lp64 set. The default may be ILP64, which we don't want.
set(MKL_INTERFACE_FULL intel_lp64)
add_definitions(-DEIGEN_USE_MKL_ALL)
find_package(SymEngine REQUIRED)
find_package(GLUT REQUIRED)
find_package(OpenGL REQUIRED)
find_package(MKL CONFIG REQUIRED)
find_package(LAPACK REQUIRED)
find_package(BLAS REQUIRED)
find_package(Threads REQUIRED)
find_package(Eigen3 3.4 REQUIRED)
find_package(OpenMP)
find_package(FCL REQUIRED)
# Run with -DWITH_MAGNUM=ON to build with Magnum library.
option(WITH_MAGNUM OFF)
if (WITH_MAGNUM)
add_definitions(-DWITH_MAGNUM)
find_package(Corrade REQUIRED Main PluginManager Utility)
find_package(Magnum REQUIRED
GL
MeshTools
Primitives
Shaders
Trade
Sdl2Application
SceneGraph)
find_package(MagnumPlugins REQUIRED PngImageConverter)
else ()
message(STATUS "Building with Magnum disabled")
endif ()
option(WITH_PYBIND OFF)
if (WITH_PYBIND)
find_package(pybind11 REQUIRED)
else ()
message(STATUS "Building with pybind disabled")
endif ()
if (${HAVE_SYMENGINE_LLVM})
message(STATUS "Testing SymEngine LLVM & SBML support - found")
else ()
message(WARNING "SymEngine library is missing LLVM and/or SBML support")
message(WARNING "${SYMENGINE_LLVM_ERROR_LOG}")
endif ()
set(SOURCES
src/world.cpp
src/rod_mechanics/base_force.cpp
src/rod_mechanics/elastic_rod.cpp
src/rod_mechanics/elastic_joint.cpp
src/rod_mechanics/soft_robots.cpp
src/rod_mechanics/force_container.cpp
src/rod_mechanics/inner_forces/inertial_force.cpp
src/rod_mechanics/inner_forces/elastic_stretching_force.cpp
src/rod_mechanics/inner_forces/elastic_bending_force.cpp
src/rod_mechanics/inner_forces/elastic_twisting_force.cpp
src/rod_mechanics/external_forces/gravity_force.cpp
src/rod_mechanics/external_forces/damping_force.cpp
src/rod_mechanics/external_forces/floor_contact_force.cpp
src/rod_mechanics/external_forces/symbolic_equations.cpp
src/rod_mechanics/external_forces/uniform_constant_force.cpp
src/rod_mechanics/external_forces/collision_detector.cpp
src/rod_mechanics/external_forces/contact_force.cpp
src/time_steppers/base_time_stepper.cpp
src/time_steppers/explicit_time_stepper.cpp
src/time_steppers/forward_euler.cpp
src/time_steppers/verlet_position.cpp
src/time_steppers/implicit_time_stepper.cpp
src/time_steppers/backward_euler.cpp
src/time_steppers/implicit_midpoint.cpp
src/solvers/base_solver.cpp
src/solvers/pardiso_solver.cpp
src/solvers/dgbsv_solver.cpp
src/logging/base_logger.cpp
src/logging/position_logger.cpp
src/logging/velocity_logger.cpp
src/simulation_environments/base_sim_env.cpp
src/simulation_environments/headless_sim_env.cpp
src/simulation_environments/opengl_sim_env.cpp
src/controllers/base_controller.cpp
src/controllers/open_loop_uniform_kappa_bar_controller.cpp
src/controllers/active_entanglement_controller.cpp
src/utils/utils.cpp
)
if (WITH_MAGNUM)
set(SOURCES ${SOURCES}
src/simulation_environments/magnum_sim_env.cpp
)
endif ()
set(LINK_LIBRARIES
${OPENGL_LIBRARIES}
${GLUT_LIBRARIES}
MKL::MKL
Eigen3::Eigen
${LAPACK_LIBRARIES}
${BLAS_LIBRARIES}
lapack
stdc++fs
Threads::Threads
m
${SYMENGINE_LIBRARIES}
fcl
)
if (WITH_MAGNUM)
set(LINK_LIBRARIES ${LINK_LIBRARIES}
Corrade::Main
Corrade::PluginManager
Corrade::Utility
Magnum::Application
Magnum::GL
Magnum::Magnum
Magnum::MeshTools
Magnum::Primitives
Magnum::SceneGraph
Magnum::Shaders
MagnumPlugins::PngImageConverter
)
endif ()
if (WITH_PYBIND)
set(LINK_LIBRARIES ${LINK_LIBRARIES}
pybind11::module
)
endif ()
if (OpenMP_CXX_FOUND)
set (LINK_LIBRARIES ${LINK_LIBRARIES}
OpenMP::OpenMP_CXX
)
endif ()
add_library(common_sources STATIC ${SOURCES})
target_include_directories(common_sources PUBLIC
${CMAKE_SOURCE_DIR}/src
)
target_include_directories(common_sources SYSTEM PRIVATE
Eigen3::Eigen
${SYMENGINE_INCLUDE_DIRS}
${OPENGL_INCLUDE_DIRS}
${GLUT_INCLUDE_DIRS})
target_link_libraries(common_sources PUBLIC
${LINK_LIBRARIES}
)
# Run with cmake --fresh -DCREATE_DOCS=ON .. only when documentation needs to be updated.
# If docs change and you want to preview the updates in index.html, you'll need to rm -rf * and
# remake everything in build. Don't make clean && make. Kind of annoying but this should only be
# done for previewing. All updates to the actual docs will be done more fluidly.
# If wanting to rebuild source code, will have to cmake --fresh .. again.
# Probably a good idea to split the documentation cmake process into its own directory later.
#option(CREATE_DOCS OFF)
#
#if (CREATE_DOCS)
# add_subdirectory("docs")
#endif ()
if (EXISTS ${CMAKE_SOURCE_DIR}/robot_description.cpp)
add_executable(disMech
src/main.cpp
robot_description.cpp
)
target_link_libraries(disMech PRIVATE
common_sources
)
else()
message(WARNING "No robot_description.cpp found. No executable will be created.")
endif()
if (WITH_PYBIND)
pybind11_add_module(py_dismech
src/app.cpp
)
target_link_libraries(py_dismech PRIVATE
common_sources
)
set_target_properties(py_dismech PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/py_dismech"
)
endif()
option(CREATE_EXAMPLES OFF)
set(EXAMPLES
examples/active_entanglement_case/active_entanglement_example.cpp
examples/cantilever_case/cantilever_example.cpp
examples/friction_case/friction_example.cpp
examples/helix_case/helix_example.cpp
examples/horton_case/horton_example.cpp
examples/real2sim_case/real2sim_example.cpp
examples/spider_case/spider_example.cpp
)
if (CREATE_EXAMPLES)
# Loop through each example file and create a build target
foreach(EXAMPLE ${EXAMPLES})
get_filename_component(EXAMPLE_NAME ${EXAMPLE} NAME_WE)
get_filename_component(EXAMPLE_DIR ${EXAMPLE} DIRECTORY)
set(EXEC_NAME "${EXAMPLE_NAME}_exec")
add_executable(${EXEC_NAME}
src/main.cpp
${EXAMPLE}
)
set_target_properties(${EXEC_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/${EXAMPLE_DIR}
)
target_link_libraries(${EXEC_NAME} PRIVATE
common_sources
)
endforeach()
endif ()