|
1 | 1 | from os import getenv, path |
| 2 | +from pathlib import Path |
| 3 | +from shutil import copy |
2 | 4 | from subprocess import DEVNULL, PIPE, run |
3 | 5 | from sys import platform |
4 | 6 | from warnings import warn |
|
37 | 39 | elif platform.lower() == "win32": |
38 | 40 | include_path_prefix = getenv("VCPKG_PREFIX") |
39 | 41 | if include_path_prefix is None: |
40 | | - include_path_prefix = "C:\\vcpkg\\installed\\x64-windows" |
| 42 | + include_path_prefix = "C:\\msys64\\mingw64" |
41 | 43 | warn(f"VCPKG_PREFIX environment variable is not set. Assuming `VCPKG_PREFIX={include_path_prefix}`") |
42 | 44 | else: |
43 | 45 | include_path_prefix = build_libs.build_libs_linux() |
44 | 46 |
|
45 | | -if include_path_prefix: |
46 | | - include_path_prefix_include = path.join(include_path_prefix, "include") |
47 | | - if include_path_prefix_include not in include_dirs: |
48 | | - include_dirs.append(include_path_prefix_include) |
49 | | - include_path_prefix_lib = path.join(include_path_prefix, "lib") |
50 | | - if include_path_prefix_lib not in library_dirs: |
51 | | - library_dirs.append(include_path_prefix_lib) |
| 47 | +# Need to include "lib" directory to find "heif" library. |
| 48 | +include_path_prefix_lib = path.join(include_path_prefix, "lib") |
| 49 | +if include_path_prefix_lib not in library_dirs: |
| 50 | + library_dirs.append(include_path_prefix_lib) |
52 | 51 |
|
53 | | -if platform.lower() in ("darwin", "win32"): |
54 | | - include_dirs.append(path.dirname(path.dirname(path.abspath(__file__)))) |
| 52 | +# MSYS2: rename "libheif.dll.a" to "libheif.lib" |
| 53 | +if platform.lower() == "win32": |
| 54 | + lib_export_file = Path(path.join(include_path_prefix_lib, "libheif.dll.a")) |
| 55 | + if lib_export_file.is_file(): |
| 56 | + copy(lib_export_file, path.join(include_path_prefix_lib, "libheif.lib")) |
| 57 | + else: |
| 58 | + warn("If you build this with MSYS2, you should not see this warning.") |
| 59 | + |
| 60 | +# Adds project root to `include` path |
| 61 | +include_dirs.append(path.dirname(path.dirname(path.abspath(__file__)))) |
55 | 62 |
|
56 | 63 | ffi.set_source( |
57 | 64 | "_pillow_heif_cffi", |
|
60 | 67 | """, |
61 | 68 | include_dirs=include_dirs, |
62 | 69 | library_dirs=library_dirs, |
63 | | - libraries=["heif"], |
| 70 | + libraries=["libheif"] if platform.lower() == "win32" else ["heif"], |
64 | 71 | extra_compile_args=["/d2FH4-"] if platform.lower() == "win32" else [], |
65 | 72 | ) |
66 | 73 |
|
|
0 commit comments