问题
Anyone have experience with using SWIG (the interface generator)?
I have a C project which I would like to expose to a bunch of other languages/frameworks, like Python, Java, .NET, Perl, PHP, Ruby.
I would like to integrate with my build system (which is CMake-based), but any method of accomplishing this will do.
回答1:
CMake comes with a module for building SWIG wrappers.
Your CMakeLists.txt should include something like this:
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 "")
SWIG_ADD_MODULE(example python example.i example.cxx)
SWIG_LINK_LIBRARIES(example ${PYTHON_LIBRARIES})
See http://www.itk.org/Wiki/CMake_FAQ#How_do_I_use_CMake_to_generate_SWIG_wrapper_libraries.3F for more details (the above example is taken from there...)
来源:https://stackoverflow.com/questions/1515374/using-swig-with-a-build-system