Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a37f501

Browse files
committed
Fix FreeType build.
1 parent 6ba91c9 commit a37f501

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

setupext.py

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import builtins
22
import configparser
3-
from distutils import sysconfig, version
3+
from distutils import ccompiler, sysconfig, version
44
from distutils.core import Extension
55
import glob
66
import hashlib
@@ -955,32 +955,30 @@ def do_custom_build(self):
955955
# compilation on windows
956956
shutil.rmtree(str(pathlib.Path(src_path, "objs")),
957957
ignore_errors=True)
958-
FREETYPE_BUILD_CMD = r"""
959-
call "%ProgramFiles%\Microsoft SDKs\Windows\v7.0\Bin\SetEnv.Cmd" ^
960-
/Release /{xXX} /xp
961-
call "{vcvarsall}" {xXX}
962-
set MSBUILD=C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
963-
%MSBUILD% "builds\windows\{vc20xx}\freetype.sln" ^
964-
/t:Clean;Build /p:Configuration="Release";Platform={WinXX}
965-
"""
966-
import distutils.msvc9compiler as msvc
967-
# Note: freetype has no build profile for 2014, so we don't bother...
968-
vc = 'vc2010'
969-
WinXX = 'x64' if platform.architecture()[0] == '64bit' else 'Win32'
970-
xXX = 'x64' if platform.architecture()[0] == '64bit' else 'x86'
971-
vcvarsall = msvc.find_vcvarsall(10.0)
972-
if vcvarsall is None:
973-
raise RuntimeError('Microsoft VS 2010 required')
974-
cmdfile = pathlib.Path("build/build_freetype.cmd")
975-
cmdfile.write_text(FREETYPE_BUILD_CMD.format(
976-
vc20xx=vc, WinXX=WinXX, xXX=xXX, vcvarsall=vcvarsall))
977-
subprocess.check_call([str(cmdfile.resolve())],
978-
shell=True, cwd=src_path)
958+
msbuild_platform = (
959+
'x64' if platform.architecture()[0] == '64bit' else 'Win32')
960+
sln_path = pathlib.Path(
961+
"build/freetype-2.6.1/builds/windows/vc2010/freetype.sln")
962+
# https://developercommunity.visualstudio.com/comments/190992/view.html
963+
(sln_path.parent / "Directory.Build.props").write_text("""
964+
<Project>
965+
<PropertyGroup>
966+
<!-- The following line *cannot* be split over multiple lines. -->
967+
<WindowsTargetPlatformVersion>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetLatestSDKTargetPlatformVersion('Windows', '10.0'))</WindowsTargetPlatformVersion>
968+
</PropertyGroup>
969+
</Project>
970+
""")
971+
cc = ccompiler.new_compiler()
972+
cc.initialize() # Get devenv & msbuild in the %PATH% of cc.spawn.
973+
cc.spawn(["devenv", str(sln_path), "/upgrade"])
974+
cc.spawn(["msbuild", str(sln_path),
975+
"/t:Clean;Build",
976+
f"/p:Configuration=Release;Platform={msbuild_platform}"])
979977
# Move to the corresponding Unix build path.
980978
pathlib.Path(src_path, "objs/.libs").mkdir()
981979
# Be robust against change of FreeType version.
982-
lib_path, = (pathlib.Path(src_path, "objs", vc, xXX)
983-
.glob("freetype*.lib"))
980+
lib_path, = (pathlib.Path(src_path)
981+
.glob("objs/vc2010/*/freetype*.lib"))
984982
shutil.copy2(
985983
str(lib_path),
986984
str(pathlib.Path(src_path, "objs/.libs/libfreetype.lib")))

0 commit comments

Comments
 (0)