CMakeLists.txt 5.89 KB
Newer Older
1
# 
2
# Copyright (c) 2015-2016 CNRS
3
# Copyright (c) 2015 Wandercraft, 86 rue de Paris 91400 Orsay, France.
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 
# 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
20
21
22
23
24
25
26
27
28
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) 
29

30
31
32
33
34
35
36
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)
37

38
MACRO(ADD_TARGET_CFLAGS target flag)
39
  SET_PROPERTY(TARGET ${target} APPEND_STRING PROPERTY COMPILE_FLAGS " ${flag}")
40
41
ENDMACRO(ADD_TARGET_CFLAGS)

jcarpent's avatar
jcarpent committed
42
43
44
45
# ----------------------------------------------------
# --- C++ --------------------------------------------
# ----------------------------------------------------

46
47
SET(${PROJECT_NAME}_MULTIBODY_SOURCES
  multibody/model.cpp
48
49
50
51
  )

SET(${PROJECT_NAME}_PARSERS_SOURCES
  parsers/sample-models.cpp
52
53
  )

54
IF(BUILD_PYTHON_INTERFACE)
55
56
57
SET(${PROJECT_NAME}_PARSERS_PYTHON_SOURCES
  parsers/python.cpp
  )
58
ENDIF(BUILD_PYTHON_INTERFACE)
jcarpent's avatar
jcarpent committed
59

60
61
62
SET(${PROJECT_NAME}_SOURCES ${${PROJECT_NAME}_MULTIBODY_SOURCES})

IF(BUILD_PYTHON_INTERFACE)
63
64
  LIST(APPEND ${PROJECT_NAME}_SOURCES ${${PROJECT_NAME}_PARSERS_SOURCES}
                                      ${${PROJECT_NAME}_PARSERS_PYTHON_SOURCES})
65
ENDIF(BUILD_PYTHON_INTERFACE)
66

jcarpent's avatar
jcarpent committed
67
68
IF(LUA5_1_FOUND)
  SET(${PROJECT_NAME}_MULTIBODY_PARSER_LUA_SOURCES 
69
70
      parsers/lua/lua_tables.cpp
      parsers/lua.cpp
jcarpent's avatar
jcarpent committed
71
    )
72
  LIST(APPEND ${PROJECT_NAME}_SOURCES ${${PROJECT_NAME}_MULTIBODY_PARSER_LUA_SOURCES})
jcarpent's avatar
jcarpent committed
73
74
ENDIF(LUA5_1_FOUND)

jcarpent's avatar
jcarpent committed
75
76
77
78
79
80
IF(UNIX)
    # Create target libpinocchio.so
    ADD_LIBRARY ( ${PROJECT_NAME} SHARED ${HEADERS} ${${PROJECT_NAME}_SOURCES} )
    SET_TARGET_PROPERTIES( ${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)
    PKG_CONFIG_USE_DEPENDENCY(${PROJECT_NAME} eigen3)
    TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${Boost_LIBRARIES})
81
82
83
84

    IF(BUILD_PYTHON_INTERFACE)
      TARGET_LINK_BOOST_PYTHON(${PROJECT_NAME})
    ENDIF(BUILD_PYTHON_INTERFACE)
jcarpent's avatar
jcarpent committed
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103

    IF(URDFDOM_FOUND)
      PKG_CONFIG_USE_DEPENDENCY(${PROJECT_NAME} urdfdom)
    ENDIF(URDFDOM_FOUND)

    IF(HPP_FCL_FOUND)
      PKG_CONFIG_USE_DEPENDENCY(${PROJECT_NAME} hpp-fcl)
      ADD_TARGET_CFLAGS (${PROJECT_NAME} "-DWITH_HPP_FCL")
    ENDIF(HPP_FCL_FOUND)

    IF(LUA5_1_FOUND)
      PKG_CONFIG_USE_DEPENDENCY(${PROJECT_NAME} lua5.1)
    ENDIF(LUA5_1_FOUND)

    ADD_HEADER_GROUP(HEADERS)
    ADD_SOURCE_GROUP(${PROJECT_NAME}_SOURCES)

    INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib)
