CMakeLists.txt 10.7 KB
Newer Older
Nicolas Mansard's avatar
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
Nicolas Mansard committed
4 5 6 7
#

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)

8 9 10 11 12
# Check if the submodule cmake have been initialized
IF(NOT EXISTS "${PROJECT_SOURCE_DIR}/cmake/base.cmake")
  MESSAGE(FATAL_ERROR "\nPlease run the following command first:\ngit submodule update --init\n")
ENDIF()

Nicolas Mansard's avatar
Nicolas Mansard committed
13 14 15
INCLUDE(cmake/base.cmake)
INCLUDE(cmake/boost.cmake)
INCLUDE(cmake/python.cmake)
16
INCLUDE(cmake/ide.cmake)
17
INCLUDE(cmake/apple.cmake)
Nicolas Mansard's avatar
Nicolas Mansard committed
18 19

SET(PROJECT_NAME pinocchio)
20
SET(PROJECT_DESCRIPTION "A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives")
jcarpent's avatar
jcarpent committed
21
SET(PROJECT_URL "http://github.com/stack-of-tasks/pinocchio")
22
SET(PROJECT_CUSTOM_HEADER_EXTENSION "hpp")
Nicolas Mansard's avatar
Nicolas Mansard committed
23

24 25
SET(DOXYGEN_USE_MATHJAX YES)

26 27
# If needed, fix CMake policy for APPLE systems
APPLY_DEFAULT_APPLE_CONFIGURATION()
28

Nicolas Mansard's avatar
Nicolas Mansard committed
29 30 31 32 33 34
# Disable -Werror on Unix for now.
SET(CXX_DISABLE_WERROR True)
SET(CMAKE_VERBOSE_MAKEFILE True)

SETUP_PROJECT()

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

41 42
# --- OPTIONS ----------------------------------------
OPTION (BUILD_BENCHMARK "Build the benchmarks" OFF)
43
OPTION (BUILD_UNIT_TESTS "Build the unitary tests" 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 50 51 52
# --- 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)
53
OPTION(BUILD_WITH_CASADI_SUPPORT "Build the library with the CASADI support" OFF)
54 55 56 57
OPTION(BUILD_WITH_CODEGEN_SUPPORT "Build the library with the Code Generation support" OFF)

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

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

63
SET(BUILD_TESTING ${BUILD_UNIT_TESTS})
64

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

Nicolas Mansard's avatar
Nicolas Mansard committed
69
# ----------------------------------------------------
Wolfgang Merkt's avatar
Typo  
Wolfgang Merkt committed
70
# --- DEPENDENCIES -----------------------------------
Nicolas Mansard's avatar
Nicolas Mansard committed
71
# ----------------------------------------------------
72
ADD_REQUIRED_DEPENDENCY("eigen3 >= 3.0.5")
73

74 75 76 77
IF(BUILD_WITH_URDF_SUPPORT)
  ADD_REQUIRED_DEPENDENCY("urdfdom >= 0.2.0")
ENDIF(BUILD_WITH_URDF_SUPPORT)

78
IF(BUILD_WITH_COLLISION_SUPPORT)
79
  ADD_REQUIRED_DEPENDENCY("hpp-fcl >= 1.0.0")
80
ENDIF(BUILD_WITH_COLLISION_SUPPORT)
81

82 83 84
IF(BUILD_WITH_AUTODIFF_SUPPORT)
  ADD_REQUIRED_DEPENDENCY("cppad >= 20180000.0")
ENDIF(BUILD_WITH_AUTODIFF_SUPPORT)
85

86
IF(CPPAD_FOUND AND BUILD_WITH_AUTODIFF_SUPPORT)
87 88 89 90 91 92
  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")
93

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

103 104 105 106
IF(BUILD_WITH_CASADI_SUPPORT)
  ADD_REQUIRED_DEPENDENCY("casadi >= 3.4.5")
ENDIF(BUILD_WITH_CASADI_SUPPORT)

107
IF(CASADI_FOUND AND BUILD_WITH_CASADI_SUPPORT)
108 109
  ADD_DEFINITIONS(-DPINOCCHIO_WITH_CASADI_SUPPORT)
  PKG_CONFIG_APPEND_CFLAGS("-DPINOCCHIO_WITH_CASADI_SUPPORT")
110
ENDIF(CASADI_FOUND AND BUILD_WITH_CASADI_SUPPORT)
111

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

  # defines types from version 0.4.0
  IF(NOT ${URDFDOM_VERSION} VERSION_LESS "0.4.0")
121 122
    ADD_DEFINITIONS(-DPINOCCHIO_URDFDOM_TYPEDEF_SHARED_PTR)
    PKG_CONFIG_APPEND_CFLAGS("-DPINOCCHIO_URDFDOM_TYPEDEF_SHARED_PTR")
123 124 125 126
  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")
127 128
    ADD_DEFINITIONS(-DPINOCCHIO_URDFDOM_USE_STD_SHARED_PTR)
    PKG_CONFIG_APPEND_CFLAGS("-DPINOCCHIO_URDFDOM_USE_STD_SHARED_PTR")
129
  ENDIF(${URDFDOM_VERSION} VERSION_GREATER "0.4.2")
130
ENDIF(URDFDOM_FOUND AND BUILD_WITH_URDF_SUPPORT)
131

132 133
# 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
134 135 136
IF(BUILD_WITH_LUA_SUPPORT)
  ADD_OPTIONAL_DEPENDENCY("lua5.2")
  IF(LUA5_2_FOUND)
137
    SET(LUA5_FOUND TRUE)
jcarpent's avatar
jcarpent committed
138
    SET(LUA5_PACKAGE "lua5.2")
139 140
    ADD_DEFINITIONS(-DPINOCCHIO_LUA_VERSION_GREATER_5_2)
    PKG_CONFIG_APPEND_CFLAGS("-DPINOCCHIO_LUA_VERSION_GREATER_5_2")
jcarpent's avatar
jcarpent committed
141 142 143 144 145 146 147 148 149 150
  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)
