From 5b202a87afbeab7ddb57bd748defce257a788427 Mon Sep 17 00:00:00 2001
From: William S Fulton
-There is growing support for SWIG in some build tools, for example CMake -is a cross-platform, open-source build tool with built in support for SWIG. It can detect the SWIG executable, -many of the target language interpreters and libraries for linking against. -It can then use this information to generate a makefile/project file for a host of different compilers/IDEs. -
-If you are using the GNU Autotools (Autoconf/ @@ -354,10 +347,45 @@ If you are using the GNU Autotools to configure SWIG use in your project, the SWIG Autoconf macros can be used. The primary macro is ac_pkg_swig, see http://www.gnu.org/software/ac-archive/htmldoc/ac_pkg_swig.html. -The ac_python_devel Autoconf macro is also helpful for SWIG generated Python interfaces, see the -Autoconf Macro Archive for further information and other . +The ac_python_devel macro is also helpful for generating Python extensions. See the +Autoconf Macro Archive +for further information on this and other Autoconf macros. +
+ ++There is growing support for SWIG in some build tools, for example CMake +is a cross-platform, open-source build manager with built in support for SWIG. CMake can detect the SWIG executable +and many of the target language libraries for linking against. +CMake knows how to build shared libraries and loadable modules on many different operating systems. +This allows easy cross platform SWIG development. It also can generate the custom commands necessary for +driving SWIG from IDE's and makefiles. All of this can be done from a single cross platform input file. +The following example is a CMake input file for creating a python wrapper for the SWIG interface file, example.i:
++ +The above example will generate native build files such as makefiles, nmake files and Visual Studio projects +which will invoke SWIG and compile the generated C++ files into _example.so (UNIX) or _example.dll (Windows). ++ +# 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) +SWIG_LINK_LIBRARIES(example ${PYTHON_LIBRARIES}) + +