CMakeLists.txt 11.2 KB
Newer Older
Nicolas Mansard's avatar
IVIGIT.  
Nicolas Mansard committed
1
#
2
# Copyright (c) 2015-2019 CNRS INRIA
3
# Copyright (c) 2015 Wandercraft, 86 rue de Paris 91400 Orsay, France.
Nicolas Mansard's avatar
IVIGIT.  
Nicolas Mansard committed
4
5
#

6
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
Nicolas Mansard's avatar
IVIGIT.  
Nicolas Mansard committed
7

8
9
10
11
12
SET(PROJECT_NAME pinocchio)
SET(PROJECT_DESCRIPTION "A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives")
SET(PROJECT_URL "http://github.com/stack-of-tasks/pinocchio")
SET(PROJECT_CUSTOM_HEADER_EXTENSION "hpp")

13
14
15
16
# Disable -Werror on Unix for now.
SET(CXX_DISABLE_WERROR True)
SET(CMAKE_VERBOSE_MAKEFILE True)

17
# Check if the submodule cmake have been initialized
Justin Carpentier's avatar
Justin Carpentier committed
18
IF(NOT EXISTS "${CMAKE_SOURCE_DIR}/cmake/base.cmake")
19
20
21
  MESSAGE(FATAL_ERROR "\nPlease run the following command first:\ngit submodule update --init\n")
ENDIF()

22
INCLUDE(cmake/base.cmake)
23
24
COMPUTE_PROJECT_ARGS(PROJECT_ARGS LANGUAGES CXX)
PROJECT(${PROJECT_NAME} ${PROJECT_ARGS})
25

Nicolas Mansard's avatar
IVIGIT.  
Nicolas Mansard committed
26
27
INCLUDE(cmake/boost.cmake)
INCLUDE(cmake/python.cmake)
28
INCLUDE(cmake/ide.cmake)
29
INCLUDE(cmake/apple.cmake)
Nicolas Mansard's avatar
IVIGIT.  
Nicolas Mansard committed
30

31
32
SET(DOXYGEN_USE_MATHJAX YES)

33
34
# If needed, fix CMake policy for APPLE systems
APPLY_DEFAULT_APPLE_CONFIGURATION()
35

36
37
38
39
40
41
IF(WIN32)
  SET(LINK copy_if_different)
ELSE(WIN32)
  SET(LINK create_symlink)
ENDIF(WIN32)

42
43
# --- OPTIONS ----------------------------------------
OPTION (BUILD_BENCHMARK "Build the benchmarks" OFF)
44
OPTION (BUILD_UNIT_TESTS "Build the unitary tests" OFF)
45
OPTION (BUILD_UTILS "Build the utils" OFF)
46
OPTION (BUILD_PYTHON_INTERFACE "Build the python binding" ON)
jcarpent's avatar
jcarpent committed
47
OPTION (BUILD_WITH_LUA_SUPPORT "Build the lua parser" OFF)
48
OPTION (BUILD_WITH_COMMIT_VERSION "Build libraries by setting specific commit version" OFF)
49

50
51
52
53
# --- OPTIONAL DEPENDENCIES -------------------------
OPTION(BUILD_WITH_URDF_SUPPORT "Build the library with the URDF format support" ON)
OPTION(BUILD_WITH_COLLISION_SUPPORT "Build the library with the Collision support (required HPP-FCL)" OFF)
OPTION(BUILD_WITH_AUTODIFF_SUPPORT "Build the library with the Automatic Differentiation support" OFF)
54
OPTION(BUILD_WITH_CASADI_SUPPORT "Build the library with the CASADI support" OFF)
55
56
57
58
OPTION(BUILD_WITH_CODEGEN_SUPPORT "Build the library with the Code Generation support" OFF)

OPTION (INITIALIZE_WITH_NAN "Initialize Eigen entries with NaN" OFF)

59
IF (INITIALIZE_WITH_NAN)
jcarpent's avatar
jcarpent committed
60
  MESSAGE (STATUS "Initialize with NaN all the Eigen entries.")
