How can I incorporate cmake file when building wit

2019-08-11 11:30发布

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条回答
ゆ 、 Hurt°
2楼-- · 2019-08-11 12:01

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)
查看更多
登录 后发表回答