CMakeLists.txt 11.4 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_UTILS "Build the utils" OFF)
45
OPTION (BUILD_PYTHON_INTERFACE "Build the python binding" ON)
jcarpent's avatar
jcarpent committed
46
OPTION (BUILD_WITH_LUA_SUPPORT "Build the lua parser" OFF)
47
OPTION (BUILD_WITH_COMMIT_VERSION "Build libraries by setting specific commit version" OFF)
48

49
IF(DEFINED BUILD_UNIT_TESTS)
50 51 52
  MESSAGE(AUTHOR_WARNING "BUILD_UNIT_TESTS is deprecated. Use BUILD_TESTING instead.\
    If you are manually building Pinocchio from source in an existing build folder,\
    we suggest that you delete your build folder and make a new one.")
53 54 55
  SET(BUILD_TESTING ${BUILD_UNIT_TESTS})
ENDIF(DEFINED BUILD_UNIT_TESTS)

56 57 58 59
# --- 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)
60
OPTION(BUILD_WITH_CASADI_SUPPORT "Build the library with the CASADI support" OFF)
61 62 63 64
OPTION(BUILD_WITH_CODEGEN_SUPPORT "Build the library with the Code Generation support" OFF)

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

65
IF (INITIALIZE_WITH_NAN)
jcarpent's avatar
jcarpent committed
66
  MESSAGE (STATUS "Initialize with NaN all the Eigen entries.")
67 68
  ADD_DEFINITIONS(-DEIGEN_INITIALIZE_MATRICES_BY_NAN)
ENDIF (INITIALIZE_WITH_NAN)
69

70 71 72 73
MACRO(TAG_LIBRARY_VERSION target)
  SET_TARGET_PROPERTIES(${target} PROPERTIES SOVERSION ${PROJECT_VERSION})
ENDMACRO(TAG_LIBRARY_VERSION)

74 75
SET(PINOCCHIO_MODEL_DIR "${PROJECT_SOURCE_DIR}/models")

Nicolas Mansard's avatar
IVIGIT.  
Nicolas Mansard committed
76
# ----------------------------------------------------
Wolfgang Merkt's avatar
Typo  
Wolfgang Merkt committed
77
# --- DEPENDENCIES -----------------------------------
Nicolas Mansard's avatar
IVIGIT.  
Nicolas Mansard committed
78
# ----------------------------------------------------
79
ADD_REQUIRED_DEPENDENCY("eigen3 >= 3.0.5")
80

81
IF(BUILD_WITH_URDF_SUPPORT)
82
  ADD_REQUIRED_DEPENDENCY("urdfdom >= 0.2.0")
83 84
ENDIF(BUILD_WITH_URDF_SUPPORT)

85
IF(BUILD_WITH_COLLISION_SUPPORT)
86
  ADD_REQUIRED_DEPENDENCY("hpp-fcl >= 1.0.0")
87
ENDIF(BUILD_WITH_COLLISION_SUPPORT)
88

89
IF(BUILD_WITH_AUTODIFF_SUPPORT)
90
  ADD_REQUIRED_DEPENDENCY("cppad >= 20180000.0")
91
ENDIF(BUILD_WITH_AUTODIFF_SUPPORT)
92

93
IF(CPPAD_FOUND AND BUILD_WITH_AUTODIFF_SUPPORT)
94 95 96 97 98 99
  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")
100

101 102 103
  IF(BUILD_WITH_CODEGEN_SUPPORT)
    ADD_OPTIONAL_DEPENDENCY("cppadcg")
  ENDIF(BUILD_WITH_CODEGEN_SUPPORT)
104
  IF(CPPADCG_FOUND AND BUILD_WITH_CODEGEN_SUPPORT)
105 106
    ADD_DEFINITIONS(-DPINOCCHIO_WITH_CPPADCG_SUPPORT)
    PKG_CONFIG_APPEND_CFLAGS("-DPINOCCHIO_WITH_CPPADCG_SUPPORT")
Justin Carpentier's avatar
Justin Carpentier committed
107
  ENDIF(CPPADCG_FOUND AND BUILD_WITH_CODEGEN_SUPPORT)
108
ENDIF(CPPAD_FOUND AND BUILD_WITH_AUTODIFF_SUPPORT)
109

