-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
394 lines (343 loc) · 14.8 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
cmake_minimum_required(VERSION 3.1)
project(orca VERSION 2.0.0)
set(CMAKE_POSITION_INDEPENDENT_CODE True)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
include(CMakePackageConfigHelpers)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
# fix the eigen _ENABLE_EXTENDED_ALIGNED_STORAGE error on msvc 2017
if(WIN32)
set(BUILD_SHARED_LIBS OFF)
add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE=1)
endif()
if(NOT BUILD_SHARED_LIBS)
set(BUILD_SHARED_LIBS ON)
endif()
set(build_shared_libs_saved ${BUILD_SHARED_LIBS})
#################### Xenomai ###########################
find_package(Xenomai QUIET)
if(XENOMAI_FOUND)
message(STATUS "[ORCA] Building with Xenomai mutexes")
endif()
#################### Eigen3 ###########################
if(EIGEN3_INCLUDE_DIR)
unset(EIGEN3_INCLUDE_DIR CACHE)
endif()
if(EIGEN3_VERSION)
unset(EIGEN3_VERSION CACHE)
endif()
find_package(Eigen3 QUIET)
if(Eigen3_FOUND)
set(system_eigen3_include_dir ${EIGEN3_INCLUDE_DIR})
set(system_eigen3_version ${EIGEN3_VERSION})
endif()
# iDynTree requires Eigen > 3.2
find_package(Eigen3 3.2.92 QUIET)
if(Eigen3_FOUND)
message(STATUS "Eigen3 ${system_eigen3_version} (> 3.2) found at ${system_eigen3_include_dir}")
else()
if(EIGEN3_INCLUDE_DIR)
unset(EIGEN3_INCLUDE_DIR CACHE)
endif()
if(EIGEN3_VERSION)
unset(EIGEN3_VERSION CACHE)
endif()
# NOTE: Adding the eigen project allows all the checks for processor features
# and system environnement libraries.
# It might be useful to add this on a very particular system to get some
# very specific processor features and link agains the right BLAS for example.
# Ex of an issue in a Xenomai env : http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1482
# Some linking issues might happend, which are fixed with the 'auto' config
# of eigen subdir. This is considered necessary for the code to be portable
set(BUILD_TESTING OFF CACHE BOOL "Disable eigen tests")
set(eigen_dir ${PROJECT_SOURCE_DIR}/external/eigen-3.3.5)
if(system_eigen3_found)
message(WARNING "Found system Eigen3 ${system_eigen3_version} at ${system_eigen3_include_dir}, but internal iDynTree requires at least 3.2.
ORCA will build using internal Eigen3 (3.3.5) for the build but will not overwrite the system version.")
# it means we have it on the system, just not the right version
# so we dont mess with the system libs
add_subdirectory(${eigen_dir}/eigen3 EXCLUDE_FROM_ALL)
else()
message(WARNING "Using internal Eigen3 (3.3.5) for the build. ORCA will export it as the system does not seem to have eigen3 installed")
# export/install the package as we really dont have eigen on the system
add_subdirectory(${eigen_dir}/eigen3)
endif()
set(ENV{EIGEN3_ROOT} ${eigen_dir})
set(EIGEN3_ROOTDIR $ENV{EIGEN3_ROOT})
set(EIGEN3_INCLUDE_DIR ${eigen_dir}/eigen3)
add_library(Eigen3::Eigen ALIAS eigen)
endif()
#################### TinyXML ###########################
set(tinyxml_SOURCE_DIR external/tinyxml/src)
add_library(${PROJECT_NAME}_priv_tinyxml STATIC
${tinyxml_SOURCE_DIR}/tinyxml.cpp
${tinyxml_SOURCE_DIR}/tinyxmlerror.cpp
${tinyxml_SOURCE_DIR}/tinyxmlparser.cpp
)
target_include_directories(${PROJECT_NAME}_priv_tinyxml PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/${tinyxml_SOURCE_DIR}>)
#################### qpOASES ##########################
set(qpOASES_INCLUDE_DIRS external/qpOASES-3.2.1/include)
file(GLOB qpOASES_srcs ${PROJECT_SOURCE_DIR}/external/qpOASES-3.2.1/src/*.cpp)
add_library(${PROJECT_NAME}_priv_qpOASES STATIC ${qpOASES_srcs})
target_compile_definitions(${PROJECT_NAME}_priv_qpOASES PRIVATE __NO_COPYRIGHT__)
target_include_directories(${PROJECT_NAME}_priv_qpOASES PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/external/qpOASES-3.2.1/include>)
#################### OSQP #########################
set(UNITTESTS OFF CACHE BOOL "")
set(PROFILING OFF CACHE BOOL "")
set(ENABLE_MKL_PARDISO OFF CACHE BOOL "")
set(DLONG OFF CACHE BOOL "Use int instead of long long for storing the indexes to match eigen sparseviews")
add_subdirectory(external/osqp-0.3.0 EXCLUDE_FROM_ALL)
#################### libxml2 #########################
# TODO : Make a properer cmake for libxml2
find_package(LibXml2 QUIET)
if(NOT LIBXML2_FOUND)
message(STATUS "Using embedded libxml2 2.9.8")
add_subdirectory(external/libxml2 EXCLUDE_FROM_ALL)
set(LIBXML2_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/external/libxml2/libxml2-2.9.8/include )
set(LIBXML2_LIBRARY xml2 )
set(LIBXML2_FOUND TRUE )
set(LIBXML2_INCLUDE_DIRS ${LIBXML2_INCLUDE_DIR} )
set(LIBXML2_LIBRARIES ${LIBXML2_LIBRARY} )
endif()
#################### iDynTree #########################
set(BUILD_SHARED_LIBS OFF)
set(IDYNTREE_SHARED_LIBRARY OFF CACHE BOOL "")
set(__ADD_UNINSTALL_TARGET_INCLUDED TRUE CACHE BOOL "")
set(IDYNTREE_USES_YARP FALSE CACHE BOOL "")
set(IDYNTREE_USES_ICUB_MAIN FALSE CACHE BOOL "")
if(EXISTS ${PROJECT_SOURCE_DIR}/external/idyntree/)
message(WARNING "Detected idyntree git version. Dev only !")
add_subdirectory(${PROJECT_SOURCE_DIR}/external/idyntree EXCLUDE_FROM_ALL)
else()
add_subdirectory(${PROJECT_SOURCE_DIR}/external/idyntree-fe5a3d7 EXCLUDE_FROM_ALL)
endif()
set(BUILD_SHARED_LIBS ${build_shared_libs_saved})
#################### Yaml cpp #########################
find_package(yaml-cpp QUIET)
if(NOT yaml-cpp_FOUND)
message(STATUS "Using embedded yaml-cpp master branch 28-sept-2018")
set(BUILD_SHARED_LIBS OFF)
set(YAML_CPP_BUILD_TESTS OFF CACHE BOOL "")
set(YAML_CPP_BUILD_TOOLS OFF CACHE BOOL "")
set(YAML_CPP_BUILD_CONTRIB OFF CACHE BOOL "")
#add_subdirectory(${PROJECT_SOURCE_DIR}/external/yaml-cpp-master/ EXCLUDE_FROM_ALL)
# TODO: Figure out how to remove yaml-cpp from headers
add_subdirectory(${PROJECT_SOURCE_DIR}/external/yaml-cpp-master/)
set(BUILD_SHARED_LIBS ${build_shared_libs_saved})
endif()
#################### Catkin ###########################
find_package(catkin QUIET)
#################### Matplotlib #########################
set(ORCA_BUILD_PLOT_EXAMPLE OFF CACHE BOOL "")
if(ORCA_BUILD_PLOT_EXAMPLE)
find_package(PythonLibs REQUIRED)
find_package(NumPy REQUIRED)
set(matplotlibcpp_include_dirs ${PROJECT_SOURCE_DIR}/external/matplotlibcpp/include)
endif()
#################### Catkin package ###########################
if(catkin_FOUND)
catkin_package(
INCLUDE_DIRS include ${EIGEN3_INCLUDE_DIR} ${matplotlibcpp_include_dirs} external/plog-1.1.4/include
LIBRARIES orca ${PYTHON_LIBRARIES} yaml-cpp
CFG_EXTRAS orca-extras.cmake
)
else()
set(CATKIN_GLOBAL_BIN_DESTINATION bin)
set(CATKIN_GLOBAL_LIB_DESTINATION lib)
set(CATKIN_GLOBAL_LIBEXEC_DESTINATION lib)
set(CATKIN_GLOBAL_INCLUDE_DESTINATION include)
set(CATKIN_PACKAGE_LIB_DESTINATION ${CATKIN_GLOBAL_LIB_DESTINATION})
set(CATKIN_GLOBAL_SHARE_DESTINATION share)
set(CATKIN_PACKAGE_SHARE_DESTINATION ${CATKIN_GLOBAL_SHARE_DESTINATION}/${PROJECT_NAME})
set(CATKIN_PACKAGE_BIN_DESTINATION ${CATKIN_GLOBAL_LIBEXEC_DESTINATION}/${PROJECT_NAME})
set(CATKIN_PACKAGE_INCLUDE_DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}/${PROJECT_NAME})
endif()
#################### ORCA #########################
set(sub-dirs
optim
constraint
common
math
robot
task
utils
)
foreach(sub : ${sub-dirs})
file(GLOB sub-srcs src/${sub}/*.cc)
list(APPEND lib-srcs ${sub-srcs})
endforeach()
source_group("Source Files" FILES ${lib-srcs})
foreach(sub : ${sub-dirs})
file(GLOB sub-hdrs include/orca/${sub}/*.h include/orca/${sub}/*.hh)
list(APPEND lib-hdrs ${sub-hdrs})
endforeach()
source_group("Header Files" FILES ${lib-hdrs})
add_library(orca ${lib-srcs})
target_compile_features(orca PUBLIC
cxx_auto_type
cxx_generalized_initializers
cxx_lambdas
)
target_include_directories(
orca PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_include_directories(
orca PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/external/plog-1.1.4/include>
$<INSTALL_INTERFACE:include>
)
#################### Matplotlib #########################
if(PYTHONLIBS_FOUND AND NUMPY_FOUND)
target_include_directories(
orca PUBLIC
$<BUILD_INTERFACE:${PYTHON_INCLUDE_DIRS}>
$<BUILD_INTERFACE:${matplotlibcpp_include_dirs}>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(orca PUBLIC ${PYTHON_LIBRARIES})
install(DIRECTORY ${matplotlibcpp_include_dirs}/matplotlibcpp/ DESTINATION include/matplotlibcpp)
endif()
#################### Public linking #########################
target_link_libraries(orca PUBLIC Eigen3::Eigen yaml-cpp)
if(XENOMAI_FOUND)
target_compile_definitions(orca PRIVATE CONFIG_XENO_VERSION_MAJOR=${XENOMAI_VERSION_MAJOR})
target_include_directories(orca PRIVATE ${XENOMAI_INCLUDE_DIRS})
target_link_libraries(orca PRIVATE ${XENOMAI_LIBRARIES})
endif()
target_include_directories(orca PRIVATE ${PROJECT_SOURCE_DIR}/external/eigquadprog)
#################### Private linking #########################
target_link_libraries(orca PRIVATE
idyntree-high-level
${PROJECT_NAME}_priv_qpOASES
osqpstatic
${PROJECT_NAME}_priv_tinyxml
${LIBXML2_LIBRARY}
)
#################### ORCA Examples #########################
add_subdirectory(examples)
#################### ORCA Tests #########################
add_subdirectory(tests)
#################### Linter #########################
add_custom_target( ${PROJECT_NAME}-compile-commands ALL
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json
${PROJECT_SOURCE_DIR}
COMMENT "Copying 'compile_commands.json' to '${PROJECT_SOURCE_DIR}'"
)
#################### Doxygen #########################
# TODO: This code would be useful as a standalone module for pure doxygen builds
# FIXME: We are using RTD to build the doxygen now. Remove this once, the module has been made.
# option(BUILD_API_DOC "Build documentation" OFF)
#
# if(BUILD_API_DOC)
# # check if Doxygen is installed
# find_package(Doxygen QUIET)
# if (DOXYGEN_FOUND)
# # set input and output files
# set(DOXYGEN_IN ${PROJECT_SOURCE_DIR}/docs/Doxyfile.in)
# set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
#
# # request to configure the file
# configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
# message("Doxygen build started")
#
# add_custom_target( doc_doxygen ALL
# COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
# WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
# COMMENT "Generating API documentation with Doxygen"
# VERBATIM )
# else (DOXYGEN_FOUND)
# message(WARNING "Doxygen needs to be installed to generate the doxygen documentation")
# endif (DOXYGEN_FOUND)
# endif(BUILD_API_DOC)
#################### Catkin devel support #########################
# In a catkin environnement, overwrite the generated config.cmake
# so we can export customs targets and include directories like eigen3
# Note that we need to copy eigen3 for ubuntu 14.04 that has eigen 3.0.x
# and does not have a FindEigen3.cmake
# catkin devel support
# if(catkin_FOUND)
#
# add_custom_target( ${PROJECT_NAME}-targets-copy ALL
# DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/orcaTargets.cmake
# COMMAND ${CMAKE_COMMAND} -E copy
# ${CMAKE_CURRENT_BINARY_DIR}/orcaTargets.cmake
# ${CATKIN_DEVEL_PREFIX}/share/${PROJECT_NAME}/cmake/orcaTargets.cmake
# COMMENT "Copying 'orcaTargets.cmake' to '${CATKIN_DEVEL_PREFIX}/share/${PROJECT_NAME}/cmake'"
# )
# add_custom_target( ${PROJECT_NAME}-eigen-copy ALL
# COMMAND ${CMAKE_COMMAND} -E copy
# ${PROJECT_SOURCE_DIR}/cmake/FindEigen3.cmake
# ${CATKIN_DEVEL_PREFIX}/share/${PROJECT_NAME}/cmake/FindEigen3.cmake
# COMMENT "Copying 'FindEigen3.cmake' to '${CATKIN_DEVEL_PREFIX}/share/${PROJECT_NAME}/cmake'"
# )
# add_custom_target( ${PROJECT_NAME}-config-copy ALL
# DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/orcaConfig.cmake
# COMMAND ${CMAKE_COMMAND} -E copy
# ${CMAKE_CURRENT_BINARY_DIR}/orcaConfig.cmake
# ${CATKIN_DEVEL_PREFIX}/share/${PROJECT_NAME}/cmake/orcaConfig.cmake
# COMMENT "Copying 'orcaConfig.cmake' to '${CATKIN_DEVEL_PREFIX}/share/${PROJECT_NAME}/cmake'"
# )
# endif()
#################### ORCA Install #########################
# Exporting private targets because of https://gitlab.kitware.com/cmake/cmake/issues/17357
install(TARGETS orca
EXPORT orcaTargets
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
)
install(DIRECTORY include/
DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.hh"
PATTERN "*.hpp"
PATTERN "*.inl"
PATTERN "*.in" EXCLUDE
)
install(DIRECTORY external/plog-1.1.4/include/
DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}
)
install(FILES
${PROJECT_SOURCE_DIR}/cmake/FindEigen3.cmake
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/cmake
)
# Plain cmake support
if(NOT catkin_FOUND)
set(INCLUDE_INSTALL_DIR ${CATKIN_PACKAGE_INCLUDE_DESTINATION})
configure_package_config_file(cmake/orcaConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/orcaConfig.cmake
INSTALL_DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/cmake
PATH_VARS INCLUDE_INSTALL_DIR
)
# Cmake Package
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/orcaConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
export(EXPORT orcaTargets
FILE "${CMAKE_CURRENT_BINARY_DIR}/orcaTargets.cmake"
NAMESPACE orca::
)
# This creates a package in ~/.cmake so we don't have to 'make install'
# and extend the CMAKE_PREFIX_PATH. This is equivalent to installing in /usr or
# /usr/local (standard path) but without sudo rights.
# With this, any cmake project calling find_package(orca) will find orca::orca
export(PACKAGE orca)
install(EXPORT orcaTargets
FILE orcaTargets.cmake
NAMESPACE orca::
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/cmake
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/orcaConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/orcaConfigVersion.cmake
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/cmake
)
endif()