CMakeLists.txt 4.17 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
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) 
12

13
14
15
16
17
18
19
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)
20

21
22
23
24
25
MACRO(ADD_TARGET_CFLAGS target flag)
  GET_TARGET_PROPERTY(${target}_CFLAGS ${target} COMPILE_FLAGS) 
  SET_PROPERTY(TARGET ${target} PROPERTY COMPILE_FLAGS "${${target}_CFLAGS} ${flag}")
ENDMACRO(ADD_TARGET_CFLAGS)

jcarpent's avatar
jcarpent committed
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# ----------------------------------------------------
# --- C++ --------------------------------------------
# ----------------------------------------------------

IF(LUA5_1_FOUND)
  SET(${PROJECT_NAME}_MULTIBODY_PARSER_LUA_SOURCES 
      multibody/parser/lua/lua_tables.cpp
      multibody/parser/lua.cpp
    )
ENDIF(LUA5_1_FOUND)

SET(${PROJECT_NAME}_SOURCES ${${PROJECT_NAME}_MULTIBODY_PARSER_LUA_SOURCES}) 

IF (UNIX )  
    # Create target libpinocchio.so
    ADD_LIBRARY ( ${PROJECT_NAME} SHARED ${HEADERS} ${${PROJECT_NAME}_SOURCES} )
		SET_TARGET_PROPERTIES( ${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)

    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 target libpinocchio.so
    INSTALL(FILES
      "${CMAKE_BINARY_DIR}/src/lib${PROJECT_NAME}.so"
      DESTINATION ${CMAKE_INSTALL_LIBDIR})
ENDIF ( )
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

# ----------------------------------------------------
# --- PYTHON -----------------------------------------
# ----------------------------------------------------

IF(EIGENPY_FOUND)
  FINDPYTHON()
  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)
  IF(URDFDOM_FOUND)
    PKG_CONFIG_USE_DEPENDENCY(${PYWRAP} urdfdom)
  ENDIF(URDFDOM_FOUND)
jcarpent's avatar
jcarpent committed
72
73
74
75
  IF(LUA5_1_FOUND)
    PKG_CONFIG_USE_DEPENDENCY(${PYWRAP} lua5.1)
  ENDIF(LUA5_1_FOUND)
  TARGET_LINK_LIBRARIES(${PYWRAP} ${Boost_LIBRARIES} ${PROJECT_NAME})
76
77
  SET_TARGET_PROPERTIES(${PYWRAP} PROPERTIES
    LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/python/${PROJECT_NAME}")
78
79
80
  IF(URDFDOM_FOUND)
    ADD_TARGET_CFLAGS (${PYWRAP} "-DWITH_URDFDOM") 
  ENDIF(URDFDOM_FOUND)
81
82
83
  IF(LUA5_1_FOUND)
    ADD_TARGET_CFLAGS (${PYWRAP} "-DWITH_LUA") 
  ENDIF(LUA5_1_FOUND)
84
85
86
87
88
89
90
91
92
  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
93
    python/romeo_wrapper.py
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
    python/rpy.py
    python/explog.py
    )
  
	FOREACH(python ${PYTHON_FILES})
    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
      ${${PROJECT_NAME}_BINARY_DIR}/lib/python/${PROJECT_NAME}/${pythonFile} )
      
    # Clean generated files.
    SET_PROPERTY(
      DIRECTORY APPEND PROPERTY
      ADDITIONAL_MAKE_CLEAN_FILES
      "${${PROJECT_NAME}_BINARY_DIR}/lib/python/${PROJECT_NAME}/${pythonFile}c")
      
    INSTALL(FILES
      "${${PROJECT_NAME}_BINARY_DIR}/lib/python/${PROJECT_NAME}/${pythonFile}"
      "${${PROJECT_NAME}_BINARY_DIR}/lib/python/${PROJECT_NAME}/${pythonFile}c"
      DESTINATION ${PYTHON_SITELIB}/${PROJECT_NAME})
  ENDFOREACH(python)

ENDIF(EIGENPY_FOUND)