Skip to content

danielunderwood/swig-example

Repository files navigation

SWIG Example

This is an example of how to use CMake with the SWIG interface generator. It is meant for those interested to use as a guide to setting up a project built by CMake with interfaces in other languages generated by SWIG.

Getting Started

Docker

If you have docker installed, the following should get you started with a sample environment

$ docker build -t swig-example .
$ docker run --name swig-example -it swig-example
$ # Now in container
# python swig/python/test.py

Local Build

To build locally, the following should be installed:

  • cmake
  • swig
  • python Headers (python-dev for debian-based systems)

It can then be built and run with

$ # Build libraries
$ mkdir build && cd build
$ cmake ..
$ make -j4
$ # Note that this currently installs in /usr/lib, which isn't ideal
$ make install
$ make install-python
$ # Go back to root dir to run
$ cd ..
$ python swig/python/test.sh

Languages

This example currently generates interfaces for the following languages:

  • Python

I will add languages as I need to use them. Anyone that wishes to add another language, feel free to open a pull request and let me know if there are any issues with using the installation procedure described below with your language.