Answers for "swig cmake c++/c to python"

0

swig cmake c++/c to python

cmake minimum required(VERSION 2.8)
    project (mongoAPI)
    
    #allow gdb to run on the shared object; required for debugging.
    set(CMAKE BUILD TYPE Debug)
    
    #this sets the output directory of anything cmake generates
    SET(CMAKE LIBRARY OUTPUT_DIRECTORY {root})
    
    #this sets the output directory of anything SWIG generates
    set(CMAKE SWIG OUTDIR {root})
    
    #gcc flags.  this is required for the Mongo driver to compile
    set(CMAKE C FLAGS "-std=c99")
    
    #point to the Mongo driver header files
    include_directories("/projects/mjacobi/lib/mongo-c-driver-master/mongoc/include/") 
    
    #this generate the actual .so file for mongofs
    add_library(mongoAPI SHARED ../mongofsAPI.c) 
    
    #this says where to put the generated .so relative to the directory "cmake" is executed from
    set target properties(mongoAPI PROPERTIES LIBRARY OUTPUT DIRECTORY ${PROJECT BINARY DIR}/..) 
    
    #this tells cmake to link my API to the Mongo object
    target link libraries(mongoAPI /path/to/libmongoc.so) 
    
    #SWIG stuff:
    #load the cmake SWIG package
    find package(SWIG REQUIRED)
    include(${SWIG USE_FILE})
    
    #load the package that SWIG uses to generate Python
    find_package(PythonLibs)
    
    #point to python headers
    include directories(${PYTHON INCLUDE_DIRS})
    
    #tell SWIG to create a new module, called mongopyAPI, 
    #in Python and point to the SWIG interface file (the .i file)
    swig add module(mongopyAPI python ../mongopyAPI.i)
    
    #link the above module to the API (the shared object) we just created
    swig link libraries(mongopyAPI mongoAPI)
    
    #also link the above module to Python
    swig link libraries(mongopyAPI ${PYTHON_LIBRARIES} )
Posted by: Guest on January-26-2022

Browse Popular Code Answers by Language