-
Notifications
You must be signed in to change notification settings - Fork 45
/
CMakeLists.txt
304 lines (267 loc) · 9.37 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
cmake_minimum_required(VERSION 3.8)
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.0")
cmake_policy(SET CMP0042 NEW)
endif()
project(biorbd VERSION 1.11.2)
set(BIORBD_ROOT_FOLDER ${PROJECT_SOURCE_DIR})
set (BIORBD_NAME_NO_SUFFIX ${PROJECT_NAME})
set (CMAKE_CXX_STANDARD 11)
# Set some variables
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/modules")
# Set all the compile options
option(MODULE_KALMAN
"If Kalman filter should be compiled" ON)
option(MODULE_MUSCLES
"Choose if the module muscles is to be added to biorbd" ON)
option(MODULE_ACTUATORS
"Choose if the module actuators is to be added to biorbd" ON)
option(MODULE_PASSIVE_TORQUES
"Choose if the module passive_torques is to be added to biorbd" ON)
option(MODULE_LIGAMENTS
"Choose if the module ligaments is to be added to biorbd" ON)
option(MODULE_STATIC_OPTIM
"If Static optimization should be compiled" ON)
option(MODULE_VTP_FILES_READER
"If reader for geometry vtp files from opensim should be compiled" ON)
option(BUILD_EXAMPLE
"Build a C++ example" ON)
option(BUILD_DOC
"Build documentation" OFF)
option(BUILD_TESTS
"Build all tests." OFF)
# Because of Eigen, it is not possible to compile biorbd as a dynamic library
if (WIN32)
SET(BUILD_SHARED_LIBS FALSE CACHE BOOL
"Choose if the dynamic library should be build" FORCE)
else()
SET(BUILD_SHARED_LIBS TRUE CACHE BOOL
"Choose if the dynamic library should be build")
endif()
# Set a default build type to 'Release' if none was specified
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build.")
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY
STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo" "Coverage")
endif()
# Choose the math's library backend to use
set(MATH_LIBRARY_BACKEND Eigen3 CACHE STRING
"Choose the backend library for the linear algebra.")
# Set the possible values of build type for cmake-gui
set_property(CACHE MATH_LIBRARY_BACKEND PROPERTY STRINGS "Eigen3" "Casadi")
# Prepare linkings
if(${MATH_LIBRARY_BACKEND} STREQUAL "Eigen3")
set(BIORBD_USE_EIGEN3_MATH true)
set(BIORBD_USE_CASADI_MATH false)
set(BIORBD_LIB_SUFFIX "eigen")
elseif(${MATH_LIBRARY_BACKEND} STREQUAL "Casadi")
set(BIORBD_USE_EIGEN3_MATH false)
set(BIORBD_USE_CASADI_MATH true)
set(BIORBD_LIB_SUFFIX "casadi")
endif()
set (BIORBD_NAME ${PROJECT_NAME}_${BIORBD_LIB_SUFFIX})
if(${MATH_LIBRARY_BACKEND} STREQUAL "Eigen3")
find_package(Eigen3 REQUIRED)
set(MATH_BACKEND_INCLUDE_DIR "${EIGEN3_INCLUDE_DIR}")
set(MATH_BACKEND_LIBRARIES "")
find_package(RBDL REQUIRED)
elseif(${MATH_LIBRARY_BACKEND} STREQUAL "Casadi")
find_package(Casadi REQUIRED)
set(MATH_BACKEND_INCLUDE_DIR
"${Casadi_INCLUDE_DIR}"
"${Casadi_INCLUDE_DIR}/.."
)
set(MATH_BACKEND_LIBRARIES "${Casadi_LIBRARY}")
find_package(RBDLCasadi REQUIRED)
set(RBDL_INCLUDE_DIR ${RBDLCasadi_INCLUDE_DIR}/rbdl-casadi ${RBDLCasadi_INCLUDE_DIR})
set(RBDL_LIBRARY ${RBDLCasadi_LIBRARY})
endif()
find_package(IPOPT)
find_package(TinyXML)
# Manage options
# MODULE_KALMAN
if (BIORBD_USE_CASADI_MATH AND MODULE_KALMAN)
message(WARNING "Casadi and Kalman cannot be used alongside, MODULE_KALMAN is automatically set to OFF")
set(MODULE_KALMAN OFF CACHE BOOL "" FORCE)
endif()
if (CMAKE_BUILD_TYPE MATCHES Debug)
option(SKIP_ASSERT
"Some checks slow the code down at run-time, but provide more robust
code. By default, it is ON when compiling in debug, but OFF in release."
ON
)
else()
option(SKIP_ASSERT
"Some checks slow the code down at run-time, but provide more robust
code. By default, it is ON when compiling in debug, but OFF in release."
OFF
)
endif()
# MODULE_STATIC_OPTIM
if (IPOPT_FOUND)
if (BIORBD_USE_CASADI_MATH AND MODULE_STATIC_OPTIM)
message(WARNING "Static optimization can't be compiled along with Casadi")
set(MODULE_STATIC_OPTIM OFF CACHE BOOL "" FORCE)
endif()
else()
set(IPOPT_INCLUDE_DIR "")
set(IPOPT_LIBRARY "")
if (MODULE_STATIC_OPTIM)
message(WARNING "Static optimization can't be compiled since Ipopt was not found")
set(MODULE_STATIC_OPTIM OFF CACHE BOOL "" FORCE)
endif()
endif()
# MODULE_VTP_FILES_READER
if (NOT TinyXML_FOUND)
set(TinyXML_INCLUDE_DIR "")
set(TinyXML_LIBRARY "")
if (MODULE_VTP_FILES_READER)
message(WARNING "VTP cannot be used since TinyXML was not found")
set(MODULE_VTP_FILES_READER OFF CACHE BOOL "" FORCE)
endif()
endif()
# Prepare add library
set(SRC_LIST
"src/BiorbdModel.cpp"
"src/ModelReader.cpp"
"src/ModelWriter.cpp"
)
if (BUILD_SHARED_LIBS)
add_library(${BIORBD_NAME} SHARED ${SRC_LIST})
else()
add_library(${BIORBD_NAME} STATIC ${SRC_LIST})
endif()
set_target_properties(${BIORBD_NAME} PROPERTIES DEBUG_POSTFIX "_debug")
# Remember the BINARY_DIR (important if biorbd is used as submodule)
set(BIORBD_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
# Create the configuration header file associated with the asked options
configure_file(${CMAKE_SOURCE_DIR}/include/biorbdConfig.h.in
"${BIORBD_BINARY_DIR}/include/biorbdConfig.h"
)
# Add headers
# Include directories when building the library:
target_include_directories(${BIORBD_NAME} PRIVATE
"${CMAKE_SOURCE_DIR}/include"
"${BIORBD_BINARY_DIR}/include"
"${RBDL_INCLUDE_DIR}"
"${MATH_BACKEND_INCLUDE_DIR}"
"${TinyXML_INCLUDE_DIR}"
)
# Include directories when other targets in this project use this library:
target_include_directories(${BIORBD_NAME} INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${BIORBD_BINARY_DIR}/include>
)
# Installation directories
if(WIN32)
set(${BIORBD_NAME}_LIB_FOLDER "Lib")
set(${BIORBD_NAME}_BIN_FOLDER "bin")
set(${BIORBD_NAME}_INCLUDE_FOLDER "include/${BIORBD_NAME}")
set(${BIORBD_NAME}_CMAKECONFIG_DIR "Lib/cmake/${BIORBD_NAME}")
else()
set(${BIORBD_NAME}_LIB_FOLDER "lib/${BIORBD_NAME}")
set(${BIORBD_NAME}_BIN_FOLDER "${CMAKE_INSTALL_PREFIX}/lib/${BIORBD_NAME}")
set(${BIORBD_NAME}_INCLUDE_FOLDER "include/${BIORBD_NAME}")
set(${BIORBD_NAME}_CMAKECONFIG_DIR "lib/cmake/${BIORBD_NAME}")
endif()
set_target_properties(${BIORBD_NAME} PROPERTIES
INSTALL_RPATH "${${BIORBD_NAME}_BIN_FOLDER}"
INSTALL_RPATH_USE_LINK_PATH TRUE
)
# Add the different modules of biorbd
set(BIORBD_MODULE_NAMES)
# Utils
add_subdirectory("src/Utils")
list(APPEND BIORBD_MODULE_NAMES "${UTILS_MODULE_NAME}")
# Utils
add_subdirectory("src/RigidBody")
list(APPEND BIORBD_MODULE_NAMES "${RIGIDBODY_MODULE_NAME}")
if (MODULE_ACTUATORS OR MODULE_MUSCLES OR MODULE_PASSIVE_TOQUES OR MODULE_LIGAMENTS)
add_subdirectory("src/InternalForces")
list(APPEND BIORBD_MODULE_NAMES "${INTERNAL_FORCES_MODULE_NAME}")
endif()
if (MODULE_MUSCLES)
add_subdirectory("src/InternalForces/Muscles")
list(APPEND BIORBD_MODULE_NAMES "${MUSCLES_MODULE_NAME}")
endif()
if (MODULE_PASSIVE_TORQUES)
add_subdirectory("src/InternalForces/PassiveTorques")
list(APPEND BIORBD_MODULE_NAMES "${PASSIVE_TORQUES_MODULE_NAME}")
endif()
if (MODULE_LIGAMENTS)
add_subdirectory("src/InternalForces/Ligaments")
list(APPEND BIORBD_MODULE_NAMES "${LIGAMENTS_MODULE_NAME}")
endif()
if (MODULE_ACTUATORS)
add_subdirectory("src/InternalForces/Actuators")
list(APPEND BIORBD_MODULE_NAMES "${ACTUATORS_MODULE_NAME}")
endif()
# Add linker
target_link_libraries(${BIORBD_NAME}
"${BIORBD_MODULE_NAMES}"
"${RBDL_LIBRARY}"
"${MATH_BACKEND_LIBRARIES}"
"${IPOPT_LIBRARY}"
"${TinyXML_LIBRARY}"
)
# install target
install(
TARGETS ${BIORBD_NAME} EXPORT biorbdTargets
ARCHIVE DESTINATION "${${BIORBD_NAME}_LIB_FOLDER}"
RUNTIME DESTINATION "${${BIORBD_NAME}_BIN_FOLDER}"
LIBRARY DESTINATION "${${BIORBD_NAME}_LIB_FOLDER}"
)
install(DIRECTORY include/
DESTINATION "${${BIORBD_NAME}_INCLUDE_FOLDER}"
PATTERN "*.h.in" EXCLUDE
)
# Include directories when a client uses the library from an installed biorbd:
target_include_directories(${BIORBD_NAME} INTERFACE
$<INSTALL_INTERFACE:${${BIORBD_NAME}_INCLUDE_FOLDER}>
)
install(FILES "${BIORBD_BINARY_DIR}/include/biorbdConfig.h"
DESTINATION "${${BIORBD_NAME}_INCLUDE_FOLDER}"
)
# Prepare share
if(WIN32 AND NOT CYGWIN)
set(CMAKE_SHARE_DIR cmake)
else()
set(CMAKE_SHARE_DIR lib/cmake/${BIORBD_NAME})
endif()
include(CMakePackageConfigHelpers)
configure_package_config_file(
"share/${BIORBD_NAME}Config.cmake.in"
"${BIORBD_BINARY_DIR}/${BIORBD_NAME}Config.cmake"
INSTALL_DESTINATION "${CMAKE_SHARE_DIR}"
)
install(FILES
"${BIORBD_BINARY_DIR}/${BIORBD_NAME}Config.cmake"
DESTINATION "${CMAKE_SHARE_DIR}"
)
# uninstall target
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${BIORBD_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY
)
add_custom_target(uninstall
COMMAND "${CMAKE_COMMAND}" -P
"${BIORBD_BINARY_DIR}/cmake_uninstall.cmake"
)
endif()
# Add binding subdirectory
add_subdirectory("binding")
# Add the example if asked
if (BUILD_EXAMPLE)
add_subdirectory("examples")
endif()
# Doc
if (BUILD_DOC)
add_subdirectory("doc")
endif (BUILD_DOC)
# Testing
if (BUILD_TESTS)
add_subdirectory("test")
endif()