Skip to content

Commit 73321ec

Browse files
committed
split compile flag into separate Windows + XNA flags (Pathoschild#767)
1 parent fdfb060 commit 73321ec

13 files changed

Lines changed: 61 additions & 40 deletions

File tree

build/common.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<LangVersion>latest</LangVersion>
1111
<AssemblySearchPaths>$(AssemblySearchPaths);{GAC}</AssemblySearchPaths>
12-
<DefineConstants Condition="$(OS) == 'Windows_NT'">$(DefineConstants);SMAPI_FOR_WINDOWS</DefineConstants>
12+
<DefineConstants Condition="$(OS) == 'Windows_NT'">$(DefineConstants);SMAPI_FOR_WINDOWS;SMAPI_FOR_XNA</DefineConstants>
1313
</PropertyGroup>
1414

1515
<!-- if game path is invalid, show one user-friendly error instead of a slew of reference errors -->

docs/technical/smapi.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ SMAPI uses a small number of conditional compilation constants, which you can se
5656

5757
flag | purpose
5858
---- | -------
59-
`SMAPI_FOR_WINDOWS` | Whether SMAPI is being compiled on Windows for players on Windows. Set automatically in `crossplatform.targets`.
59+
`SMAPI_FOR_WINDOWS` | Whether SMAPI is being compiled for Windows; if not set, the code assumes Linux/MacOS. Set automatically in `common.targets`.
60+
`SMAPI_FOR_XNA` | Whether SMAPI is being compiled for XNA Framework; if not set, the code assumes MonoGame. Set automatically in `common.targets` with the same value as `SMAPI_FOR_WINDOWS`.
6061
`HARMONY_2` | Whether to enable experimental Harmony 2.0 support and rewrite existing Harmony 1._x_ mods for compatibility. Note that you need to replace `build/0Harmony.dll` with a Harmony 2.0 build (or switch to a package reference) to use this flag.
6162

6263
## For SMAPI developers

src/SMAPI.ModBuildConfig/build/smapi.targets

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,27 @@
4747
<Reference Include="0Harmony" Condition="'$(EnableHarmony)' == 'true'" HintPath="$(GamePath)\smapi-internal\0Harmony.dll" Private="$(CopyModReferencesToBuildOutput)" />
4848
</ItemGroup>
4949

50-
<!-- Windows -->
50+
<!-- Windows only -->
5151
<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
52-
<Reference Include="Microsoft.Xna.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" Private="$(CopyModReferencesToBuildOutput)" />
53-
<Reference Include="Microsoft.Xna.Framework.Game, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" Private="$(CopyModReferencesToBuildOutput)" />
54-
<Reference Include="Microsoft.Xna.Framework.Graphics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" Private="$(CopyModReferencesToBuildOutput)" />
55-
<Reference Include="Microsoft.Xna.Framework.Xact, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" Private="$(CopyModReferencesToBuildOutput)" />
5652
<Reference Include="Netcode" HintPath="$(GamePath)\Netcode.dll" Private="$(CopyModReferencesToBuildOutput)" />
5753
</ItemGroup>
5854

59-
<!-- Linux/Mac -->
60-
<ItemGroup Condition="'$(OS)' != 'Windows_NT'">
61-
<Reference Include="MonoGame.Framework" HintPath="$(GamePath)\MonoGame.Framework.dll" Private="$(CopyModReferencesToBuildOutput)" />
62-
</ItemGroup>
55+
<!-- Game framework -->
56+
<Choose>
57+
<When Condition="$(DefineConstants.Contains(SMAPI_FOR_XNA))">
58+
<ItemGroup>
59+
<Reference Include="Microsoft.Xna.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" Private="$(CopyModReferencesToBuildOutput)" />
60+
<Reference Include="Microsoft.Xna.Framework.Game, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" Private="$(CopyModReferencesToBuildOutput)" />
61+
<Reference Include="Microsoft.Xna.Framework.Graphics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" Private="$(CopyModReferencesToBuildOutput)" />
62+
<Reference Include="Microsoft.Xna.Framework.Xact, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" Private="$(CopyModReferencesToBuildOutput)" />
63+
</ItemGroup>
64+
</When>
65+
<Otherwise>
66+
<ItemGroup>
67+
<Reference Include="MonoGame.Framework" HintPath="$(GamePath)\MonoGame.Framework.dll" Private="$(CopyModReferencesToBuildOutput)" />
68+
</ItemGroup>
69+
</Otherwise>
70+
</Choose>
6371

6472

6573
<!--*********************************************

src/SMAPI.Mods.ConsoleCommands/SMAPI.Mods.ConsoleCommands.csproj

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
<PlatformTarget>x86</PlatformTarget>
88
</PropertyGroup>
99

10+
<Import Project="..\..\build\common.targets" />
11+
1012
<ItemGroup>
1113
<ProjectReference Include="..\SMAPI\SMAPI.csproj" Private="False" />
1214
</ItemGroup>
@@ -16,19 +18,21 @@
1618
<Reference Include="StardewValley.GameData" HintPath="$(GamePath)\StardewValley.GameData.dll" Private="False" />
1719
</ItemGroup>
1820

21+
<!-- Windows only -->
22+
<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
23+
<Reference Include="Netcode" HintPath="$(GamePath)\Netcode.dll" Private="False" />
24+
</ItemGroup>
25+
26+
<!-- Game framework -->
1927
<Choose>
20-
<!-- Windows -->
21-
<When Condition="$(OS) == 'Windows_NT'">
28+
<When Condition="$(DefineConstants.Contains(SMAPI_FOR_XNA))">
2229
<ItemGroup>
23-
<Reference Include="Netcode" HintPath="$(GamePath)\Netcode.dll" Private="False" />
2430
<Reference Include="Microsoft.Xna.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" Private="False" />
2531
<Reference Include="Microsoft.Xna.Framework.Game, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" Private="False" />
2632
<Reference Include="Microsoft.Xna.Framework.Graphics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" Private="False" />
2733
<Reference Include="Microsoft.Xna.Framework.Xact, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" Private="False" />
2834
</ItemGroup>
2935
</When>
30-
31-
<!-- Linux/Mac -->
3236
<Otherwise>
3337
<ItemGroup>
3438
<Reference Include="MonoGame.Framework" HintPath="$(GamePath)\MonoGame.Framework.dll" Private="False" />
@@ -41,5 +45,4 @@
4145
</ItemGroup>
4246

4347
<Import Project="..\SMAPI.Internal\SMAPI.Internal.projitems" Label="Shared" />
44-
<Import Project="..\..\build\common.targets" />
4548
</Project>

src/SMAPI.Mods.ErrorHandler/Patches/SpriteBatchValidationPatches.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public void Apply(HarmonyInstance harmony)
2727
#endif
2828
{
2929
harmony.Patch(
30-
#if SMAPI_FOR_WINDOWS
30+
#if SMAPI_FOR_XNA
3131
original: AccessTools.Method(typeof(SpriteBatch), "InternalDraw"),
3232
#else
3333
original: AccessTools.Method(typeof(SpriteBatch), "CheckValid", new[] { typeof(Texture2D) }),
@@ -40,7 +40,7 @@ public void Apply(HarmonyInstance harmony)
4040
/*********
4141
** Private methods
4242
*********/
43-
#if SMAPI_FOR_WINDOWS
43+
#if SMAPI_FOR_XNA
4444
/// <summary>The method to call instead of <see cref="SpriteBatch.InternalDraw"/>.</summary>
4545
/// <param name="texture">The texture to validate.</param>
4646
#else

src/SMAPI.Mods.ErrorHandler/SMAPI.Mods.ErrorHandler.csproj

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
<PlatformTarget>x86</PlatformTarget>
88
</PropertyGroup>
99

10+
<Import Project="..\..\build\common.targets" />
11+
1012
<ItemGroup>
1113
<ProjectReference Include="..\SMAPI\SMAPI.csproj" Private="False" />
1214
<Reference Include="..\..\build\0Harmony.dll" Private="False" />
@@ -16,19 +18,21 @@
1618
<Reference Include="$(GameExecutableName)" HintPath="$(GamePath)\$(GameExecutableName).exe" Private="False" />
1719
</ItemGroup>
1820

21+
<!-- Windows only -->
22+
<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
23+
<Reference Include="Netcode" HintPath="$(GamePath)\Netcode.dll" Private="False" />
24+
</ItemGroup>
25+
26+
<!-- Game framework -->
1927
<Choose>
20-
<!-- Windows -->
21-
<When Condition="$(OS) == 'Windows_NT'">
28+
<When Condition="$(DefineConstants.Contains(SMAPI_FOR_XNA))">
2229
<ItemGroup>
23-
<Reference Include="Netcode" HintPath="$(GamePath)\Netcode.dll" Private="False" />
2430
<Reference Include="Microsoft.Xna.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" Private="False" />
2531
<Reference Include="Microsoft.Xna.Framework.Game, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" Private="False" />
2632
<Reference Include="Microsoft.Xna.Framework.Graphics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" Private="False" />
2733
<Reference Include="Microsoft.Xna.Framework.Xact, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" Private="False" />
2834
</ItemGroup>
2935
</When>
30-
31-
<!-- Linux/Mac -->
3236
<Otherwise>
3337
<ItemGroup>
3438
<Reference Include="MonoGame.Framework" HintPath="$(GamePath)\MonoGame.Framework.dll" Private="False" />
@@ -42,5 +46,4 @@
4246
</ItemGroup>
4347

4448
<Import Project="..\SMAPI.Internal\SMAPI.Internal.projitems" Label="Shared" />
45-
<Import Project="..\..\build\common.targets" />
4649
</Project>

src/SMAPI.Mods.SaveBackup/SMAPI.Mods.SaveBackup.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
<PlatformTarget>x86</PlatformTarget>
88
</PropertyGroup>
99

10+
<Import Project="..\..\build\common.targets" />
11+
1012
<ItemGroup>
1113
<ProjectReference Include="..\SMAPI\SMAPI.csproj" Private="False" />
1214
</ItemGroup>
@@ -20,5 +22,4 @@
2022
</ItemGroup>
2123

2224
<Import Project="..\SMAPI.Internal\SMAPI.Internal.projitems" Label="Shared" />
23-
<Import Project="..\..\build\common.targets" />
2425
</Project>

src/SMAPI.Tests/SMAPI.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
<PlatformTarget>x86</PlatformTarget>
99
</PropertyGroup>
1010

11+
<Import Project="..\..\build\common.targets" />
12+
1113
<ItemGroup>
1214
<ProjectReference Include="..\SMAPI.Toolkit.CoreInterfaces\SMAPI.Toolkit.CoreInterfaces.csproj" />
1315
<ProjectReference Include="..\SMAPI.Toolkit\SMAPI.Toolkit.csproj" />
@@ -30,6 +32,4 @@
3032
<ItemGroup>
3133
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
3234
</ItemGroup>
33-
34-
<Import Project="..\..\build\common.targets" />
3535
</Project>

src/SMAPI.Toolkit/SMAPI.Toolkit.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
<PlatformTarget Condition="'$(TargetFramework)' == 'net4.5'">x86</PlatformTarget>
88
</PropertyGroup>
99

10+
<Import Project="..\..\build\common.targets" />
11+
1012
<ItemGroup>
1113
<PackageReference Include="HtmlAgilityPack" Version="1.11.28" />
1214
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />

src/SMAPI.Web/SMAPI.Web.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
<LangVersion>latest</LangVersion>
77
</PropertyGroup>
88

9+
<Import Project="..\..\build\common.targets" />
10+
911
<ItemGroup>
1012
<Content Remove="aws-beanstalk-tools-defaults.json" />
1113
</ItemGroup>
@@ -44,6 +46,4 @@
4446
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
4547
</Content>
4648
</ItemGroup>
47-
48-
<Import Project="..\..\build\common.targets" />
4949
</Project>

0 commit comments

Comments
 (0)