[sword-svn] r2538 - in trunk: . bindings/swig bindings/swig/local cmake
greg.hellings at crosswire.org
greg.hellings at crosswire.org
Sun Aug 22 20:53:41 MST 2010
Author: greg.hellings
Date: 2010-08-22 20:53:41 -0700 (Sun, 22 Aug 2010)
New Revision: 2538
Added:
trunk/bindings/swig/local/
trunk/bindings/swig/local/std_multimap.i
Modified:
trunk/CMakeLists.txt
trunk/bindings/swig/sword.i
trunk/bindings/swig/sword.pl
trunk/bindings/swig/templates.i
trunk/cmake/bindings.cmake
Log:
Updated the source tree to build Perl bindings from the CMake settings.
Modified: trunk/CMakeLists.txt
===================================================================
--- trunk/CMakeLists.txt 2010-08-19 03:12:29 UTC (rev 2537)
+++ trunk/CMakeLists.txt 2010-08-23 03:53:41 UTC (rev 2538)
@@ -166,9 +166,9 @@
# Bindings are good, right?
#
-IF(SWORD_BINDINGS STREQUAL "Python")
+IF(NOT SWORD_BINDINGS STREQUAL "")
INCLUDE("${CMAKE_CURRENT_SOURCE_DIR}/cmake/bindings.cmake")
-ENDIF(SWORD_BINDINGS STREQUAL "Python")
+ENDIF(NOT SWORD_BINDINGS STREQUAL "")
##############################################################################################
# Utilities are hawt
Added: trunk/bindings/swig/local/std_multimap.i
===================================================================
--- trunk/bindings/swig/local/std_multimap.i (rev 0)
+++ trunk/bindings/swig/local/std_multimap.i 2010-08-23 03:53:41 UTC (rev 2538)
@@ -0,0 +1,166 @@
+//file std_multimap.i
+
+%include <std_common.i>
+
+
+%{
+#include <map>
+#include <algorithm>
+#include <stdexcept>
+#include <iostream>
+%}
+
+// exported class
+
+namespace std {
+
+ template<class T1, class T2> class multimap {
+ // add typemaps here
+ public:
+ multimap();
+ multimap(const multimap<T1,T2> &);
+
+ unsigned int size() const;
+ bool empty() const;
+ void clear();
+
+ %extend {
+ //need a way to get the first element
+ const T1 getElementOne(std::multimap<T1,T2>::iterator it) throw (std::out_of_range) {
+ return it->first;
+ }
+ //and the second
+ T2 getElementTwo(std::multimap<T1,T2>::iterator it) throw (std::out_of_range) {
+ return it->second;
+ }
+ //nice to have the beginning iterator
+ std::multimap<T1,T2>::iterator getBeginIterator() {
+ return self->begin();
+ }
+ //and to get the next iterator
+ std::multimap<T1,T2>::iterator getNextIterator(std::multimap<T1,T2>::iterator it) {
+ if (it != self->end()) {
+ return ++it;
+ } else {
+ return it;
+ }
+ }
+ }
+ };
+
+ //The rest is pretty much straight from std_map.i with name and signature changes
+ // specializations for built-ins
+
+ %define specialize_std_multimap_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO)
+
+ template<class T> class multimap<K,T> {
+ // add typemaps here
+ public:
+ multimap();
+ multimap(const multimap<K,T> &);
+
+ unsigned int size() const;
+ bool empty() const;
+ void clear();
+ %extend {
+ T& get(K key) throw (std::out_of_range) {
+ std::multimap<K,T >::iterator i = self->find(key);
+ if (i != self->end())
+ return i->second;
+ else
+ throw std::out_of_range("key not found");
+ }
+ void set(K key, const T& x) {
+ (*self)[key] = x;
+ }
+ void del(K key) throw (std::out_of_range) {
+ std::multimap<K,T >::iterator i = self->find(key);
+ if (i != self->end())
+ self->erase(i);
+ else
+ throw std::out_of_range("key not found");
+ }
+ bool has_key(K key) {
+ std::multimap<K,T >::iterator i = self->find(key);
+ return i != self->end();
+ }
+ }
+ };
+ %enddef
+
+ %define specialize_std_multimap_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO)
+ template<class K> class multimap<K,T> {
+ // add typemaps here
+ public:
+ multimap();
+ multimap(const multimap<K,T> &);
+
+ unsigned int size() const;
+ bool empty() const;
+ void clear();
+ %extend {
+ T get(const K& key) throw (std::out_of_range) {
+ std::multimap<K,T >::iterator i = self->find(key);
+ if (i != self->end())
+ return i->second;
+ else
+ throw std::out_of_range("key not found");
+ }
+ void set(const K& key, T x) {
+ (*self)[key] = x;
+ }
+ void del(const K& key) throw (std::out_of_range) {
+ std::multimap<K,T >::iterator i = self->find(key);
+ if (i != self->end())
+ self->erase(i);
+ else
+ throw std::out_of_range("key not found");
+ }
+ bool has_key(const K& key) {
+ std::multimap<K,T >::iterator i = self->find(key);
+ return i != self->end();
+ }
+ }
+ };
+ %enddef
+
+ %define specialize_std_multimap_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO,
+ T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO)
+ template<> class multimap<K,T> {
+ // add typemaps here
+ public:
+ multimap();
+ multimap(const multimap<K,T> &);
+
+ unsigned int size() const;
+ bool empty() const;
+ void clear();
+ %extend {
+ T get(K key) throw (std::out_of_range) {
+ std::multimap<K,T >::iterator i = self->find(key);
+ if (i != self->end())
+ return i->second;
+ else
+ throw std::out_of_range("key not found");
+ }
+ void set(K key, T x) {
+ (*self)[key] = x;
+ }
+ void del(K key) throw (std::out_of_range) {
+ std::multimap<K,T >::iterator i = self->find(key);
+ if (i != self->end())
+ self->erase(i);
+ else
+ throw std::out_of_range("key not found");
+ }
+ bool has_key(K key) {
+ std::multimap<K,T >::iterator i = self->find(key);
+ return i != self->end();
+ }
+ }
+ };
+ %enddef
+
+ // add specializations here
+
+}
Modified: trunk/bindings/swig/sword.i
===================================================================
--- trunk/bindings/swig/sword.i 2010-08-19 03:12:29 UTC (rev 2537)
+++ trunk/bindings/swig/sword.i 2010-08-23 03:53:41 UTC (rev 2538)
@@ -6,7 +6,9 @@
/* Ignore warnings about Unknown base class */
%warnfilter(401);
+#ifdef SWIGPYTHON
%include "directors.i"
+#endif
/* Some generic ignores. These don't map into any Python operators */
%ignore *::operator=;
Modified: trunk/bindings/swig/sword.pl
===================================================================
--- trunk/bindings/swig/sword.pl 2010-08-19 03:12:29 UTC (rev 2537)
+++ trunk/bindings/swig/sword.pl 2010-08-23 03:53:41 UTC (rev 2538)
@@ -49,29 +49,31 @@
$mgr = new Sword::SWMgr();
print "init ... ";
#$module = $mgr->module("GerLut1545-temp");
-$module = $mgr->module("WEB");
+$module = $mgr->getModule("WEB");
print "Printing WEB Module information: \n";
print "Name:\t", $module->Name(),"\nDescription:\t", $module->Description(), "\nLang:\t", $module->Lang(), "\n";
$key = new Sword::VerseKey("Matthew 3:16");
-$key->setPersist(1);
+#$key->setPersist(1);
$module->SetKey($key);
for ($i = 0; $i < 15; $i++) {
print "(", $module->KeyText() ,")\t", $module->StripText(), "\n";
- $key->next();
+ $key->increment();
+ $module->SetKey($key);
}
$key->increment(103);
+$module->SetKey($key);
print "(", $module->KeyText() ,")\t", $module->StripText(), "\n";
#testing write interface
$key->setText("John 3:16");
-#$module->SetKey($key);
-$module->write("This is a test entry! This tests the write abilities of the Sword Perl classes");
+$module->SetKey($key);
+$module->setEntry("This is a test entry! This tests the write abilities of the Sword Perl classes", 78);
print "(", $module->KeyText() ,")\t", $module->StripText(), "\n";
print "Searching for God: ";
-$list = $module->Search("Gott");
+$list = $module->doSearch("God");
print $list->Count(), " entries found!\n";
#for ( $i = 0; $i < $list->Count(); $i++) {
# print "(", $i, ")\t", $list->GetElement()->getText(), "\n";
@@ -105,7 +107,7 @@
print "Created module;\n";
$newkey = $newmod->CreateKey();
-$newkey->setPersist(1);
+#$newkey->setPersist(1);
$newkey->setText(" ");
$module->SetKey($newkey);
@@ -119,7 +121,8 @@
$newmod->SetKey($newkey);
- $newmod->write( $module->StripText() );
- $list->next();
+ $entry = $module->StripText();
+ $newmod->setEntry( $entry, length $entry );
+ $list->increment();
}
Modified: trunk/bindings/swig/templates.i
===================================================================
--- trunk/bindings/swig/templates.i 2010-08-19 03:12:29 UTC (rev 2537)
+++ trunk/bindings/swig/templates.i 2010-08-23 03:53:41 UTC (rev 2538)
@@ -3,7 +3,11 @@
%include <std_list.i>
%include <std_pair.i>
+#ifdef SWIGPYTHON
%include <std_multimap.i>
+#else
+%include "local/std_multimap.i"
+#endif
%include <multimapwdef.h>
/*
@@ -40,7 +44,9 @@
%template(AttributeTypeListMap) std::map < sword::SWBuf, AttributeListMap>;
/* Used by SWConfig */
+#ifdef SWIGPYTHON
%template(PyConfigEntMap) std::multimap < sword::SWBuf, sword::SWBuf, std::less <sword::SWBuf> >;
+#endif
/* %template() std::less <sword::SWBuf>;*/
%template() std::pair < sword::SWBuf, std::multimap < sword::SWBuf,
sword::SWBuf > >/*PyConfigEntMap >*/;
Modified: trunk/cmake/bindings.cmake
===================================================================
--- trunk/cmake/bindings.cmake 2010-08-19 03:12:29 UTC (rev 2537)
+++ trunk/cmake/bindings.cmake 2010-08-23 03:53:41 UTC (rev 2538)
@@ -15,6 +15,9 @@
ELSE(NOT SWIG_FOUND)
MESSAGE(STATUS "Swig found at ${SWIG_EXECUTABLE}")
+ SET(SWORD_SWIG_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/bindings/swig")
+ SET(SWORD_SWIG_BINARY "${CMAKE_CURRENT_BINARY_DIR}/bindings/swig")
+
# This code that is commented out is basically how CMake suggests that you do it. I, on the
# other hand, can't seem to get it to do that. The manual seems to work though, so go with that
# instead.
@@ -34,33 +37,98 @@
#"${CMAKE_CURRENT_SOURCE_DIR}/bindings/swig/python/Sword.cxx"
# )
#SWIG_LINK_LIBRARIES(sword ${PYTHON_LIBRARIES})
+
# Borrowed this from the CMake UseSWIG.cmake file
GET_DIRECTORY_PROPERTY(cmake_include_directories INCLUDE_DIRECTORIES)
SET(SWIG_INCLUDES)
FOREACH(direct ${cmake_include_directories})
SET(SWIG_INCLUDES ${SWIG_INCLUDES} "-I${direct}")
ENDFOREACH(direct ${cmake_include_directories})
- MESSAGE(STATUS "${SWIG_INCLUDES} include directories")
- # This should add the pythonswig target to be built when the "make" command is executed
- ADD_CUSTOM_TARGET(pythonswig ALL
- mkdir -p "${CMAKE_CURRENT_BINARY_DIR}/bindings/swig/python"
- COMMAND ${SWIG_EXECUTABLE} -python -c++ -shadow -o "${CMAKE_CURRENT_BINARY_DIR}/bindings/swig/python/Sword.cxx" -I${CMAKE_CURRENT_SOURCE_DIR}/bindings/swig ${SWIG_INCLUDES} ${CMAKE_CURRENT_SOURCE_DIR}/bindings/swig/sword.i
- COMMAND echo "#! /usr/bin/python" > ${CMAKE_CURRENT_BINARY_DIR}/bindings/swig/python/setup.py
- COMMAND echo "" >> ${CMAKE_CURRENT_BINARY_DIR}/bindings/swig/python/setup.py
- COMMAND echo "from distutils.core import setup, Extension" >> ${CMAKE_CURRENT_BINARY_DIR}/bindings/swig/python/setup.py
- COMMAND echo "setup (name = \"sword\"," >> ${CMAKE_CURRENT_BINARY_DIR}/bindings/swig/python/setup.py
- COMMAND echo " version = \"${SWORD_VERSION}\"," >> ${CMAKE_CURRENT_BINARY_DIR}/bindings/swig/python/setup.py
- COMMAND echo " maintainer = \"Sword Developers\"," >> ${CMAKE_CURRENT_BINARY_DIR}/bindings/swig/python/setup.py
- COMMAND echo " maintainer_email = \"sword-devel at crosswire.org\"," >> ${CMAKE_CURRENT_BINARY_DIR}/bindings/swig/python/setup.py
- COMMAND echo " url = \"http://www.crosswire.org/sword\"," >> ${CMAKE_CURRENT_BINARY_DIR}/bindings/swig/python/setup.py
- COMMAND echo " py_modules = [\"Sword\"]," >> ${CMAKE_CURRENT_BINARY_DIR}/bindings/swig/python/setup.py
- COMMAND echo " include_dirs=['${CMAKE_CURRENT_SOURCE_DIR}/bindings/swig', '${CMAKE_CURRENT_SOURCE_DIR}/include', '..', '../..']," >> ${CMAKE_CURRENT_BINARY_DIR}/bindings/swig/python/setup.py
- COMMAND echo " ext_modules = [Extension(\"_Sword\", [\"Sword.cxx\"]," >> ${CMAKE_CURRENT_BINARY_DIR}/bindings/swig/python/setup.py
- COMMAND echo " libraries=[('sword')], " >> ${CMAKE_CURRENT_BINARY_DIR}/bindings/swig/python/setup.py
- COMMAND echo " )], " >> ${CMAKE_CURRENT_BINARY_DIR}/bindings/swig/python/setup.py
- COMMAND echo ")" >> ${CMAKE_CURRENT_BINARY_DIR}/bindings/swig/python/setup.py
- DEPENDS sword
- WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bindings/swig"
- VERBATIM
- )
-ENDIF(NOT SWIG_FOUND)
\ No newline at end of file
+# MESSAGE(STATUS "${SWIG_INCLUDES} include directories")
+
+ IF(SWORD_BINDINGS MATCHES ".*Python.*")
+ # This should add the pythonswig target to be built when the "make" command is executed
+ ADD_CUSTOM_TARGET(pythonswig ALL
+ mkdir -p "${SWORD_SWIG_BINARY}/python"
+ COMMAND ${SWIG_EXECUTABLE} "-w503,+509" -python -c++ -shadow -o "${SWORD_SWIG_BINARY}/python/Sword.cxx" "-I${SWORD_SWIG_SOURCE}" ${SWIG_INCLUDES} "${SWORD_SWIG_SOURCE}/sword.i"
+ COMMAND echo "#! /usr/bin/python" > ${SWORD_SWIG_BINARY}/python/setup.py
+ COMMAND echo "" >> ${SWORD_SWIG_BINARY}/python/setup.py
+ COMMAND echo "from distutils.core import setup, Extension" >> ${SWORD_SWIG_BINARY}/python/setup.py
+ COMMAND echo "setup (name = \"sword\"," >> ${SWORD_SWIG_BINARY}/python/setup.py
+ COMMAND echo " version = \"${SWORD_VERSION}\"," >> ${SWORD_SWIG_BINARY}/python/setup.py
+ COMMAND echo " maintainer = \"Sword Developers\"," >> ${SWORD_SWIG_BINARY}/python/setup.py
+ COMMAND echo " maintainer_email = \"sword-devel at crosswire.org\"," >> ${SWORD_SWIG_BINARY}/python/setup.py
+ COMMAND echo " url = \"http://www.crosswire.org/sword\"," >> ${SWORD_SWIG_BINARY}/python/setup.py
+ COMMAND echo " py_modules = [\"Sword\"]," >> ${SWORD_SWIG_BINARY}/python/setup.py
+ COMMAND echo " include_dirs=['${SWORD_SWIG_SOURCE}', '${CMAKE_CURRENT_SOURCE_DIR}/include', '${SWORD_SWIG_SOURCE}/..', '${SWORD_SWIG_SOURCE}/../..']," >> ${SWORD_SWIG_BINARY}/python/setup.py
+ COMMAND echo " ext_modules = [Extension(\"_Sword\", [\"Sword.cxx\"]," >> ${SWORD_SWIG_BINARY}/python/setup.py
+ COMMAND echo " libraries=[('sword')], " >> ${SWORD_SWIG_BINARY}/python/setup.py
+ COMMAND echo " )], " >> ${SWORD_SWIG_BINARY}/python/setup.py
+ COMMAND echo ")" >> ${SWORD_SWIG_BINARY}/python/setup.py
+ COMMAND echo "Python bindings built, to install change into ${SWORD_SWIG_BINARY}/python and type 'python setup.py install'"
+ DEPENDS sword
+ WORKING_DIRECTORY "${SWORD_SWIG_SOURCE}"
+ VERBATIM
+ )
+
+ MESSAGE(STATUS "Configured for building Python bindings.")
+ ENDIF(SWORD_BINDINGS MATCHES ".*Python.*")
+
+ IF(SWORD_BINDINGS MATCHES ".*Perl.*")
+ FIND_PACKAGE(Perl REQUIRED)
+ IF(PERL_FOUND)
+ # This is a terrible hack. Don't leave it stay here. It's ugly
+ SET(LIB_SWORD "${CMAKE_CURRENT_BINARY_DIR}/libsword.a")
+# MESSAGE(STATUS "LIB_SWORD is ${LIB_SWORD}")
+ # This should add the perlswig target to be build with the "make" command is executed
+ ADD_CUSTOM_TARGET(perlswig ALL
+ mkdir -p "${SWORD_SWIG_BINARY}/perl"
+ COMMAND ${SWIG_EXECUTABLE} "-w503,+509" -perl -c++ -shadow -o "${SWORD_SWIG_BINARY}/perl/Sword.cxx" "-I${SWORD_SWIG_SOURCE}" ${SWIG_INCLUDES} "${SWORD_SWIG_SOURCE}/sword.i"
+ COMMAND echo "Writing ${SWORD_SWIG_BINARY}/perl/Makefile.PL"
+ COMMAND echo "#! /usr/bin/perl" > ${SWORD_SWIG_BINARY}/perl/Makefile.PL
+ COMMAND echo "" >> ${SWORD_SWIG_BINARY}/perl/Makefile.PL
+ COMMAND echo "use ExtUtils::MakeMaker;" >> ${SWORD_SWIG_BINARY}/perl/Makefile.PL
+ COMMAND echo "" >> ${SWORD_SWIG_BINARY}/perl/Makefile.PL
+ COMMAND echo "# See lib/ExtUtils/MakeMaker.pm for details of how to influence" >> ${SWORD_SWIG_BINARY}/perl/Makefile.PL
+ COMMAND echo "# the contents of the Makefile that is written." >> ${SWORD_SWIG_BINARY}/perl/Makefile.PL
+ COMMAND echo "WriteMakefile(" >> ${SWORD_SWIG_BINARY}/perl/Makefile.PL
+ COMMAND echo " 'NAME' => 'Sword'," >> ${SWORD_SWIG_BINARY}/perl/Makefile.PL
+ COMMAND echo " 'VERSION' => '${SWORD_VERSION}'," >> ${SWORD_SWIG_BINARY}/perl/Makefile.PL
+ COMMAND echo " 'INC' => '-I${CMAKE_CURRENT_SOURCE_DIR}/include -I${SWORD_SWIG_SOURCE}'," >> ${SWORD_SWIG_BINARY}/perl/Makefile.PL
+ COMMAND echo " 'DEFINE' => '-DSWIG'," >> ${SWORD_SWIG_BINARY}/perl/Makefile.PL
+ COMMAND echo " 'LIBS' => '-lsword -lz'," >> ${SWORD_SWIG_BINARY}/perl/Makefile.PL
+ COMMAND echo " 'PREREQ_PM' => {}, # e.g., Module::Name => 1.1" >> ${SWORD_SWIG_BINARY}/perl/Makefile.PL
+ COMMAND echo " ($] >= 5.005 ? ## Add these new keywords supported since 5.005" >> ${SWORD_SWIG_BINARY}/perl/Makefile.PL
+ COMMAND echo " (ABSTRACT => 'Sword Project perl bindings', # retrieve abstract from module" >> ${SWORD_SWIG_BINARY}/perl/Makefile.PL
+ COMMAND echo " AUTHOR => 'Sword Project <sword-devel at crosswire.org>') : ())," >> ${SWORD_SWIG_BINARY}/perl/Makefile.PL
+ COMMAND echo ");" >> ${SWORD_SWIG_BINARY}/perl/Makefile.PL
+ COMMAND echo "" >> ${SWORD_SWIG_BINARY}/perl/Makefile.PL
+ COMMAND echo "rename 'Makefile', 'Makefile.old' or die \"can't rename Makefile\";" >> ${SWORD_SWIG_BINARY}/perl/Makefile.PL
+ COMMAND echo "open(INPUT, '<Makefile.old') or die \"can't open input Makefile.old\";" >> ${SWORD_SWIG_BINARY}/perl/Makefile.PL
+ COMMAND echo "open(OUTPUT, '>Makefile') or die \"can't open output Makefile\";" >> ${SWORD_SWIG_BINARY}/perl/Makefile.PL
+ COMMAND echo "while (<INPUT>) {" >> ${SWORD_SWIG_BINARY}/perl/Makefile.PL
+ COMMAND echo " s/\\-lsword/\\-lsword \\-lstdc\\+\\+/;" >> ${SWORD_SWIG_BINARY}/perl/Makefile.PL
+ COMMAND echo " print OUTPUT \"$_\";" >> ${SWORD_SWIG_BINARY}/perl/Makefile.PL
+ COMMAND echo "}" >> ${SWORD_SWIG_BINARY}/perl/Makefile.PL
+ COMMAND echo "" >> ${SWORD_SWIG_BINARY}/perl/Makefile.PL
+ COMMAND echo "close INPUT;" >> ${SWORD_SWIG_BINARY}/perl/Makefile.PL
+ COMMAND echo "close OUTPUT;" >> ${SWORD_SWIG_BINARY}/perl/Makefile.PL
+ COMMAND cd ${SWORD_SWIG_BINARY}/perl && ${PERL_EXECUTABLE} Makefile.PL && make clean
+ COMMAND echo "\\.old" > ${SWORD_SWIG_BINARY}/perl/MANIFEST.SKIP
+ COMMAND echo "~$" >> ${SWORD_SWIG_BINARY}/perl/MANIFEST.SKIP
+ COMMAND echo "\\.bak" >> ${SWORD_SWIG_BINARY}/perl/MANIFEST.SKIP
+ COMMAND echo "^CVS" >> ${SWORD_SWIG_BINARY}/perl/MANIFEST.SKIP
+ COMMAND echo "Makefile$" >> ${SWORD_SWIG_BINARY}/perl/MANIFEST.SKIP
+ COMMAND cd ${SWORD_SWIG_BINARY}/perl && ${PERL_EXECUTABLE} Makefile.PL && make manifest
+ COMMAND echo "Perl bindings built, to install change into ${SWORD_SWIG_BINARY}/perl and type 'make install'"
+ DEPENDS sword
+ WORKING_DIRECTORY "${SWORD_SWIG_SOURCE}"
+ VERBATIM
+ )
+
+ MESSAGE(STATUS "Configured for building Perl bindings.")
+ ELSE(PERL_FOUND)
+ MESSAGE(FATAL_ERROR "Perl not found. Can't create perl bindings without Perl to bind")
+ ENDIF(PERL_FOUND)
+ ENDIF(SWORD_BINDINGS MATCHES ".*Perl.*")
+ENDIF(NOT SWIG_FOUND)
More information about the sword-cvs
mailing list