61
62
  ADD_DEFINITIONS(-DEIGEN_INITIALIZE_MATRICES_BY_NAN)
ENDIF (INITIALIZE_WITH_NAN)
63

64
SET(BUILD_TESTING ${BUILD_UNIT_TESTS})
65

66
67
68
69
MACRO(TAG_LIBRARY_VERSION target)
  SET_TARGET_PROPERTIES(${target} PROPERTIES SOVERSION ${PROJECT_VERSION})
ENDMACRO(TAG_LIBRARY_VERSION)

70
71
SET(PINOCCHIO_MODEL_DIR "${PROJECT_SOURCE_DIR}/models")

Nicolas Mansard's avatar
IVIGIT.  
Nicolas Mansard committed
72
# ----------------------------------------------------
Wolfgang Merkt's avatar
Typo    
Wolfgang Merkt committed
73
# --- DEPENDENCIES -----------------------------------
Nicolas Mansard's avatar
IVIGIT.  
Nicolas Mansard committed
74
# ----------------------------------------------------
75
ADD_REQUIRED_DEPENDENCY("eigen3 >= 3.0.5")
76

77
IF(BUILD_WITH_URDF_SUPPORT)
78
  ADD_REQUIRED_DEPENDENCY("urdfdom >= 0.2.0")
79
80
ENDIF(BUILD_WITH_URDF_SUPPORT)

81
IF(BUILD_WITH_COLLISION_SUPPORT)
82
  ADD_REQUIRED_DEPENDENCY("hpp-fcl >= 1.0.0")
83
ENDIF(BUILD_WITH_COLLISION_SUPPORT)
84

85
IF(BUILD_WITH_AUTODIFF_SUPPORT)
86
  ADD_REQUIRED_DEPENDENCY("cppad >= 20180000.0")
87
ENDIF(BUILD_WITH_AUTODIFF_SUPPORT)
88

89
IF(CPPAD_FOUND AND BUILD_WITH_AUTODIFF_SUPPORT)
90
91
92
93
94
95
  ADD_DEFINITIONS(-DPINOCCHIO_WITH_CPPAD_SUPPORT)
  PKG_CONFIG_APPEND_CFLAGS("-DPINOCCHIO_WITH_CPPAD_SUPPORT")
  IF(NOT ${CPPAD_VERSION} VERSION_GREATER "3.3.0")
    ADD_DEFINITIONS(-DPINOCCHIO_CPPAD_REQUIRES_MATRIX_BASE_PLUGIN)
    PKG_CONFIG_APPEND_CFLAGS("-DPINOCCHIO_CPPAD_REQUIRES_MATRIX_BASE_PLUGIN")
  ENDIF(NOT ${CPPAD_VERSION} VERSION_GREATER "3.3.0")
96

97
98
99
  IF(BUILD_WITH_CODEGEN_SUPPORT)
    ADD_OPTIONAL_DEPENDENCY("cppadcg")
  ENDIF(BUILD_WITH_CODEGEN_SUPPORT)
100
  IF(CPPADCG_FOUND AND BUILD_WITH_CODEGEN_SUPPORT)
101
102
    ADD_DEFINITIONS(-DPINOCCHIO_WITH_CPPADCG_SUPPORT)
    PKG_CONFIG_APPEND_CFLAGS("-DPINOCCHIO_WITH_CPPADCG_SUPPORT")
Justin Carpentier's avatar
Justin Carpentier committed
103
  ENDIF(CPPADCG_FOUND AND BUILD_WITH_CODEGEN_SUPPORT)
104
ENDIF(CPPAD_FOUND AND BUILD_WITH_AUTODIFF_SUPPORT)
105

106
IF(BUILD_WITH_CASADI_SUPPORT)
107
  ADD_REQUIRED_DEPENDENCY("casadi >= 3.4.5")
108
109
ENDIF(BUILD_WITH_CASADI_SUPPORT)

110
IF(CASADI_FOUND AND BUILD_WITH_CASADI_SUPPORT)
111
112
  ADD_DEFINITIONS(-DPINOCCHIO_WITH_CASADI_SUPPORT)
  PKG_CONFIG_APPEND_CFLAGS("-DPINOCCHIO_WITH_CASADI_SUPPORT")
