Committing TBB 2019 Update 9 source code
[platform/upstream/tbb.git] / python / setup.py
1 #!/usr/bin/env python
2 #
3 # Copyright (c) 2016-2019 Intel Corporation
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17
18 # System imports
19 from __future__ import print_function
20 from glob import glob
21 import platform
22 import os
23
24 from distutils.core import *
25 from distutils.command.build import build
26
27 rundir = os.getcwd()
28 os.chdir(os.path.abspath(os.path.dirname(__file__)))
29
30 if any(i in os.environ for i in ["CC", "CXX"]):
31     if "CC" not in os.environ:
32         os.environ['CC'] = os.environ['CXX']
33     if "CXX" not in os.environ:
34         os.environ['CXX'] = os.environ['CC']
35     if platform.system() == 'Linux':
36         os.environ['LDSHARED'] = os.environ['CXX'] + " -shared"
37     print("Environment specifies CC=%s CXX=%s"%(os.environ['CC'], os.environ['CXX']))
38
39 intel_compiler = os.getenv('CC', '') in ['icl', 'icpc', 'icc']
40 try:
41     tbb_root = os.environ['TBBROOT']
42     print("Using TBBROOT=", tbb_root)
43 except:
44     tbb_root = '..'
45     if not intel_compiler:
46         print("Warning: TBBROOT env var is not set and Intel's compiler is not used. It might lead\n"
47               "    !!!: to compile/link problems. Source tbbvars.sh/.csh file to set environment")
48 use_compiler_tbb = intel_compiler and tbb_root == '..'
49 if use_compiler_tbb:
50     print("Using Intel TBB from Intel's compiler")
51 if platform.system() == 'Windows':
52     if intel_compiler:
53         os.environ['DISTUTILS_USE_SDK'] = '1'  # Enable environment settings in distutils
54         os.environ['MSSdk'] = '1'
55         print("Using compiler settings from environment")
56     tbb_flag = ['/Qtbb'] if use_compiler_tbb else []
57     tbb_flag += ['/EHsc'] # for Python 2
58     compile_flags = ['/Qstd=c++11'] if intel_compiler else []
59 else:
60     tbb_flag = ['-tbb'] if use_compiler_tbb else []
61     compile_flags = ['-std=c++11', '-Wno-unused-variable']
62
63 _tbb = Extension("tbb._api", ["tbb/api.i"],
64         include_dirs=[os.path.join(tbb_root, 'include')] if not use_compiler_tbb else [],
65         swig_opts   =['-c++', '-O', '-threads'] + (  # add '-builtin' later
66               ['-I' + os.path.join(tbb_root, 'include')] if not use_compiler_tbb else []),
67         extra_compile_args=compile_flags + tbb_flag,
68         extra_link_args=tbb_flag,
69         libraries   =(['tbb'] if not use_compiler_tbb else []) +
70                      (['irml'] if platform.system() == "Linux" else []),   # TODO: why do we need this?
71         library_dirs=[ rundir,                                              # for custom-builds
72                        os.path.join(tbb_root, 'lib', 'intel64', 'gcc4.8'),  # for Linux
73                        os.path.join(tbb_root, 'lib'),                       # for MacOS
74                        os.path.join(tbb_root, 'lib', 'intel64', 'vc_mt'),   # for Windows
75                      ] if not use_compiler_tbb else [],
76         language    ='c++',
77         )
78
79
80 class TBBBuild(build):
81     sub_commands = [  # define build order
82         ('build_ext', build.has_ext_modules),
83         ('build_py', build.has_pure_modules),
84     ]
85
86
87 setup(  name        ="TBB",
88         description ="Python API for Intel TBB",
89         long_description="Python API to Intel(R) Threading Building Blocks library (Intel(R) TBB) "
90                          "extended with standard Pool implementation and monkey-patching",
91         url         ="https://software.intel.com/en-us/intel-tbb",
92         author      ="Intel Corporation",
93         author_email="inteltbbdevelopers@intel.com",
94         license     ="Dual license: Apache or Proprietary",
95         version     ="0.1",
96         classifiers =[
97             'Development Status :: 4 - Beta',
98             'Environment :: Console',
99             'Environment :: Plugins',
100             'Intended Audience :: Developers',
101             'Intended Audience :: System Administrators',
102             'Intended Audience :: Other Audience',
103             'Intended Audience :: Science/Research',
104             'License :: OSI Approved :: Apache Software License',
105             'Operating System :: MacOS :: MacOS X',
106             'Operating System :: Microsoft :: Windows',
107             'Operating System :: POSIX :: Linux',
108             'Programming Language :: Python',
109             'Programming Language :: Python :: 2',
110             'Programming Language :: Python :: 3',
111             'Programming Language :: C++',
112             'Topic :: System :: Hardware :: Symmetric Multi-processing',
113             'Topic :: Software Development :: Libraries',
114           ],
115         keywords='TBB multiprocessing multithreading composable parallelism',
116         ext_modules=[_tbb],
117         packages=['tbb'],
118         py_modules=['TBB'],
119         cmdclass={'build': TBBBuild}
120 )