forked from Simple-Robotics/aligator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
324 lines (264 loc) · 11.4 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
#
# Copyright (C) 2022 LAAS-CNRS, INRIA
#
cmake_minimum_required(VERSION 3.12)
set(PROJECT_NAME aligator)
set(PROJECT_DESCRIPTION
"A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.")
set(PROJECT_URL "https://github.com/Simple-Robotics/aligator")
set(PROJECT_CUSTOM_HEADER_EXTENSION "hpp")
set(PROJECT_USE_KEYWORD_LINK_LIBRARIES True)
set(CXX_DISABLE_WERROR True)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(PROJECT_USE_CMAKE_EXPORT True)
option(INSTALL_DOCUMENTATION "Generate and install the documentation" ON)
set(DOXYGEN_USE_MATHJAX YES)
set(DOXYGEN_USE_TEMPLATE_CSS YES)
include(${CMAKE_CURRENT_LIST_DIR}/cmake/base.cmake)
compute_project_args(PROJECT_ARGS LANGUAGES CXX)
project(${PROJECT_NAME} ${PROJECT_ARGS})
set(CMAKE_VERBOSE_MAKEFILE OFF)
include(${CMAKE_CURRENT_LIST_DIR}/cmake/boost.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/cmake/ide.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/cmake/apple.cmake)
if(APPLE) # Use the handmade approach
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake/find-external/OpenMP ${CMAKE_MODULE_PATH})
elseif(UNIX)
if(${CMAKE_VERSION} VERSION_GREATER "3.20.0" OR ${CMAKE_VERSION} VERSION_EQUAL "3.20.0")
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake/find-external/OpenMP ${CMAKE_MODULE_PATH})
endif()
endif(APPLE)
include(CMakeDependentOption)
apply_default_apple_configuration()
if(WIN32)
set(LINK copy_if_different)
else(WIN32)
set(LINK create_symlink)
endif(WIN32)
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." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel"
"RelWithDebInfo")
endif()
# --- OPTIONS ----------------------------------------
option(BUILD_PYTHON_INTERFACE "Build the Python bindings" ON)
option(BUILD_WITH_VERSION_SUFFIX "Build libraries with version appended to suffix" OFF)
option(ENABLE_TEMPLATE_INSTANTIATION "Template instantiation of the main library" ON)
# --- OPTIONAL DEPENDENCIES -------------------------
option(BUILD_WITH_PINOCCHIO_SUPPORT "Build the library with support for Pinocchio" ON)
option(BUILD_CROCODDYL_COMPAT "Build the Crocoddyl compatibility module" OFF)
option(BUILD_WITH_OPENMP_SUPPORT "Build the library with the OpenMP support" ON)
option(BUILD_BENCHMARKS "Build benchmarks" ON)
option(BUILD_EXAMPLES "Build examples" ON)
cmake_dependent_option(
GENERATE_PYTHON_STUBS "Generate the Python stubs associated to the Python library" ON
BUILD_PYTHON_INTERFACE OFF)
option(INITIALIZE_WITH_NAN "Initialize Eigen entries with NaN" OFF)
option(CHECK_RUNTIME_MALLOC "Check if some memory allocations are performed at runtime" OFF)
# Variable containing all the cflags definition relative to optional dependencies
# and options
set(CFLAGS_DEPENDENCIES)
if(INITIALIZE_WITH_NAN)
message(STATUS "Initialize with NaN all the Eigen entries.")
add_compile_definitions(EIGEN_INITIALIZE_MATRICES_BY_NAN)
endif(INITIALIZE_WITH_NAN)
if(CHECK_RUNTIME_MALLOC)
message(STATUS "Check if some memory allocations are performed at runtime.")
add_compile_definitions(ALIGATOR_EIGEN_CHECK_MALLOC)
add_compile_definitions(EIGEN_RUNTIME_NO_MALLOC)
endif(CHECK_RUNTIME_MALLOC)
if(ENABLE_TEMPLATE_INSTANTIATION)
add_compile_definitions(ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION)
list(APPEND CFLAGS_DEPENDENCIES "-DALIGATOR_ENABLE_TEMPLATE_INSTANTIATION")
endif(ENABLE_TEMPLATE_INSTANTIATION)
# ----------------------------------------------------
# --- DEPENDENCIES -----------------------------------
# ----------------------------------------------------
add_project_dependency(Eigen3 3.3.7 REQUIRED PKG_CONFIG_REQUIRES "eigen3 >= 3.3.7")
add_project_dependency(fmt "9.1.0...<11" REQUIRED PKG_CONFIG_REQUIRES "fmt >= 9.1.0")
if(BUILD_WITH_OPENMP_SUPPORT)
message(STATUS "Building with OpenMP support.")
find_package(OpenMP REQUIRED)
add_compile_definitions(ALIGATOR_MULTITHREADING)
list(APPEND CFLAGS_DEPENDENCIES "-DALIGATOR_MULTITHREADING")
endif()
if(BUILD_WITH_PINOCCHIO_SUPPORT)
message(STATUS "Building with Pinocchio support.")
add_compile_definitions(ALIGATOR_WITH_PINOCCHIO)
list(APPEND CFLAGS_DEPENDENCIES "-DALIGATOR_WITH_PINOCCHIO")
endif()
if(BUILD_CROCODDYL_COMPAT)
message(STATUS "Building with Crocoddyl compatibility.")
add_compile_definitions(ALIGATOR_WITH_CROCODDYL_COMPAT)
list(APPEND CFLAGS_DEPENDENCIES "-DALIGATOR_WITH_CROCODDYL_COMPAT")
endif()
set(BOOST_REQUIRED_COMPONENTS filesystem)
set_boost_default_options()
export_boost_default_options()
add_project_dependency(Boost REQUIRED COMPONENTS ${BOOST_REQUIRED_COMPONENTS})
if(BUILD_PYTHON_INTERFACE)
set(PYTHON_COMPONENTS Interpreter Development.Module NumPy Development)
add_project_dependency(eigenpy 3.1.0 REQUIRED PKG_CONFIG_REQUIRES "eigenpy >= 3.1.0")
set(PYLIB_NAME "py${PROJECT_NAME}")
set(${PYLIB_NAME}_INSTALL_DIR ${PYTHON_SITELIB}/${PROJECT_NAME})
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "import platform; print(platform.python_implementation())"
OUTPUT_VARIABLE _python_implementation_value
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
message(STATUS "Python compiler: ${_python_implementation_value}")
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "import proxsuite_nlp"
RESULT_VARIABLE _proxsuite_nlp_python_bindings_not_found
OUTPUT_QUIET ERROR_QUIET)
if(_proxsuite_nlp_python_bindings_not_found EQUAL 0)
message(STATUS "Found proxsuite_nlp Python bindings.")
else()
message(FATAL_ERROR "proxsuite_nlp Python bindings NOT found.")
endif()
unset(_proxsuite_nlp_python_bindings_not_found)
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "import pinocchio"
RESULT_VARIABLE _pinocchio_python_bindings_not_found
OUTPUT_QUIET ERROR_QUIET)
if(_pinocchio_python_bindings_not_found EQUAL 0)
message(STATUS "Found pinocchio Python bindings.")
set(BUILD_WITH_PINOCCHIO_PYTHON_BINDINGS True)
else()
message(STATUS "pinocchio Python bindings NOT found.")
endif()
unset(_pinocchio_python_bindings_not_found)
endif(BUILD_PYTHON_INTERFACE)
add_project_dependency(proxsuite-nlp 0.2.3 REQUIRED)
set(LIB_SOURCES src/utils/logger.cpp)
file(GLOB_RECURSE LIB_HEADERS ${PROJECT_SOURCE_DIR}/include/aligator/*.hpp
${PROJECT_SOURCE_DIR}/include/aligator/*.hxx)
if(ENABLE_TEMPLATE_INSTANTIATION)
file(
GLOB_RECURSE
LIB_TEMPLATE_SOURCES
${PROJECT_SOURCE_DIR}/src/core/*.cpp
${PROJECT_SOURCE_DIR}/src/solvers/fddp/*.cpp
${PROJECT_SOURCE_DIR}/src/solvers/proxddp/*.cpp
${PROJECT_SOURCE_DIR}/src/modelling/*.cpp
${PROJECT_SOURCE_DIR}/src/parlqr/*.cpp)
file(GLOB_RECURSE LIB_TEMPLATE_DECLARATIONS ${PROJECT_SOURCE_DIR}/include/aligator/*.txx)
list(APPEND LIB_HEADERS ${LIB_TEMPLATE_DECLARATIONS})
list(APPEND LIB_SOURCES ${LIB_TEMPLATE_SOURCES})
endif(ENABLE_TEMPLATE_INSTANTIATION)
list(FILTER LIB_HEADERS EXCLUDE REGEX ${PROJECT_SOURCE_DIR}/include/aligator/compat/*)
# Create the main shared library.
function(create_library)
add_library(${PROJECT_NAME} SHARED ${LIB_HEADERS} ${LIB_SOURCES})
set_target_properties(
${PROJECT_NAME}
PROPERTIES LINKER_LANGUAGE CXX
VERSION ${PROJECT_VERSION}
INSTALL_RPATH "\$ORIGIN")
if(BUILD_WITH_PINOCCHIO_SUPPORT)
target_link_libraries(${PROJECT_NAME} PUBLIC pinocchio::pinocchio)
endif(BUILD_WITH_PINOCCHIO_SUPPORT)
if(BUILD_WITH_OPENMP_SUPPORT)
target_link_libraries(${PROJECT_NAME} PRIVATE OpenMP::OpenMP_CXX)
endif(BUILD_WITH_OPENMP_SUPPORT)
target_link_libraries(${PROJECT_NAME} PUBLIC proxsuite-nlp::proxsuite-nlp)
target_link_libraries(${PROJECT_NAME} PUBLIC Boost::boost)
target_link_libraries(${PROJECT_NAME} PUBLIC fmt::fmt)
# set the install-tree include dirs
# used by dependent projects to consume this target
target_include_directories(${PROJECT_NAME} PUBLIC $<INSTALL_INTERFACE:include>)
foreach(headerFile ${LIB_HEADERS})
string(REGEX REPLACE "${PROJECT_SOURCE_DIR}/" "" headerFileRelative ${headerFile})
get_filename_component(headerPath ${headerFileRelative} PATH)
install(
FILES ${headerFileRelative}
DESTINATION ${headerPath}
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ OWNER_WRITE)
endforeach(headerFile ${LIB_HEADERS})
endfunction()
create_library()
add_header_group(LIB_HEADERS)
add_source_group(LIB_SOURCES)
install(
TARGETS ${PROJECT_NAME}
EXPORT ${TARGETS_EXPORT_NAME}
INCLUDES
DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR})
if(BUILD_CROCODDYL_COMPAT)
add_project_dependency(crocoddyl REQUIRED)
add_subdirectory(src/compat/crocoddyl)
endif()
add_subdirectory(bindings)
# benchmarks, examples, and tests
macro(create_ex_or_bench exfile exname)
add_executable(${exname} ${exfile})
message(STATUS "Adding cpp example ${exname}")
set_target_properties(${exname} PROPERTIES LINKER_LANGUAGE CXX)
target_include_directories(${exname} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(${exname} PUBLIC ${PROJECT_NAME})
target_link_libraries(${exname} PUBLIC Boost::filesystem)
if(BUILD_WITH_OPENMP_SUPPORT)
target_link_libraries(${exname} PRIVATE OpenMP::OpenMP_CXX)
endif()
endmacro()
macro(target_add_example_robot_data target_name)
target_link_libraries(${target_name} PRIVATE example-robot-data::example-robot-data)
endmacro()
if(BUILD_WITH_PINOCCHIO_SUPPORT AND (BUILD_EXAMPLES OR BUILD_BENCHMARKS))
find_package(example-robot-data 4.0.9 REQUIRED)
endif()
# create an utility library to avoid recompiling crocoddyl talos arm problem
# used in examples and benchmarks
if(BUILD_CROCODDYL_COMPAT)
add_library(croc_talos_arm_utils STATIC ${CMAKE_SOURCE_DIR}/examples/croc-talos-arm.cpp
${CMAKE_SOURCE_DIR}/examples/croc-talos-arm.hpp)
target_include_directories(croc_talos_arm_utils PUBLIC ${CMAKE_SOURCE_DIR}/examples)
target_link_libraries(croc_talos_arm_utils PUBLIC ${PROJECT_NAME} Boost::boost
crocoddyl::crocoddyl)
target_add_example_robot_data(croc_talos_arm_utils)
endif()
if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
if(BUILD_BENCHMARKS)
add_subdirectory(bench)
endif()
if(BUILD_TESTING)
add_subdirectory(tests)
endif()
# --- PACKAGING ----------------------------------------------------------------
macro(EXPORT_VARIABLE var_name var_value)
get_directory_property(has_parent PARENT_DIRECTORY)
if(has_parent)
set(${var_name}
${var_value}
PARENT_SCOPE)
else()
set(${var_name} ${var_value})
endif()
string(APPEND PACKAGE_EXTRA_MACROS "\nset(${var_name} ${var_value})")
endmacro()
if(BUILD_WITH_PINOCCHIO_SUPPORT)
export_variable(ALIGATOR_WITH_PINOCCHIO_SUPPORT ON)
endif()
if(BUILD_PYTHON_INTERFACE)
export_variable(ALIGATOR_WITH_PYTHON_INTERFACE ON)
endif()
if(BUILD_WITH_OPENMP_SUPPORT)
export_variable(ALIGATOR_WITH_OPENMP_SUPPORT ON)
endif()
if(BUILD_CROCODDYL_COMPAT)
export_variable(ALIGATOR_WITH_CROCODDYL_COMPAT ON)
pkg_config_append_libs(aligator_croc_compat)
endif()
pkg_config_append_libs(${PROJECT_NAME})
pkg_config_append_boost_libs(${BOOST_REQUIRED_COMPONENTS})
pkg_config_append_cflags("${CFLAGS_DEPENDENCIES}")
# Install catkin package.xml
install(FILES package.xml DESTINATION share/${PROJECT_NAME})