113
ENDIF(CASADI_FOUND AND BUILD_WITH_CASADI_SUPPORT)
114

115
# Special care of urdfdom version
116
IF(URDFDOM_FOUND AND BUILD_WITH_URDF_SUPPORT)
117
  IF(${URDFDOM_VERSION} VERSION_LESS "0.3.0")
118
119
    ADD_DEFINITIONS(-DPINOCCHIO_URDFDOM_COLLISION_WITH_GROUP_NAME)
    PKG_CONFIG_APPEND_CFLAGS("-DPINOCCHIO_URDFDOM_COLLISION_WITH_GROUP_NAME")
120
  ENDIF(${URDFDOM_VERSION} VERSION_LESS "0.3.0")
121
122
123

  # defines types from version 0.4.0
  IF(NOT ${URDFDOM_VERSION} VERSION_LESS "0.4.0")
124
125
    ADD_DEFINITIONS(-DPINOCCHIO_URDFDOM_TYPEDEF_SHARED_PTR)
    PKG_CONFIG_APPEND_CFLAGS("-DPINOCCHIO_URDFDOM_TYPEDEF_SHARED_PTR")
126
127
128
129
  ENDIF(NOT ${URDFDOM_VERSION} VERSION_LESS "0.4.0")
  
  # std::shared_ptr appears from version 1.0.0
  IF(${URDFDOM_VERSION} VERSION_GREATER "0.4.2")
130
131
    ADD_DEFINITIONS(-DPINOCCHIO_URDFDOM_USE_STD_SHARED_PTR)
    PKG_CONFIG_APPEND_CFLAGS("-DPINOCCHIO_URDFDOM_USE_STD_SHARED_PTR")
132
  ENDIF(${URDFDOM_VERSION} VERSION_GREATER "0.4.2")
133
ENDIF(URDFDOM_FOUND AND BUILD_WITH_URDF_SUPPORT)
134

135
136
# Special care of lua which can be of versions 5.1 or 5.2
# Priority is set to lua5.2
jcarpent's avatar
jcarpent committed
137
138
139
IF(BUILD_WITH_LUA_SUPPORT)
  ADD_OPTIONAL_DEPENDENCY("lua5.2")
  IF(LUA5_2_FOUND)
140
    SET(LUA5_FOUND TRUE)
jcarpent's avatar
jcarpent committed
141
    SET(LUA5_PACKAGE "lua5.2")
142
143
    ADD_DEFINITIONS(-DPINOCCHIO_LUA_VERSION_GREATER_5_2)
    PKG_CONFIG_APPEND_CFLAGS("-DPINOCCHIO_LUA_VERSION_GREATER_5_2")
jcarpent's avatar
jcarpent committed
144
145
146
147
148
149
150
151
152
153
  ELSE(LUA5_2_FOUND)
    ADD_OPTIONAL_DEPENDENCY("lua5.1")
    IF(LUA5_1_FOUND)
      SET(LUA5_FOUND TRUE)
      SET(LUA5_PACKAGE "lua5.1")
    ELSE(LUA5_1_FOUND)
      MESSAGE(FATAL_ERROR "Cannot find a suitable version of Lua 5.1 or 5.2")
    ENDIF(LUA5_1_FOUND)
  ENDIF(LUA5_2_FOUND)
ENDIF(BUILD_WITH_LUA_SUPPORT)
154

Sébastien Barthélémy's avatar
Sébastien Barthélémy committed
155
SET(BOOST_REQUIRED_COMPONENTS filesystem serialization system)
jcarpent's avatar
jcarpent committed
156
157
158
SET(BOOST_BUILD_COMPONENTS unit_test_framework)
SET(BOOST_OPTIONAL_COMPONENTS "")

159
IF(BUILD_PYTHON_INTERFACE)
jcarpent's avatar
jcarpent committed
160
  SET(BOOST_OPTIONAL_COMPONENTS ${BOOST_OPTIONAL_COMPONENTS} python)
161
  FINDPYTHON()
