setup.py 3.44 KB
Newer Older
Martin Reinecke's avatar
Martin Reinecke committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from setuptools import setup, Extension, Distribution
import setuptools.command.build_ext

import sys
import sysconfig
import os
import os.path
import distutils.sysconfig
import itertools
from glob import iglob


def _get_distutils_build_directory():
    """
    Returns the directory distutils uses to build its files.
    We need this directory since we build extensions which have to link
    other ones.
    """
    pattern = "lib.{platform}-{major}.{minor}"
    return os.path.join(
        'build', pattern.format(platform=sysconfig.get_platform(),
                                major=sys.version_info[0],
                                minor=sys.version_info[1]))


class _deferred_pybind11_include(object):
    def __init__(self, user=False):
        self.user = user

    def __str__(self):
        import pybind11
        return pybind11.get_include(self.user)


def _get_cc_files(directory):
    path = directory
    iterable_sources = (iglob(os.path.join(root, '*.cc'))
                        for root, dirs, files in os.walk(path))
    source_files = itertools.chain.from_iterable(iterable_sources)
    return list(source_files)


def _remove_strict_prototype_option_from_distutils_config():
    strict_prototypes = '-Wstrict-prototypes'
    config = distutils.sysconfig.get_config_vars()
    for key, value in config.items():
        if strict_prototypes in str(value):
            config[key] = config[key].replace(strict_prototypes, '')


_remove_strict_prototype_option_from_distutils_config()


extra_compile_args = []
extra_cc_compile_args = []
include_dirs = ['./', _deferred_pybind11_include(),
                _deferred_pybind11_include(True)]

library_dirs = [_get_distutils_build_directory()]
python_module_link_args = []
base_library_link_args = []

if sys.platform == 'darwin':
    extra_cc_compile_args.append('--std=c++14')
    extra_cc_compile_args.append('--stdlib=libc++')
    extra_compile_args.append('-mmacosx-version-min=10.9')

    vars = distutils.sysconfig.get_config_vars()
    vars['LDSHARED'] = vars['LDSHARED'].replace('-bundle', '')
    python_module_link_args.append('-bundle')
    builder = setuptools.command.build_ext.build_ext(Distribution())
    base_library_link_args.append('-dynamiclib')
else:
74
    extra_compile_args += ['-march=native', '-O3', '-Wfatal-errors', '-Wno-ignored-attributes']
Martin Reinecke's avatar
Martin Reinecke committed
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
    python_module_link_args += ['-march=native']
    extra_cc_compile_args.append('--std=c++14')
    python_module_link_args.append("-Wl,-rpath,$ORIGIN")

extra_cc_compile_args = extra_compile_args + extra_cc_compile_args


def get_extension_modules():
    extension_modules = []

    pocketfft_sources = ['pocketfft.cc']
    pocketfft_library = Extension('pypocketfft',
                                sources=pocketfft_sources,
                                include_dirs=include_dirs,
                                extra_compile_args=extra_cc_compile_args,
                                extra_link_args=python_module_link_args,
                                library_dirs=library_dirs)
    extension_modules.append(pocketfft_library)

    return extension_modules


setup(name='pypocketfft',
      version='0.0.1',
      description='Python interface for pocketfft',
      include_package_data=True,
      author='Martin Reinecke',
      author_email='martin@mpa-garching.mpg.de',
      packages=[],
      setup_requires=['numpy>=1.10.4', 'pybind11>=2.2.1'],
      ext_modules=get_extension_modules(),
      install_requires=['numpy>=1.10.4', 'pybind11>=2.2.1']
      )