From 22f41dfa3260e023737a67ef572cca94723d12b0 Mon Sep 17 00:00:00 2001 From: Stefan Seefeld Date: Thu, 13 Oct 2016 21:16:29 -0400 Subject: [PATCH] Add support for NumPy extension. --- src/tools/python.jam | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/tools/python.jam b/src/tools/python.jam index 8f6a97360..4d72f7ae0 100644 --- a/src/tools/python.jam +++ b/src/tools/python.jam @@ -829,6 +829,25 @@ local rule configure ( version ? : cmd-or-prefix ? : includes * : libraries ? : debug-message " DLL search path:" \"$(exec-prefix:E=)\" ; } + # + # Discover the presence of NumPy + # + local full-cmd = "import sys; sys.stderr = sys.stdout; import numpy; print(numpy.get_include())" ; + local full-cmd = $(interpreter-cmd)" -c \"$(full-cmd)\"" ; + local result = [ SHELL $(full-cmd) : strip-eol : exit-status ] ; + if $(result[2]) = 0 + { + .numpy = true ; + numpy-include = $(result[1]) ; + } + else + { + .numpy = false ; + debug-message "NumPy not configured. Reason:" ; + debug-message " $(full-cmd) aborted with " ; + debug-message " $(result[1])" ; + } + # # End autoconfiguration sequence. # @@ -1012,6 +1031,11 @@ rule configured ( ) return $(.configured) ; } +rule numpy ( ) +{ + return $(.numpy) ; +} + type.register PYTHON_EXTENSION : : SHARED_LIB ; @@ -1268,5 +1292,20 @@ rule bpl-test ( name : sources * : requirements * ) : $(requirements) : $(name) ] ; } +# The same as bpl-test but additionally require (and link to) boost_numpy. +# Masked whenever NumPy is not enabled. +rule numpy-test ( name : sources * : requirements * ) +{ + # yuk ! + if $(.numpy) = false + { + requirements += no ; + } + sources ?= $(name).py $(name).cpp ; + return [ testing.make-test run-pyd + : $(sources) /boost/python//boost_numpy /boost/python//boost_python + : $(requirements) : $(name) ] ; +} IMPORT $(__name__) : bpl-test : : bpl-test ; +IMPORT $(__name__) : numpy-test : : numpy-test ;