1<?xml version="1.0" encoding="utf-8"?>
2<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3  <PropertyGroup>
4    <__Python_Props_Imported>true</__Python_Props_Imported>
5    <Platform Condition="'$(Platform)' == ''">Win32</Platform>
6    <Configuration Condition="'$(Configuration)' == ''">Release</Configuration>
7    <!--
8    Use the latest available version of Visual Studio to build. To override
9    this and build with an earlier version, pass "/p:PlatformToolset=v100"
10    (for example) when building.
11
12    We set BasePlatformToolset for ICC's benefit, it's otherwise ignored.
13    -->
14    <BasePlatformToolset Condition="'$(BasePlatformToolset)' == '' and '$(VisualStudioVersion)' == '17.0'">v143</BasePlatformToolset>
15    <BasePlatformToolset Condition="'$(BasePlatformToolset)' == '' and '$(VisualStudioVersion)' == '16.0'">v142</BasePlatformToolset>
16    <BasePlatformToolset Condition="'$(BasePlatformToolset)' == '' and ('$(MSBuildToolsVersion)' == '15.0' or '$(VisualStudioVersion)' == '15.0')">v141</BasePlatformToolset>
17    <BasePlatformToolset Condition="'$(BasePlatformToolset)' == '' and '$(VCTargetsPath14)' != ''">v140</BasePlatformToolset>
18    <BasePlatformToolset Condition="'$(BasePlatformToolset)' == '' and '$(VCTargetsPath12)' != ''">v120</BasePlatformToolset>
19    <BasePlatformToolset Condition="'$(BasePlatformToolset)' == '' and '$(VCTargetsPath11)' != ''">v110</BasePlatformToolset>
20    <BasePlatformToolset Condition="'$(BasePlatformToolset)' == '' and '$(VCTargetsPath10)' != ''">v100</BasePlatformToolset>
21
22    <PlatformToolset Condition="'$(PlatformToolset)' == ''">$(BasePlatformToolset)</PlatformToolset>
23    <ICCBuild>false</ICCBuild>
24    <ICCBuild Condition="$(PlatformToolset.StartsWith(`Intel C++ Compiler`))">true</ICCBuild>
25
26    <!--
27    Convincing MSVC/MSBuild to prefer our platform names is too difficult,
28    so we define our own constant ArchName and use wherever we need it.
29    -->
30    <ArchName Condition="'$(ArchName)' == '' and $(Platform) == 'x64'">amd64</ArchName>
31    <ArchName Condition="'$(ArchName)' == '' and $(Platform) == 'ARM'">arm32</ArchName>
32    <ArchName Condition="'$(ArchName)' == '' and $(Platform) == 'ARM64'">arm64</ArchName>
33    <ArchName Condition="'$(ArchName)' == ''">win32</ArchName>
34
35    <!-- Root directory of the repository -->
36    <PySourcePath Condition="'$(PySourcePath)' == ''">$([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)\..\))</PySourcePath>
37    <PySourcePath Condition="!HasTrailingSlash($(PySourcePath))">$(PySourcePath)\</PySourcePath>
38
39    <!-- Directory where build outputs are put -->
40    <BuildPath32 Condition="'$(Py_OutDir)' == ''">$(PySourcePath)PCbuild\win32\</BuildPath32>
41    <BuildPath32 Condition="'$(Py_OutDir)' != ''">$(Py_OutDir)\win32\</BuildPath32>
42    <BuildPath64 Condition="'$(Py_OutDir)' == ''">$(PySourcePath)PCbuild\amd64\</BuildPath64>
43    <BuildPath64 Condition="'$(Py_OutDir)' != ''">$(Py_OutDir)\amd64\</BuildPath64>
44    <BuildPathArm32 Condition="'$(Py_OutDir)' == ''">$(PySourcePath)PCbuild\arm32\</BuildPathArm32>
45    <BuildPathArm32 Condition="'$(Py_OutDir)' != ''">$(Py_OutDir)\arm32\</BuildPathArm32>
46    <BuildPathArm64 Condition="'$(Py_OutDir)' == ''">$(PySourcePath)PCbuild\arm64\</BuildPathArm64>
47    <BuildPathArm64 Condition="'$(Py_OutDir)' != ''">$(Py_OutDir)\arm64\</BuildPathArm64>
48    <BuildPath Condition="'$(ArchName)' == 'win32'">$(BuildPath32)</BuildPath>
49    <BuildPath Condition="'$(ArchName)' == 'amd64'">$(BuildPath64)</BuildPath>
50    <BuildPath Condition="'$(ArchName)' == 'arm32'">$(BuildPathArm32)</BuildPath>
51    <BuildPath Condition="'$(ArchName)' == 'arm64'">$(BuildPathArm64)</BuildPath>
52    <BuildPath Condition="'$(BuildPath)' == ''">$(PySourcePath)PCbuild\$(ArchName)\</BuildPath>
53    <BuildPath Condition="!HasTrailingSlash($(BuildPath))">$(BuildPath)\</BuildPath>
54    <BuildPath Condition="$(Configuration) == 'PGInstrument'">$(BuildPath)instrumented\</BuildPath>
55
56    <!-- VPATH definition (escaped) -->
57    <PyVPath Condition="$(Configuration) != 'PGInstrument'">..\\..</PyVPath>
58    <PyVPath Condition="$(Configuration) == 'PGInstrument'">..\\..\\..</PyVPath>
59  </PropertyGroup>
60
61  <!-- Directories of external projects. tcltk is handled in tcltk.props -->
62  <PropertyGroup>
63    <ExternalsDir Condition="$(ExternalsDir) == ''">$(EXTERNALS_DIR)</ExternalsDir>
64    <ExternalsDir Condition="$(ExternalsDir) == ''">$([System.IO.Path]::GetFullPath(`$(PySourcePath)externals`))</ExternalsDir>
65    <ExternalsDir Condition="!HasTrailingSlash($(ExternalsDir))">$(ExternalsDir)\</ExternalsDir>
66  </PropertyGroup>
67
68  <Import Project="$(ExternalProps)" Condition="$(ExternalProps) != '' and Exists('$(ExternalProps)')" />
69
70  <PropertyGroup>
71    <sqlite3Dir Condition="$(sqlite3Dir) == ''">$(ExternalsDir)sqlite-3.42.0.0\</sqlite3Dir>
72    <bz2Dir Condition="$(bz2Dir) == ''">$(ExternalsDir)bzip2-1.0.8\</bz2Dir>
73    <lzmaDir Condition="$(lzmaDir) == ''">$(ExternalsDir)xz-5.2.5\</lzmaDir>
74    <libffiDir Condition="$(libffiDir) == ''">$(ExternalsDir)libffi-3.4.4\</libffiDir>
75    <libffiOutDir Condition="$(libffiOutDir) == ''">$(libffiDir)$(ArchName)\</libffiOutDir>
76    <libffiIncludeDir Condition="$(libffiIncludeDir) == ''">$(libffiOutDir)include</libffiIncludeDir>
77    <opensslDir Condition="$(opensslDir) == ''">$(ExternalsDir)openssl-1.1.1u\</opensslDir>
78    <opensslOutDir Condition="$(opensslOutDir) == ''">$(ExternalsDir)openssl-bin-1.1.1u\$(ArchName)\</opensslOutDir>
79    <opensslIncludeDir Condition="$(opensslIncludeDir) == ''">$(opensslOutDir)include</opensslIncludeDir>
80    <nasmDir Condition="$(nasmDir) == ''">$(ExternalsDir)\nasm-2.11.06\</nasmDir>
81    <zlibDir Condition="$(zlibDir) == ''">$(ExternalsDir)\zlib-1.2.13\</zlibDir>
82  </PropertyGroup>
83
84  <PropertyGroup>
85    <!-- Suffix for all binaries when building for debug -->
86    <PyDebugExt Condition="'$(PyDebugExt)' == '' and $(Configuration) == 'Debug'">_d</PyDebugExt>
87
88    <!-- Suffix for versions/keys when building with test markers -->
89    <PyTestExt Condition="$(UseTestMarker) == 'true'">-test</PyTestExt>
90
91    <!-- Suffix for versions/keys when building for particular platforms -->
92    <PyArchExt Condition="'$(ArchName)' == 'win32'">-32</PyArchExt>
93    <PyArchExt Condition="'$(ArchName)' == 'arm32'">-arm32</PyArchExt>
94    <PyArchExt Condition="'$(ArchName)' == 'arm64'">-arm64</PyArchExt>
95
96    <!-- Full path of the resulting python.exe binary -->
97    <PythonExe Condition="'$(PythonExe)' == ''">$(BuildPath)python$(PyDebugExt).exe</PythonExe>
98
99    <!-- Include Tkinter by default -->
100    <IncludeTkinter Condition="'$(IncludeTkinter)' == ''">true</IncludeTkinter>
101  </PropertyGroup>
102
103  <PropertyGroup Condition="'$(Platform)'=='ARM'" Label="ArmConfiguration">
104    <WindowsSDKDesktopARMSupport>true</WindowsSDKDesktopARMSupport>
105  </PropertyGroup>
106
107  <PropertyGroup Condition="'$(Platform)'=='ARM64'" Label="Arm64Configuration">
108    <WindowsSDKDesktopARMSupport>true</WindowsSDKDesktopARMSupport>
109  </PropertyGroup>
110
111  <PropertyGroup Condition="$(DefaultWindowsSDKVersion) == ''">
112    <!--
113    Attempt to select the latest installed WinSDK. If we don't find any, then we will
114    let the MSBuild targets determine which one it wants to use (typically the earliest
115    possible version). Since we limit WINVER to Windows 7 anyway, it doesn't really
116    matter which WinSDK version we use.
117    -->
118    <_RegistryVersion>$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0@ProductVersion)</_RegistryVersion>
119    <_RegistryVersion Condition="$(_RegistryVersion) == ''">$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft SDKs\Windows\v10.0@ProductVersion)</_RegistryVersion>
120    <!-- Sometimes the version in the registry has to .0 suffix, and sometimes it doesn't. Check and add it -->
121    <_RegistryVersion Condition="$(_RegistryVersion) != '' and !$(_RegistryVersion.EndsWith('.0'))">$(_RegistryVersion).0</_RegistryVersion>
122
123    <!-- The minimum allowed SDK version to use for building -->
124    <DefaultWindowsSDKVersion>10.0.10586.0</DefaultWindowsSDKVersion>
125    <DefaultWindowsSDKVersion Condition="$(_RegistryVersion) != '' and $([System.Version]::Parse($(_RegistryVersion))) > $([System.Version]::Parse($(DefaultWindowsSDKVersion)))">$(_RegistryVersion)</DefaultWindowsSDKVersion>
126  </PropertyGroup>
127
128  <Target Name="_CheckWindowsSDKFound" BeforeTargets="_CheckWindowsSDKInstalled" Condition="$(_RegistryVersion) == ''">
129    <PropertyGroup>
130      <_Message>Failed to locate a Windows SDK installation.</_Message>
131      <_Message>$(_Message) If the build fails, please use the Visual Studio Installer to install the Windows SDK.</_Message>
132      <_Message>$(_Message) (Ignore the version number specified in the error message and select the latest.)</_Message>
133    </PropertyGroup>
134    <Warning Text="$(_Message)" />
135  </Target>
136
137  <PropertyGroup Condition="$(WindowsTargetPlatformVersion) == ''">
138    <WindowsTargetPlatformVersion>$(DefaultWindowsSDKVersion)</WindowsTargetPlatformVersion>
139  </PropertyGroup>
140
141  <PropertyGroup Condition="'$(OverrideVersion)' == ''">
142    <!--
143    Read version information from Include\patchlevel.h. The following properties are set:
144
145        MajorVersionNumber  -   the '3' in '3.5.2a1'
146        MinorVersionNumber  -   the '5' in '3.5.2a1'
147        MicroVersionNumber  -   the '2' in '3.5.2a1'
148        ReleaseSerial       -   the '1' in '3.5.2a1'
149        ReleaseLevelName    -   the 'a1' in '3.5.2a1'
150        PythonVersionNumber -   '3.5.2' for '3.5.2a1'
151        PythonVersion       -   '3.5.2a1'
152        PythonVersionHex    -   0x030502a1 for '3.5.2a1'
153        ReleaseLevelNumber  -   10 for alpha, 11 for beta, 12 for RC (gamma), and 15 for final
154        Field3Value         -   2101 for '3.5.2a1' (== 1000*2 + 10*10 ('a') + 1)
155    -->
156    <_PatchLevelContent>$([System.IO.File]::ReadAllText(`$(PySourcePath)Include\patchlevel.h`))</_PatchLevelContent>
157    <MajorVersionNumber>$([System.Text.RegularExpressions.Regex]::Match($(_PatchLevelContent), `define\s+PY_MAJOR_VERSION\s+(\d+)`).Groups[1].Value)</MajorVersionNumber>
158    <MinorVersionNumber>$([System.Text.RegularExpressions.Regex]::Match($(_PatchLevelContent), `define\s+PY_MINOR_VERSION\s+(\d+)`).Groups[1].Value)</MinorVersionNumber>
159    <MicroVersionNumber>$([System.Text.RegularExpressions.Regex]::Match($(_PatchLevelContent), `define\s+PY_MICRO_VERSION\s+(\d+)`).Groups[1].Value)</MicroVersionNumber>
160    <_ReleaseLevel>$([System.Text.RegularExpressions.Regex]::Match($(_PatchLevelContent), `define\s+PY_RELEASE_LEVEL\s+PY_RELEASE_LEVEL_(\w+)`).Groups[1].Value)</_ReleaseLevel>
161    <ReleaseSerial>$([System.Text.RegularExpressions.Regex]::Match($(_PatchLevelContent), `define\s+PY_RELEASE_SERIAL\s+(\d+)`).Groups[1].Value)</ReleaseSerial>
162    <ReleaseLevelNumber>15</ReleaseLevelNumber>
163    <ReleaseLevelNumber Condition="$(_ReleaseLevel) == 'ALPHA'">10</ReleaseLevelNumber>
164    <ReleaseLevelNumber Condition="$(_ReleaseLevel) == 'BETA'">11</ReleaseLevelNumber>
165    <ReleaseLevelNumber Condition="$(_ReleaseLevel) == 'GAMMA'">12</ReleaseLevelNumber>
166    <ReleaseLevelName Condition="$(_ReleaseLevel) == 'ALPHA'">a$(ReleaseSerial)</ReleaseLevelName>
167    <ReleaseLevelName Condition="$(_ReleaseLevel) == 'BETA'">b$(ReleaseSerial)</ReleaseLevelName>
168    <ReleaseLevelName Condition="$(_ReleaseLevel) == 'GAMMA'">rc$(ReleaseSerial)</ReleaseLevelName>
169  </PropertyGroup>
170
171  <PropertyGroup Condition="'$(OverrideVersion)' != ''">
172    <!--
173    Override the version number when building by specifying OverrideVersion.
174    For example:
175
176        PCbuild\build.bat "/p:OverrideVersion=3.5.2a1"
177
178    Use the -V option to check your version is valid:
179
180        PCbuild\build.bat -V "/p:OverrideVersion=3.5.2a1"
181          PythonVersionNumber: 3.5.2
182          PythonVersion:       3.5.2a1
183          PythonVersionHex:    0x030502A1
184          Field3Value:         2101
185
186    Note that this only affects the version numbers embedded in resources and
187    installers, but not sys.version.
188    -->
189    <MajorVersionNumber>$([System.Text.RegularExpressions.Regex]::Match($(OverrideVersion), `(\d+)\.(\d+)\.(\d+)((a|b|rc)(\d))?`).Groups[1].Value)</MajorVersionNumber>
190    <MinorVersionNumber>$([System.Text.RegularExpressions.Regex]::Match($(OverrideVersion), `(\d+)\.(\d+)\.(\d+)((a|b|rc)(\d))?`).Groups[2].Value)</MinorVersionNumber>
191    <MicroVersionNumber>$([System.Text.RegularExpressions.Regex]::Match($(OverrideVersion), `(\d+)\.(\d+)\.(\d+)((a|b|rc)(\d))?`).Groups[3].Value)</MicroVersionNumber>
192    <ReleaseLevelName>$([System.Text.RegularExpressions.Regex]::Match($(OverrideVersion), `(\d+)\.(\d+)\.(\d+)((a|b|rc)(\d))?`).Groups[4].Value)</ReleaseLevelName>
193    <_ReleaseLevel>$([System.Text.RegularExpressions.Regex]::Match($(OverrideVersion), `(\d+)\.(\d+)\.(\d+)((a|b|rc)(\d))?`).Groups[5].Value)</_ReleaseLevel>
194    <ReleaseSerial>$([System.Text.RegularExpressions.Regex]::Match($(OverrideVersion), `(\d+)\.(\d+)\.(\d+)((a|b|rc)(\d))?`).Groups[6].Value)</ReleaseSerial>
195    <ReleaseSerial Condition="'$(ReleaseSerial)' == ''">0</ReleaseSerial>
196    <ReleaseLevelNumber>15</ReleaseLevelNumber>
197    <ReleaseLevelNumber Condition="$(_ReleaseLevel) == 'a'">10</ReleaseLevelNumber>
198    <ReleaseLevelNumber Condition="$(_ReleaseLevel) == 'b'">11</ReleaseLevelNumber>
199    <ReleaseLevelNumber Condition="$(_ReleaseLevel) == 'rc'">12</ReleaseLevelNumber>
200  </PropertyGroup>
201
202  <PropertyGroup>
203    <PythonVersionNumber>$(MajorVersionNumber).$(MinorVersionNumber).$(MicroVersionNumber)</PythonVersionNumber>
204    <PythonVersion>$(MajorVersionNumber).$(MinorVersionNumber).$(MicroVersionNumber)$(ReleaseLevelName)</PythonVersion>
205    <PythonVersionHex>$([msbuild]::BitwiseOr(
206        $([msbuild]::Multiply($(MajorVersionNumber), 16777216)),
207        $([msbuild]::BitwiseOr(
208            $([msbuild]::Multiply($(MinorVersionNumber), 65536)),
209            $([msbuild]::BitwiseOr(
210                $([msbuild]::Multiply($(MicroVersionNumber), 256)),
211                $([msbuild]::BitwiseOr(
212                    $([msbuild]::Multiply($(ReleaseLevelNumber), 16)),
213                    $(ReleaseSerial)
214                ))
215            ))
216        ))
217    ))</PythonVersionHex>
218    <Field3Value>$([msbuild]::Add(
219        $(ReleaseSerial),
220        $([msbuild]::Add(
221            $([msbuild]::Multiply($(ReleaseLevelNumber), 10)),
222            $([msbuild]::Multiply($(MicroVersionNumber), 1000))
223        ))
224    ))</Field3Value>
225    <Field3Value Condition="$(UseTestMarker) == 'true'">$([msbuild]::Add($(Field3Value), 9000))</Field3Value>
226
227    <!-- The name of the resulting pythonXY.dll (without the extension) -->
228    <PyDllName>python$(MajorVersionNumber)$(MinorVersionNumber)$(PyDebugExt)</PyDllName>
229    <!-- The name of the resulting pythonX.dll (without the extension) -->
230    <Py3DllName>python3$(PyDebugExt)</Py3DllName>
231
232    <!-- The version and platform tag to include in .pyd filenames -->
233    <PydTag Condition="$(ArchName) == 'win32'">.cp$(MajorVersionNumber)$(MinorVersionNumber)-win32</PydTag>
234    <PydTag Condition="$(ArchName) == 'arm32'">.cp$(MajorVersionNumber)$(MinorVersionNumber)-win_arm32</PydTag>
235    <PydTag Condition="$(ArchName) == 'arm64'">.cp$(MajorVersionNumber)$(MinorVersionNumber)-win_arm64</PydTag>
236    <PydTag Condition="$(ArchName) == 'amd64'">.cp$(MajorVersionNumber)$(MinorVersionNumber)-win_amd64</PydTag>
237
238    <!-- The version number for sys.winver -->
239    <SysWinVer>$(MajorVersionNumber).$(MinorVersionNumber)$(PyArchExt)$(PyTestExt)</SysWinVer>
240  </PropertyGroup>
241
242  <!-- Displays the calculated version info -->
243  <Target Name="ShowVersionInfo">
244    <Message Importance="high" Text="PythonVersionNumber: $(PythonVersionNumber)" />
245    <Message Importance="high" Text="PythonVersion:       $(PythonVersion)" />
246    <Message Importance="high" Text="PythonVersionHex:    0x$([System.UInt32]::Parse($(PythonVersionHex)).ToString(`X08`))" />
247    <Message Importance="high" Text="PythonVersionUnique: $(MajorVersionNumber).$(MinorVersionNumber).$(Field3Value)" />
248    <Message Importance="high" Text="Field3Value:         $(Field3Value)" />
249    <Message Importance="high" Text="SysWinVer:           $(SysWinVer)" />
250    <Message Importance="high" Text="PyDllName:           $(PyDllName)" />
251    <Message Importance="high" Text="WindowsSdkVersion:   $(TargetPlatformVersion)" />
252  </Target>
253</Project>
254