11from __future__ import annotations
22
33import glob
4+ import platform
45from pathlib import Path
56from setuptools import Extension , setup
67
8+ # No ZIP support for windows, building with zlib is a pain
9+ ZIP_SUPPORT = platform .system () != "Windows"
10+
711
812def get_extensions () -> list [Extension ]:
913 import numpy # Lazy import; numpy provided via build-system requires
@@ -13,26 +17,38 @@ def get_extensions() -> list[Extension]:
1317 libgambatte_sources = [
1418 p
1519 for p in glob .glob ("libgambatte/**/*.cpp" , recursive = True )
16- if not p .endswith ("file.cpp" )
20+ if (ZIP_SUPPORT and not p .endswith ("file.cpp" ))
21+ or (not ZIP_SUPPORT and not p .endswith ("file_zip.cpp" ))
1722 ]
1823
19- # Add minizip C sources for ZIP support
20- minizip_sources = glob .glob ("libgambatte/src/file/unzip/*.c" , recursive = True )
24+ # Add unzip C sources for ZIP support
25+ if ZIP_SUPPORT :
26+ libgambatte_sources += glob .glob (
27+ "libgambatte/src/file/unzip/*.c" , recursive = True
28+ )
29+
30+ # Add zlib library for ZIP support
31+ libraries = []
32+ if ZIP_SUPPORT :
33+ libraries += ["z" ]
2134
2235 # Include dirs: parents of all headers
23- include_dirs = list (
36+ libgambatte_include_dirs = list (
2437 {str (Path (h ).parent ) for h in glob .glob ("libgambatte/**/*.h" , recursive = True )}
2538 )
2639
2740 gambatte_extension = Extension (
2841 "gambaterm.libgambatte" ,
2942 language = "c++" ,
30- include_dirs = [* include_dirs , "libgambatte_ext" , numpy .get_include ()],
43+ include_dirs = [
44+ * libgambatte_include_dirs ,
45+ "libgambatte_ext" ,
46+ numpy .get_include (),
47+ ],
3148 extra_compile_args = ["-DHAVE_STDINT_H" ],
32- libraries = [ "z" ], # Link against zlib for ZIP support
49+ libraries = libraries ,
3350 sources = [
3451 * libgambatte_sources ,
35- * minizip_sources ,
3652 "libgambatte_ext/libgambatte.pyx" ,
3753 ],
3854 )
0 commit comments