|
1 | 1 | import configparser
|
2 |
| -from distutils import sysconfig |
| 2 | +from distutils import ccompiler, sysconfig |
3 | 3 | from distutils.core import Extension
|
4 | 4 | import functools
|
5 | 5 | import glob
|
@@ -569,30 +569,35 @@ def do_custom_build(self):
|
569 | 569 | subprocess.check_call(["make"], env=env, cwd=src_path)
|
570 | 570 | else:
|
571 | 571 | # compilation on windows
|
572 |
| - shutil.rmtree(pathlib.Path(src_path, "objs"), ignore_errors=True) |
573 |
| - import distutils.msvc9compiler as msvc |
574 |
| - # FreeType has no build profile for 2014, so we don't bother. |
| 572 | + shutil.rmtree(str(pathlib.Path(src_path, "objs")), |
| 573 | + ignore_errors=True) |
| 574 | + msbuild_platform = ( |
| 575 | + 'x64' if platform.architecture()[0] == '64bit' else 'Win32') |
| 576 | + base_path = pathlib.Path("build/freetype-2.6.1/builds/windows") |
575 | 577 | vc = 'vc2010'
|
576 |
| - WinXX = 'x64' if platform.architecture()[0] == '64bit' else 'Win32' |
577 |
| - xXX = 'x64' if platform.architecture()[0] == '64bit' else 'x86' |
578 |
| - vcvarsall = msvc.find_vcvarsall(10.0) |
579 |
| - if vcvarsall is None: |
580 |
| - raise RuntimeError('Microsoft VS 2010 required') |
581 |
| - cmdfile = pathlib.Path("build/build_freetype.cmd") |
582 |
| - cmdfile.write_text(fr""" |
583 |
| -call "%ProgramFiles%\Microsoft SDKs\Windows\v7.0\Bin\SetEnv.Cmd" ^ |
584 |
| - /Release /{xXX} /xp |
585 |
| -call "{vcvarsall}" {xXX} |
586 |
| -set MSBUILD=C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe |
587 |
| -%MSBUILD% "builds\windows\{vc}\freetype.sln" ^ |
588 |
| - /t:Clean;Build /p:Configuration="Release";Platform={WinXX} |
| 578 | + sln_path = ( |
| 579 | + base_path / vc / "freetype.sln" |
| 580 | + ) |
| 581 | + # https://developercommunity.visualstudio.com/comments/190992/view.html |
| 582 | + (sln_path.parent / "Directory.Build.props").write_text(""" |
| 583 | +<Project> |
| 584 | + <PropertyGroup> |
| 585 | + <!-- The following line *cannot* be split over multiple lines. --> |
| 586 | + <WindowsTargetPlatformVersion>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetLatestSDKTargetPlatformVersion('Windows', '10.0'))</WindowsTargetPlatformVersion> |
| 587 | + </PropertyGroup> |
| 588 | +</Project> |
589 | 589 | """)
|
590 |
| - subprocess.check_call([str(cmdfile.resolve())], |
591 |
| - shell=True, cwd=src_path) |
| 590 | + cc = ccompiler.new_compiler() |
| 591 | + cc.initialize() # Get devenv & msbuild in the %PATH% of cc.spawn. |
| 592 | + cc.spawn(["devenv", str(sln_path), "/upgrade"]) |
| 593 | + cc.spawn(["msbuild", str(sln_path), |
| 594 | + "/t:Clean;Build", |
| 595 | + f"/p:Configuration=Release;Platform={msbuild_platform}"]) |
592 | 596 | # Move to the corresponding Unix build path.
|
593 | 597 | (src_path / "objs" / ".libs").mkdir()
|
594 | 598 | # Be robust against change of FreeType version.
|
595 |
| - lib_path, = (src_path / "objs" / vc / xXX).glob("freetype*.lib") |
| 599 | + lib_path, = (src_path / "objs" / vc / msbuild_platform).glob( |
| 600 | + "freetype*.lib") |
596 | 601 | shutil.copy2(lib_path, src_path / "objs/.libs/libfreetype.lib")
|
597 | 602 |
|
598 | 603 |
|
@@ -630,8 +635,7 @@ def get_extension(self):
|
630 | 635 | default_libraries=(
|
631 | 636 | ['png', 'z'] if os.name == 'posix' else
|
632 | 637 | # libpng upstream names their lib libpng16.lib, not png.lib.
|
633 |
| - # zlib upstream names their lib zlib.lib, not z.lib. |
634 |
| - ['libpng16', 'zlib'] if os.name == 'nt' else |
| 638 | + ['libpng16'] if os.name == 'nt' else |
635 | 639 | []
|
636 | 640 | ))
|
637 | 641 | add_numpy_flags(ext)
|
|
0 commit comments