# IT4Innovations 2019

easyblock = 'CMakeMake'

name = 'OpenCV'
version = '3.4.6'

homepage = 'http://opencv.org/'
description = """OpenCV (Open Source Computer Vision Library) is an open source local_computer vision
 and machine learning software library. OpenCV was built to provide
 a common infrastructure for local_computer vision applications and to accelerate
 the use of machine perception in the commercial products."""

toolchain = {'name': 'intel', 'version': '2017c'}

source_urls = [
    'https://github.com/Itseez/opencv/archive/'
]
sources = [
    '%(version)s.zip',
]

builddependencies = [
    ('CMake', '3.14.1', '', True),
]

dependencies = [
    ('Python', '3.7.3', '', ('GCCcore', '6.3.0')),
    ('zlib', '1.2.11', '', True),
    ('FFmpeg', '4.1', '', True),
    ('pkg-config', '0.29.2', '', True),
    ('OpenCL-sdk', '7.0.0.2568', '', True),
]

separate_build_dir = True

preconfigopts = 'wget https://github.com/opencv/opencv_contrib/archive/3.4.6.zip && '
preconfigopts += 'unzip 3.4.6.zip && '

configopts = '-DCMAKE_BUILD_TYPE=RELEASE '
configopts += '-DBUILD_PYTHON_SUPPORT=ON '
configopts += '-DPYTHON_PACKAGES_PATH=%(installdir)s/lib/python%(local_pyshortver)s/site-packages '
configopts += '-DBUILD_NEW_PYTHON_SUPPORT=ON '
configopts += '-DWITH_CUDA=OFF '
configopts += '-DOPENCV_ENABLE_NONFREE:BOOL=ON '
configopts += '-D BUILD_opencv_ts=OFF '
configopts += '-DPYTHON3_EXECUTABLE=$(which python3.7) '
configopts += '-DPYTHON_INCLUDE_DIR=$(python3.7 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") '
configopts += '-DPYTHON_PACKAGES_PATH=$(python3.7 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") '
configopts += '-DOPENCV_EXTRA_MODULES_PATH=%(builddir)s/easybuild_obj/opencv_contrib-3.4.6/modules '

sanity_check_paths = {
    'files': [
        'lib/libopencv_core.%s' %
        SHLIB_EXT] + [
            'lib/python3.7/site-packages/cv2/python-3.7/cv2.cpython-37m-x86_64-linux-gnu.so'] + [
                'bin/opencv_%s' %
                x for x in [
                    'annotation', 'createsamples', 'traincascade']], 'dirs': ['include']}

modextrapaths = {
    'PYTHONPATH': 'lib/python%(local_pyshortver)s/site-packages',
    'CLASSPATH': 'share/OpenCV/java',
}

moduleclass = 'vis'
