CMakeLists.txt 8.66 KB
Newer Older
1
# 
2
# Copyright (c) 2015-2017 CNRS
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Copyright (c) 2015 Wandercraft, 86 rue de Paris 91400 Orsay, France.
# 
# This file is part of Pinocchio
# Pinocchio is free software: you can redistribute it
# and/or modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation, either version
# 3 of the License, or (at your option) any later version.
# Pinocchio is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Lesser Public License for more details. You should have
# received a copy of the GNU Lesser General Public License along with
# Pinocchio If not, see
# <http://www.gnu.org/licenses/>.

18
19
# --- MACROS --- #

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
MACRO(ADD_GROUP GROUP_NAME FILENAMES)
  FOREACH(filename ${${FILENAMES}})
    GET_FILENAME_COMPONENT(filenamePath ${filename} PATH)
    IF(NOT (filenamePath STREQUAL ""))
      STRING(REGEX REPLACE "/" "\\\\" filenamePath ${filenamePath}) 
      SOURCE_GROUP("${GROUP_NAME}\\${filenamePath}" FILES ${filename})
    ELSE()
      SOURCE_GROUP("${GROUP_NAME}" FILES ${filename})
    ENDIF()
  ENDFOREACH()
ENDMACRO(ADD_GROUP) 

MACRO(ADD_HEADER_GROUP FILENAMES)
  ADD_GROUP("Header Files" ${FILENAMES})
ENDMACRO(ADD_HEADER_GROUP FILENAMES)

MACRO(ADD_SOURCE_GROUP FILENAMES)
  ADD_GROUP("Source Files" ${FILENAMES})
ENDMACRO(ADD_SOURCE_GROUP FILENAMES)

40
41
42
43
44
45
46
MACRO(SYMLINK_AND_INSTALL_HEADERS HEADERS SUBPATH)
  FOREACH(header ${HEADERS})
    GET_FILENAME_COMPONENT(headerName ${header} NAME)
    GET_FILENAME_COMPONENT(headerPath ${header} PATH)
    EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E ${LINK}
      ${CMAKE_CURRENT_SOURCE_DIR}/${header}
      ${${PROJECT_NAME}_BINARY_DIR}/include/${PROJECT_NAME}/${SUBPATH}/${header})
jcarpent's avatar
jcarpent committed
47

48
    INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${header}
jcarpent's avatar
jcarpent committed
49
      DESTINATION ${CMAKE_INSTALL_PREFIX}/include/${PROJECT_NAME}/${SUBPATH}/${headerPath}
50
51
52
53
            PERMISSIONS OWNER_READ GROUP_READ WORLD_READ OWNER_WRITE)
  ENDFOREACH(header)
ENDMACRO(SYMLINK_AND_INSTALL_HEADERS HEADERS SUBPATH)

54
55
56
# --- DEPENDENCIES --- #
SET(PKG_CONFIG_PYWRAP_REQUIRES "eigenpy >= 1.3.1")
FOREACH(dep ${PKG_CONFIG_PYWRAP_REQUIRES})
jcarpent's avatar
jcarpent committed
57
  ADD_COMPILE_DEPENDENCY(${dep})
58
ENDFOREACH(dep ${PKG_CONFIG_PYWRAP_REQUIRES})
59

60
# --- LIBRARY --- #
61
SET(${PYWRAP}_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/${PYTHON_SITELIB}/${PROJECT_NAME})
62

63
SET(${PROJECT_NAME}_PYTHON_HEADERS
jcarpent's avatar
jcarpent committed
64
65
  utils/eigen_container.hpp
  utils/handler.hpp
66
  utils/copyable.hpp
jcarpent's avatar
jcarpent committed
67
  utils/printable.hpp
68
69
  utils/std-vector.hpp
  utils/std-aligned-vector.hpp
70
  fwd.hpp
jcarpent's avatar
jcarpent committed
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
  spatial/se3.hpp
  spatial/force.hpp
  spatial/motion.hpp
  spatial/inertia.hpp
  spatial/explog.hpp
  multibody/frame.hpp
  multibody/model.hpp
  multibody/data.hpp
  multibody/geometry-object.hpp
  multibody/geometry-model.hpp
  multibody/geometry-data.hpp
  multibody/joint/joints-models.hpp
  multibody/joint/joints-variant.hpp
  multibody/joint/joint.hpp
  multibody/joint/joint-derived.hpp
86
87
  multibody/fcl/contact.hpp
  multibody/fcl/collision-result.hpp
jcarpent's avatar
jcarpent committed
88
#  multibody/fcl/distance-result.hpp
89
  multibody/fcl/collision-geometry.hpp
90
  algorithm/algorithms.hpp 
jcarpent's avatar
jcarpent committed
91
  parsers/parsers.hpp
92
93
94
95
  )

SET(${PROJECT_NAME}_PYTHON_SOURCES
  module.cpp
jcarpent's avatar
jcarpent committed
96
97
98
99
100
101
102
103
104
105
  spatial/expose-SE3.cpp
  spatial/expose-motion.cpp
  spatial/expose-force.cpp
  spatial/expose-inertia.cpp
  spatial/expose-explog.cpp
  multibody/expose-frame.cpp
  multibody/expose-model.cpp
  multibody/expose-data.cpp
  multibody/expose-geometry.cpp
  multibody/joint/expose-joints.cpp
106
  multibody/fcl/expose-fcl.cpp
107
108
109
110
111
112
113
114
115
116
117
118
  algorithm/expose-algorithms.cpp
  algorithm/expose-com.cpp
  algorithm/expose-kinematics.cpp
  algorithm/expose-dynamics.cpp
  algorithm/expose-crba.cpp
  algorithm/expose-rnea.cpp
  algorithm/expose-aba.cpp
  algorithm/expose-jacobian.cpp
  algorithm/expose-joints.cpp
  algorithm/expose-energy.cpp
  algorithm/expose-frames.cpp
  algorithm/expose-cat.cpp
jcarpent's avatar
jcarpent committed
119
  algorithm/expose-geometry.cpp
jcarpent's avatar
jcarpent committed
120
  parsers/expose-parsers.cpp
121
122
  )

jcarpent's avatar
jcarpent committed
123
124
SET(${PROJECT_NAME}_PARSER_PYTHON_HEADERS
  parsers/python.hpp
125
126
  )

jcarpent's avatar
jcarpent committed
127
128
SET(${PROJECT_NAME}_PARSER_PYTHON_SOURCES
  parsers/python/model.cpp
129
130
131
132
133
134
135
  )

LIST(APPEND HEADERS ${${PROJECT_NAME}_PYTHON_HEADERS})
LIST(REMOVE_DUPLICATES HEADERS)

# Headers of the python binding
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/bindings/python")
jcarpent's avatar
jcarpent committed
136
137
138
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/bindings/python/spatial")
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/bindings/python/multibody")
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/bindings/python/multibody/joint")
139
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/bindings/python/multibody/fcl")
jcarpent's avatar
jcarpent committed
140
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/bindings/python/parsers")
141
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/bindings/python/algorithm")
jcarpent's avatar
jcarpent committed
142
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/bindings/python/utils")
143
144
145
146
147
148
149
SYMLINK_AND_INSTALL_HEADERS("${${PROJECT_NAME}_PYTHON_HEADERS}" "bindings/python")

# Headers of the python parser
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/include/pinocchio/parsers/python")
SYMLINK_AND_INSTALL_HEADERS("${${PROJECT_NAME}_PARSER_PYTHON_HEADERS}" "")

# --- COMPILE WRAPPER
150
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/bindings/python/${PROJECT_NAME}")
151
152
153
154
SET(${PYWRAP}_SOURCES ${${PROJECT_NAME}_PYTHON_SOURCES} ${${PROJECT_NAME}_PARSER_PYTHON_SOURCES})
SET(${PYWRAP}_HEADERS ${${PROJECT_NAME}_PYTHON_HEADERS} ${${PROJECT_NAME}_PARSER_PYTHON_HEADERS})

ADD_LIBRARY(${PYWRAP} SHARED ${${PYWRAP}_SOURCES} ${${PYWRAP}_HEADERS})
155
156
157
IF(BUILD_WITH_COMMIT_VERSION)
  TAG_LIBRARY_VERSION(${PYWRAP})
ENDIF(BUILD_WITH_COMMIT_VERSION)
jcarpent's avatar
jcarpent committed
158
159
ADD_HEADER_GROUP(${PYWRAP}_HEADERS)
ADD_SOURCE_GROUP(${PYWRAP}_SOURCES)
160
161
162
163
164
PKG_CONFIG_USE_DEPENDENCY(${PYWRAP} eigenpy)

TARGET_LINK_LIBRARIES(${PYWRAP} ${PROJECT_NAME})
TARGET_LINK_BOOST_PYTHON(${PYWRAP})

165
166
167
168
IF(HPP_FCL_FOUND)
  PKG_CONFIG_USE_DEPENDENCY(${PYWRAP} hpp-fcl)
ENDIF(HPP_FCL_FOUND)

169
170
171
172
173
174
IF(APPLE)
  # We need to change the extension for python bindings
  SET_TARGET_PROPERTIES(${PYWRAP} PROPERTIES SUFFIX ".so")
ENDIF(APPLE)

