[CMake] Swig Generation

Michael Wild themiwi at gmail.com
Thu Jul 15 02:45:09 EDT 2010

On 14. Jul, 2010, at 22:36 , Michael.Schmidt at L-3com.com wrote:

> Hello again,
> I read the FAQ on Swig generation, but I still have a couple questions.
> Here's a snippet from my original Makefile.am:
> mylib_la_SOURCES = swig_main.i regular.cxx swig_gen.cxx
> ...
> swig_gen.cxx : swig_main.i swig_a.i swig_b.i regular.h
> 	swig -Wall $(INCLUDES) -c++ -python -o swig_gen.cxx swig_main.i
> Basically, I'm trying to build a library with a regular cxx file and a
> swig generated cxx file.  The swig ".i" file includes the swig_a.i and
> the swig_b.i files.  I couldn't figure out how to do this in cmake after
> reading the swig example.
> Thanks for your help,
> Mike

Never done it myself, but reading the FAQ and the docs, I'd suggest something like this:

find_package(SWIG REQUIRED)
find_package(PythonLibs REQUIRED)

set_source_files_properties(swig_main.i PROPERTIES
  # SWIG_FLAGS "-includeall" # enable if needed by you

set(SWIG_MODULE_mylib__EXTRA_DEPS swig_a.i swig_b.i regular.h)
swig_add_module(mylib python swig_main.i regular.cxx)
swig_link_libraries(mylib ${PYTHON_LIBRARIES})

I hope this helps getting you started


More information about the CMake mailing list