Add python wrapper

This commit is contained in:
John Zhao 2018-05-17 17:28:43 +08:00
parent 2ff0ed504d
commit 072fe4d397
5 changed files with 191 additions and 0 deletions

View File

@ -27,6 +27,7 @@ help:
@echo " make samples build samples" @echo " make samples build samples"
@echo " make tools build tools" @echo " make tools build tools"
@echo " make ros build ros wrapper" @echo " make ros build ros wrapper"
@echo " make py build python wrapper"
@echo " make clean|cleanall clean generated or useless things" @echo " make clean|cleanall clean generated or useless things"
.PHONY: help .PHONY: help
@ -158,6 +159,23 @@ cleanros:
.PHONY: cleanros .PHONY: cleanros
# python
py: python
python: install
@$(call echo,Make $@)
@$(call cmake_build,./wrappers/python/_build)
.PHONY: py python
cleanpy:
@$(call echo,Make $@)
@$(call rm,./wrappers/python/_build/)
@$(call rm,./wrappers/python/_output/)
.PHONY: cleanpy
# clean # clean
clean: clean:
@ -175,6 +193,7 @@ clean:
ifeq ($(HOST_OS),Linux) ifeq ($(HOST_OS),Linux)
@$(MAKE) cleanros @$(MAKE) cleanros
endif endif
@$(MAKE) cleanpy
cleanlog: cleanlog:
@$(call rm_f,*INFO*) @$(call rm_f,*INFO*)

View File

@ -1,3 +1,4 @@
# Wrappers for MYNT® EYE SDK # Wrappers for MYNT® EYE SDK
* [MYNT® EYE ROS Wrapper](https://github.com/slightech/MYNT-EYE-SDK-2/tree/master/wrappers/ros) * [MYNT® EYE ROS Wrapper](https://github.com/slightech/MYNT-EYE-SDK-2/tree/master/wrappers/ros)
* [MYNT® EYE Python Wrapper](https://github.com/slightech/MYNT-EYE-SDK-2/tree/master/wrappers/python)

View File

@ -0,0 +1,148 @@
# Copyright 2018 Slightech Co., Ltd. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required(VERSION 3.0)
project(mynteye_python VERSION 2.0.0 LANGUAGES C CXX)
get_filename_component(PRO_DIR "${PROJECT_SOURCE_DIR}/../.." ABSOLUTE)
include(${PRO_DIR}/cmake/Common.cmake)
# configs
#set(BOOST_ROOT)
#set(BOOST_FIND_VERSION 1.67)
# Boost Python 2.7
set(PYTHON_FIND_VERSION 2.7)
set(PYTHON_BOOST_SUFFIX 27)
set(PYTHON_BOOST_CODE)
# Boost Python 3.6
#set(PYTHON_FIND_VERSION 3.6)
#set(PYTHON_BOOST_SUFFIX 36)
#set(PYTHON_BOOST_CODE 3)
if(OS_MAC)
execute_process(
COMMAND brew --prefix python@2
OUTPUT_VARIABLE PYTHON_INSTALL_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(PYTHON_INSTALL_PREFIX)
message(STATUS "PYTHON_INSTALL_PREFIX: ${PYTHON_INSTALL_PREFIX}")
set(PYTHON_INCLUDE_DIR "${PYTHON_INSTALL_PREFIX}/Frameworks/Python.framework/Headers")
set(PYTHON_LIBRARY "${PYTHON_INSTALL_PREFIX}/Frameworks/Python.framework/Python")
endif()
endif()
# options
include(${PRO_DIR}/cmake/Option.cmake)
if(NOT WITH_API)
message(FATAL_ERROR "Must with API layer :(")
endif()
# flags
if(OS_WIN)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
endif()
include(${PRO_DIR}/cmake/DetectCXX11.cmake)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
string(STRIP "${CMAKE_C_FLAGS}" CMAKE_C_FLAGS)
string(STRIP "${CMAKE_CXX_FLAGS}" CMAKE_CXX_FLAGS)
message(STATUS "C_FLAGS: ${CMAKE_C_FLAGS}")
message(STATUS "CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
# packages
LIST(APPEND CMAKE_PREFIX_PATH ${PRO_DIR}/third_party/glog/_build)
find_package(glog REQUIRED)
message(STATUS "Found glog: ${glog_VERSION}")
LIST(APPEND CMAKE_PREFIX_PATH ${PRO_DIR}/_install/lib/cmake)
find_package(mynteye REQUIRED)
message(STATUS "Found mynteye: ${mynteye_VERSION}")
if(CMAKE_VERSION VERSION_LESS "3.10" OR CMAKE_VERSION VERSION_EQUAL "3.10")
find_package(Boost ${BOOST_FIND_VERSION} REQUIRED
COMPONENTS python${PYTHON_BOOST_CODE}
)
else()
find_package(Boost ${BOOST_FIND_VERSION} REQUIRED COMPONENTS
python${PYTHON_BOOST_SUFFIX}
)
endif()
message(STATUS "Found Boost: ${Boost_VERSION}")
message(STATUS " Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
message(STATUS " Boost_LIBRARIES: ${Boost_LIBRARIES}")
find_package(PythonLibs ${PYTHON_FIND_VERSION} REQUIRED)
message(STATUS "Found PythonLibs: ${PYTHONLIBS_VERSION_STRING}")
message(STATUS " PYTHON_INCLUDE_DIRS: ${PYTHON_INCLUDE_DIRS}")
message(STATUS " PYTHON_LIBRARIES: ${PYTHON_LIBRARIES}")
#LIST(APPEND CMAKE_MODULE_PATH ${PRO_DIR}/cmake)
# targets
set(OUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/_output")
set_outdir(
"${OUT_DIR}/lib"
"${OUT_DIR}/lib"
"${OUT_DIR}/bin"
)
if(OS_WIN)
add_definitions(${Boost_LIB_DIAGNOSTIC_DEFINITIONS})
endif()
# add_library_py(NAME
# [SRCS src1 src2 ...]
# [LINK_LIBS lib1 lib2 ...])
macro(add_library_py NAME)
set(options)
set(oneValueArgs)
set(multiValueArgs SRCS LINK_LIBS)
cmake_parse_arguments(THIS "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN})
add_library(${NAME} SHARED ${THIS_SRCS})
target_link_libraries(${NAME}
${THIS_LINK_LIBS} ${Boost_LIBRARIES} ${PYTHON_LIBRARIES}
)
target_include_directories(${NAME} PUBLIC
${Boost_INCLUDE_DIRS}
${PYTHON_INCLUDE_DIR}
)
set_target_properties(${NAME} PROPERTIES PREFIX "")
if(OS_MAC)
set_target_properties(${NAME} PROPERTIES SUFFIX ".so")
endif()
endmacro()
## mynteye_py
add_library_py(mynteye_py SRCS src/mynteye_py.cc LINK_LIBS mynteye)

18
wrappers/python/README.md Normal file
View File

@ -0,0 +1,18 @@
# MYNT® EYE Python Wrapper
## Prerequisites
* [Boost.Python](https://www.boost.org/doc/libs/1_67_0/libs/python/doc/html/index.html)
## Build
```bash
cd <sdk>
make python
```
## Run
```bash
python
```

View File

@ -0,0 +1,5 @@
#include <boost/python.hpp>
using namespace boost::python; // NOLINT
BOOST_PYTHON_MODULE(mynteye_py) {}