-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsetup.py
More file actions
117 lines (105 loc) · 3.45 KB
/
Copy pathsetup.py
File metadata and controls
117 lines (105 loc) · 3.45 KB
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
74
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
108
109
110
111
112
113
114
115
116
117
"""
Modern setup.py for CMTJ using pybind11 helpers
"""
import os
import sys
from pathlib import Path
from pybind11.setup_helpers import Pybind11Extension, build_ext
from setuptools import setup, find_packages
# Get version from setuptools_scm
try:
from setuptools_scm import get_version
version = get_version(root=".", relative_to=__file__)
except (ImportError, LookupError):
# Fallback: try to read from _version.py if it exists
try:
from cmtj._version import version
except ImportError:
version = "dev"
# Handle platform-specific compilation issues
extra_compile_args = []
extra_link_args = []
define_macros = [("VERSION_INFO", f'"{version}"')]
if "CXXFLAGS" not in os.environ:
extra_compile_args.extend(["-O3"]) # keep conservative numerics, but optimise hot loops harder
if "LDFLAGS" not in os.environ:
extra_link_args.extend(["-O2"])
if sys.platform == "darwin":
# macOS-specific flags
extra_compile_args.extend(
[
"-mmacosx-version-min=10.9", # Ensure compatibility
"-stdlib=libc++", # Use libc++ on macOS
"-fvisibility=hidden", # Hide symbols by default
"-Wno-unused-variable", # Suppress warnings that might be errors
"-Wno-deprecated-declarations", # Handle deprecated API warnings
]
)
elif sys.platform == "win32":
# Windows-specific flags
extra_compile_args.extend(
[
"/EHsc", # Enable exception handling
"/bigobj", # Allow large object files
"/wd4244", # Disable conversion warnings
"/wd4267", # Disable size_t conversion warnings
]
)
define_macros.extend(
[
("WIN32_LEAN_AND_MEAN", None),
("NOMINMAX", None), # Prevent Windows.h from defining min/max macros
("_USE_MATH_DEFINES", None), # Enable M_PI and other math constants
]
)
else:
# Linux/Unix flags
extra_compile_args.extend(
[
"-fvisibility=hidden",
"-Wno-unused-variable",
]
)
# Define the extension module with cross-platform include paths
# Use absolute paths and ensure they exist
try:
project_root = Path(__file__).parent.resolve()
except NameError:
# Fallback when __file__ is not available (e.g., in some build environments)
project_root = Path(".").resolve()
include_dirs = [
str(project_root), # Project root for relative includes
str(project_root / "core"), # Core headers
str(project_root / "third_party"), # Third party headers root
str(project_root / "third_party" / "kissfft"), # Specific kissfft path
]
# Verify all include directories exist
for inc_dir in include_dirs:
if not Path(inc_dir).exists():
print(f"Warning: Include directory does not exist: {inc_dir}")
ext_modules = [
Pybind11Extension(
"_cmtj", # Internal C++ extension name
sorted(
[
"python/cmtj.cpp", # Use relative path as required by setuptools
]
),
include_dirs=include_dirs,
define_macros=define_macros,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
cxx_std=17,
language="c++",
),
]
setup(
ext_modules=ext_modules,
cmdclass={"build_ext": build_ext},
packages=find_packages(include=["cmtj", "cmtj.*"]),
package_data={
"cmtj": ["py.typed", "**/*.pyi"],
},
include_package_data=True,
zip_safe=False,
)