From bb1994f685e3a2e019bb676166f0c6602a5f619f Mon Sep 17 00:00:00 2001 From: Ryan Burns Date: Mon, 3 Aug 2020 12:07:57 -0700 Subject: [PATCH 1/3] Add Numpy + OpenCV autodetection to SCons --- SConstruct | 22 ++++++++++++++++++++++ contrib/SConscript | 6 +++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/SConstruct b/SConstruct index a979b3cb3..5ae7c4e1f 100644 --- a/SConstruct +++ b/SConstruct @@ -103,6 +103,28 @@ inst = env['PRJ_SCONS_INSTALL'] ####new part #####PSA. Check for header files and libraries up front confinst = Configure(env) + +# Try to autodetect numpy +if confinst.CheckCHeader("numpy/arrayobject.h"): + print("Numpy header found.") +else: + print("Numpy not found. Attempting to autodetect...") + try: + import numpy + confinst.env["CPPPATH"].append(numpy.get_include()) + print("Added autodetected numpy include to CPPPATH.") + except ImportError: + raise RuntimeError("""Could not autodetect numpy include. + Please add the numpy include dir to your CPPPATH.""") + +# Check for OpenCV +if confinst.CheckCXXHeader("opencv2/imgproc/imgproc.hpp"): + confinst.env["HAVE_OPENCV"] = True + print("OpenCV detected - enabled.") +else: + confinst.env["HAVE_OPENCV"] = False + print("OpenCV not detected - disabled.") + hdrparams = [('python3 header', 'Python.h', 'Install python3-dev or add path to Python.h to CPPPATH'), ('fftw3', 'fftw3.h', 'Install fftw3 or libfftw3-dev or add path to fftw3.h to CPPPATH and FORTRANPATH'), ('hdf5', 'hdf5.h', 'Install HDF5 of libhdf5-dev or add path to hdf5.h to CPPPATH'), diff --git a/contrib/SConscript b/contrib/SConscript index 11366b4ba..d623947af 100644 --- a/contrib/SConscript +++ b/contrib/SConscript @@ -80,4 +80,8 @@ SConscript('splitSpectrum/SConscript') SConscript('alos2filter/SConscript') SConscript('alos2proc/SConscript') SConscript('alos2proc_f/SConscript') -SConscript('geo_autoRIFT/SConscript') + +if envcontrib["HAVE_OPENCV"]: + SConscript('geo_autoRIFT/SConscript') +else: + print("Skipping autoRIFT, due to lack of OpenCV support.") From b23e8f5864791a694e5f9031fd5fcc755fb249de Mon Sep 17 00:00:00 2001 From: Ryan Burns Date: Thu, 13 Aug 2020 15:17:48 -0700 Subject: [PATCH 2/3] Disable autodetection on python2 --- SConstruct | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/SConstruct b/SConstruct index 5ae7c4e1f..e94869ff6 100644 --- a/SConstruct +++ b/SConstruct @@ -108,7 +108,12 @@ confinst = Configure(env) if confinst.CheckCHeader("numpy/arrayobject.h"): print("Numpy header found.") else: - print("Numpy not found. Attempting to autodetect...") + print("Numpy not found.") + + if sys.version_info.major == 2: + raise RuntimeError("Cannot autodetect numpy from python2") + + print("Attempting to autodetect...") try: import numpy confinst.env["CPPPATH"].append(numpy.get_include()) From 379e913455574b6d2399b0f76eb1e6c6e17cde1a Mon Sep 17 00:00:00 2001 From: Ryan Burns Date: Mon, 17 Aug 2020 13:45:22 -0700 Subject: [PATCH 3/3] Use py2-compatible major version check --- SConstruct | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SConstruct b/SConstruct index e94869ff6..62f0ddadc 100644 --- a/SConstruct +++ b/SConstruct @@ -110,7 +110,7 @@ if confinst.CheckCHeader("numpy/arrayobject.h"): else: print("Numpy not found.") - if sys.version_info.major == 2: + if sys.version_info[0] == 2: raise RuntimeError("Cannot autodetect numpy from python2") print("Attempting to autodetect...")