User Tools

Site Tools


info:cython

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
info:cython [2011-12-15 16:36]
sam [Disadvantages]
info:cython [2011-12-15 17:12] (current)
sam [Notes/Tricks] cmake
Line 55: Line 55:
     memcpy(<​void*>​ctypes_buffer,​ &​s_cython,​ sizeof(MyStruct))     memcpy(<​void*>​ctypes_buffer,​ &​s_cython,​ sizeof(MyStruct))
     return s_ctypes     return s_ctypes
 +</​code>​
 +
 +===== CMake Example =====
 +
 +<code cmake>
 +cmake_minimum_required(VERSION 2.8)
 +project(someproject)
 +
 +find_package(PythonLibs)
 +include_directories(${PYTHON_INCLUDE_PATH})
 +
 +# TODO: add --gdb option to cython if in Debug mode? Separate option?
 +set(FOO_PYX ${CMAKE_CURRENT_SOURCE_DIR}/​foo.pyx)
 +set(FOO_CPP ${CMAKE_CURRENT_BINARY_DIR}/​foo.cpp)
 +add_custom_command(OUTPUT ${FOO_CPP}
 +    COMMAND cython --cplus ${FOO_PYX} -o ${FOO_CPP}
 +    DEPENDS ${FOO_PYX})
 +set(PYLIB foo)
 +add_library(${PYLIB} SHARED ${FOO_CPP})
 +# Remove lib prefix, which Python doesn'​t use
 +set_target_properties(${PYLIB} PROPERTIES PREFIX ""​)
 +target_link_libraries(${PYLIB} ${PYTHON_LIBRARIES})
 +# ... add other libraries if needed
 </​code>​ </​code>​
info/cython.txt · Last modified: 2011-12-15 17:12 by sam