Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Numpy + OpenCV autodetection to SCons #173

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,33 @@ 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.")

if sys.version_info[0] == 2:
raise RuntimeError("Cannot autodetect numpy from python2")

print("Attempting to autodetect...")
try:
import numpy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is tricky because scons could be using a different python version than the one being used for installation - notably macports. Its lot easier with cmake to do this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think I have always used the scons from Python2. Not sure why I got started with that, but I never changed it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. Unless you know how to have scons invoke the python used for installation, maybe I should just disable this when scons is using python 2.

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'),
Expand Down
6 changes: 5 additions & 1 deletion contrib/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -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.")