110
IF(BUILD_WITH_CASADI_SUPPORT)
111
  ADD_REQUIRED_DEPENDENCY("casadi >= 3.4.5")
112 113
ENDIF(BUILD_WITH_CASADI_SUPPORT)

114
IF(CASADI_FOUND AND BUILD_WITH_CASADI_SUPPORT)
115 116
  ADD_DEFINITIONS(-DPINOCCHIO_WITH_CASADI_SUPPORT)
  PKG_CONFIG_APPEND_CFLAGS("-DPINOCCHIO_WITH_CASADI_SUPPORT")
117
ENDIF(CASADI_FOUND AND BUILD_WITH_CASADI_SUPPORT)
118

119
# Special care of urdfdom version
120
IF(URDFDOM_FOUND AND BUILD_WITH_URDF_SUPPORT)
121
  IF(${URDFDOM_VERSION} VERSION_LESS "0.3.0")
122 123
    ADD_DEFINITIONS(-DPINOCCHIO_URDFDOM_COLLISION_WITH_GROUP_NAME)
    PKG_CONFIG_APPEND_CFLAGS("-DPINOCCHIO_URDFDOM_COLLISION_WITH_GROUP_NAME")
124
  ENDIF(${URDFDOM_VERSION} VERSION_LESS "0.3.0")
125 126 127

  # defines types from version 0.4.0
  IF(NOT ${URDFDOM_VERSION} VERSION_LESS "0.4.0")
128 129
    ADD_DEFINITIONS(-DPINOCCHIO_URDFDOM_TYPEDEF_SHARED_PTR)
    PKG_CONFIG_APPEND_CFLAGS("-DPINOCCHIO_URDFDOM_TYPEDEF_SHARED_PTR")
130 131 132 133
  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")
134 135
    ADD_DEFINITIONS(-DPINOCCHIO_URDFDOM_USE_STD_SHARED_PTR)
    PKG_CONFIG_APPEND_CFLAGS("-DPINOCCHIO_URDFDOM_USE_STD_SHARED_PTR")
136
  ENDIF(${URDFDOM_VERSION} VERSION_GREATER "0.4.2")
137
ENDIF(URDFDOM_FOUND AND BUILD_WITH_URDF_SUPPORT)
138

139 140
# 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
141 142 143
IF(BUILD_WITH_LUA_SUPPORT)
  ADD_OPTIONAL_DEPENDENCY("lua5.2")
  IF(LUA5_2_FOUND)
144
    SET(LUA5_FOUND TRUE)
jcarpent's avatar
jcarpent committed
145
    SET(LUA5_PACKAGE "lua5.2")
146 147
    ADD_DEFINITIONS(-DPINOCCHIO_LUA_VERSION_GREATER_5_2)
    PKG_CONFIG_APPEND_CFLAGS("-DPINOCCHIO_LUA_VERSION_GREATER_5_2")
jcarpent's avatar
jcarpent committed
148 149 150 151 152 153 154 155 156 157
  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)
158

Sébastien Barthélémy's avatar
Sébastien Barthélémy committed
159
SET(BOOST_REQUIRED_COMPONENTS filesystem serialization system)
jcarpent's avatar
jcarpent committed
160 161 162
SET(BOOST_BUILD_COMPONENTS unit_test_framework)
SET(BOOST_OPTIONAL_COMPONENTS "")

163
IF(BUILD_PYTHON_INTERFACE)
jcarpent's avatar
jcarpent committed
164
  SET(BOOST_OPTIONAL_COMPONENTS ${BOOST_OPTIONAL_COMPONENTS} python)
165
  FINDPYTHON()
166
  INCLUDE_DIRECTORIES(SYSTEM ${PYTHON_INCLUDE_DIRS}) 
167 168
ENDIF(BUILD_PYTHON_INTERFACE)

Sébastien Barthélémy's avatar
Sébastien Barthélémy committed
169
SET(BOOST_COMPONENTS ${BOOST_REQUIRED_COMPONENTS} ${BOOST_OPTIONAL_COMPONENTS} ${BOOST_BUILD_COMPONENTS})
170
SEARCH_FOR_BOOST()
171 172 173 174 175
# 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)
176

