[CMake] SWIG support throughts : naming conventions

Antoine PREVOT tonio_lesec at yahoo.fr
Fri Aug 8 09:33:36 EDT 2008


Hi again,

I am still struggling with SWIG, and tested various things. Since UseSWIG.cmake seems quite similar from 2.4 to 2.6-1, here are some throughts I had while using it.

I don't know if my patches are relevant or not, I am probably using cmake the wrong way, but I'll give it a try ...

Oh, and sorry for multi-posting, but I think it's better to keep different subjects on different threads ;)

- throught

First thing is the naming convention of generated wrappers.

Wrappers (_wrap.cxx files) names are built from their interface file (.i) basename, then concatenated with the wrapped language. ie: wrapping to python, example.i will produce an examplePYTHON_wrap.cxx file. It's intended to wrap a single interface to different languages, great !

BUT, this file name doesn't match swig naming convention. wrapping an "example" module with an example.i interface should generate an example_wrap.cxx file, -and- an example.py script (proxy class declaration).

For now, concatenating the target language to the file name results on a simple low level library generation (C-style static calls of the form module_name_method(self, args...)), but swig won't be able to produce the corresponding proxy script.

Having the wrappers files named correctly results on a full generation after /usr/bin/swig call (C-style wrapper + proxy script).

- patch

I added a custom source file property "APPENDLANGUAGE", and modified UseSWIG.cmake this way :

******************** UseSWIG.cmake
MACRO(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile)
...
  GET_SOURCE_FILE_PROPERTY(swig_source_file_appendlanguage ${infile} APPENDLANGUAGE)
...
  IF(swig_source_file_appendlanguage)
    SET(swig_generated_file_fullname "${swig_generated_file_fullname}${SWIG_MODULE_${name}_LANGUAGE}_wrap")
  ELSE(swig_source_file_appendlanguage)
    SET(swig_generated_file_fullname
      "${swig_generated_file_fullname}_wrap")
  ENDIF(swig_source_file_appendlanguage)
...


So that I only have to write some lines on my CMakeLists.txt files, ie :
SET_SOURCE_FILES_PROPERTIES(example.i PROPERTIES APPENDLANGUAGE OFF)

That should be convenient for people wrapping to a single language anyway.

Tonio




      _____________________________________________________________________________ 
Envoyez avec Yahoo! Mail. Une boite mail plus intelligente http://mail.yahoo.fr


More information about the CMake mailing list