A project I was working on recently in CMake required I build many SWIG interfaces, and I wanted a compact and clean way to do so. Below is a script that can be embeded in your CMake project to generate SWIG files based on your incoming arguments, as well as the signature for the function. This script assumes that you keep SWIG somewhere on your PATH. Note: It is your resposibility to compile the generated file(s). I recommend doing so with wildcards out of a personal preference.
swig_generate_wrapper(
ARGS_TO_SWIG - This represents the arguments you wish to pass to SWIG
OUTPUT_DIRECTORY - Where you want to generate new files. Set CURRENT_SOURCE_DIR to use current directory.
INPUT_FILE - The (relative!) path to the interface file you wish to compile.
)
Here is an example project that compiles a C++ wrap file with Node.JS:
...
project (my_cool_project)
swig_generate_wrapper("-c++ -javascript -jsc" "src" "src/my_cool_interface.i")
file(GLOB SOURCE_FILES "src/*.cpp" "src/*.h" "src/*.cxx")
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES})
...