如何在构建distutils python时合并cmake文件? [英] How can I incorporate cmake file when building with distutils python?
问题描述
我有一个C ++逻辑,我从Python调用。我创建了一个setup.py使用distutils来构建和安装。 C ++逻辑有一个cmake文件。要构建C ++,需要将这个cmake文件合并到setup.py文件中。我如何做到这一点?下面是我的cmake文件的C ++代码。
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)
下面是我的setup.py文件。
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])
我是嵌入式python和cmake的新手。
I am new to embedded python and cmake. Please advice on how to do this.
推荐答案
因此,不要混淆cmake和setup.py,我将Python头文件转换为cmake并构建了一个共享库。然后使用这个共享库从Python调用我的函数。我的cmake如下,
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)
这篇关于如何在构建distutils python时合并cmake文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!