xref: /oneTBB/python/setup.py (revision 5f1ae0dc)
1# Copyright (c) 2016-2023 Intel Corporation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15
16# System imports
17import platform
18import os
19
20from distutils.core import *
21from distutils.command.build import build
22
23rundir = os.getcwd()
24os.chdir(os.path.abspath(os.path.dirname(__file__)))
25
26if any(i in os.environ for i in ["CC", "CXX"]):
27    if "CC" not in os.environ:
28        os.environ['CC'] = os.environ['CXX']
29    if "CXX" not in os.environ:
30        os.environ['CXX'] = os.environ['CC']
31    if platform.system() == 'Linux':
32        os.environ['LDSHARED'] = os.environ['CXX'] + " -shared"
33    print("Environment specifies CC=%s CXX=%s"%(os.environ['CC'], os.environ['CXX']))
34
35intel_compiler = os.getenv('CC', '') in ['icl', 'icpc', 'icc']
36try:
37    tbb_root = os.environ['TBBROOT']
38    print("Using TBBROOT=", tbb_root)
39except:
40    tbb_root = '..'
41    if not intel_compiler:
42        print("Warning: TBBROOT env var is not set and Intel's compiler is not used. It might lead\n"
43              "    !!!: to compile/link problems. Source tbbvars.sh/.csh file to set environment")
44use_compiler_tbb = intel_compiler and tbb_root == '..'
45if use_compiler_tbb:
46    print("Using oneTBB from Intel(R) C++ Compiler")
47if platform.system() == 'Windows':
48    if intel_compiler:
49        os.environ['DISTUTILS_USE_SDK'] = '1'  # Enable environment settings in distutils
50        os.environ['MSSdk'] = '1'
51        print("Using compiler settings from environment")
52    tbb_flag = ['/Qtbb'] if use_compiler_tbb else []
53    compile_flags = ['/Qstd=c++11'] if intel_compiler else []
54    tbb_lib_name = 'tbb12'
55else:
56    tbb_flag = ['-tbb'] if use_compiler_tbb else []
57    compile_flags = ['-std=c++11', '-Wno-unused-variable']
58    tbb_lib_name = 'tbb'
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_lib_name] 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://www.intel.com/content/www/us/en/developer/tools/oneapi/onetbb.html",
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