2019-01-01 14:04:23 +08:00
|
|
|
# Copyright 2013-2019 Lawrence Livermore National Security, LLC and other
|
2018-10-08 04:52:23 +08:00
|
|
|
# Spack Project Developers. See the top-level COPYRIGHT file for details.
|
2016-05-12 12:22:25 +08:00
|
|
|
#
|
2018-10-08 04:52:23 +08:00
|
|
|
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
|
|
|
|
2016-07-21 08:19:03 +08:00
|
|
|
from spack import *
|
2016-02-01 17:53:27 +08:00
|
|
|
|
|
|
|
|
2017-08-05 23:15:18 +08:00
|
|
|
class Opencv(CMakePackage):
|
2016-07-13 10:29:04 +08:00
|
|
|
"""OpenCV is released under a BSD license and hence it's free for both
|
|
|
|
academic and commercial use. It has C++, C, Python and Java interfaces and
|
|
|
|
supports Windows, Linux, Mac OS, iOS and Android. OpenCV was designed for
|
|
|
|
computational efficiency and with a strong focus on real-time applications.
|
|
|
|
Written in optimized C/C++, the library can take advantage of multi-core
|
|
|
|
processing. Enabled with OpenCL, it can take advantage of the hardware
|
|
|
|
acceleration of the underlying heterogeneous compute platform. Adopted all
|
|
|
|
around the world, OpenCV has more than 47 thousand people of user community
|
|
|
|
and estimated number of downloads exceeding 9 million. Usage ranges from
|
|
|
|
interactive art, to mines inspection, stitching maps on the web or through
|
|
|
|
advanced robotics.
|
2016-02-01 17:53:27 +08:00
|
|
|
"""
|
2016-07-13 10:29:04 +08:00
|
|
|
|
2016-02-01 17:53:27 +08:00
|
|
|
homepage = 'http://opencv.org/'
|
2018-07-23 15:00:15 +08:00
|
|
|
url = 'https://github.com/Itseez/opencv/archive/3.1.0.tar.gz'
|
|
|
|
git = 'https://github.com/opencv/opencv.git'
|
2016-02-01 17:53:27 +08:00
|
|
|
|
2018-07-23 15:00:15 +08:00
|
|
|
version('master', branch='master')
|
2019-05-01 02:37:47 +08:00
|
|
|
version('4.1.0-openvino', sha256='58764d2487c6fb4cd950fb46483696ae7ae28e257223d6e44e162caa22ee9e5c')
|
|
|
|
version('4.1.0', sha256='8f6e4ab393d81d72caae6e78bd0fd6956117ec9f006fba55fcdb88caf62989b7', preferred=True)
|
|
|
|
version('4.0.1-openvino', sha256='8cbe32d12a70decad7a8327eb4fba46016a9c47ff3ba6e114d27b450f020716f')
|
|
|
|
version('4.0.1', sha256='7b86a0ee804244e0c407321f895b15e4a7162e9c5c0d2efc85f1cadec4011af4')
|
|
|
|
version('4.0.0-openvino', sha256='aa910078ed0b7e17bd10067e04995c131584a6ed6d0dcc9ca44a292aa8e296fc')
|
|
|
|
version('4.0.0', sha256='3787b3cc7b21bba1441819cb00c636911a846c0392ddf6211d398040a1e4886c')
|
|
|
|
version('3.4.6', sha256='e7d311ff97f376b8ee85112e2b536dbf4bdf1233673500175ed7cf21a0089f6d')
|
|
|
|
version('3.4.5', sha256='0c57d9dd6d30cbffe68a09b03f4bebe773ee44dc8ff5cd6eaeb7f4d5ef3b428e')
|
|
|
|
version('3.4.4', sha256='a35b00a71d77b484f73ec485c65fe56c7a6fa48acd5ce55c197aef2e13c78746')
|
2019-10-11 13:44:41 +08:00
|
|
|
version('3.4.3', sha256='4eef85759d5450b183459ff216b4c0fa43e87a4f6aa92c8af649f89336f002ec')
|
|
|
|
version('3.4.1', sha256='f1b87684d75496a1054405ae3ee0b6573acaf3dad39eaf4f1d66fdd7e03dc852')
|
|
|
|
version('3.4.0', sha256='678cc3d2d1b3464b512b084a8cca1fad7de207c7abdf2caa1fed636c13e916da')
|
|
|
|
version('3.3.1', sha256='5dca3bb0d661af311e25a72b04a7e4c22c47c1aa86eb73e70063cd378a2aa6ee')
|
|
|
|
version('3.3.0', sha256='8bb312b9d9fd17336dc1f8b3ac82f021ca50e2034afc866098866176d985adc6')
|
|
|
|
version('3.2.0', sha256='9541efbf68f298f45914b4e837490647f4d5e472b4c0c04414a787d116a702b2')
|
|
|
|
version('3.1.0', sha256='f3b160b9213dd17aa15ddd45f6fb06017fe205359dbd1f7219aad59c98899f15')
|
|
|
|
version('2.4.13.2', sha256='4b00c110e6c54943cbbb7cf0d35c5bc148133ab2095ee4aaa0ac0a4f67c58080')
|
|
|
|
version('2.4.13.1', sha256='0d5ce5e0973e3a745f927d1ee097aaf909aae59f787be6d27a03d639e2d96bd7')
|
|
|
|
version('2.4.13', sha256='94ebcca61c30034d5fb16feab8ec12c8a868f5162d20a9f0396f0f5f6d8bbbff')
|
|
|
|
version('2.4.12.3', sha256='a4cbcd2d470860b0cf1f8faf504619c18a8ac38fd414c5a88ed3e94c963aa750')
|
|
|
|
version('2.4.12.2', sha256='150a165eb14a5ea74fb94dcc16ac7d668a6ff20a4449df2570734a2abaab9c0e')
|
|
|
|
version('2.4.12.1', sha256='c1564771f79304a2597ae4f74f44032021e3a46657e4a117060c08f5ed05ad83')
|
2016-02-01 17:53:27 +08:00
|
|
|
|
2018-05-09 08:55:12 +08:00
|
|
|
# Standard variants
|
2016-07-13 10:29:04 +08:00
|
|
|
variant('shared', default=True,
|
|
|
|
description='Enables the build of shared libraries')
|
2018-05-09 08:55:12 +08:00
|
|
|
variant('lapack', default=True, description='Include Lapack library support')
|
|
|
|
variant('powerpc', default=False, description='Enable PowerPC for GCC')
|
|
|
|
variant('vsx', default=False, description='Enable POWER8 and above VSX (64-bit little-endian)')
|
|
|
|
variant('fast-math', default=False,
|
|
|
|
description='Enable -ffast-math (not recommended for GCC 4.6.x)')
|
2016-02-01 17:53:27 +08:00
|
|
|
|
2018-05-09 08:55:12 +08:00
|
|
|
# OpenCV modules
|
|
|
|
variant('calib3d', default=True, description='calib3d module')
|
|
|
|
variant('core', default=True, description='Include opencv_core module into the OpenCV build')
|
|
|
|
variant('dnn', default=True, description='Build DNN support')
|
|
|
|
variant('features2d', default=True, description='features2d module')
|
|
|
|
variant('flann', default=True, description='flann module')
|
|
|
|
variant('highgui', default=True, description='Include opencv_highgui module into the OpenCV build')
|
|
|
|
variant('imgproc', default=True, description='Include opencv_imgproc module into the OpenCV build')
|
|
|
|
variant('java', default=True,
|
|
|
|
description='Activates support for Java')
|
|
|
|
variant('ml', default=True, description='Build ML support')
|
|
|
|
variant('python', default=True,
|
|
|
|
description='Enables the build of Python extensions')
|
|
|
|
variant('stitching', default=True, description='stitching module')
|
|
|
|
variant('superres', default=True, description='superres module')
|
|
|
|
variant('ts', default=True, description='Include opencv_ts module into the OpenCV build')
|
|
|
|
variant('video', default=True, description='video module')
|
|
|
|
variant('videostab', default=True, description='videostab module')
|
|
|
|
variant('videoio', default=True, description='videoio module')
|
|
|
|
|
|
|
|
# Optional 3rd party components
|
|
|
|
variant('cuda', default=True, description='Activates support for CUDA')
|
2019-05-01 02:37:47 +08:00
|
|
|
# Cuda@10.0.130 does not support gcc > 7
|
|
|
|
conflicts('%gcc@7:', when='+cuda')
|
2016-02-01 17:53:27 +08:00
|
|
|
variant('eigen', default=True, description='Activates support for eigen')
|
|
|
|
variant('ipp', default=True, description='Activates support for IPP')
|
2018-05-09 08:55:12 +08:00
|
|
|
variant('ipp_iw', default=True, description='Build IPP IW from source')
|
2016-07-19 06:49:37 +08:00
|
|
|
variant('jasper', default=True, description='Activates support for JasPer')
|
2018-05-09 08:55:12 +08:00
|
|
|
variant('jpeg', default=True, description='Include JPEG support')
|
|
|
|
variant('opencl', default=True, description='Include OpenCL Runtime support')
|
|
|
|
variant('opencl_svm', default=True, description='Include OpenCL Shared Virtual Memory support')
|
|
|
|
variant('openclamdfft', default=True, description='Include OpenCL AMD OpenCL FFT library support')
|
|
|
|
variant('openclamdblas', default=True, description='Include OpenCL AMD OpenCL BLAS library support')
|
|
|
|
variant('openmp', default=True, description='Activates support for OpenMP threads')
|
|
|
|
variant('pthreads_pf', default=True, description='Use pthreads-based parallel_for')
|
|
|
|
variant('png', default=True, description='Include PNG support')
|
2016-07-14 06:30:28 +08:00
|
|
|
variant('qt', default=False, description='Activates support for QT')
|
2018-05-09 08:55:12 +08:00
|
|
|
variant('gtk', default=True, description='Activates support for GTK')
|
|
|
|
variant('tiff', default=True, description='Include TIFF support')
|
|
|
|
variant('vtk', default=True, description='Activates support for VTK')
|
|
|
|
variant('zlib', default=True, description='Build zlib from source')
|
2016-02-01 17:53:27 +08:00
|
|
|
|
2018-06-18 22:53:48 +08:00
|
|
|
# Patch to fix conflict between CUDA and OpenCV (reproduced with 3.3.0
|
|
|
|
# and 3.4.1) header file that have the same name.Problem is fixed in
|
|
|
|
# the current development branch of OpenCV. See #8461 for more information.
|
|
|
|
patch('dnn_cuda.patch', when='@3.3.0:3.4.1+cuda+dnn')
|
|
|
|
|
2017-11-02 04:50:06 +08:00
|
|
|
depends_on('eigen~mpfr', when='+eigen', type='build')
|
2016-07-21 08:19:03 +08:00
|
|
|
|
2017-08-08 02:41:13 +08:00
|
|
|
depends_on('zlib', when='+zlib')
|
|
|
|
depends_on('libpng', when='+png')
|
2017-08-24 16:30:35 +08:00
|
|
|
depends_on('jpeg', when='+jpeg')
|
|
|
|
depends_on('libtiff', when='+tiff')
|
2016-02-01 17:53:27 +08:00
|
|
|
|
2016-07-19 06:49:37 +08:00
|
|
|
depends_on('jasper', when='+jasper')
|
2016-07-13 10:15:12 +08:00
|
|
|
depends_on('cuda', when='+cuda')
|
2016-07-14 06:30:28 +08:00
|
|
|
depends_on('gtkplus', when='+gtk')
|
|
|
|
depends_on('vtk', when='+vtk')
|
|
|
|
depends_on('qt', when='+qt')
|
2017-08-06 03:53:09 +08:00
|
|
|
depends_on('java', when='+java')
|
2017-01-08 11:59:02 +08:00
|
|
|
depends_on('py-numpy', when='+python', type=('build', 'run'))
|
2019-05-01 02:37:47 +08:00
|
|
|
depends_on('protobuf@3.5.0', when='@3.4.1: +dnn')
|
|
|
|
depends_on('protobuf@3.1.0', when='@3.3.0:3.4.0 +dnn')
|
2016-07-16 10:28:50 +08:00
|
|
|
|
2018-05-09 08:55:12 +08:00
|
|
|
depends_on('ffmpeg', when='+videoio')
|
|
|
|
depends_on('mpi', when='+videoio')
|
|
|
|
|
2016-07-16 10:28:50 +08:00
|
|
|
extends('python', when='+python')
|
2016-07-13 10:27:21 +08:00
|
|
|
|
2017-08-05 23:15:18 +08:00
|
|
|
def cmake_args(self):
|
|
|
|
spec = self.spec
|
2016-02-01 17:53:27 +08:00
|
|
|
|
2018-05-09 08:55:12 +08:00
|
|
|
# Standard variants
|
2017-08-05 23:15:18 +08:00
|
|
|
args = [
|
2016-07-19 01:40:39 +08:00
|
|
|
'-DBUILD_SHARED_LIBS:BOOL={0}'.format((
|
|
|
|
'ON' if '+shared' in spec else 'OFF')),
|
2016-07-14 08:33:37 +08:00
|
|
|
'-DENABLE_PRECOMPILED_HEADERS:BOOL=OFF',
|
2018-05-09 08:55:12 +08:00
|
|
|
'-DWITH_LAPACK={0}'.format((
|
|
|
|
'ON' if '+lapack' in spec else 'OFF')),
|
|
|
|
'-DENABLE_POWERPC={0}'.format((
|
|
|
|
'ON' if '+powerpc' in spec else 'OFF')),
|
|
|
|
'-DENABLE_VSX={0}'.format((
|
|
|
|
'ON' if '+vsx' in spec else 'OFF')),
|
|
|
|
'-DENABLE_FAST_MATH={0}'.format((
|
|
|
|
'ON' if '+fast-math' in spec else 'OFF')),
|
|
|
|
]
|
|
|
|
|
|
|
|
# modules
|
|
|
|
args.extend([
|
|
|
|
'-DBUILD_opencv_calib3d={0}'.format((
|
|
|
|
'ON' if '+calib3d' in spec else 'OFF')),
|
2017-08-08 02:41:13 +08:00
|
|
|
'-DBUILD_opencv_core:BOOL={0}'.format((
|
|
|
|
'ON' if '+core' in spec else 'OFF')),
|
2018-05-09 08:55:12 +08:00
|
|
|
'-DBUILD_opencv_dnn:BOOL={0}'.format((
|
|
|
|
'ON' if '+dnn' in spec else 'OFF')),
|
|
|
|
'-DBUILD_opencv_features2d={0}'.format((
|
|
|
|
'ON' if '+features2d' in spec else 'OFF')),
|
|
|
|
'-DBUILD_opencv_flann={0}'.format((
|
|
|
|
'ON' if '+flann' in spec else 'OFF')),
|
2017-08-08 02:41:13 +08:00
|
|
|
'-DBUILD_opencv_highgui:BOOL={0}'.format((
|
|
|
|
'ON' if '+highgui' in spec else 'OFF')),
|
|
|
|
'-DBUILD_opencv_imgproc:BOOL={0}'.format((
|
|
|
|
'ON' if '+imgproc' in spec else 'OFF')),
|
2018-05-09 08:55:12 +08:00
|
|
|
'-DBUILD_opencv_java:BOOL={0}'.format((
|
|
|
|
'ON' if '+java' in spec else 'OFF')),
|
|
|
|
'-DBUILD_opencv_ml={0}'.format((
|
|
|
|
'ON' if '+ml' in spec else 'OFF')),
|
|
|
|
'-DBUILD_opencv_stitching={0}'.format((
|
|
|
|
'ON' if '+stitching' in spec else 'OFF')),
|
|
|
|
'-DBUILD_opencv_superres={0}'.format((
|
|
|
|
'ON' if '+superres' in spec else 'OFF')),
|
|
|
|
'-DBUILD_opencv_ts={0}'.format((
|
|
|
|
'ON' if '+ts' in spec else 'OFF')),
|
|
|
|
'-DBUILD_opencv_video={0}'.format((
|
|
|
|
'ON' if '+video' in spec else 'OFF')),
|
|
|
|
'-DBUILD_opencv_videostab={0}'.format((
|
|
|
|
'ON' if '+videostab' in spec else 'OFF')),
|
|
|
|
'-DBUILD_opencv_videoio={0}'.format((
|
|
|
|
'ON' if '+videoio' in spec else 'OFF')),
|
|
|
|
])
|
|
|
|
|
|
|
|
# 3rd party components
|
|
|
|
args.extend([
|
2018-05-26 13:44:18 +08:00
|
|
|
'-DBUILD_IPP_IW:BOOL={0}'.format((
|
|
|
|
'ON' if '+ipp_iw' in spec else 'OFF')),
|
2018-05-09 08:55:12 +08:00
|
|
|
'-DWITH_CUDA:BOOL={0}'.format((
|
|
|
|
'ON' if '+cuda' in spec else 'OFF')),
|
2018-05-26 13:44:18 +08:00
|
|
|
'-DWITH_EIGEN:BOOL={0}'.format((
|
2018-05-09 08:55:12 +08:00
|
|
|
'ON' if '+eigen' in spec else 'OFF')),
|
|
|
|
'-DWITH_IPP:BOOL={0}'.format((
|
|
|
|
'ON' if '+ipp' in spec else 'OFF')),
|
2018-05-26 13:44:18 +08:00
|
|
|
'-DWITH_JASPER:BOOL={0}'.format((
|
|
|
|
'ON' if '+jasper' in spec else 'OFF')),
|
2017-08-08 02:41:13 +08:00
|
|
|
'-DWITH_JPEG:BOOL={0}'.format((
|
|
|
|
'ON' if '+jpeg' in spec else 'OFF')),
|
2018-05-26 13:44:18 +08:00
|
|
|
'-DWITH_OPENCL:BOOL={0}'.format((
|
2018-05-09 08:55:12 +08:00
|
|
|
'ON' if '+opencl' in spec else 'OFF')),
|
2018-05-26 13:44:18 +08:00
|
|
|
'-DWITH_OPENCL_SVM:BOOL={0}'.format((
|
2018-05-09 08:55:12 +08:00
|
|
|
'ON' if '+opencl_svm' in spec else 'OFF')),
|
2018-05-26 13:44:18 +08:00
|
|
|
'-DWITH_OPENCLAMDFFT:BOOL={0}'.format((
|
2018-05-09 08:55:12 +08:00
|
|
|
'ON' if '+openclamdfft' in spec else 'OFF')),
|
2018-05-26 13:44:18 +08:00
|
|
|
'-DWITH_OPENCLAMDBLAS:BOOL={0}'.format((
|
2018-05-09 08:55:12 +08:00
|
|
|
'ON' if '+openclamdblas' in spec else 'OFF')),
|
|
|
|
'-DWITH_OPENMP:BOOL={0}'.format((
|
|
|
|
'ON' if '+openmp' in spec else 'OFF')),
|
2018-05-26 13:44:18 +08:00
|
|
|
'-DWITH_PTHREADS_PF:BOOL={0}'.format((
|
2018-05-09 08:55:12 +08:00
|
|
|
'ON' if '+pthreads_pf' in spec else 'OFF')),
|
2017-08-08 02:41:13 +08:00
|
|
|
'-DWITH_PNG:BOOL={0}'.format((
|
|
|
|
'ON' if '+png' in spec else 'OFF')),
|
2018-05-09 08:55:12 +08:00
|
|
|
'-DWITH_QT:BOOL={0}'.format((
|
|
|
|
'ON' if '+qt' in spec else 'OFF')),
|
2017-08-08 02:41:13 +08:00
|
|
|
'-DWITH_TIFF:BOOL={0}'.format((
|
|
|
|
'ON' if '+tiff' in spec else 'OFF')),
|
2018-05-09 08:55:12 +08:00
|
|
|
'-DWITH_VTK:BOOL={0}'.format((
|
|
|
|
'ON' if '+vtk' in spec else 'OFF')),
|
2019-05-01 02:37:47 +08:00
|
|
|
'-DWITH_PROTOBUF:BOOL={0}'.format((
|
|
|
|
'ON' if '@3.3.0: +dnn' in spec else 'OFF')),
|
|
|
|
'-DBUILD_PROTOBUF:BOOL=OFF',
|
2018-05-09 08:55:12 +08:00
|
|
|
])
|
2016-07-14 06:30:28 +08:00
|
|
|
|
2016-07-21 08:19:59 +08:00
|
|
|
# Media I/O
|
2017-08-10 04:40:10 +08:00
|
|
|
if '+zlib' in spec:
|
|
|
|
zlib = spec['zlib']
|
|
|
|
args.extend([
|
|
|
|
'-DZLIB_LIBRARY_{0}:FILEPATH={1}'.format((
|
2018-05-19 06:30:25 +08:00
|
|
|
'DEBUG' if 'build_type=Debug' in spec else 'RELEASE'),
|
|
|
|
zlib.libs[0]),
|
|
|
|
'-DZLIB_INCLUDE_DIR:PATH={0}'.format(
|
|
|
|
zlib.headers.directories[0])
|
2017-08-10 04:40:10 +08:00
|
|
|
])
|
|
|
|
|
|
|
|
if '+png' in spec:
|
|
|
|
libpng = spec['libpng']
|
|
|
|
args.extend([
|
|
|
|
'-DPNG_LIBRARY_{0}:FILEPATH={1}'.format((
|
2018-05-19 06:30:25 +08:00
|
|
|
'DEBUG' if 'build_type=Debug' in spec else 'RELEASE'),
|
|
|
|
libpng.libs[0]),
|
|
|
|
'-DPNG_INCLUDE_DIR:PATH={0}'.format(
|
|
|
|
libpng.headers.directories[0])
|
2017-08-10 04:40:10 +08:00
|
|
|
])
|
2016-07-19 06:39:07 +08:00
|
|
|
|
2017-08-08 02:41:13 +08:00
|
|
|
if '+jpeg' in spec:
|
2017-08-24 16:30:35 +08:00
|
|
|
libjpeg = spec['jpeg']
|
2017-08-10 04:40:10 +08:00
|
|
|
args.extend([
|
2017-08-08 02:41:13 +08:00
|
|
|
'-DBUILD_JPEG:BOOL=OFF',
|
2018-05-19 06:30:25 +08:00
|
|
|
'-DJPEG_LIBRARY:FILEPATH={0}'.format(libjpeg.libs[0]),
|
|
|
|
'-DJPEG_INCLUDE_DIR:PATH={0}'.format(
|
|
|
|
libjpeg.headers.directories[0])
|
2017-08-08 02:41:13 +08:00
|
|
|
])
|
2016-07-19 06:35:37 +08:00
|
|
|
|
2017-08-08 02:41:13 +08:00
|
|
|
if '+tiff' in spec:
|
|
|
|
libtiff = spec['libtiff']
|
2017-08-10 04:40:10 +08:00
|
|
|
args.extend([
|
2017-08-08 02:41:13 +08:00
|
|
|
'-DTIFF_LIBRARY_{0}:FILEPATH={1}'.format((
|
2018-05-19 06:30:25 +08:00
|
|
|
'DEBUG' if 'build_type=Debug' in spec else 'RELEASE'),
|
|
|
|
libtiff.libs[0]),
|
|
|
|
'-DTIFF_INCLUDE_DIR:PATH={0}'.format(
|
|
|
|
libtiff.headers.directories[0])
|
2017-08-08 02:41:13 +08:00
|
|
|
])
|
2016-07-19 06:30:31 +08:00
|
|
|
|
2017-08-08 02:41:13 +08:00
|
|
|
if '+jasper' in spec:
|
|
|
|
jasper = spec['jasper']
|
2017-08-10 04:40:10 +08:00
|
|
|
args.extend([
|
2017-08-08 02:41:13 +08:00
|
|
|
'-DJASPER_LIBRARY_{0}:FILEPATH={1}'.format((
|
2018-05-19 06:30:25 +08:00
|
|
|
'DEBUG' if 'build_type=Debug' in spec else 'RELEASE'),
|
|
|
|
jasper.libs[0]),
|
|
|
|
'-DJASPER_INCLUDE_DIR:PATH={0}'.format(
|
|
|
|
jasper.headers.directories[0])
|
2017-08-08 02:41:13 +08:00
|
|
|
])
|
2016-07-19 07:09:01 +08:00
|
|
|
|
2016-07-21 08:19:59 +08:00
|
|
|
# GUI
|
2016-07-16 10:19:23 +08:00
|
|
|
if '+gtk' not in spec:
|
2017-08-05 23:15:18 +08:00
|
|
|
args.extend([
|
2016-07-19 01:40:39 +08:00
|
|
|
'-DWITH_GTK:BOOL=OFF',
|
|
|
|
'-DWITH_GTK_2_X:BOOL=OFF'
|
|
|
|
])
|
2016-07-16 10:19:23 +08:00
|
|
|
elif '^gtkplus@3:' in spec:
|
2017-08-05 23:15:18 +08:00
|
|
|
args.extend([
|
2016-07-16 10:30:37 +08:00
|
|
|
'-DWITH_GTK:BOOL=ON',
|
|
|
|
'-DWITH_GTK_2_X:BOOL=OFF'
|
|
|
|
])
|
2016-07-14 06:30:28 +08:00
|
|
|
elif '^gtkplus@2:3' in spec:
|
2017-08-05 23:15:18 +08:00
|
|
|
args.extend([
|
2016-07-16 10:30:37 +08:00
|
|
|
'-DWITH_GTK:BOOL=OFF',
|
|
|
|
'-DWITH_GTK_2_X:BOOL=ON'
|
|
|
|
])
|
2016-02-01 17:53:27 +08:00
|
|
|
|
2016-07-21 08:19:59 +08:00
|
|
|
# Python
|
2016-07-16 10:28:50 +08:00
|
|
|
if '+python' in spec:
|
Python command, libraries, and headers (#3367)
## Motivation
Python installations are both important and unfortunately inconsistent. Depending on the Python version, OS, and the strength of the Earth's magnetic field when it was installed, the name of the Python executable, directory containing its libraries, library names, and the directory containing its headers can vary drastically.
I originally got into this mess with #3274, where I discovered that Boost could not be built with Python 3 because the executable is called `python3` and we were telling it to use `python`. I got deeper into this mess when I started hacking on #3140, where I discovered just how difficult it is to find the location and name of the Python libraries and headers.
Currently, half of the packages that depend on Python and need to know this information jump through hoops to determine the correct information. The other half are hard-coded to use `python`, `spec['python'].prefix.lib`, and `spec['python'].prefix.include`. Obviously, none of these packages would work for Python 3, and there's no reason to duplicate the effort. The Python package itself should contain all of the information necessary to use it properly. This is in line with the recent work by @alalazo and @davydden with respect to `spec['blas'].libs` and friends.
## Prefix
For most packages in Spack, we assume that the installation directory is `spec['python'].prefix`. This generally works for anything installed with Spack, but gets complicated when we include external packages. Python is a commonly used external package (it needs to be installed just to run Spack). If it was installed with Homebrew, `which python` would return `/usr/local/bin/python`, and most users would erroneously assume that `/usr/local` is the installation directory. If you peruse through #2173, you'll immediately see why this is not the case. Homebrew actually installs Python in `/usr/local/Cellar/python/2.7.12_2` and symlinks the executable to `/usr/local/bin/python`. `PYTHONHOME` (and presumably most things that need to know where Python is installed) needs to be set to the actual installation directory, not `/usr/local`.
Normally I would say, "sounds like user error, make sure to use the real installation directory in your `packages.yaml`". But I think we can make a special case for Python. That's what we decided in #2173 anyway. If we change our minds, I would be more than happy to simplify things.
To solve this problem, I created a `spec['python'].home` attribute that works the same way as `spec['python'].prefix` but queries Python to figure out where it was actually installed. @tgamblin Is there any way to overwrite `spec['python'].prefix`? I think it's currently immutable.
## Command
In general, Python 2 comes with both `python` and `python2` commands, while Python 3 only comes with a `python3` command. But this is up to the OS developers. For example, `/usr/bin/python` on Gentoo is actually Python 3. Worse yet, if someone is using an externally installed Python, all 3 commands may exist in the same directory! Here's what I'm thinking:
If the spec is for Python 3, try searching for the `python3` command.
If the spec is for Python 2, try searching for the `python2` command.
If neither are found, try searching for the `python` command.
## Libraries
Spack installs Python libraries in `spec['python'].prefix.lib`. Except on openSUSE 13, where it installs to `spec['python'].prefix.lib64` (see #2295 and #2253). On my CentOS 6 machine, the Python libraries are installed in `/usr/lib64`. Both need to work.
The libraries themselves change name depending on OS and Python version. For Python 2.7 on macOS, I'm seeing:
```
lib/libpython2.7.dylib
```
For Python 3.6 on CentOS 6, I'm seeing:
```
lib/libpython3.so
lib/libpython3.6m.so.1.0
lib/libpython3.6m.so -> lib/libpython3.6m.so.1.0
```
Notice the `m` after the version number. Yeah, that's a thing.
## Headers
In Python 2.7, I'm seeing:
```
include/python2.7/pyconfig.h
```
In Python 3.6, I'm seeing:
```
include/python3.6m/pyconfig.h
```
It looks like all Python 3 installations have this `m`. Tested with Python 3.2 and 3.6 on macOS and CentOS 6
Spack has really nice support for libraries (`find_libraries` and `LibraryList`), but nothing for headers. Fixed.
2017-04-30 08:24:13 +08:00
|
|
|
python_exe = spec['python'].command.path
|
|
|
|
python_lib = spec['python'].libs[0]
|
|
|
|
python_include_dir = spec['python'].headers.directories[0]
|
2016-07-19 08:53:36 +08:00
|
|
|
|
2016-07-16 10:28:50 +08:00
|
|
|
if '^python@3:' in spec:
|
2017-08-05 23:15:18 +08:00
|
|
|
args.extend([
|
2016-07-16 10:28:50 +08:00
|
|
|
'-DBUILD_opencv_python3=ON',
|
2016-07-19 01:40:39 +08:00
|
|
|
'-DPYTHON3_EXECUTABLE={0}'.format(python_exe),
|
2016-07-19 04:45:34 +08:00
|
|
|
'-DPYTHON3_LIBRARY={0}'.format(python_lib),
|
2016-07-19 08:53:36 +08:00
|
|
|
'-DPYTHON3_INCLUDE_DIR={0}'.format(python_include_dir),
|
2016-07-16 10:28:50 +08:00
|
|
|
'-DBUILD_opencv_python2=OFF',
|
|
|
|
])
|
|
|
|
elif '^python@2:3' in spec:
|
2017-08-05 23:15:18 +08:00
|
|
|
args.extend([
|
2016-07-16 10:28:50 +08:00
|
|
|
'-DBUILD_opencv_python2=ON',
|
2016-07-19 01:40:39 +08:00
|
|
|
'-DPYTHON2_EXECUTABLE={0}'.format(python_exe),
|
2016-07-19 04:45:34 +08:00
|
|
|
'-DPYTHON2_LIBRARY={0}'.format(python_lib),
|
2016-07-19 08:53:36 +08:00
|
|
|
'-DPYTHON2_INCLUDE_DIR={0}'.format(python_include_dir),
|
2016-07-16 10:28:50 +08:00
|
|
|
'-DBUILD_opencv_python3=OFF',
|
|
|
|
])
|
|
|
|
else:
|
2017-08-05 23:15:18 +08:00
|
|
|
args.extend([
|
2016-07-16 10:21:26 +08:00
|
|
|
'-DBUILD_opencv_python2=OFF',
|
2016-07-16 10:28:50 +08:00
|
|
|
'-DBUILD_opencv_python3=OFF'
|
2016-07-16 10:21:26 +08:00
|
|
|
])
|
2016-07-13 10:27:21 +08:00
|
|
|
|
2017-08-05 23:15:18 +08:00
|
|
|
return args
|
2017-11-26 12:00:18 +08:00
|
|
|
|
|
|
|
@property
|
|
|
|
def libs(self):
|
|
|
|
shared = "+shared" in self.spec
|
|
|
|
return find_libraries(
|
2018-03-01 03:15:26 +08:00
|
|
|
"libopencv_*", root=self.prefix, shared=shared, recursive=True
|
2017-11-26 12:00:18 +08:00
|
|
|
)
|