CMakeLists.txt 6.45 KB
Newer Older
Olivier Lantsoght's avatar
Olivier Lantsoght committed
1
cmake_minimum_required(VERSION 3.4)
Olivier Lantsoght's avatar
Olivier Lantsoght committed
2
project("Python Interface for MBsysC")
3
message("Starting the ${PROJECT_NAME}")
Olivier Lantsoght's avatar
Olivier Lantsoght committed
4
5

set(CMAKE_MODULE_PATH   ${CMAKE_CURRENT_SOURCE_DIR}/../../conf)
6
7
set(CMAKE_C_FLAGS         "-fPIC")
set(CMAKE_C_FLAGS_RELEASE "-O3"  )
Olivier Lantsoght's avatar
Olivier Lantsoght committed
8

9
10
# Variable created for this module have the prefix "IPY_"

Olivier Lantsoght's avatar
Olivier Lantsoght committed
11
find_package(Python REQUIRED)
12
#==============================================================================
13
# Defining useful variable
14
#==============================================================================
15
16
17
    # PATH to the root of MBsysC
    set(ROBOTRAN_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../")
    # PATH to the root of mbs_common
18
    set(MBS_SOURCE_DIR      "${ROBOTRAN_SOURCE_DIR}mbs_common")
19
    # PATH to the build folder of MBsysC
20
    set(MBS_BUILD_DIR       "${CMAKE_BINARY_DIR}")
21
22
23
24
    # Find MBsysC Libraries
    find_path(LibRobotranC_DIR LibRobotranCConfig.cmake "${MBS_BUILD_DIR}")
    find_package( LibRobotranC REQUIRED )
    
Olivier Lantsoght's avatar
Olivier Lantsoght committed
25
26
27
28
29
30
31
32
33
# Defining path to useful folders
    # Folders related to python
    include_directories(${PYTHON_INCLUDE_DIR} 
                        ${NUMPY_INCLUDE_DIR}
                        ${CMAKE_CURRENT_SOURCE_DIR}
                       )
    # Folder containing interfaces libraries
    link_directories (${LIBRARY_OUTPUT_PATH})
    # Folders containing MBsysC headers
34
35
36
37
38
39
40
41
42
43
44
45
    include_directories(${LIB_MBSYSC_INCLUDE_DIRS})

# Set library extension
    if(UNIX)
        set(IPY_LIB_EXT ".so")
    elseif(WIN32)
        set(IPY_LIB_EXT ".pyd")
    else()
        message("Unknow operating system, extension for cython library arbitrary choose: .so")
        set(IPY_LIB_EXT ".so")
    endif()
    
Olivier Lantsoght's avatar
Olivier Lantsoght committed
46

47
48
49
50
51
52
#==============================================================================
# Removing olds files
#=============================================================================
file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/mbs_data_py.c)
file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/mbs_part_py.c)
file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/mbs_dirdyn_py.c)
Olivier Lantsoght's avatar
Olivier Lantsoght committed
53
file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/mbs_solvekin_py.c)
54
55
56
file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/mbs_lmgc_py.cpp)
# Backward compatibility:
    file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/mbs_lmgc_py.c)
57
58


59
#==============================================================================
60
# Building the interface
61
62
63
#==============================================================================
# 1. MBS_DATA
#==============================================================================
64
add_custom_command(OUTPUT mbs_data_py.c
65
                   COMMAND ${CYTHON_EXECUTABLE} -f ${CMAKE_CURRENT_SOURCE_DIR}/mbs_data_py.pyx  -o ${CMAKE_CURRENT_BINARY_DIR}/mbs_data_py.c
66
                   DEPENDS mbs_data_py.pxd mbs_data_py.pyx
67
68
                   )
add_library(mbs_data_py SHARED  ${CMAKE_CURRENT_BINARY_DIR}/mbs_data_py.c)
69
set_target_properties(mbs_data_py   PROPERTIES PREFIX ""      )
70
set_target_properties(mbs_data_py   PROPERTIES SUFFIX "${IPY_LIB_EXT}"   )
71
target_link_libraries(mbs_data_py MBsysC_module MBsysC_loadXML MBsysC_utilities ${PYTHON_LIBRARIES})
72
73
74
75
76

#==============================================================================
# 2. MBS_DIRDYN
#==============================================================================
add_custom_command(OUTPUT mbs_dirdyn_py.c
77
                  COMMAND ${CYTHON_EXECUTABLE} -f ${CMAKE_CURRENT_SOURCE_DIR}/mbs_dirdyn_py.pyx  -o ${CMAKE_CURRENT_BINARY_DIR}/mbs_dirdyn_py.c
78
                   DEPENDS mbs_dirdyn_py.pxd mbs_dirdyn_py.pyx
79
80
                  )
