使用CMake生成SWIG绑定

时间:2009-09-30 15:44:42

标签: c cmake swig introspection

如何为使用CMake构建的C项目生成自动绑定?

我想自动生成Python,Java,.NET,PHP,Perl,TCL,Ruby和Octave的绑定。

1 个答案:

答案 0 :(得分:9)

您可以找到示例here

段:

  

以下示例是一个CMake输入文件,用于为SWIG接口文件创建python包装器,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})