[CMake] python wrappers through xcode

Antoine PREVOT tonio_lesec at yahoo.fr
Thu Jul 31 09:33:46 EDT 2008


> [Alan]
>
> Hi Tonio:
> 
> See CMakeLists.txt at
> http://plplot.svn.sourceforge.net/viewvc/plplot/trunk/bindings/python/

[Tonio]

Hi Alan,

Thanks again for your help !

I somehow managed to get a good-looking behavior in XCode, but I now have to deal with a "Fatal Python error: Interpreter not initialized (version mismatch?)" while trying to import the generated _example.so .

I will check the linked ${PYTHON_LIBRARIES} to make sure it's the attended one, and the generated debug/release configurations. From what I googled, it seems to be a very common issue.

> [Alan]
>
> it looked like you were not setting some key
> SWIG-related variables that we use above.
> (e.g., CMAKE_SWIG_FLAGS, CMAKE_SWIG_OUTDIR,
> SWIG_MODULE_<modulename>_EXTRA_DEPS, and the
> SWIG_MODULE_NAME property)

[Tonio]

The global CMAKE_SWIG_FLAG is only set to "-c++" in the top level CMakeLists of my example. More contextual SWIG_FLAG is set later, with SET_SOURCE_FILE_PROPERTIES ("-includeall").

I added CMAKE_SWIG_OUTDIR, but it's only useful to overcome any default project path (it's a good thing to do yet).

SWIG_MODULE_name_EXTRA_DEPS is not mandatory, nor SWIG_MODULE_NAME, i'll skip them for now.

According to the man page SWIG_ADD_MODULE and SWIG_LINK_LIBRARIES should be sufficient.

> [Alan]
>
> I hope this help on the fundamentals of Swig support in CMake
> gets rid of or at least reduces the XCODE problems you are seeing.

[Tonio]

I tried some different orders and ways to declare things, and have finally come to the conclusion that the main problems were :
- I was re-declaring source files (SWIG_ADD_MODULE & ADD_LIBRARY) which probably explains by itself this strange entries duplication.
- I was only linking my module against the python lib (SWIG_LINK_LIBRARIES)

Here's the working trunk\src\mysdk\CMakeLists.txt example (I got rid of the "Utils" subpart to make it cleaner) :

******************** trunk\src\mysdk\CMakeLists.txt
SET(MYSDK_SOURCES example.cpp)
ADD_LIBRARY(mysdk ${MYSDK_SOURCES})
SET(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR})
SET_SOURCE_FILES_PROPERTIES(example.i PROPERTIES CPLUSPLUS ON)
SET_SOURCE_FILES_PROPERTIES(example.i PROPERTIES SWIG_FLAGS "-includeall")
SWIG_ADD_MODULE(example python example.i)
SWIG_LINK_LIBRARIES(example mysdk ${PYTHON_LIBRARIES})

In this test I declare example.cpp once for the mysdk lib build, and example.i for the swig module (since it is pointing to example.cpp by itself). I also added mysdk in the SWIG_LINK_LIBRARIES to get rid of a "undefined symbol" error at compilation time.

This example correctly produces an additionnal library "_example(.so)" containing example.i and a reference to examplePYTHON_wrapper.cxx. The mysdk lib only contains example.cpp, which is exactly what I want.

Building with XCode successfully generates and compile examplePYTHON_wrap.cxx.

I will now try to get a working _example.so (should be easy), and then extend this method to the entire fluid library. Then I will test all this stuff in a Leopard/Xcode 3.0/CMake 2.6 configuration ... "god bless me" (c)(r)(tm)

Tonio




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


More information about the CMake mailing list