177 178
# Variable containing all the cflags definition relative to optional dependencies
SET(CFLAGS_DEPENDENCIES)
179
LIST(APPEND CFLAGS_DEPENDENCIES "-DBOOST_MPL_LIMIT_LIST_SIZE=30")
180

181
# Path to boost headers
182
INCLUDE_DIRECTORIES(SYSTEM ${Boost_INCLUDE_DIRS})
183

Nicolas Mansard's avatar
IVIGIT.  
Nicolas Mansard committed
184 185 186
# ----------------------------------------------------
# --- INCLUDE ----------------------------------------
# ----------------------------------------------------
187 188 189 190
FILE(GLOB_RECURSE HEADERS 
     ${PROJECT_SOURCE_DIR}/src/*.hpp 
     ${PROJECT_SOURCE_DIR}/src/*.hxx 
     ) 
191

192
IF(URDFDOM_FOUND)
193 194
  ADD_DEFINITIONS(-DPINOCCHIO_WITH_URDFDOM)
  LIST(APPEND CFLAGS_DEPENDENCIES "-DPINOCCHIO_WITH_URDFDOM")
195 196 197 198 199 200 201 202
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
    )
203 204
ENDIF(URDFDOM_FOUND)

205

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

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

225
LIST(APPEND HEADERS macros.hpp)
226

Nicolas Mansard's avatar
IVIGIT.  
Nicolas Mansard committed
227
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio")
228
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/core")
229
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/math")
Nicolas Mansard's avatar
IVIGIT.  
Nicolas Mansard committed
230 231
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/spatial")
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/multibody")
232
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/multibody/joint")
233
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/multibody/liegroup")
234
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/multibody/visitor")
235 236 237
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
238
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/utils")
239
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/serialization")
240
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/algorithm")
241
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/container")
242
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/codegen")
243 244
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/autodiff")

245
SET(HEADERS_)
246
FOREACH(header ${HEADERS})
247
  STRING(REGEX REPLACE "${PROJECT_SOURCE_DIR}/src/" "" header ${header})
248
  LIST(APPEND HEADERS_ ${header})
Nicolas Mansard's avatar
IVIGIT.  
Nicolas Mansard committed
249
  GET_FILENAME_COMPONENT(headerName ${header} NAME)
250 251 252 253 254
  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
255
          DESTINATION ${CMAKE_INSTALL_PREFIX}/include/${PROJECT_NAME}/${headerPath}
Nicolas Mansard's avatar
IVIGIT.  
Nicolas Mansard committed
256 257
          PERMISSIONS OWNER_READ GROUP_READ WORLD_READ OWNER_WRITE)
ENDFOREACH(header)
258
SET(HEADERS ${HEADERS_})
Nicolas Mansard's avatar
IVIGIT.  
Nicolas Mansard committed
259

260 261 262 263 264
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)

265
# --- MAIN LIBRARY -------------------------------------------------------------
266
ADD_SUBDIRECTORY(src)
267 268 269 270

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

271
# --- EXECUTABLES --------------------------------------------------------------
272 273 274
ADD_SUBDIRECTORY(utils)

# --- UNIT TESTS ---------------------------------------------------------------
275
ADD_SUBDIRECTORY(unittest)
276

277
# --- CHECK EXAMPLES -----------------------------------------------------------
278
ADD_SUBDIRECTORY(examples)
279

280
# --- BENCHMARKS ---------------------------------------------------------------
281
ADD_SUBDIRECTORY(benchmark)
jcarpent's avatar
jcarpent committed
282

283 284
# --- PACKAGING ----------------------------------------------------------------
PKG_CONFIG_APPEND_LIBS (${PROJECT_NAME})
Sébastien Barthélémy's avatar
Sébastien Barthélémy committed
285
PKG_CONFIG_APPEND_BOOST_LIBS(${BOOST_REQUIRED_COMPONENTS})
Nicolas Mansard's avatar
Nicolas Mansard committed
286

287 288 289
FOREACH(cflags ${CFLAGS_DEPENDENCIES})
  PKG_CONFIG_APPEND_CFLAGS(${cflags})
ENDFOREACH(cflags ${CFLAGS_DEPENDENCIES})
Wolfgang Merkt's avatar
Wolfgang Merkt committed
290 291 292

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