xref: /oneTBB/python/setup.py (revision 6caecf96)
1#!/usr/bin/env python3
2#
3# Copyright (c) 2016-2021 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 []
56    tbb_lib_name = 'tbb12'
57else:
58    tbb_flag = ['-tbb'] if use_compiler_tbb else []
59    compile_flags = ['-std=c++11', '-Wno-unused-variable']
60    tbb_lib_name = 'tbb'
61
62_tbb = Extension("tbb._api", ["tbb/api.i"],
63        include_dirs=[os.path.join(tbb_root, 'include')] if not use_compiler_tbb else [],
64        swig_opts   =['-c++', '-O', '-threads'] + (  # add '-builtin' later
65              ['-I' + os.path.join(tbb_root, 'include')] if not use_compiler_tbb else []),
66        extra_compile_args=compile_flags + tbb_flag,
67        extra_link_args=tbb_flag,
68        libraries   =([tbb_lib_name] if not use_compiler_tbb else []) +
69                     (['irml'] if platform.system() == "Linux" else []),
70        library_dirs=[ rundir,                                              # for custom-builds
71                       os.path.join(tbb_root, 'lib', 'intel64', 'gcc4.8'),  # for Linux
72                       os.path.join(tbb_root, 'lib'),                       # for MacOS
73                       os.path.join(tbb_root, 'lib', 'intel64', 'vc_mt'),   # for Windows
74                     ] if not use_compiler_tbb else [],
75        language    ='c++',
76        )
77
78
79class TBBBuild(build):
80    sub_commands = [  # define build order
81        ('build_ext', build.has_ext_modules),
82        ('build_py', build.has_pure_modules),
83    ]
84
85
86setup(  name        ="TBB",
87        description ="Python API for oneTBB",
88        long_description="Python API to Intel(R) oneAPI Threading Building Blocks library (oneTBB) "
89                         "extended with standard Pool implementation and monkey-patching",
90        url         ="https://software.intel.com/en-us/intel-tbb",
91        author      ="Intel Corporation",
92        author_email="[email protected]",
93        license     ="Dual license: Apache or Proprietary",
94        version     ="0.2",
95        classifiers =[
96            'Development Status :: 4 - Beta',
97            'Environment :: Console',
98            'Environment :: Plugins',
99            'Intended Audience :: Developers',
100            'Intended Audience :: System Administrators',
101            'Intended Audience :: Other Audience',
102            'Intended Audience :: Science/Research',
103            'License :: OSI Approved :: Apache Software License',
104            'Operating System :: MacOS :: MacOS X',
105            'Operating System :: Microsoft :: Windows',
106            'Operating System :: POSIX :: Linux',
107            'Programming Language :: Python',
108            'Programming Language :: Python :: 3',
109            'Programming Language :: C++',
110            'Topic :: System :: Hardware :: Symmetric Multi-processing',
111            'Topic :: Software Development :: Libraries',
112          ],
113        keywords='TBB multiprocessing multithreading composable parallelism',
114        ext_modules=[_tbb],
115        packages=['tbb'],
116        py_modules=['TBB'],
117        cmdclass={'build': TBBBuild}
118)
119