-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
97 lines (82 loc) · 2.44 KB
/
setup.py
File metadata and controls
97 lines (82 loc) · 2.44 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
import os
import sys
import platform
import subprocess
import shutil
from setuptools import setup, Extension, find_packages
import pybind11
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
SDL_ROOT = os.path.join(BASE_DIR, "deps", "SDL2")
PLATFORM = platform.system()
def ensure_sdl():
include = os.path.join(SDL_ROOT, "include", "SDL.h")
if os.path.isfile(include):
return
print("SDL2 not found. Running download script...")
subprocess.check_call([sys.executable, "scripts/download_sdl.py"])
def find_static_sdl():
candidates = [
os.path.join(SDL_ROOT, "lib", "libSDL2.a"),
os.path.join(SDL_ROOT, "lib64", "libSDL2.a"),
os.path.join(SDL_ROOT, "build", "libSDL2.a"),
]
for c in candidates:
if os.path.isfile(c):
return c
raise RuntimeError(
"SDL2 static library not found after build. Checked:\n" +
"\n".join(candidates)
)
ensure_sdl()
include_dirs = [
pybind11.get_include(),
os.path.join(SDL_ROOT, "include"),
os.path.join(BASE_DIR, "src", "cpp"),
]
library_dirs = []
libraries = []
extra_objects = []
package_data = {}
if PLATFORM == "Windows":
lib_dir = os.path.join(SDL_ROOT, "lib", "x64")
library_dirs.append(lib_dir)
libraries.append("SDL2")
dll_src = os.path.join(lib_dir, "SDL2.dll")
dll_dst = os.path.join(BASE_DIR, "src", "pyverse", "SDL2.dll")
os.makedirs(os.path.dirname(dll_dst), exist_ok=True)
if os.path.isfile(dll_src):
shutil.copy2(dll_src, dll_dst)
print("Copied SDL2.dll to package directory")
else:
raise RuntimeError("SDL2.dll not found in expected location")
package_data = {"pyverse": ["SDL2.dll"]}
elif PLATFORM in ["Linux", "Darwin"]:
static_lib = find_static_sdl()
extra_objects = [static_lib]
print("Using SDL static library:", static_lib)
else:
raise RuntimeError(f"Unsupported platform: {PLATFORM}")
ext_modules = [
Extension(
"pyverse.pyverse",
[
"src/cpp/pyverse.cpp",
"src/cpp/app.cpp",
"src/cpp/window.cpp",
],
include_dirs=include_dirs,
library_dirs=library_dirs,
libraries=libraries,
extra_objects=extra_objects,
language="c++",
)
]
setup(
name="PyVerse",
version="0.1.0",
packages=find_packages(where="src"),
package_dir={"": "src"},
ext_modules=ext_modules,
include_package_data=True,
package_data=package_data,
)