CMakeLists.txt 10.7 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 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
IVIGIT.  
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/test.cmake)
Nicolas Mansard's avatar
IVIGIT.  
Nicolas Mansard committed
18 19 20

SET(PROJECT_NAME pinocchio)
SET(PROJECT_DESCRIPTION "Rigid multi body dynamics algorithms")
jcarpent's avatar
jcarpent committed
21
SET(PROJECT_URL "http://github.com/stack-of-tasks/pinocchio")
22
SET(PROJECT_CUSTOM_HEADER_EXTENSION "hpp")
jcarpent's avatar
jcarpent committed
23
OPTION(INSTALL_DOCUMENTATION "Generate and install the documentation" ON)
Nicolas Mansard's avatar
IVIGIT.  
Nicolas Mansard committed
24

25 26
SET(DOXYGEN_USE_MATHJAX YES)

27
IF(APPLE)
28 29 30 31 32 33 34 35 36 37
  SET(CMAKE_MACOSX_RPATH TRUE)
  SET(CMAKE_SKIP_BUILD_RPATH  FALSE)
  SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
  SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

  set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
  list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
  if("${isSystemDir}" STREQUAL "-1")
     set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
  endif("${isSystemDir}" STREQUAL "-1")
38 39
ENDIF(APPLE)

Nicolas Mansard's avatar
IVIGIT.  
Nicolas Mansard committed
40 41 42 43 44 45
# Disable -Werror on Unix for now.
SET(CXX_DISABLE_WERROR True)
SET(CMAKE_VERBOSE_MAKEFILE True)

SETUP_PROJECT()

46 47 48 49 50 51
IF(WIN32)
  SET(LINK copy_if_different)
ELSE(WIN32)
  SET(LINK create_symlink)
ENDIF(WIN32)

52 53
# --- OPTIONS ----------------------------------------
OPTION (BUILD_BENCHMARK "Build the benchmarks" OFF)
54
OPTION (BUILD_UNIT_TESTS "Build the unitary tests" ON)
55
OPTION (BUILD_UTILS "Build the utils" OFF)
56
OPTION (BUILD_PYTHON_INTERFACE "Build the python binding" ON)
jcarpent's avatar
jcarpent committed
57
OPTION (BUILD_WITH_LUA_SUPPORT "Build the lua parser" OFF)
58
OPTION (BUILD_WITH_COMMIT_VERSION "Build libraries by setting specific commit version" OFF)
59

60 61 62 63
# --- 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)
64
OPTION(BUILD_WITH_CASADI_SUPPORT "Build the library with the CASADI support" OFF)
65 66 67 68
OPTION(BUILD_WITH_CODEGEN_SUPPORT "Build the library with the Code Generation support" OFF)

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

69
IF (INITIALIZE_WITH_NAN)
jcarpent's avatar
jcarpent committed
70
  MESSAGE (STATUS "Initialize with NaN all the Eigen entries.")
71 72
  ADD_DEFINITIONS(-DEIGEN_INITIALIZE_MATRICES_BY_NAN)
ENDIF (INITIALIZE_WITH_NAN)
73

74 75 76 77 78 79
IF(BUILD_UNIT_TESTS)
  SET(DISABLE_TESTS OFF)
ELSE(BUILD_UNIT_TESTS)
  SET(DISABLE_TESTS ON)
ENDIF(BUILD_UNIT_TESTS)

80 81 82 83
MACRO(TAG_LIBRARY_VERSION target)
  SET_TARGET_PROPERTIES(${target} PROPERTIES SOVERSION ${PROJECT_VERSION})
ENDMACRO(TAG_LIBRARY_VERSION)

Nicolas Mansard's avatar
IVIGIT.  
Nicolas Mansard committed
84
# ----------------------------------------------------
Wolfgang Merkt's avatar
Typo  
Wolfgang Merkt committed
85
# --- DEPENDENCIES -----------------------------------
Nicolas Mansard's avatar
IVIGIT.  
Nicolas Mansard committed
86
# ----------------------------------------------------
87
ADD_REQUIRED_DEPENDENCY("eigen3 >= 3.0.5")
88

89 90 91 92
IF(BUILD_WITH_URDF_SUPPORT)
  ADD_REQUIRED_DEPENDENCY("urdfdom >= 0.2.0")
ENDIF(BUILD_WITH_URDF_SUPPORT)

