[CMake] CMake + SWIG

Brad King brad.king at kitware.com
Tue Jul 25 09:19:13 EDT 2006


Daniel Tihelka wrote:
> Hallo everybody,
> 
> may I have two more simple questions about CMake and SWIG module?
> 
> The first is connected to the setting of SWIG parameters - when I create
>  wrapper for Java, I need to set -package <name> to SWIG.
> 
> It is impossible to set is as:
> 
> 	SET_SOURCE_FILES_PROPERTIES( ErisJava.i PROPERTIES SWIG_FLAGS "-package
>  my_package" )
> 
> as it is replaced by "-package\ my_package" in the call of SWIG. Moreover, it
>  overwrites all previous definitions of "PROPERTIES SWIG_FLAGS".

You can use GET_SOURCE_FILE_PROPERTY to get the old value and then
append.  Add the two options with a semicolon to separate them:

... SWIG_FLAGS "-package;my_package" ...

to make sure they are passed as separate arguments.  Basically the
property contains a CMake list of options, and CMake lists are semicolon
separated strings.

>  There is possibility of using:
> 
> 	SET(CMAKE_SWIG_FLAGS "-package my_package")
> 
> but if I understand it well, it swithes this parameter globally, for all swig
>  calls (also when wrapping e.g. python). So, how to deal with this? Is there
>  another way or is the second way correct?

You can set this variable before each call to SWIG_ADD_MODULE and unset
it afterwards.

> The second question is about "cmake -E copy" command. I have notices that the
>  use of wildcards is not possible in this command (event not documented?) - I
>  need to copy all generated Java wrappign classes, but I cannot use the
>  command "cmake -E copy source_dir/*.java destin_dir". I have solved it by
>  "cmake -E chdir dir comand", but I have completely lost the platform
>  independence.
> 
> I want kindly to ask you, if it would be possible to add support for
>  wildcards in the "cmake -E copy" command (or mabye to the others as well?) -
>  it will extend the abilities of the cmake while still be platform
>  independent. Or can it be solved in another way?

You can use "cmake -P myscript.cmake" to run a CMake script in place of
this command.  The script could use FILE(GLOB) and CONFIGURE_FILE(...
COPY_ONLY) to copy the files.

-Brad


More information about the CMake mailing list