1

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.

AnOldSoul
  • 4,017
  • 12
  • 57
  • 118
  • I have no idea how `setup.py` works, But, try to add system commands before calling `setup()` See http://stackoverflow.com/questions/89228/calling-an-external-command-in-python – bhathiya-perera Aug 01 '15 at 15:14
  • 1
    That didn't work mchn since Opencv is involved in this. When I tried system commands opencv rejects them throwing ownership exceptions. Managed to pull it off using only cmake. Removed the whole setup.py. Thanks! :) – AnOldSoul Aug 02 '15 at 02:10
  • You should post it as an answer for others to learn from then :) – bhathiya-perera Aug 02 '15 at 04:56

1 Answers1

-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)
AnOldSoul
  • 4,017
  • 12
  • 57
  • 118
  • 2
    This answers a question different from what you posed... Removing setup.py is not helpful from a Python perspective (e.g. install in virtualenv with `pip`) – Jorge Leitao Jan 23 '17 at 23:16