How can I incorporate cmake file when building with distutils python?

我与影子孤独终老i 提交于 2019-12-11 12:14:12

问题


I have a C++ logic which I'm calling from Python. I have created a setup.py using distutils to build and install. The C++ logic has a cmake file. To build the C++ this cmake file needs to be incorporated into the setup.py file. How can I do this? Below is my cmake file for the C++ code.

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)

set(name "facerec")
project(facerec_cpp_samples)

#SET(OpenCV_DIR /path/to/your/opencv/installation)

# packages
find_package(OpenCV REQUIRED) # http://opencv.willowgarage.com

add_executable(fisherfaces_app fisherfaces_app.cpp)
target_link_libraries(fisherfaces_app opencv_contrib opencv_core opencv_imgproc opencv_highgui)

Below is my setup.py file.

from distutils.core import setup,Extension

extension_mod=Extension("getGender",["getGender.cpp"])

setup(name="getGender",ext_modules=[extension_mod])

I am new to embedded python and cmake. Please advice on how to do this.


回答1:


So rather than messing it up with both cmake and setup.py, I incorporated the Python header file into cmake and built a shared library. Then used this shared library to call my functions from Python. My cmake is as follows,

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)

set(name "facerec")
project(facerec_cpp_samples)

#SET(OpenCV_DIR /path/to/your/opencv/installation)

# packages
find_package(OpenCV REQUIRED) # http://opencv.willowgarage.com

find_package(PythonLibs REQUIRED)
include_directories(/usr/include/python2.7)




add_library(getAge SHARED getAge.cpp)
target_link_libraries(getAge opencv_contrib opencv_core opencv_imgproc opencv_highgui python2.7)


来源:https://stackoverflow.com/questions/31577539/how-can-i-incorporate-cmake-file-when-building-with-distutils-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!