forked from loco-3d/crocoddyl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
201 lines (168 loc) · 7.6 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
CMAKE_MINIMUM_REQUIRED(VERSION 3.1)
# Set up project properties
SET(PROJECT_NAMESPACE loco-3d)
SET(PROJECT_NAME crocoddyl)
SET(PROJECT_DESCRIPTION "Contact RObot COntrol by Differential DYnamic programming Library (Crocoddyl)")
SET(PROJECT_URL https://github.com/${PROJECT_NAMESPACE}/${PROJECT_NAME})
# Check if the submodule cmake have been initialized
IF(NOT EXISTS "${CMAKE_SOURCE_DIR}/cmake/base.cmake")
MESSAGE(FATAL_ERROR "\nPlease run the following command first:\ngit submodule update --init\n")
ENDIF()
# Include important cmake modules
INCLUDE(cmake/base.cmake)
INCLUDE(cmake/boost.cmake)
INCLUDE(cmake/python.cmake)
INCLUDE(cmake/apple.cmake)
# Print initial message
MESSAGE(STATUS "${PROJECT_DESCRIPTION}, version ${PROJECT_VERSION}")
MESSAGE(STATUS "Copyright (C) 2018-2021 CNRS-LAAS, University of Edinburgh, INRIA")
MESSAGE(STATUS "All rights reserved.")
MESSAGE(STATUS "Released under the BSD 3-Clause License.")
# 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." FORCE)
# Set the possible values of build type for cmake-gui
SET_PROPERTY(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
ENDIF()
SET(DOXYGEN_USE_MATHJAX YES)
SET(DOXYGEN_USE_TEMPLATE_CSS YES)
SET(CXX_DISABLE_WERROR False)
SET(PROJECT_USE_CMAKE_EXPORT True)
# Create different building options
OPTION(ENABLE_VECTORIZATION "Enable vectorization and further processor-related optimizations" OFF)
OPTION(BUILD_PYTHON_INTERFACE "Build the python binding" ON)
OPTION(BUILD_BENCHMARK "Build the benchmark" ON)
OPTION(BUILD_EXAMPLES "Build the examples" ON)
IF(DEFINED BUILD_UNIT_TESTS)
MESSAGE(AUTHOR_WARNING "BUILD_UNIT_TESTS is deprecated. Use BUILD_TESTING instead.\
If you are manually building Crocoddyl from source in an existing build folder,\
we suggest that you delete your build folder and make a new one.")
OPTION(BUILD_TESTING ${BUILD_UNIT_TESTS})
ENDIF(DEFINED BUILD_UNIT_TESTS)
IF(ENABLE_VECTORIZATION)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
ENDIF()
COMPUTE_PROJECT_ARGS(PROJECT_ARGS LANGUAGES CXX)
PROJECT(${PROJECT_NAME} ${PROJECT_ARGS})
# If needed, fix CMake policy for APPLE systems
APPLY_DEFAULT_APPLE_CONFIGURATION()
CHECK_MINIMAL_CXX_STANDARD(14 ENFORCE)
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/find-external/CppAD/" ${CMAKE_MODULE_PATH})
# Add the different required and optional dependencies
ADD_PROJECT_DEPENDENCY(pinocchio 2.6.3 REQUIRED PKG_CONFIG_REQUIRES "pinocchio >= 2.6.3")
IF(BUILD_EXAMPLES OR BUILD_TESTING OR BUILD_BENCHMARK)
ADD_PROJECT_DEPENDENCY(example-robot-data 3.7.0 REQUIRED PKG_CONFIG_REQUIRES "example-robot-data >= 3.7.0")
ELSE()
ADD_OPTIONAL_DEPENDENCY(example-robot-data)
ENDIF()
ADD_OPTIONAL_DEPENDENCY("scipy")
OPTION(BUILD_WITH_CODEGEN_SUPPORT "Build the library with the Code Generation support (required CppADCodeGen)" OFF)
OPTION(BUILD_WITH_MULTITHREADS "Build the library with the Multithreading support (required OpenMP)" OFF)
IF(BUILD_WITH_MULTITHREADS)
# If BUILD_WITH_NTHREADS defined, use the value - otherwise detect
IF(NOT DEFINED BUILD_WITH_NTHREADS)
INCLUDE(ProcessorCount)
ProcessorCount(NPROCESSOR)
IF(NOT NPROCESSOR EQUAL 0)
MATH(EXPR NPROCESSOR ${NPROCESSOR}/2)
SET(BUILD_WITH_NTHREADS ${NPROCESSOR} CACHE STRING "Number of threads")
ELSE()
SET(BUILD_WITH_NTHREADS "4" CACHE STRING "Number of threads") # Default setting
ENDIF()
ENDIF()
string(REGEX MATCH "^[0-9]+$" BUILD_WITH_NTHREADS ${BUILD_WITH_NTHREADS})
IF(NOT BUILD_WITH_NTHREADS MATCHES "^[0-9]+$")
SET(BUILD_WITH_NTHREADS 4) # Default setting 4.
MESSAGE(WARNING "The number of threads has to be an integer value, set to ${BUILD_WITH_NTHREADS}")
ENDIF()
ENDIF()
IF(BUILD_WITH_CODEGEN_SUPPORT)
ADD_PROJECT_DEPENDENCY(cppad 20200000.0 REQUIRED)
ADD_PROJECT_DEPENDENCY(cppadcg 2.4.1 REQUIRED)
ADD_DEFINITIONS(-DCROCODDYL_WITH_CODEGEN)
#Pinocchio codegen related preproccessor defs.
ADD_DEFINITIONS(-DPINOCCHIO_WITH_CPPADCG_SUPPORT)
ADD_DEFINITIONS(-DPINOCCHIO_WITH_CPPAD_SUPPORT)
#Packaging for downstream.
SET(PACKAGE_EXTRA_MACROS "${PACKAGE_EXTRA_MACROS}\nADD_DEFINITIONS(-DCROCODDYL_WITH_CODEGEN -DPINOCCHIO_WITH_CPPAD_SUPPORT -DPINOCCHIO_WITH_CPPADCG_SUPPORT)")
IF(NOT ${EIGEN3_VERSION} VERSION_GREATER "3.3.0")
ADD_DEFINITIONS(-DPINOCCHIO_CPPAD_REQUIRES_MATRIX_BASE_PLUGIN)
SET(PACKAGE_EXTRA_MACROS "${PACKAGE_EXTRA_MACROS}\nADD_DEFINITIONS(-DPINOCCHIO_CPPAD_REQUIRES_MATRIX_BASE_PLUGIN)")
ENDIF(NOT ${EIGEN3_VERSION} VERSION_GREATER "3.3.0")
ENDIF()
# Add OpenMP
if(BUILD_WITH_MULTITHREADS)
FIND_PACKAGE(OpenMP)
ENDIF()
if(OPENMP_FOUND AND BUILD_WITH_MULTITHREADS)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
ADD_DEFINITIONS(-DCROCODDYL_WITH_MULTITHREADING)
ADD_DEFINITIONS(-DCROCODDYL_WITH_NTHREADS=${BUILD_WITH_NTHREADS})
SET(PACKAGE_EXTRA_MACROS "${PACKAGE_EXTRA_MACROS}\nADD_DEFINITIONS(-DCROCODDYL_WITH_MULTITHREADING -DCROCODDYL_WITH_NTHREADS=${BUILD_WITH_NTHREADS})")
SET(OMP_NUM_THREADS ${BUILD_WITH_NTHREADS})
ENDIF()
SET(BOOST_REQUIERED_COMPONENTS filesystem serialization system)
SET(BOOST_BUILD_COMPONENTS unit_test_framework)
SET_BOOST_DEFAULT_OPTIONS()
EXPORT_BOOST_DEFAULT_OPTIONS()
ADD_PROJECT_DEPENDENCY(Boost REQUIRED COMPONENTS ${BOOST_REQUIERED_COMPONENTS})
FIND_PACKAGE(Boost REQUIRED COMPONENTS ${BOOST_BUILD_COMPONENTS})
IF(Boost_VERSION GREATER 107299)
# Silence a warning about a deprecated use of boost bind by boost python
# at least fo boost 1.73 to 1.75
ADD_DEFINITIONS(-DBOOST_BIND_GLOBAL_PLACEHOLDERS)
ENDIF()
IF(BUILD_PYTHON_INTERFACE)
FINDPYTHON()
SEARCH_FOR_BOOST_PYTHON(REQUIRED)
ADD_PROJECT_DEPENDENCY(eigenpy 2.5.0 REQUIRED PKG_CONFIG_REQUIRES "eigenpy >= 2.5.0")
ENDIF(BUILD_PYTHON_INTERFACE)
# Main library
FILE(GLOB_RECURSE ${PROJECT_NAME}_SOURCES
src/*.cpp
)
FILE(GLOB_RECURSE ${PROJECT_NAME}_HEADERS
include/${PROJECT_NAME}/*.h*
)
IF(UNIX)
# Build options
# We'd like to deactivate sign conversion since we frequently convert Eigen::Index<>std::size_t
# Otherwise, activate all warnings.
ADD_COMPILE_OPTIONS(-Wall -Wpedantic -Wextra -Wno-sign-conversion)
ADD_LIBRARY(${PROJECT_NAME} SHARED ${${PROJECT_NAME}_SOURCES} ${${PROJECT_NAME}_HEADERS})
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)
TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} PUBLIC $<INSTALL_INTERFACE:include>)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} pinocchio::pinocchio)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY}
${Boost_SERIALIZATION_LIBRARY})
if(OPENMP_FOUND)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${OpenMP_CXX_LIBRARIES})
ENDIF()
INSTALL(TARGETS ${PROJECT_NAME} EXPORT ${TARGETS_EXPORT_NAME} DESTINATION lib)
ENDIF(UNIX)
# Build the Python interface
IF(BUILD_PYTHON_INTERFACE)
# Include and add the bindings directory
INCLUDE_DIRECTORIES(bindings)
ADD_SUBDIRECTORY(bindings)
ENDIF(BUILD_PYTHON_INTERFACE)
# Build the unit tests
IF(BUILD_TESTING)
ADD_SUBDIRECTORY(unittest)
ENDIF(BUILD_TESTING)
# Build the benchmark
IF(BUILD_BENCHMARK)
ADD_SUBDIRECTORY(benchmark)
ENDIF(BUILD_BENCHMARK)
# Build the examples
IF(BUILD_EXAMPLES)
IF(BUILD_PYTHON_INTERFACE)
ADD_SUBDIRECTORY(examples)
ELSE(BUILD_PYTHON_INTERFACE)
MESSAGE(WARNING "Python interface is not built, hence cannot build examples.")
ENDIF(BUILD_PYTHON_INTERFACE)
ENDIF(BUILD_EXAMPLES)
# PkgConfig packaging of the project
PKG_CONFIG_APPEND_LIBS(${PROJECT_NAME})
PKG_CONFIG_APPEND_BOOST_LIBS(${BOOST_REQUIRED_COMPONENTS})