File size: 1,412 Bytes
6c21feb
bdb714e
 
 
6c21feb
 
 
bdb714e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6c21feb
 
 
 
bdb714e
 
 
 
6c21feb
 
 
 
 
 
 
 
bdb714e
6c21feb
 
 
 
bdb714e
6c21feb
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
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
import sys
import os
import pybind11
import numpy as np

class BuildExt(build_ext):
    """Custom build extension for pybind11."""
    def build_extensions(self):
        # Print debug info
        print(f"Python {sys.version}")
        print(f"Building extension with {self.compiler.compiler_type}")
        
        # Apply relevant compiler flags based on compiler
        if self.compiler.compiler_type == 'unix':
            opts = ['-std=c++11', '-O3', '-fvisibility=hidden']
            if sys.platform == 'darwin':
                opts.append('-stdlib=libc++')
        elif self.compiler.compiler_type == 'msvc':
            opts = ['/EHsc', '/O2']
        else:
            opts = []

        # Apply options to all extensions
        for ext in self.extensions:
            ext.extra_compile_args = opts
        
        build_ext.build_extensions(self)

ext_modules = [
    Extension(
        'cubic_cpp',
        ['cubic_cpp.cpp'],
        include_dirs=[
            pybind11.get_include(),
            np.get_include(),
        ],
        language='c++',
    ),
]

setup(
    name="cubic_cpp",
    version="0.1",
    ext_modules=ext_modules,
    cmdclass={'build_ext': BuildExt},
    install_requires=[
        'pybind11>=2.6.0',
        'numpy>=1.19.0',
    ],
    zip_safe=False,  # Required for pybind11
)