opencv : Make extending python optional

This commit is contained in:
mwilliammyers 2016-07-15 20:28:50 -06:00
parent c588ce9648
commit 8cf03c209f

View file

@ -55,22 +55,23 @@ class Opencv(Package):
variant('gtk', default=False, description='Activates support for GTK') variant('gtk', default=False, description='Activates support for GTK')
variant('vtk', default=False, description='Activates support for VTK') variant('vtk', default=False, description='Activates support for VTK')
variant('qt', default=False, description='Activates support for QT') variant('qt', default=False, description='Activates support for QT')
variant('python', default=False,
description='Enables the build of Python extensions')
depends_on('zlib') depends_on('zlib')
depends_on('libpng') depends_on('libpng')
depends_on('libjpeg-turbo') depends_on('libjpeg-turbo')
depends_on('libtiff') depends_on('libtiff')
depends_on('python')
depends_on('py-numpy')
depends_on('eigen', when='+eigen') depends_on('eigen', when='+eigen')
depends_on('cuda', when='+cuda') depends_on('cuda', when='+cuda')
depends_on('gtkplus', when='+gtk') depends_on('gtkplus', when='+gtk')
depends_on('vtk', when='+vtk') depends_on('vtk', when='+vtk')
depends_on('qt', when='+qt') depends_on('qt', when='+qt')
extends('python') depends_on('py-numpy', when='+python')
extends('python', when='+python')
def install(self, spec, prefix): def install(self, spec, prefix):
cmake_options = [] cmake_options = []
@ -97,30 +98,36 @@ def install(self, spec, prefix):
cmake_options.extend(['-DWITH_GTK:BOOL=OFF', cmake_options.extend(['-DWITH_GTK:BOOL=OFF',
'-DWITH_GTK_2_X:BOOL=ON']) '-DWITH_GTK_2_X:BOOL=ON'])
python = spec['python'] if '+python' in spec:
if '^python@3:' in spec: python = spec['python']
python_exe = join_path(python.prefix.bin, 'python3') if '^python@3:' in spec:
python_exe = join_path(python.prefix.bin, 'python3')
cmake_options.extend([
'-DBUILD_opencv_python3=ON',
'-DPYTHON3_EXECUTABLE=%s' % python_exe,
'-DPYTHON3_LIBRARIES=%s' % python.prefix.lib,
'-DPYTHON3_INCLUDE_DIR=%s' % python.prefix.include,
'-DBUILD_opencv_python2=OFF',
'-DPYTHON2_EXECUTABLE=',
'-DPYTHON2_LIBRARIES=',
'-DPYTHON2_INCLUDE_DIR=',
])
elif '^python@2:3' in spec:
python_exe = join_path(python.prefix.bin, 'python2')
cmake_options.extend([
'-DBUILD_opencv_python2=ON',
'-DPYTHON2_EXECUTABLE=%s' % python_exe,
'-DPYTHON2_LIBRARIES=%s' % python.prefix.lib,
'-DPYTHON2_INCLUDE_DIR=%s' % python.prefix.include,
'-DBUILD_opencv_python3=OFF',
'-DPYTHON3_EXECUTABLE=',
'-DPYTHON3_LIBRARIES=',
'-DPYTHON3_INCLUDE_DIR=',
])
else:
cmake_options.extend([ cmake_options.extend([
'-DBUILD_opencv_python3=ON',
'-DPYTHON3_EXECUTABLE=%s' % python_exe,
'-DPYTHON3_LIBRARIES=%s' % python.prefix.lib,
'-DPYTHON3_INCLUDE_DIR=%s' % python.prefix.include,
'-DBUILD_opencv_python2=OFF', '-DBUILD_opencv_python2=OFF',
'-DPYTHON2_EXECUTABLE=', '-DBUILD_opencv_python3=OFF'
'-DPYTHON2_LIBRARIES=',
'-DPYTHON2_INCLUDE_DIR=',
])
elif '^python@2:3' in spec:
python_exe = join_path(python.prefix.bin, 'python2')
cmake_options.extend([
'-DBUILD_opencv_python2=ON',
'-DPYTHON2_EXECUTABLE=%s' % python_exe,
'-DPYTHON2_LIBRARIES=%s' % python.prefix.lib,
'-DPYTHON2_INCLUDE_DIR=%s' % python.prefix.include,
'-DBUILD_opencv_python3=OFF',
'-DPYTHON3_EXECUTABLE=',
'-DPYTHON3_LIBRARIES=',
'-DPYTHON3_INCLUDE_DIR=',
]) ])
with working_dir('spack_build', create=True): with working_dir('spack_build', create=True):