Skip to content

Commit

Permalink
Enable building with libgphoto2 version 2.4.
Browse files Browse the repository at this point in the history
The installed version of gphoto2 is detected in setup.py and appropriate
pre-processor defines allow conditional code in the interface definition
files.
Some of the examples work with version 2.4, but not all.
  • Loading branch information
jim-easterbrook committed Jun 14, 2014
1 parent d40672a commit 9d1f71e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 10 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

from distutils.core import setup, Extension
import os
import subprocess

gphoto2_version = subprocess.check_output(['gphoto2-config', '--version'])
gphoto2_version = tuple(gphoto2_version.split()[1].split('.'))

mod_names = map(lambda x: x[0],
filter(lambda x: x[1] == '.i',
Expand All @@ -27,11 +31,16 @@

ext_modules = []
init_module = ''
swig_opts = ['-I/usr/include', '-builtin', '-O', '-Wall']
if gphoto2_version[0:2] == ('2', '4'):
swig_opts. append('-DGPHOTO2_24')
elif gphoto2_version[0:2] == ('2', '5'):
swig_opts. append('-DGPHOTO2_25')
for mod_name in mod_names:
ext_modules.append(Extension(
'_%s' % mod_name,
sources = ['source/lib/%s.i' % mod_name],
swig_opts = ['-I/usr/include', '-builtin', '-O', '-Wall'],
swig_opts = swig_opts,
libraries = ['gphoto2', 'gphoto2_port'],
extra_compile_args = ['-O3', '-Wno-unused-variable'],
))
Expand Down
5 changes: 4 additions & 1 deletion source/lib/gphoto2_port_info_list.i
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
PyList_Append($result, SWIG_NewPointerObj(*$1, SWIGTYPE_p__GPPortInfoList, 0));
}

// gp_port_info_new() returns a pointer in an output parameter
// In libgphoto2 version 2.4 GPPortInfo is a structure, in version 2.5 it's a
// pointer to a structure.
#ifdef GPHOTO2_25
%typemap(in, numinputs=0) GPPortInfo * (GPPortInfo temp) {
$1 = &temp;
}
Expand All @@ -53,6 +55,7 @@
}
PyList_Append($result, SWIG_NewPointerObj(*$1, SWIGTYPE_p__GPPortInfo, 0));
}
#endif

// several getter functions return string pointers in output params
%typemap(in, numinputs=0) char ** (char *temp) {
Expand Down

0 comments on commit 9d1f71e

Please sign in to comment.