151

152
SET(BOOST_REQUIERED_COMPONENTS filesystem serialization system)
jcarpent's avatar
jcarpent committed
153 154 155
SET(BOOST_BUILD_COMPONENTS unit_test_framework)
SET(BOOST_OPTIONAL_COMPONENTS "")

156
IF(BUILD_PYTHON_INTERFACE)
jcarpent's avatar
jcarpent committed
157
  SET(BOOST_OPTIONAL_COMPONENTS ${BOOST_OPTIONAL_COMPONENTS} python)
158
  FINDPYTHON()
159
  INCLUDE_DIRECTORIES(SYSTEM ${PYTHON_INCLUDE_DIRS}) 
160 161
ENDIF(BUILD_PYTHON_INTERFACE)

jcarpent's avatar
jcarpent committed
162
SET(BOOST_COMPONENTS ${BOOST_REQUIERED_COMPONENTS} ${BOOST_OPTIONAL_COMPONENTS} ${BOOST_BUILD_COMPONENTS})
163
SEARCH_FOR_BOOST()
164 165 166 167 168
# 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)
169

170 171
# Variable containing all the cflags definition relative to optional dependencies
SET(CFLAGS_DEPENDENCIES)
172
LIST(APPEND CFLAGS_DEPENDENCIES "-DBOOST_MPL_LIMIT_LIST_SIZE=30")
173

174
# Path to boost headers
175
INCLUDE_DIRECTORIES(SYSTEM ${Boost_INCLUDE_DIRS})
176

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

185
IF(URDFDOM_FOUND)
186 187
  ADD_DEFINITIONS(-DPINOCCHIO_WITH_URDFDOM)
  LIST(APPEND CFLAGS_DEPENDENCIES "-DPINOCCHIO_WITH_URDFDOM")
188 189 190 191 192 193 194 195
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
    )
196 197
ENDIF(URDFDOM_FOUND)

198

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

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

218 219 220 221 222

LIST(APPEND HEADERS
     exception.hpp
     macros.hpp
     )
223

Nicolas Mansard's avatar
Nicolas Mansard committed
224
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio")
225
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/core")
226
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/math")
Nicolas Mansard's avatar
Nicolas Mansard committed
227 228
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/spatial")
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/multibody")
229
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/multibody/joint")
230
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/multibody/liegroup")
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")
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
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}
251
    DESTINATION ${CMAKE_INSTALL_PREFIX}/include/${PROJECT_NAME}/${headerPath}
Nicolas Mansard's avatar
Nicolas Mansard committed
252 253
          PERMISSIONS OWNER_READ GROUP_READ WORLD_READ OWNER_WRITE)
ENDFOREACH(header)
254
SET(HEADERS ${HEADERS_})
Nicolas Mansard's avatar
Nicolas Mansard committed
255

256
# --- MAIN LIBRARY -------------------------------------------------------------
257
ADD_SUBDIRECTORY(src)
258 259 260 261

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

262
# --- EXECUTABLES --------------------------------------------------------------
263 264 265
ADD_SUBDIRECTORY(utils)

# --- UNIT TESTS ---------------------------------------------------------------
266
ADD_SUBDIRECTORY(unittest)
267

268
# --- CHECK EXAMPLES -----------------------------------------------------------
269
ADD_SUBDIRECTORY(examples)
270

271
# --- BENCHMARKS ---------------------------------------------------------------
272
ADD_SUBDIRECTORY(benchmark)
273

274 275
# --- PACKAGING ----------------------------------------------------------------
PKG_CONFIG_APPEND_LIBS (${PROJECT_NAME})
jcarpent's avatar
jcarpent committed
276
PKG_CONFIG_APPEND_BOOST_LIBS(${BOOST_REQUIERED_COMPONENTS})
Nicolas Mansard's avatar
Nicolas Mansard committed
277

278 279 280 281
FOREACH(cflags ${CFLAGS_DEPENDENCIES})
  PKG_CONFIG_APPEND_CFLAGS(${cflags})
ENDFOREACH(cflags ${CFLAGS_DEPENDENCIES})

Nicolas Mansard's avatar
Nicolas Mansard committed
282
SETUP_PROJECT_FINALIZE()