Skip to content

Commit 15d35e3

Browse files
authored
MSBuild platform guessing in a shareable props file (microsoft#299)
1 parent 692ba00 commit 15d35e3

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

Include/httpClient/config.h

+4
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,7 @@
7474

7575
#define HC_PLATFORM_IS_MICROSOFT \
7676
(HC_PLATFORM == HC_PLATFORM_WIN32 || HC_PLATFORM == HC_PLATFORM_UWP || HC_PLATFORM == HC_PLATFORM_XDK)
77+
78+
#if defined(HC_PLATFORM_MSBUILD_GUESS) && (HC_PLATFORM_MSBUILD_GUESS != HC_PLATFORM)
79+
#error The platform guessed by MSBuild does not agree with the platform selected by config.h
80+
#endif

Include/httpClient/pal.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include <httpClient/config.h>
1313

14-
#if HC_PLATFORM == HC_PLATFORM_WIN32 || HC_PLATFORM == HC_PLATFORM_UWP || HC_PLATFORM == HC_PLATFORM_XDK
14+
#if HC_PLATFORM_IS_MICROSOFT
1515

1616
#ifndef WIN32_LEAN_AND_MEAN
1717
#define WIN32_LEAN_AND_MEAN

libHttpClient.props

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
-->
66
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
77

8+
<Import Project="$(MSBuildThisFileDirectory)platform_select.props" />
9+
<PropertyGroup>
10+
<HCLibPlatformType>$(HCPlatform)</HCLibPlatformType>
11+
</PropertyGroup>
12+
813
<!-- Valid values for HCLibPlatformType:
914
Android
1015
UWP
@@ -17,8 +22,8 @@
1722
<HCLibPlatformType Condition="'$(ApplicationType)'=='' AND '$(Platform)'!='Durango'">Win32</HCLibPlatformType>
1823
<HCLibPlatformType Condition="'$(ApplicationType)'=='' AND '$(Platform)'=='Durango'">XDK</HCLibPlatformType>
1924
<HCLibPlatformType Condition="'$(ApplicationType)'=='Android'">Android</HCLibPlatformType>
20-
</PropertyGroup>
21-
25+
</PropertyGroup>
26+
2227
<PropertyGroup>
2328
<useWsppWebsockets>false</useWsppWebsockets>
2429
<useWsppWebsockets Condition="'$(HCLibPlatformType)'=='Android'">true</useWsppWebsockets>

platform_select.props

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<!--If the HCPlatform is not set, infer it-->
4+
<Choose>
5+
<When Condition="'$(HCPlatform)'!=''">
6+
</When>
7+
<When Condition="'$(ApplicationType)'=='Android'">
8+
<PropertyGroup>
9+
<HCPlatform>Android</HCPlatform>
10+
</PropertyGroup>
11+
</When>
12+
<When Condition="'$(ApplicationType)'=='Windows Store'">
13+
<PropertyGroup>
14+
<HCPlatform>UWP</HCPlatform>
15+
</PropertyGroup>
16+
</When>
17+
<When Condition="'$(Platform)'=='Durango'">
18+
<PropertyGroup>
19+
<HCPlatform>XDK</HCPlatform>
20+
</PropertyGroup>
21+
</When>
22+
<Otherwise>
23+
<PropertyGroup>
24+
<HCPlatform>Win32</HCPlatform>
25+
</PropertyGroup>
26+
</Otherwise>
27+
</Choose>
28+
29+
<ItemDefinitionGroup>
30+
<ClCompile>
31+
<PreprocessorDefinitions Condition="'$(HCPlatform)'=='Android'">%(PreprocessorDefinitions);HC_PLATFORM_MSBUILD_GUESS=HC_PLATFORM_ANDROID</PreprocessorDefinitions>
32+
<PreprocessorDefinitions Condition="'$(HCPlatform)'=='UWP'">%(PreprocessorDefinitions);HC_PLATFORM_MSBUILD_GUESS=HC_PLATFORM_UWP</PreprocessorDefinitions>
33+
<PreprocessorDefinitions Condition="'$(HCPlatform)'=='XDK'">%(PreprocessorDefinitions);HC_PLATFORM_MSBUILD_GUESS=HC_PLATFORM_XDK</PreprocessorDefinitions>
34+
<PreprocessorDefinitions Condition="'$(HCPlatform)'=='Win32'">%(PreprocessorDefinitions);HC_PLATFORM_MSBUILD_GUESS=HC_PLATFORM_WIN32</PreprocessorDefinitions>
35+
</ClCompile>
36+
</ItemDefinitionGroup>
37+
</Project>

0 commit comments

Comments
 (0)