Skip to content

Instantly share code, notes, and snippets.

@nfarring
Created October 28, 2010 17:51
Show Gist options
  • Save nfarring/651913 to your computer and use it in GitHub Desktop.
Save nfarring/651913 to your computer and use it in GitHub Desktop.
Example of how *not* to generate a Python wrapper library from a C library using CMake. Instead, CMake should only be used to build and install the C library, and distutils should be used for the Python wrapper library.
find_package(PythonLibs)
if(PYTHONLIBS_FOUND)
include_directories(${PYTHON_INCLUDE_PATH})
find_package(SWIG REQUIRED)
if(SWIG_FOUND)
include(${SWIG_USE_FILE})
#set(CMAKE_SWIG_FLAGS "")
#set_source_files_properties(my_swig_file.i
# PROPERTIES SWIG_FLAGS "")
#
# Define swig module with given name and specified language.
# SWIG_ADD_MODULE(name language [ files ])
#
SWIG_ADD_MODULE(MyPythonModule python
my_swig_file.i)
#
# Link libraries to swig module
# SWIG_LINK_LIBRARIES(name [ libraries ])
#
SWIG_LINK_LIBRARIES(MyPythonModule
${PYTHON_LIBRARIES}
my_c_library)
#
# This will probably install the Python library to the wrong place.
#
install(FILES
${PROJECT_BINARY_DIR}/python/MyPythonModule.py
${PROJECT_BINARY_DIR}/python/_MyPythonModule.so
DESTINATION lib/python2.7/site-packages)
else(SWIG_FOUND)
message("could not find swig; skipping swig library wrapper")
endif(SWIG_FOUND)
else(PYTHONLIBS_FOUND)
message("could not find python libraries; skipping swig library wrapper")
endif(PYTHONLIBS_FOUND)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment