|
3 | 3 | from subprocess import run, DEVNULL, PIPE |
4 | 4 | from cffi import FFI |
5 | 5 |
|
6 | | -ffibuilder = FFI() |
| 6 | +ffi = FFI() |
7 | 7 |
|
8 | 8 |
|
9 | 9 | with open("libheif/heif.h", "r", encoding="utf-8") as f: |
10 | | - ffibuilder.cdef(f.read()) |
| 10 | + ffi.cdef(f.read()) |
11 | 11 |
|
12 | 12 |
|
13 | 13 | include_dirs = ["/usr/local/include", "/usr/include", "/opt/local/include"] |
14 | 14 | library_dirs = ["/usr/local/lib", "/usr/lib", "/lib", "/opt/local/lib"] |
15 | 15 |
|
| 16 | +if platform.lower() in ("darwin", "win32"): |
| 17 | + include_dirs.append(path.dirname(path.dirname(path.abspath(__file__)))) |
| 18 | + |
| 19 | +include_path_prefix = "" |
16 | 20 | if platform.lower() == "darwin": |
17 | | - homebrew_prefix = getenv("HOMEBREW_PREFIX") |
18 | | - if not homebrew_prefix: |
19 | | - _result = run(['brew', '--prefix'], stderr=DEVNULL, stdout=PIPE, check=False) |
| 21 | + include_path_prefix = getenv("HOMEBREW_PREFIX") |
| 22 | + if not include_path_prefix: |
| 23 | + _result = run(["brew", "--prefix"], stderr=DEVNULL, stdout=PIPE, check=False) |
20 | 24 | if not _result.returncode and _result.stdout is not None: |
21 | | - homebrew_prefix = _result.stdout.decode('utf-8').rstrip('\n') |
22 | | - if homebrew_prefix: |
23 | | - homebrew_include = path.join(homebrew_prefix, "include") |
24 | | - if homebrew_include not in include_dirs: |
25 | | - include_dirs.append(homebrew_include) |
26 | | - homebrew_library = path.join(homebrew_prefix, "lib") |
27 | | - if homebrew_library not in library_dirs: |
28 | | - library_dirs.append(homebrew_library) |
29 | | - project_root = path.dirname(path.dirname(path.abspath(__file__))) |
30 | | - include_dirs.append(project_root) |
31 | | - |
32 | | - |
33 | | -ffibuilder.set_source( |
34 | | - "pillow_heif._libheif", |
| 25 | + include_path_prefix = _result.stdout.decode("utf-8").rstrip("\n") |
| 26 | +elif platform.lower() == "win32": |
| 27 | + include_path_prefix = getenv("VCPKG_PREFIX") |
| 28 | +if include_path_prefix: |
| 29 | + include_path_prefix_include = path.join(include_path_prefix, "include") |
| 30 | + if include_path_prefix_include not in include_dirs: |
| 31 | + include_dirs.append(include_path_prefix_include) |
| 32 | + include_path_prefix_lib = path.join(include_path_prefix, "lib") |
| 33 | + if include_path_prefix_lib not in library_dirs: |
| 34 | + library_dirs.append(include_path_prefix_lib) |
| 35 | + |
| 36 | + |
| 37 | +ffi.set_source( |
| 38 | + "pillow_heif.libheif", |
35 | 39 | """ |
36 | 40 | #include "libheif/heif.h" |
37 | 41 | """, |
38 | 42 | include_dirs=include_dirs, |
39 | 43 | library_dirs=library_dirs, |
40 | 44 | libraries=["heif"], |
| 45 | + extra_compile_args=["/d2FH4-"] if platform.lower() == "win32" else [], |
41 | 46 | ) |
42 | 47 |
|
43 | 48 | if __name__ == "__main__": |
44 | | - ffibuilder.compile(verbose=True) |
| 49 | + ffi.compile(verbose=True) |
0 commit comments