setup.py 2.55 KB
Newer Older
Martin Reinecke's avatar
Martin Reinecke committed
1 2
from setuptools import setup, Extension
import sys
Martin Reinecke's avatar
Martin Reinecke committed
3 4 5
import os.path
import itertools
from glob import iglob
Martin Reinecke's avatar
Martin Reinecke committed
6

Martin Reinecke's avatar
Martin Reinecke committed
7
pkgname = 'ducc_0_1'
Martin Reinecke's avatar
Martin Reinecke committed
8 9 10 11 12 13 14 15 16 17

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

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


Martin Reinecke's avatar
Martin Reinecke committed
18 19 20 21 22 23 24
def _get_files_by_suffix(directory, suffix):
    path = directory
    iterable_sources = (iglob(os.path.join(root, '*.'+suffix))
                        for root, dirs, files in os.walk(path))
    return list(itertools.chain.from_iterable(iterable_sources))


Martin Reinecke's avatar
Martin Reinecke committed
25
include_dirs = ['.', './src/',
Martin Reinecke's avatar
Martin Reinecke committed
26 27 28 29
                _deferred_pybind11_include(True),
                _deferred_pybind11_include()]
extra_compile_args = ['--std=c++17', '-march=native', '-ffast-math', '-O3']
python_module_link_args = []
Martin Reinecke's avatar
Martin Reinecke committed
30
define_macros = [("PKGNAME", pkgname)]
Martin Reinecke's avatar
Martin Reinecke committed
31 32 33 34 35 36 37 38 39 40 41

if sys.platform == 'darwin':
    import distutils.sysconfig
    extra_compile_args += ['-mmacosx-version-min=10.9']
    python_module_link_args += ['-mmacosx-version-min=10.9', '-bundle']
    vars = distutils.sysconfig.get_config_vars()
    vars['LDSHARED'] = vars['LDSHARED'].replace('-bundle', '')
elif sys.platform == 'win32':
    extra_compile_args = ['/Ox', '/EHsc', '/std:c++17']
else:
    extra_compile_args += ['-Wfatal-errors', '-Wfloat-conversion', '-W', '-Wall', '-Wstrict-aliasing=2', '-Wwrite-strings', '-Wredundant-decls', '-Woverloaded-virtual', '-Wcast-qual', '-Wcast-align', '-Wpointer-arith']
42
    python_module_link_args += ['-march=native', '-Wl,-rpath,$ORIGIN', '-s']
Martin Reinecke's avatar
Martin Reinecke committed
43

Martin Reinecke's avatar
cleanup  
Martin Reinecke committed
44
# if you want debugging info, remove the "-s" from python_module_link_args
Martin Reinecke's avatar
Martin Reinecke committed
45 46

def get_extension_modules():
Martin Reinecke's avatar
Martin Reinecke committed
47
    depfiles = _get_files_by_suffix('.', 'h') + _get_files_by_suffix('.', 'cc') + ['setup.py']
48
    return [Extension(pkgname,
Martin Reinecke's avatar
Martin Reinecke committed
49
                      language='c++',
Martin Reinecke's avatar
Martin Reinecke committed
50
                      sources=['python/ducc.cc'],
Martin Reinecke's avatar
Martin Reinecke committed
51
                      depends=depfiles,
Martin Reinecke's avatar
Martin Reinecke committed
52 53 54
                      include_dirs=include_dirs,
                      define_macros=define_macros,
                      extra_compile_args=extra_compile_args,
Martin Reinecke's avatar
Martin Reinecke committed
55
                      extra_link_args=python_module_link_args)]
Martin Reinecke's avatar
Martin Reinecke committed
56 57


58
setup(name=pkgname,
Martin Reinecke's avatar
Martin Reinecke committed
59 60
      version='0.1.0',
      description='Definitely useful code collection',
Martin Reinecke's avatar
cleanup  
Martin Reinecke committed
61
      url='https://gitlab.mpcdf.mpg.de/mtr/cxxbase',
Martin Reinecke's avatar
Martin Reinecke committed
62 63 64 65
      include_package_data=True,
      author='Martin Reinecke',
      author_email='martin@mpa-garching.mpg.de',
      packages=[],
Martin Reinecke's avatar
Martin Reinecke committed
66
      setup_requires=['numpy>=1.17.0', 'pybind11>=2.5.0'],
Martin Reinecke's avatar
Martin Reinecke committed
67
      ext_modules=get_extension_modules(),
Martin Reinecke's avatar
cleanup  
Martin Reinecke committed
68 69
      install_requires=['numpy>=1.17.0', 'pybind11>=2.5.0'],
      license="GPLv2",
Martin Reinecke's avatar
Martin Reinecke committed
70
      )