Reputation: 993
Starting with SWIG's help file, I want to run the following code
# This is a CMake example for Python
FIND_PACKAGE(SWIG REQUIRED)
INCLUDE(${SWIG_USE_FILE})
FIND_PACKAGE(PythonLibs)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
SET(CMAKE_SWIG_FLAGS "")
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 example.cxx) # I need to link to an external library
SWIG_LINK_LIBRARIES(example ${PYTHON_LIBRARIES})
This would work fine except that example.cxx in my case needs to be linked to a prexisting library, let's call it libmylibrary.a. I tried add this to the SWIG_LINK_LIBRARIES command but that didn't do the trick. Any ideas?
Upvotes: 1
Views: 2764
Reputation: 993
It turns out you just need to modify the last line above to read
SWIG_LINK_LIBRARIES(example mylibrary ${PYTHON_LIBRARIES})
where mylibrary is understood at the libmylibrary.a file.
Upvotes: 4