SET_TARGET_PROPERTIES(${PYWRAP} PROPERTIES
175
  LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bindings/python/${PROJECT_NAME}")
176

177
INSTALL(TARGETS ${PYWRAP} DESTINATION ${${PYWRAP}_INSTALL_DIR})
178
179
180
181
182
183
184
185
186
187
188
189
190
191

# --- INSTALL SCRIPTS 
SET(PYTHON_FILES
  __init__.py
  utils.py
  robot_wrapper.py
  romeo_wrapper.py
  rpy.py
  explog.py
  )

FOREACH(python ${PYTHON_FILES})
  GET_FILENAME_COMPONENT(pythonFile ${python} NAME)
  EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E ${LINK}
192
193
    ${${PROJECT_NAME}_SOURCE_DIR}/bindings/python/scripts/${python}
    ${${PROJECT_NAME}_BINARY_DIR}/bindings/python/${PROJECT_NAME}/${pythonFile})
194
    
195
196
197
198
  # Generate pyc file
  EXECUTE_PROCESS(COMMAND
    ${PYTHON_EXECUTABLE} -m py_compile
    ${${PROJECT_NAME}_BINARY_DIR}/bindings/python/${PROJECT_NAME}/${pythonFile})
199
200
  # Tag pyc file as generated.
  SET_SOURCE_FILES_PROPERTIES(
201
    "${${PROJECT_NAME}_BINARY_DIR}/bindings/python/${PROJECT_NAME}/${pythonFile}c"
202
203
204
205
206
207
208
    PROPERTIES GENERATED TRUE)
    
    
  # Clean generated files.
  SET_PROPERTY(
    DIRECTORY APPEND PROPERTY
    ADDITIONAL_MAKE_CLEAN_FILES
209
    "${${PROJECT_NAME}_BINARY_DIR}/bindings/python/${PROJECT_NAME}/${pythonFile}c")
210
    
211
  INSTALL(FILES
212
213
    "${${PROJECT_NAME}_SOURCE_DIR}/bindings/python/scripts/${python}"
    "${${PROJECT_NAME}_BINARY_DIR}/bindings/python/${PROJECT_NAME}/${pythonFile}c"
214
    DESTINATION ${${PYWRAP}_INSTALL_DIR})
215
216
ENDFOREACH(python)

217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# --- PACKAGING --- #

# Format string
SET(_PKG_CONFIG_PYWRAP_LIBDIR ${${PYWRAP}_INSTALL_DIR})
SET(_PKG_CONFIG_PYWRAP_BINDIR ${${PYWRAP}_INSTALL_DIR})
SET(_PKG_CONFIG_PYWRAP_CONFLICTS)
SET(_PKG_CONFIG_PYWRAP_REQUIRES "${PROJECT_NAME}")
FOREACH(dep ${PKG_CONFIG_PYWRAP_REQUIRES})
  SET(_PKG_CONFIG_PYWRAP_REQUIRES "${_PKG_CONFIG_PYWRAP_REQUIRES}, ${dep}")
ENDFOREACH(dep ${PKG_CONFIG_PYWRAP_REQUIRES})

SET(_PKG_CONFIG_PYWRAP_LIBS "-L\${libdir} -l${PYWRAP}")
IF(APPLE)
  SET(_PKG_CONFIG_PYWRAP_LIBS "${_PKG_CONFIG_PYWRAP_LIBS} -Wl,-undefined,dynamic_lookup,${Boost_${UPPERCOMPONENT}_LIBRARY}")
ELSE(APPLE)
  SET(_PKG_CONFIG_PYWRAP_LIBS "${_PKG_CONFIG_PYWRAP_LIBS} ${LIBINCL_KW}boost_python")
ENDIF(APPLE)

SET(_PKG_CONFIG_PYWRAP_CFLAGS "-I\${includedir} -I/usr/local/include")
SET(_PKG_CONFIG_PYWRAP_CFLAGS "${_PKG_CONFIG_PYWRAP_CFLAGS} -I${PYTHON_INCLUDE_DIRS}")
FOREACH(cflags ${CFLAGS_DEPENDENCIES})
  SET(_PKG_CONFIG_PYWRAP_CFLAGS "${_PKG_CONFIG_PYWRAP_CFLAGS} ${cflags}")
ENDFOREACH(cflags ${CFLAGS_DEPENDENCIES})

CONFIGURE_FILE(
   "${CMAKE_CURRENT_SOURCE_DIR}/pinocchiopy.pc.cmake"
   "${CMAKE_CURRENT_BINARY_DIR}/pinocchiopy.pc")

INSTALL(
    FILES "${CMAKE_CURRENT_BINARY_DIR}/pinocchiopy.pc"
    DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
    PERMISSIONS OWNER_READ GROUP_READ WORLD_READ OWNER_WRITE)
249