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