162
  INCLUDE_DIRECTORIES(SYSTEM ${PYTHON_INCLUDE_DIRS}) 
163
164
ENDIF(BUILD_PYTHON_INTERFACE)

Sébastien Barthélémy's avatar
Sébastien Barthélémy committed
165
SET(BOOST_COMPONENTS ${BOOST_REQUIRED_COMPONENTS} ${BOOST_OPTIONAL_COMPONENTS} ${BOOST_BUILD_COMPONENTS})
166
SEARCH_FOR_BOOST()
167
168
169
170
171
# Enforce the preprocessed version of boost::list and boost::vector
# This information is redundant with the content of include/pinocchio/container/boost-container-limits.hpp
# but it avoids any compilation issue.
ADD_DEFINITIONS(-DBOOST_MPL_LIMIT_LIST_SIZE=30)
ADD_DEFINITIONS(-DBOOST_MPL_LIMIT_VECTOR_SIZE=30)
172

173
174
# Variable containing all the cflags definition relative to optional dependencies
SET(CFLAGS_DEPENDENCIES)
175
LIST(APPEND CFLAGS_DEPENDENCIES "-DBOOST_MPL_LIMIT_LIST_SIZE=30")
176

177
# Path to boost headers
178
INCLUDE_DIRECTORIES(SYSTEM ${Boost_INCLUDE_DIRS})
179

