[CMake] CMake SWIG support for nested python modules
Bill Spotz
wfspotz at sandia.gov
Sun Apr 12 22:39:00 EDT 2009
So I was able to solve my problem of duplicate python target names
generated from SWIG interface files:
PyTrilinos/NOX/___init__.so
PyTrilinos/NOX/Epetra/___init__.so
by overhauling UseSWIG.cmake to take advantage of the OUTPUT_NAME
property of the SET_TARGET_PROPERTIES() function.
My problem now is that SWIG modules whose NAME and OUTPUT_NAME are
different are always built, even if they don't need to be. Is there a
way to get dependencies to work in this situation?
Thanks
On Apr 3, 2009, at 11:53 AM, Spotz, William F wrote:
> Bill,
>
> Thanks for the help. Once I realized I needed to do
>
> INCLUDE(UseSWIG)
>
> instead of
>
> INCLUDE(${SWIG_USE_FILE})
>
> in order to include my local copy, I made some good progress. Now I
> am facing the problem of duplicate swig module names. Here is
> (partially) what my resulting python package directory hierarchy
> should look like:
>
> PyTrilinos/
> NOX/
> __init__.py
> ___init__.so
> Abstract.py
> _Abstract.so
> Solver.py
> _Solver.so
> StatusTest.py
> _StatusTest.so
> Epetra/
> __init__.py
> ___init__.so
> Interface.py
> _Interface.so
>
> The problem is the multiple __init__ module names. Here is what I am
> currently trying, knowing full well it will fail:
>
> # Python module PyTrilinos.NOX
> SET(CMAKE_SWIG_OUTDIR PyTrilinos/NOX)
> SET_SOURCE_FILES_PROPERTIES(NOX.__init__.i PROPERTIES CPLUSPLUS ON)
> SWIG_ADD_MODULE(__init__ python NOX.__init__.i)
> SET_TARGET_PROPERTIES(${SWIG_MODULE___init___REAL_NAME}
> PROPERTIES LIBRARY_OUTPUT_DIRECTORY PyTrilinos/NOX)
>
> # Python module PyTrilinos.NOX.Epetra
> SET(CMAKE_SWIG_OUTDIR PyTrilinos/NOX/Epetra)
> SET_SOURCE_FILES_PROPERTIES(NOX.Epetra.__init__.i PROPERTIES
> CPLUSPLUS ON)
> SWIG_ADD_MODULE(__init__ python NOX.Epetra.__init__.i) # Repeat
> module name!
> SET_TARGET_PROPERTIES(${SWIG_MODULE___init___REAL_NAME}
> PROPERTIES LIBRARY_OUTPUT_DIRECTORY PyTrilinos/NOX/Epetra)
>
> Any ideas how to approach this?
>
> (I was thinking it would be nice to allow SWIG_ADD_MODULE to take, for
> example, NOX/__init__ or NOX/Epetra/__init__ as its first argument.
> But then SWIG_MODULE_<name>_REAL_NAME is not a valid variable name.
> In the latter case, we could substitute "_" for "/", but the UseSWIG
> module would have to know how to handle that.)
>
> Thanks
>
> On Apr 2, 2009, at 2:55 PM, Bill Hoffman wrote:
>
>>> I'm guessing there is a parsing of the swig interface filename which
>>> splits on the first "." it finds rather than the last.
>>
>> Yup, that is the problem...
>>
>>
>> MACRO(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile)
>>
>> ...
>> GET_FILENAME_COMPONENT(swig_source_file_path "${infile}" PATH)
>> GET_FILENAME_COMPONENT(swig_source_file_name_we "${infile}" NAME_WE)
>>
>> /**
>> * Return file name without extension of a full filename (i.e. without
>> path).
>> * Warning: it considers the longest extension (for example: .tar.gz)
>> */
>> kwsys_stl::string SystemTools::GetFilenameWithoutExtension(const
>> kwsys_stl::string& filename)
>> {
>>
>> So, how to fix it....
>>
>> You could copy the UseSwig.cmake into Trilinos and modify it. I
>> guess
>> we could change the code to use a regex replace and exchange the .i
>> for
>> empty.
>>
>> GET_FILENAME_COMPONENT(swig_source_file_name_we "${infile}" NAME_WE)
>> with
>> STRING(REGEX REPLACE "(.*)\\.i$" "\\1" swig_source_file_name_we $
>> {infile})
>>
>> -Bill
>
> ** Bill Spotz **
> ** Sandia National Laboratories Voice: (505)845-0170 **
> ** P.O. Box 5800 Fax: (505)284-0154 **
> ** Albuquerque, NM 87185-0370 Email: wfspotz at sandia.gov **
>
>
>
>
>
** Bill Spotz **
** Sandia National Laboratories Voice: (505)845-0170 **
** P.O. Box 5800 Fax: (505)284-0154 **
** Albuquerque, NM 87185-0370 Email: wfspotz at sandia.gov **
More information about the CMake
mailing list