|
| 1 | +# -*- python -*- |
| 2 | +# |
| 3 | +# Copyright (c) 2016 Stefan Seefeld |
| 4 | +# All rights reserved. |
| 5 | +# |
| 6 | +# Distributed under the Boost Software License, Version 1.0. |
| 7 | +# (See accompanying file LICENSE_1_0.txt or copy at |
| 8 | +# http://www.boost.org/LICENSE_1_0.txt) |
| 9 | + |
| 10 | +from faber.feature import set |
| 11 | +from faber.types import cxx |
| 12 | +from faber.tools.compiler import cxxflags, define, include |
| 13 | +from faber.tools.python import python |
| 14 | +from faber.config import report, cxx_checks |
| 15 | +from faber.config.try_run import try_run |
| 16 | + |
| 17 | +features += include('include') |
| 18 | +features += define('BOOST_ALL_NO_LIB') # disable auto-linking |
| 19 | +boost_include = options.get_with('boost-include') |
| 20 | +if boost_include: |
| 21 | + features += include(boost_include) |
| 22 | +python = python.instance() |
| 23 | +features |= set(python.include, python.linkpath, python.libs) |
| 24 | + |
| 25 | +class has_numpy(try_run): |
| 26 | + |
| 27 | + src = r""" |
| 28 | +// If defined, enforces linking against PythonXXd.lib, which |
| 29 | +// is usually not included in Python environments. |
| 30 | +#undef _DEBUG |
| 31 | +#include "Python.h" |
| 32 | +#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION |
| 33 | +#include "numpy/arrayobject.h" |
| 34 | +
|
| 35 | +#if PY_VERSION_HEX >= 0x03000000 |
| 36 | +void *initialize() { import_array();} |
| 37 | +#else |
| 38 | +void initialize() { import_array();} |
| 39 | +#endif |
| 40 | +
|
| 41 | +int main() |
| 42 | +{ |
| 43 | + int result = 0; |
| 44 | + Py_Initialize(); |
| 45 | + initialize(); |
| 46 | + if (PyErr_Occurred()) |
| 47 | + { |
| 48 | + result = 1; |
| 49 | + } |
| 50 | + else |
| 51 | + { |
| 52 | + npy_intp dims = 2; |
| 53 | + PyObject * a = PyArray_SimpleNew(1, &dims, NPY_INT); |
| 54 | + if (!a) result = 1; |
| 55 | + Py_DECREF(a); |
| 56 | + } |
| 57 | + Py_Finalize(); |
| 58 | + return result; |
| 59 | +} |
| 60 | +""" |
| 61 | + def __init__(self, features=()): |
| 62 | + |
| 63 | + inc = '' |
| 64 | + try: |
| 65 | + inc = python.check_python('import numpy; print(numpy.get_include())') |
| 66 | + features |= include(inc) |
| 67 | + except Exception: |
| 68 | + # ignore errors, the check will fail during compilation... |
| 69 | + pass |
| 70 | + try_run.__init__(self, 'has_numpy', has_numpy.src, cxx, features, |
| 71 | + if_=(include(inc), define('HAS_NUMPY'))) |
| 72 | + |
| 73 | +checks = [cxx_checks.has_cxx11(features, define('HAS_CXX11')), |
| 74 | + has_numpy(features)] |
| 75 | +config = report('config', checks) |
| 76 | + |
| 77 | +src = module('src', features=config.use) |
| 78 | +test = module('test', features=config.use) |
| 79 | + |
| 80 | +default = src.default |
0 commit comments