93
IF(BUILD_WITH_COLLISION_SUPPORT)
94
  ADD_REQUIRED_DEPENDENCY("hpp-fcl >= 1.0.0")
95
ENDIF(BUILD_WITH_COLLISION_SUPPORT)
96

97 98 99
IF(BUILD_WITH_AUTODIFF_SUPPORT)
  ADD_REQUIRED_DEPENDENCY("cppad >= 20180000.0")
ENDIF(BUILD_WITH_AUTODIFF_SUPPORT)
100

101
IF(CPPAD_FOUND AND BUILD_WITH_AUTODIFF_SUPPORT)
102 103 104 105 106 107
  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")
108

109 110 111
  IF(BUILD_WITH_CODEGEN_SUPPORT)
    ADD_OPTIONAL_DEPENDENCY("cppadcg")
  ENDIF(BUILD_WITH_CODEGEN_SUPPORT)
112
  IF(CPPADCG_FOUND AND BUILD_WITH_CODEGEN_SUPPORT)
113 114
    ADD_DEFINITIONS(-DPINOCCHIO_WITH_CPPADCG_SUPPORT)
    PKG_CONFIG_APPEND_CFLAGS("-DPINOCCHIO_WITH_CPPADCG_SUPPORT")
Justin Carpentier's avatar
Justin Carpentier committed
115
  ENDIF(CPPADCG_FOUND AND BUILD_WITH_CODEGEN_SUPPORT)
116
ENDIF(CPPAD_FOUND AND BUILD_WITH_AUTODIFF_SUPPORT)
117

118 119 120 121
IF(BUILD_WITH_CASADI_SUPPORT)
  ADD_REQUIRED_DEPENDENCY("casadi >= 3.4.5")
ENDIF(BUILD_WITH_CASADI_SUPPORT)

122
IF(CASADI_FOUND AND BUILD_WITH_CASADI_SUPPORT)
123 124
  ADD_DEFINITIONS(-DPINOCCHIO_WITH_CASADI_SUPPORT)
  PKG_CONFIG_APPEND_CFLAGS("-DPINOCCHIO_WITH_CASADI_SUPPORT")
125
ENDIF(CASADI_FOUND AND BUILD_WITH_CASADI_SUPPORT)
126

127
# Special care of urdfdom version
128
IF(URDFDOM_FOUND AND BUILD_WITH_URDF_SUPPORT)
129
  IF(${URDFDOM_VERSION} VERSION_LESS "0.3.0")
130 131
    ADD_DEFINITIONS(-DPINOCCHIO_URDFDOM_COLLISION_WITH_GROUP_NAME)
    PKG_CONFIG_APPEND_CFLAGS("-DPINOCCHIO_URDFDOM_COLLISION_WITH_GROUP_NAME")
132
  ENDIF(${URDFDOM_VERSION} VERSION_LESS "0.3.0")
133 134 135

  # defines types from version 0.4.0
  IF(NOT ${URDFDOM_VERSION} VERSION_LESS "0.4.0")
136 137
    ADD_DEFINITIONS(-DPINOCCHIO_URDFDOM_TYPEDEF_SHARED_PTR)
    PKG_CONFIG_APPEND_CFLAGS("-DPINOCCHIO_URDFDOM_TYPEDEF_SHARED_PTR")
138 139 140 141
  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")
142 143
    ADD_DEFINITIONS(-DPINOCCHIO_URDFDOM_USE_STD_SHARED_PTR)
    PKG_CONFIG_APPEND_CFLAGS("-DPINOCCHIO_URDFDOM_USE_STD_SHARED_PTR")
144
  ENDIF(${URDFDOM_VERSION} VERSION_GREATER "0.4.2")
145
ENDIF(URDFDOM_FOUND AND BUILD_WITH_URDF_SUPPORT)
146

147 148
# 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
149 150 151
IF(BUILD_WITH_LUA_SUPPORT)
  ADD_OPTIONAL_DEPENDENCY("lua5.2")
  IF(LUA5_2_FOUND)
152
    SET(LUA5_FOUND TRUE)
jcarpent's avatar
jcarpent committed
153
    SET(LUA5_PACKAGE "lua5.2")
154 155
    ADD_DEFINITIONS(-DPINOCCHIO_LUA_VERSION_GREATER_5_2)
    PKG_CONFIG_APPEND_CFLAGS("-DPINOCCHIO_LUA_VERSION_GREATER_5_2")
