1
"""Detect zmq version"""
2
#-----------------------------------------------------------------------------
3
# Copyright (C) 2011 Brian Granger, Min Ragan-Kelley
5
# This file is part of pyzmq, copied and adapted from h5py.
6
# h5py source used under the New BSD license
8
# h5py: <http://code.google.com/p/h5py/>
10
# Distributed under the terms of the New BSD License. The full license is in
11
# the file COPYING.BSD, distributed as part of this software.
12
#-----------------------------------------------------------------------------
19
from distutils import ccompiler
20
from distutils.sysconfig import customize_compiler
21
from subprocess import Popen, PIPE
25
#-----------------------------------------------------------------------------
26
# Utility functions (adapted from h5py: http://h5py.googlecode.com)
27
#-----------------------------------------------------------------------------
29
def detect_zmq(basedir, **compiler_attrs):
30
"""Compile, link & execute a test program, in empty directory `basedir`.
32
The C compiler will be updated with any keywords given via setattr.
38
The location where the test program will be compiled and run
39
**compiler_attrs : dict
40
Any extra compiler attributes, which will be set via ``setattr(cc)``.
45
A dict of properties for zmq compilation, with the following two keys:
48
The ZMQ version as a tuple of ints, e.g. (2,2,0)
50
The compiler options used to compile the test function, e.g. `include_dirs`,
51
`library_dirs`, `libs`, etc.
54
cc = ccompiler.new_compiler()
55
customize_compiler(cc)
56
for name, val in compiler_attrs.items():
57
setattr(cc, name, val)
59
cfile = pjoin(basedir, 'vers.c')
60
efile = pjoin(basedir, 'vers')
62
shutil.copy(pjoin(os.path.dirname(__file__), 'vers.c'), cfile)
64
cpreargs = lpreargs = None
65
if sys.platform == 'darwin':
66
# use appropriate arch for compiler
67
if platform.architecture()[0]=='32bit':
68
cpreargs = ['-arch','i386']
69
lpreargs = ['-arch', 'i386', '-undefined', 'dynamic_lookup']
71
# allow for missing UB arch, since it will still work:
72
lpreargs = ['-undefined', 'dynamic_lookup']
74
objs = cc.compile([cfile],extra_preargs=cpreargs)
75
cc.link_executable(objs, efile, extra_preargs=lpreargs)
77
result = Popen(efile, stdout=PIPE, stderr=PIPE)
78
so, se = result.communicate()
83
msg = "Error running version detection script:\n%s\n%s" % (so,se)
87
handlers = {'vers': lambda val: tuple(int(v) for v in val.split('.'))}
90
for line in (x for x in so.split('\n') if x):
91
key, val = line.split(':')
92
props[key] = handlers[key](val)
94
props['settings'] = compiler_attrs