|
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,26 +569,27 @@ 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. |
575 |
| - 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} |
| 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 | + sln_path = pathlib.Path( |
| 577 | + "build/freetype-2.6.1/builds/windows/vc2010/freetype.sln") |
| 578 | + # https://developercommunity.visualstudio.com/comments/190992/view.html |
| 579 | + (sln_path.parent / "Directory.Build.props").write_text(""" |
| 580 | +<Project> |
| 581 | + <PropertyGroup> |
| 582 | + <!-- The following line *cannot* be split over multiple lines. --> |
| 583 | + <WindowsTargetPlatformVersion>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetLatestSDKTargetPlatformVersion('Windows', '10.0'))</WindowsTargetPlatformVersion> |
| 584 | + </PropertyGroup> |
| 585 | +</Project> |
589 | 586 | """)
|
590 |
| - subprocess.check_call([str(cmdfile.resolve())], |
591 |
| - shell=True, cwd=src_path) |
| 587 | + cc = ccompiler.new_compiler() |
| 588 | + cc.initialize() # Get devenv & msbuild in the %PATH% of cc.spawn. |
| 589 | + cc.spawn(["devenv", str(sln_path), "/upgrade"]) |
| 590 | + cc.spawn(["msbuild", str(sln_path), |
| 591 | + "/t:Clean;Build", |
| 592 | + f"/p:Configuration=Release;Platform={msbuild_platform}"]) |
592 | 593 | # Move to the corresponding Unix build path.
|
593 | 594 | (src_path / "objs" / ".libs").mkdir()
|
594 | 595 | # Be robust against change of FreeType version.
|
|
0 commit comments