Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating SWIG bindings with CMake

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.

like image 364
joemoe Avatar asked Sep 30 '09 15:09

joemoe


1 Answers

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})
like image 180
Tristram Gräbener Avatar answered Oct 17 '22 08:10

Tristram Gräbener