[CMake] Fwd: SWIG + install

Tristan Carel tristan.carel at gmail.com
Tue Nov 7 20:05:49 EST 2006


On 11/7/06, Dan Tihelka <dtihelka at kky.zcu.cz> wrote:
> Hallo all,

Hi,

>
> I have become quite familiar with the basic use of SWIG from CMake. However,
>  I still have two things unresolved. Hopefully, it will not be an big
> problem ...
>
> The first think is: how to tell to SWIG other parameters? I have:
>
> SET_SOURCE_FILES_PROPERTIES(MyModule.i PROPERTIES CPLUSPLUS  ON)
> SET_SOURCE_FILES_PROPERTIES(MyModule.i PROPERTIES SWIG_FLAGS
> "-I${CMAKE_CURRENT_SOURCE_DIR}/../")
>
> to tell SWIG to include also .i files from one directory up (platform
> independent .i files are placed there.) But, I need to tell SWIG to add the
> name of package -package ,,,, for java wrapper:
>
> SET_SOURCE_FILES_PROPERTIES(MyModule.i PROPERTIES SWIG_FLAGS "-package
> my_module")
> But, it does not work. I think that the second set overwrites the first set.
> So the question is: how to join more parameters set to SWIG. I would like to
> note, that I build wrappers for several languages in one step (python, perl,
> java, ...)

Use a list instead of a string:

LIST(APPEND options -package Foo -module Bar)
SET_SOURCE_FILES_PROPERTIES(test.i PROPERTIES SWIG_FLAGS "${options}")

I guess UseSWIG.cmake should calls the macro `SEPARATE_ARGUMENTS' to
split the paramater.

> And the second think is how to create install target for those wrapped
> languages. My first idea was to use INSTALL(FILES ...) - or the old
> INSTALL_FLES - command and specify the mask of the files to install in each
> wrapped language, e.g. *.py + _*.so  for python, *.java + *.so for java, etc.
> However, the list of files to install (in cmake_install.cmake) is generated
> BEFORE those files are generated (e.g. during ccmake call), so it is usually
> empty. Moreover, the default path to serach for the files given by the regexp
> is the CMAKE_CURRENT_SOURCE_DIR, not the build dir. The use of
> INSTALL_TARGETS installs the library only, but not the wrapper file.
>
> The question, therefore, is. How to create install target for files generated
> by SWIG (both wrapper file(s) and library). Note, that, e.g. for java,
> several wrapp files are generated, and their names does not have to match the
> original .i files.

the ADD_CUSTOM_COMMAND defined by the SWIG_ADD_MODULE macro only
considers the generated source file, not the wrapped language's file
as the filename can be specified in the .i file (with %module).


So if you assume that the .i filename is the same than the module
name, you can write:
-------------------------------------------------------------------------------------------------------
PROJECT(SwigInstall)
FIND_PACKAGE(PythonLibs)
FIND_PACKAGE(SWIG)
INCLUDE(UseSWIG)

GET_FILENAME_COMPONENT(PYTHON_LIBRARY_PATH ${PYTHON_LIBRARY} PATH)
LINK_DIRECTORIES(${PYTHON_LIBRARY_PATH})
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})

SWIG_ADD_MODULE(test python my_module.i)
INSTALL(FILES ${CMAKE_BINARY_DIR}/${outdir}/my_module.py
	      DESTINATION share/python)
-------------------------------------------------------------------------------------------------------

If you use the swig command line option "-module <module>" in your
CMakeLists.txt, you are able to know the wrapped filenames.

SET_SOURCE_FILE_PROPERTIES(foo.i PROPERTIES SWIG_FLAGS
 "-java -module bar")
SWIG_ADD_MODULE(test python foo.i)
INSTALL(FILES
  ${CMAKE_BINARY_DIR}/${outdir}/bar.java
  ${CMAKE_BINARY_DIR}/${outdir}/barJNI.java
  DESTINATION share/java)

-- 
Tristan Carel
Music with dinner is an insult both to the cook and the violinist.


More information about the CMake mailing list