forked from pyomeca/biorbd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
252 lines (221 loc) · 7.58 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
cmake_minimum_required(VERSION 3.8)
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.0")
cmake_policy(SET CMP0042 NEW)
endif()
project(biorbd VERSION 1.3.5)
set (CMAKE_CXX_STANDARD 11)
set (BIORBD_NAME ${PROJECT_NAME})
# Set some variables
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/modules")
# 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")
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
find_package(RBDL REQUIRED)
if(${MATH_LIBRARY_BACKEND} STREQUAL "Eigen3")
find_package(Eigen3 REQUIRED)
set(MATH_BACKEND_INCLUDE_DIR "${EIGEN3_INCLUDE_DIR}")
set(MATH_BACKEND_LIBRARIES "")
set(BIORBD_USE_EIGEN3_MATH true)
set(BIORBD_USE_CASADI_MATH false)
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}")
set(BIORBD_USE_EIGEN3_MATH false)
set(BIORBD_USE_CASADI_MATH true)
endif()
find_package(IPOPT)
find_package(TinyXML)
# Manage options
option(MODULE_KALMAN "If Kalman filter should be compiled" ON)
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()
if (IPOPT_FOUND)
option(MODULE_STATIC_OPTIM "If Static optimization should be compiled" ON)
if (BIORBD_USE_CASADI_MATH)
set(MODULE_STATIC_OPTIM OFF CACHE BOOL
"Static optimization can't be compiled along with Casadi" FORCE)
endif()
else()
set(IPOPT_INCLUDE_DIR "")
set(IPOPT_LIBRARY "")
set(MODULE_STATIC_OPTIM OFF CACHE BOOL
"Static optimization can't be compiled since Ipopt was not found" FORCE)
endif()
if (TinyXML_FOUND)
option(MODULE_VTP_FILES_READER
"If reader for geometry vtp files from opensim should be compiled" ON)
else()
set(TinyXML_INCLUDE_DIR "")
set(TinyXML_LIBRARY "")
set(MODULE_VTP_FILES_READER OFF CACHE BOOL
"VTP cannot be used since TinyXML was not found" FORCE)
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}"
"${RBDL_INCLUDE_DIR}/.."
"${MATH_BACKEND_INCLUDE_DIR}"
"${TinyXML_INCLUDE_DIR}"
)
# Include directories when other targets in this project use this library:
target_include_directories(${PROJECT_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}")
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}")
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}")
# Actuators
option(MODULE_ACTUATORS
"Choose if the module actuators is to be added to biorbd" ON)
if (MODULE_ACTUATORS)
add_subdirectory("src/Actuators")
list(APPEND BIORBD_MODULE_NAMES "${ACTUATOR_MODULE_NAME}")
endif()
# Muscles
option(MODULE_MUSCLES
"Choose if the module actuators is to be added to biorbd" ON)
if (MODULE_MUSCLES)
add_subdirectory("src/Muscles")
list(APPEND BIORBD_MODULE_NAMES "${MUSCLE_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
include(CMakePackageConfigHelpers)
configure_package_config_file(
"share/${BIORBD_NAME}Config.cmake.in"
"${BIORBD_BINARY_DIR}/${BIORBD_NAME}Config.cmake"
INSTALL_DESTINATION "${BIORBD_NAME}_LIB_FOLDER/cmake"
)
install(FILES
"${BIORBD_BINARY_DIR}/${BIORBD_NAME}Config.cmake"
DESTINATION "${${BIORBD_NAME}_LIB_FOLDER}/cmake"
)
# 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
option(BUILD_EXAMPLE "Build a C++ example" ON)
if (BUILD_EXAMPLE)
add_subdirectory("examples")
endif()
# Doc
option(BUILD_DOC "Build documentation" OFF)
if (BUILD_DOC)
add_subdirectory("doc")
endif (BUILD_DOC)
# Testing
option(BUILD_TESTS "Build all tests." OFF) # Makes boolean 'test' available.
if (BUILD_TESTS)
add_subdirectory("test")
endif()