ENDIF(UNIX)
jcarpent's avatar
jcarpent committed
104

105
106
107
# ----------------------------------------------------
# --- PYTHON -----------------------------------------
# ----------------------------------------------------
108
IF(BUILD_PYTHON_INTERFACE)
109
110
111
112
113
114
  MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/lib/python/${PROJECT_NAME}")
  
  # --- COMPILE WRAPPER
  SET(PYWRAP ${PROJECT_NAME}_pywrap)
  ADD_LIBRARY(${PYWRAP} SHARED python/module.cpp python/python.cpp)
  PKG_CONFIG_USE_DEPENDENCY(${PYWRAP} eigenpy)
115

116
117
118
  IF(URDFDOM_FOUND)
    PKG_CONFIG_USE_DEPENDENCY(${PYWRAP} urdfdom)
  ENDIF(URDFDOM_FOUND)
119
  IF(HPP_FCL_FOUND)
120
121
    PKG_CONFIG_USE_DEPENDENCY(${PYWRAP} hpp-fcl)
    ADD_TARGET_CFLAGS (${PYWRAP} "-DWITH_HPP_FCL")
122
  ENDIF(HPP_FCL_FOUND)
jcarpent's avatar
jcarpent committed
123
124
125
  IF(LUA5_1_FOUND)
    PKG_CONFIG_USE_DEPENDENCY(${PYWRAP} lua5.1)
  ENDIF(LUA5_1_FOUND)
126
127
128

  TARGET_LINK_LIBRARIES(${PYWRAP} ${PROJECT_NAME} ${Boost_LIBRARIES})
  TARGET_LINK_BOOST_PYTHON(${PYWRAP})
129
130
131
132
133
134

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

135
136
  SET_TARGET_PROPERTIES(${PYWRAP} PROPERTIES
    LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/python/${PROJECT_NAME}")
137

138
139
140
141
142
143
144
145
146
  INSTALL(FILES
    "${CMAKE_BINARY_DIR}/lib/python/${PROJECT_NAME}/lib${PYWRAP}.so"
    DESTINATION ${PYTHON_SITELIB}/${PROJECT_NAME})
  
  # --- INSTALL SCRIPTS 
  SET(PYTHON_FILES
    python/__init__.py
    python/utils.py
    python/robot_wrapper.py
147
    python/romeo_wrapper.py
148
149
150
151
    python/rpy.py
    python/explog.py
    )
  
152
  FOREACH(python ${PYTHON_FILES})
153
154
155
156
157
158
159
160
161
162
163
164
    GET_FILENAME_COMPONENT(pythonFile ${python} NAME)
    EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E ${LINK}
      ${${PROJECT_NAME}_SOURCE_DIR}/src/${python}
      ${${PROJECT_NAME}_BINARY_DIR}/lib/python/${PROJECT_NAME}/${pythonFile})
      
    # Tag pyc file as generated.
    SET_SOURCE_FILES_PROPERTIES(
      "${${PROJECT_NAME}_BINARY_DIR}/lib/python/${PROJECT_NAME}/${pythonFile}c"
      PROPERTIES GENERATED TRUE)
      
    EXECUTE_PROCESS(COMMAND
      ${PYTHON_EXECUTABLE} -m py_compile
165
      ${${PROJECT_NAME}_BINARY_DIR}/lib/python/${PROJECT_NAME}/${pythonFile})
166
167
168
169
170
171
172
173
      
    # Clean generated files.
    SET_PROPERTY(
      DIRECTORY APPEND PROPERTY
      ADDITIONAL_MAKE_CLEAN_FILES
      "${${PROJECT_NAME}_BINARY_DIR}/lib/python/${PROJECT_NAME}/${pythonFile}c")
      
    INSTALL(FILES
174
      "${${PROJECT_NAME}_SOURCE_DIR}/src/${python}"
175
176
177
178
      "${${PROJECT_NAME}_BINARY_DIR}/lib/python/${PROJECT_NAME}/${pythonFile}c"
      DESTINATION ${PYTHON_SITELIB}/${PROJECT_NAME})
  ENDFOREACH(python)

179
180
ENDIF(BUILD_PYTHON_INTERFACE)