Nicolas Mansard's avatar
IVIGIT.  
Nicolas Mansard committed
180
181
182
# ----------------------------------------------------
# --- INCLUDE ----------------------------------------
# ----------------------------------------------------
183
184
185
186
FILE(GLOB_RECURSE HEADERS 
     ${PROJECT_SOURCE_DIR}/src/*.hpp 
     ${PROJECT_SOURCE_DIR}/src/*.hxx 
     ) 
187

188
IF(URDFDOM_FOUND)
189
190
  ADD_DEFINITIONS(-DPINOCCHIO_WITH_URDFDOM)
  LIST(APPEND CFLAGS_DEPENDENCIES "-DPINOCCHIO_WITH_URDFDOM")
191
192
193
194
195
196
197
198
ELSE(URDFDOM_FOUND)
  LIST(REMOVE_ITEM HEADERS
    ${PROJECT_SOURCE_DIR}/src/parsers/urdf.hpp
    ${PROJECT_SOURCE_DIR}/src/parsers/urdf/model.hxx
    ${PROJECT_SOURCE_DIR}/src/parsers/urdf/geometry.hxx
    ${PROJECT_SOURCE_DIR}/src/parsers/urdf/utils.hpp
    ${PROJECT_SOURCE_DIR}/src/parsers/urdf/types.hpp
    )
199
200
ENDIF(URDFDOM_FOUND)

201

202
IF(HPP_FCL_FOUND)
203
204
  ADD_DEFINITIONS(-DPINOCCHIO_WITH_HPP_FCL)
  LIST(APPEND CFLAGS_DEPENDENCIES "-DPINOCCHIO_WITH_HPP_FCL")
205
206
207
208
ELSE(HPP_FCL_FOUND)
  LIST(REMOVE_ITEM HEADERS 
    ${PROJECT_SOURCE_DIR}/src/spatial/fcl-pinocchio-conversions.hpp
    )
209
210
ENDIF(HPP_FCL_FOUND)

211
IF(LUA5_FOUND)
212
213
  ADD_DEFINITIONS(-DPINOCCHIO_WITH_LUA5)
  LIST(APPEND CFLAGS_DEPENDENCIES "-DPINOCCHIO_WITH_LUA5")
214
215
216
217
218
ELSE(LUA5_FOUND)
  LIST(REMOVE_ITEM HEADERS
    ${PROJECT_SOURCE_DIR}/src/parsers/lua.hpp
    ${PROJECT_SOURCE_DIR}/src/parsers/lua/lua_tables.hpp
    )
219
ENDIF(LUA5_FOUND)
jcarpent's avatar
jcarpent committed
220

221
LIST(APPEND HEADERS macros.hpp)
222

Nicolas Mansard's avatar
IVIGIT.  
Nicolas Mansard committed
223
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio")
224
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/core")
225
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/math")
Nicolas Mansard's avatar
IVIGIT.  
Nicolas Mansard committed
226
227
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/spatial")
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/multibody")
228
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/multibody/joint")
229
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/multibody/liegroup")
230
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/multibody/visitor")
231
232
233
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/parsers/lua")
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/parsers")
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/parsers/urdf")
jcarpent's avatar
jcarpent committed
234
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/utils")
235
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/serialization")
236
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/algorithm")
237
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/container")
238
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/codegen")
239
240
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/autodiff")

241
SET(HEADERS_)
242
FOREACH(header ${HEADERS})
243
  STRING(REGEX REPLACE "${PROJECT_SOURCE_DIR}/src/" "" header ${header})
244
  LIST(APPEND HEADERS_ ${header})
Nicolas Mansard's avatar
IVIGIT.  
Nicolas Mansard committed
245
  GET_FILENAME_COMPONENT(headerName ${header} NAME)
246
247
248
249
250
  GET_FILENAME_COMPONENT(headerPath ${header} PATH)
  EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E ${LINK}
    ${${PROJECT_NAME}_SOURCE_DIR}/src/${header}
    ${${PROJECT_NAME}_BINARY_DIR}/include/${PROJECT_NAME}/${header})
  INSTALL(FILES ${${PROJECT_NAME}_SOURCE_DIR}/src/${header}
Justin Carpentier's avatar
Justin Carpentier committed
251
          DESTINATION ${CMAKE_INSTALL_PREFIX}/include/${PROJECT_NAME}/${headerPath}
Nicolas Mansard's avatar
IVIGIT.  
Nicolas Mansard committed
252
253
          PERMISSIONS OWNER_READ GROUP_READ WORLD_READ OWNER_WRITE)
ENDFOREACH(header)
254
SET(HEADERS ${HEADERS_})
Nicolas Mansard's avatar
IVIGIT.  
Nicolas Mansard committed
255

256
257
258
259
260
LIST(APPEND HEADERS
     ${${PROJECT_NAME}_BINARY_DIR}/include/${PROJECT_NAME}/config.hpp
     ${${PROJECT_NAME}_BINARY_DIR}/include/${PROJECT_NAME}/deprecated.hpp
     ${${PROJECT_NAME}_BINARY_DIR}/include/${PROJECT_NAME}/warning.hpp)

261
# --- MAIN LIBRARY -------------------------------------------------------------
262
ADD_SUBDIRECTORY(src)
263
264
265
266

# --- BINDINGS -----------------------------------------------------------------
ADD_SUBDIRECTORY(bindings)

267
# --- EXECUTABLES --------------------------------------------------------------
268
269
270
ADD_SUBDIRECTORY(utils)

# --- UNIT TESTS ---------------------------------------------------------------
271
ADD_SUBDIRECTORY(unittest)
272

273
# --- CHECK EXAMPLES -----------------------------------------------------------
274
ADD_SUBDIRECTORY(examples)
275

276
# --- BENCHMARKS ---------------------------------------------------------------
277
ADD_SUBDIRECTORY(benchmark)
jcarpent's avatar
jcarpent committed
278

279
280
# --- PACKAGING ----------------------------------------------------------------
PKG_CONFIG_APPEND_LIBS (${PROJECT_NAME})
Sébastien Barthélémy's avatar
Sébastien Barthélémy committed
281
PKG_CONFIG_APPEND_BOOST_LIBS(${BOOST_REQUIRED_COMPONENTS})
Nicolas Mansard's avatar
Nicolas Mansard committed
282

283
284
285
FOREACH(cflags ${CFLAGS_DEPENDENCIES})
  PKG_CONFIG_APPEND_CFLAGS(${cflags})
ENDFOREACH(cflags ${CFLAGS_DEPENDENCIES})
Wolfgang Merkt's avatar
Wolfgang Merkt committed
286
287
288

# Install catkin package.xml
INSTALL(FILES package.xml DESTINATION share/${PROJECT_NAME})