xref: /oneTBB/python/setup.py (revision 51c0b2f7)
1#!/usr/bin/env python3
2#
3# Copyright (c) 2016-2020 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
19import platform
20import os
21
22from distutils.core import *
23from distutils.command.build import build
24
25rundir = os.getcwd()
26os.chdir(os.path.abspath(os.path.dirname(__file__)))
27
28if any(i in os.environ for i in ["CC", "CXX"]):
29    if "CC" not in os.environ:
30        os.environ['CC'] = os.environ['CXX']
31    if "CXX" not in os.environ:
32        os.environ['CXX'] = os.environ['CC']
33    if platform.system() == 'Linux':
34        os.environ['LDSHARED'] = os.environ['CXX'] + " -shared"
35    print("Environment specifies CC=%s CXX=%s"%(os.environ['CC'], os.environ['CXX']))
36
37intel_compiler = os.getenv('CC', '') in ['icl', 'icpc', 'icc']
38try:
39    tbb_root = os.environ['TBBROOT']
40    print("Using TBBROOT=", tbb_root)
41except:
42    tbb_root = '..'
43    if not intel_compiler:
44        print("Warning: TBBROOT env var is not set and Intel's compiler is not used. It might lead\n"
45              "    !!!: to compile/link problems. Source tbbvars.sh/.csh file to set environment")
46use_compiler_tbb = intel_compiler and tbb_root == '..'
47if use_compiler_tbb:
48    print("Using oneTBB from Intel(R) C++ Compiler")
49if platform.system() == 'Windows':
50    if intel_compiler:
51        os.environ['DISTUTILS_USE_SDK'] = '1'  # Enable environment settings in distutils
52        os.environ['MSSdk'] = '1'
53        print("Using compiler settings from environment")
54    tbb_flag = ['/Qtbb'] if use_compiler_tbb else []
55    compile_flags = ['/Qstd=c++11'] if intel_compiler else []
56else:
57    tbb_flag = ['-tbb'] if use_compiler_tbb else []
58    compile_flags = ['-std=c++11', '-Wno-unused-variable']
59
60_tbb = Extension("tbb._api", ["tbb/api.i"],
61        include_dirs=[os.path.join(tbb_root, 'include')] if not use_compiler_tbb else [],
62        swig_opts   =['-c++', '-O', '-threads'] + (  # add '-builtin' later
63              ['-I' + os.path.join(tbb_root, 'include')] if not use_compiler_tbb else []),
64        extra_compile_args=compile_flags + tbb_flag,
65        extra_link_args=tbb_flag,
66        libraries   =(['tbb'] if not use_compiler_tbb else []) +
67                     (['irml'] if platform.system() == "Linux" else []),
68        library_dirs=[ rundir,                                              # for custom-builds
69                       os.path.join(tbb_root, 'lib', 'intel64', 'gcc4.8'),  # for Linux
70                       os.path.join(tbb_root, 'lib'),                       # for MacOS
71                       os.path.join(tbb_root, 'lib', 'intel64', 'vc_mt'),   # for Windows
72                     ] if not use_compiler_tbb else [],
73        language    ='c++',
74        )
75
76
77class TBBBuild(build):
78    sub_commands = [  # define build order
79        ('build_ext', build.has_ext_modules),
80        ('build_py', build.has_pure_modules),
81    ]
82
83
84setup(  name        ="TBB",
85        description ="Python API for oneTBB",
86        long_description="Python API to Intel(R) oneAPI Threading Building Blocks library (oneTBB) "
87                         "extended with standard Pool implementation and monkey-patching",
88        url         ="https://software.intel.com/en-us/intel-tbb",
89        author      ="Intel Corporation",
90        author_email="[email protected]",
91        license     ="Dual license: Apache or Proprietary",
92        version     ="0.2",
93        classifiers =[
94            'Development Status :: 4 - Beta',
95            'Environment :: Console',
96            'Environment :: Plugins',
97            'Intended Audience :: Developers',
98            'Intended Audience :: System Administrators',
99            'Intended Audience :: Other Audience',
100            'Intended Audience :: Science/Research',
101            'License :: OSI Approved :: Apache Software License',
102            'Operating System :: MacOS :: MacOS X',
103            'Operating System :: Microsoft :: Windows',
104            'Operating System :: POSIX :: Linux',
105            'Programming Language :: Python',
106            'Programming Language :: Python :: 3',
107            'Programming Language :: C++',
108            'Topic :: System :: Hardware :: Symmetric Multi-processing',
109            'Topic :: Software Development :: Libraries',
110          ],
111        keywords='TBB multiprocessing multithreading composable parallelism',
112        ext_modules=[_tbb],
113        packages=['tbb'],
114        py_modules=['TBB'],
115        cmdclass={'build': TBBBuild}
116)
117