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

6 7
from setuptools import setup, Extension
import pybind11
Martin Reinecke's avatar
Martin Reinecke committed
8

9
pkgname = 'ducc'
10
version = '0.1.0'
11
cppname = '_'.join((pkgname, version.replace('.', '_')))
Martin Reinecke's avatar
Martin Reinecke committed
12

Martin Reinecke's avatar
Martin Reinecke committed
13 14 15 16 17 18 19
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
20
include_dirs = ['.', './src/',
21 22 23
                pybind11.get_include(True),
                pybind11.get_include(False)]

Martin Reinecke's avatar
Martin Reinecke committed
24
extra_compile_args = ['--std=c++17', '-march=native', '-ffast-math', '-O3']
25

Martin Reinecke's avatar
Martin Reinecke committed
26
python_module_link_args = []
27

28
define_macros = [("PKGNAME", cppname),
29
                 ("PKGVERSION", '"%s"' % version)]
Martin Reinecke's avatar
Martin Reinecke committed
30 31 32 33 34

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']
35 36
    cfg_vars = distutils.sysconfig.get_config_vars()
    cfg_vars['LDSHARED'] = cfg_vars['LDSHARED'].replace('-bundle', '')
Martin Reinecke's avatar
Martin Reinecke committed
37 38 39
elif sys.platform == 'win32':
    extra_compile_args = ['/Ox', '/EHsc', '/std:c++17']
else:
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
    extra_compile_args += ['-Wfatal-errors',
                           '-Wfloat-conversion',
                           '-W',
                           '-Wall',
                           '-Wstrict-aliasing=2',
                           '-Wwrite-strings',
                           '-Wredundant-decls',
                           '-Woverloaded-virtual',
                           '-Wcast-qual',
                           '-Wcast-align',
                           '-Wpointer-arith']

    python_module_link_args += ['-march=native',
                                '-Wl,-rpath,$ORIGIN',
                                '-s']
Martin Reinecke's avatar
Martin Reinecke committed
55

Martin Reinecke's avatar
cleanup  
Martin Reinecke committed
56
# if you want debugging info, remove the "-s" from python_module_link_args
57 58 59
depfiles = (_get_files_by_suffix('.', 'h') +
            _get_files_by_suffix('.', 'cc') +
            ['setup.py'])
Martin Reinecke's avatar
Martin Reinecke committed
60

61 62 63 64
# ducc.ducc_0_1_0
extname = '.'.join((pkgname, cppname))

extensions = [Extension(extname,
65 66 67 68 69 70 71
                        language='c++',
                        sources=['python/ducc.cc'],
                        depends=depfiles,
                        include_dirs=include_dirs,
                        define_macros=define_macros,
                        extra_compile_args=extra_compile_args,
                        extra_link_args=python_module_link_args)]
Martin Reinecke's avatar
Martin Reinecke committed
72 73


74
setup(name=pkgname,
75
      version=version,
Martin Reinecke's avatar
Martin Reinecke committed
76
      description='Definitely useful code collection',
77
      url='https://gitlab.mpcdf.mpg.de/mtr/ducc',
Martin Reinecke's avatar
Martin Reinecke committed
78 79 80 81
      include_package_data=True,
      author='Martin Reinecke',
      author_email='martin@mpa-garching.mpg.de',
      packages=[],
82 83
      python_requires=">=3.6",
      ext_modules=extensions,
84
      install_requires=['numpy>=1.17.0'],
Martin Reinecke's avatar
cleanup  
Martin Reinecke committed
85
      license="GPLv2",
Martin Reinecke's avatar
Martin Reinecke committed
86
      )