[CMake] Fwd: CMAKE + SWIG + more wrapped languages
Daniel Tihelka
dtihelka at kky.zcu.cz
Mon Jul 24 04:47:31 EDT 2006
Hallo everybody.
May I ask you for a help with SWIG module in CMake? I need to create more
wrapping libraries from one set of .i SWIG files. To use SWIG from CMake is
really trivial for one wrapped language, but I need to create more wrappers
in one step, as illustrated below:
I have directory structure like this:
wrap
|
+-- Module.i
+-- *.i (other SWIG interface files included by Module.i)
|
+-- python
+-- perl
+-- java
The "wrap/CMakeLists.txt" looks simple:
SUBDIRS(python perl java)
And for example "wrap/python/CMakeLists.txt" looks like (the CMakeLists will
look similarly for "perl" and "java" packages):
# Find and include required packages
FIND_PACKAGE( SWIG REQUIRED )
FIND_PACKAGE( PythonLibs REQUIRED )
INCLUDE( ${SWIG_USE_FILE} )
# Set include python path
INCLUDE_DIRECTORIES( ${PYTHON_INCLUDE_PATH} )
# Generated file is C++, tell it to SWIG
SET_SOURCE_FILES_PROPERTIES( Module.i PROPERTIES CPLUSPLUS ON )
# !!!!! Tell to SWIG that .i files are one directory up !!!!!
SET_SOURCE_FILES_PROPERTIES( Module.i PROPERTIES SWIG_FLAGS "-I../")
# Create wrapper
SWIG_ADD_MODULE( module python Module.i )
SWIG_LINK_LIBRARIES( module python2.4 )
# Copy the generated files as post-build step
ADD_CUSTOM_COMMAND( TARGET ${SWIG_MODULE_module_REAL_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND}
ARGS -E copy ${CMAKE_CURRENT_BINARY_DIR}/*.py
${CMAKE_CURRENT_SOURCE_DIR} )
#
ADD_CUSTOM_COMMAND( TARGET ${SWIG_MODULE_module_REAL_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND}
ARGS -E copy ${CMAKE_CURRENT_BINARY_DIR}/*.so
${CMAKE_CURRENT_SOURCE_DIR} )
However, when the build process is started, it finishes by error:
make[5]: Entering directory `/home/..../build//wrap/python'
make[5]: *** No rule to make target `/home/..../wrap/python/Module.i',
needed by `/home/..../build//wrap/python/Module_wrap.c'. Stop.
When I looked at ".../build/python/Makefile", there is target:
/home/..../build//wrap/python/Module_wrap.c: /home/..../wrap/python/Module.i
@echo "Building Swig
source /home/..../build/wrap/python/Module_wrap.c..."
/usr/bin/swig -python -I/usr/include/python2.4 -o
/home/..../build//wrap/python/Module_wrap.c /home/..../wrap/python/Module.i
However, there is no "-I../" switch specified by
"SET_SOURCE_FILES_PROPERTIES( Module.i PROPERTIES SWIG_FLAGS "-I../")".
Moreover, there is absolute path to the "Module.i" which is, however, wrong.
When I tries to call SWIG directly, but only with Module.i it was OK - the
-I switch seems to ensure the right path.
I have also tried to set "relative paths" during CMake configuration, but it
leaded to other errors during the build.
Could someone give me a hint how to solve this problem? Did I choose the
right approach, or should it be solved in different way? Or how to instruct
CMake not to use the whole path to .i file (neither absolute, nor relative)?
Any help will really be appreciated.
Thank you very much,
Dan
More information about the CMake
mailing list