add_library(mbs_dirdyn_py SHARED  ${CMAKE_CURRENT_BINARY_DIR}/mbs_dirdyn_py.c)
81
set_target_properties(mbs_dirdyn_py   PROPERTIES PREFIX ""      )
82
set_target_properties(mbs_dirdyn_py   PROPERTIES SUFFIX "${IPY_LIB_EXT}"   )
83
target_link_libraries(mbs_dirdyn_py MBsysC_module MBsysC_loadXML MBsysC_utilities mbs_data_py)
84
85
86
87
88

#==============================================================================
# 3. MBS_PART
#==============================================================================
add_custom_command(OUTPUT mbs_part_py.c
89
                  COMMAND ${CYTHON_EXECUTABLE} -f ${CMAKE_CURRENT_SOURCE_DIR}/mbs_part_py.pyx  -o ${CMAKE_CURRENT_BINARY_DIR}/mbs_part_py.c
90
                   DEPENDS mbs_part_py.pxd mbs_part_py.pyx
91
92
93
                  )
add_library(mbs_part_py SHARED  ${CMAKE_CURRENT_BINARY_DIR}/mbs_part_py.c)
set_target_properties(mbs_part_py   PROPERTIES PREFIX ""      )
94
set_target_properties(mbs_part_py   PROPERTIES SUFFIX "${IPY_LIB_EXT}"   )
95
target_link_libraries(mbs_part_py MBsysC_module MBsysC_loadXML MBsysC_utilities mbs_data_py)
96
97

#==============================================================================
Olivier Lantsoght's avatar
Olivier Lantsoght committed
98
99
100
101
102
103
104
105
106
107
108
109
110
# 4. MBS_SOLVEKIN
#==============================================================================
add_custom_command(OUTPUT mbs_solvekin_py.c
                  COMMAND ${CYTHON_EXECUTABLE} -f ${CMAKE_CURRENT_SOURCE_DIR}/mbs_solvekin_py.pyx  -o ${CMAKE_CURRENT_BINARY_DIR}/mbs_solvekin_py.c
                   DEPENDS mbs_solvekin_py.pxd mbs_solvekin_py.pyx
                  )
add_library(mbs_solvekin_py SHARED  ${CMAKE_CURRENT_BINARY_DIR}/mbs_solvekin_py.c)
set_target_properties(mbs_solvekin_py   PROPERTIES PREFIX ""      )
set_target_properties(mbs_solvekin_py   PROPERTIES SUFFIX "${IPY_LIB_EXT}"   )
target_link_libraries(mbs_solvekin_py MBsysC_module MBsysC_loadXML MBsysC_utilities mbs_data_py)

#==============================================================================
# 5. MBS_LMGC
111
#==============================================================================
112
IF(FLAG_IPY_WITH_MBS_LMGC)
113
114
115
    # Specify C++
    set( cxx_arg "--cplus" )
    set( pyx_lang "CXX" )
116
    # Folder containing the mbs-lmgc add-on
117
118
    link_directories (${MBS_BUILD_DIR}/mbs_add_on/mbs_lmgc/lib)
    # Header of the mbs-LMGC add-on
119
120
    include_directories(${MBS_SOURCE_DIR}/mbs_add_on/mbs_lmgc)
    # Building interface
121
122
123
124
125
    add_custom_command(OUTPUT mbs_lmgc_py.cpp
                      COMMAND ${CYTHON_EXECUTABLE} -f ${CMAKE_CURRENT_SOURCE_DIR}/mbs_lmgc_py.pyx  -o ${CMAKE_CURRENT_BINARY_DIR}/mbs_lmgc_py.cpp
                      ARGS ${cxx_arg}
                      #IMPLICIT_DEPENDS ${pyx_lang}
                      DEPENDS mbs_lmgc_py.pxd mbs_lmgc_py.pyx 
126
                      )
127
    add_library(mbs_lmgc_py SHARED  ${CMAKE_CURRENT_BINARY_DIR}/mbs_lmgc_py.cpp)
128
129
    set_target_properties(mbs_lmgc_py   PROPERTIES PREFIX ""      )
    set_target_properties(mbs_lmgc_py   PROPERTIES SUFFIX "${IPY_LIB_EXT}"   )
130
    target_link_libraries(mbs_lmgc_py MBsysC_module MBsysC_loadXML MBsysC_utilities mbs_data_py Robotran_Lmgc90)
131
ENDIF(FLAG_IPY_WITH_MBS_LMGC)