Generating SWIG bindings with CMake

荒凉一梦 提交于 2019-11-30 03:55:47

问题


How would I generate automatic bindings for a C project that is built using CMake?

I want to generate bindings for Python, Java, .NET, PHP, Perl, TCL, Ruby and Octave automatically.


回答1:


You can find an example here.

Snippet:

The following example is a CMake input file for creating a python wrapper for the SWIG interface file, example.i:

# This is a CMake example for Python

FIND_PACKAGE(SWIG REQUIRED)
INCLUDE(${SWIG_USE_FILE})

FIND_PACKAGE(PythonLibs)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})

SET(CMAKE_SWIG_FLAGS "")

SET_SOURCE_FILES_PROPERTIES(example.i PROPERTIES CPLUSPLUS ON)
SET_SOURCE_FILES_PROPERTIES(example.i PROPERTIES SWIG_FLAGS "-includeall")
SWIG_ADD_MODULE(example python example.i example.cxx)
SWIG_LINK_LIBRARIES(example ${PYTHON_LIBRARIES})


来源:https://stackoverflow.com/questions/1498969/generating-swig-bindings-with-cmake

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