jcarpent's avatar
jcarpent committed
156 157 158 159 160 161 162 163 164 165
  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)
166

167
SET(BOOST_REQUIERED_COMPONENTS filesystem serialization system)
jcarpent's avatar
jcarpent committed
168 169 170
SET(BOOST_BUILD_COMPONENTS unit_test_framework)
SET(BOOST_OPTIONAL_COMPONENTS "")

171
IF(BUILD_PYTHON_INTERFACE)
jcarpent's avatar
jcarpent committed
172
  SET(BOOST_OPTIONAL_COMPONENTS ${BOOST_OPTIONAL_COMPONENTS} python)
173
  FINDPYTHON()
174
  INCLUDE_DIRECTORIES(SYSTEM ${PYTHON_INCLUDE_DIRS}) 
175 176
ENDIF(BUILD_PYTHON_INTERFACE)

jcarpent's avatar
jcarpent committed
177
SET(BOOST_COMPONENTS ${BOOST_REQUIERED_COMPONENTS} ${BOOST_OPTIONAL_COMPONENTS} ${BOOST_BUILD_COMPONENTS})
178
SEARCH_FOR_BOOST()
179

180 181 182
# Variable containing all the cflags definition relative to optional dependencies
SET(CFLAGS_DEPENDENCIES)

183
# Path to boost headers
184
INCLUDE_DIRECTORIES(SYSTEM ${Boost_INCLUDE_DIRS})
185

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

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

207

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

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

227 228 229 230 231

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

Nicolas Mansard's avatar
IVIGIT.  
Nicolas Mansard committed
233
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio")
234
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/core")
235
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/math")
Nicolas Mansard's avatar
IVIGIT.  
Nicolas Mansard committed
236 237
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/spatial")
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/multibody")
238
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/multibody/joint")
239
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/multibody/liegroup")
240 241 242
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
243
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/utils")
244
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/serialization")
245
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/algorithm")
246
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/container")
247
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/codegen")
248
SET(HEADERS_)
249
FOREACH(header ${HEADERS})
250
  STRING(REGEX REPLACE "${PROJECT_SOURCE_DIR}/src/" "" header ${header})
251
  LIST(APPEND HEADERS_ ${header})
Nicolas Mansard's avatar
IVIGIT.  
Nicolas Mansard committed
252
  GET_FILENAME_COMPONENT(headerName ${header} NAME)
253 254 255 256 257
  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}
258
    DESTINATION ${CMAKE_INSTALL_PREFIX}/include/${PROJECT_NAME}/${headerPath}
Nicolas Mansard's avatar
IVIGIT.  
Nicolas Mansard committed
259 260
          PERMISSIONS OWNER_READ GROUP_READ WORLD_READ OWNER_WRITE)
ENDFOREACH(header)
261
SET(HEADERS ${HEADERS_})
Nicolas Mansard's avatar
IVIGIT.  
Nicolas Mansard committed
262

263
# --- MAIN LIBRARY -------------------------------------------------------------
264
ADD_SUBDIRECTORY(src)
265 266 267 268

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

269
# --- EXECUTABLES --------------------------------------------------------------
270 271 272
ADD_SUBDIRECTORY(utils)

# --- UNIT TESTS ---------------------------------------------------------------
273
ADD_SUBDIRECTORY(unittest)
274

275
# --- CHECK EXAMPLES -----------------------------------------------------------
276
ADD_SUBDIRECTORY(examples)
277

278
# --- BENCHMARKS ---------------------------------------------------------------
279
ADD_SUBDIRECTORY(benchmark)
jcarpent's avatar
jcarpent committed
280

281 282
# --- PACKAGING ----------------------------------------------------------------
PKG_CONFIG_APPEND_LIBS (${PROJECT_NAME})
jcarpent's avatar
jcarpent committed
283
PKG_CONFIG_APPEND_BOOST_LIBS(${BOOST_REQUIERED_COMPONENTS})
Nicolas Mansard's avatar
Nicolas Mansard committed
284

285 286 287 288
FOREACH(cflags ${CFLAGS_DEPENDENCIES})
  PKG_CONFIG_APPEND_CFLAGS(${cflags})
ENDFOREACH(cflags ${CFLAGS_DEPENDENCIES})

Nicolas Mansard's avatar
IVIGIT.  
Nicolas Mansard committed
289
SETUP_PROJECT_FINALIZE()