|
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
|
@@ -583,32 +583,30 @@ def do_custom_build(self):
|
583 | 583 | # compilation on windows
|
584 | 584 | shutil.rmtree(str(pathlib.Path(src_path, "objs")),
|
585 | 585 | ignore_errors=True)
|
586 |
| - FREETYPE_BUILD_CMD = r""" |
587 |
| -call "%ProgramFiles%\Microsoft SDKs\Windows\v7.0\Bin\SetEnv.Cmd" ^ |
588 |
| - /Release /{xXX} /xp |
589 |
| -call "{vcvarsall}" {xXX} |
590 |
| -set MSBUILD=C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe |
591 |
| -%MSBUILD% "builds\windows\{vc20xx}\freetype.sln" ^ |
592 |
| - /t:Clean;Build /p:Configuration="Release";Platform={WinXX} |
593 |
| -""" |
594 |
| - import distutils.msvc9compiler as msvc |
595 |
| - # Note: freetype has no build profile for 2014, so we don't bother... |
596 |
| - vc = 'vc2010' |
597 |
| - WinXX = 'x64' if platform.architecture()[0] == '64bit' else 'Win32' |
598 |
| - xXX = 'x64' if platform.architecture()[0] == '64bit' else 'x86' |
599 |
| - vcvarsall = msvc.find_vcvarsall(10.0) |
600 |
| - if vcvarsall is None: |
601 |
| - raise RuntimeError('Microsoft VS 2010 required') |
602 |
| - cmdfile = pathlib.Path("build/build_freetype.cmd") |
603 |
| - cmdfile.write_text(FREETYPE_BUILD_CMD.format( |
604 |
| - vc20xx=vc, WinXX=WinXX, xXX=xXX, vcvarsall=vcvarsall)) |
605 |
| - subprocess.check_call([str(cmdfile.resolve())], |
606 |
| - shell=True, cwd=src_path) |
| 586 | + msbuild_platform = ( |
| 587 | + 'x64' if platform.architecture()[0] == '64bit' else 'Win32') |
| 588 | + sln_path = pathlib.Path( |
| 589 | + "build/freetype-2.6.1/builds/windows/vc2010/freetype.sln") |
| 590 | + # https://developercommunity.visualstudio.com/comments/190992/view.html |
| 591 | + (sln_path.parent / "Directory.Build.props").write_text(""" |
| 592 | +<Project> |
| 593 | + <PropertyGroup> |
| 594 | + <!-- The following line *cannot* be split over multiple lines. --> |
| 595 | + <WindowsTargetPlatformVersion>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetLatestSDKTargetPlatformVersion('Windows', '10.0'))</WindowsTargetPlatformVersion> |
| 596 | + </PropertyGroup> |
| 597 | +</Project> |
| 598 | +""") |
| 599 | + cc = ccompiler.new_compiler() |
| 600 | + cc.initialize() # Get devenv & msbuild in the %PATH% of cc.spawn. |
| 601 | + cc.spawn(["devenv", str(sln_path), "/upgrade"]) |
| 602 | + cc.spawn(["msbuild", str(sln_path), |
| 603 | + "/t:Clean;Build", |
| 604 | + f"/p:Configuration=Release;Platform={msbuild_platform}"]) |
607 | 605 | # Move to the corresponding Unix build path.
|
608 | 606 | pathlib.Path(src_path, "objs/.libs").mkdir()
|
609 | 607 | # Be robust against change of FreeType version.
|
610 |
| - lib_path, = (pathlib.Path(src_path, "objs", vc, xXX) |
611 |
| - .glob("freetype*.lib")) |
| 608 | + lib_path, = (pathlib.Path(src_path) |
| 609 | + .glob("objs/vc2010/*/freetype*.lib")) |
612 | 610 | shutil.copy2(
|
613 | 611 | str(lib_path),
|
614 | 612 | str(pathlib.Path(src_path, "objs/.libs/libfreetype.lib")))
|
|
0 commit comments