fabscript 2.2 KB

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