forked from dotnet/samples
/
NativeHost.csproj
123 lines (104 loc) · 5.59 KB
/
NativeHost.csproj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="$(SourceRoot)/DotNetLib/DotNetLib.csproj" />
</ItemGroup>
<!-- This is to hide all the source files in VS to make the project cleaner,
but also to include them in the build so that when the source is modified the build will rerun the C++ compiler. -->
<ItemGroup>
<Content Include="*.*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</Content>
<Content Include="inc/*.*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</Content>
<Content Include="inc.vs/*.*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</Content>
</ItemGroup>
<PropertyGroup>
<NativeBinDir>$(BinRoot)/$(Configuration)</NativeBinDir>
<NativeOutputName>nativehost</NativeOutputName>
<NativePlatform>$([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture)</NativePlatform>
<NativeObjDir>$(MSBuildThisFileDirectory)obj/$(Configuration)/$(NativePlatform)/</NativeObjDir>
<NativeHostDirectory>$(MSBuildThisFileDirectory)</NativeHostDirectory>
</PropertyGroup>
<!-- Properties for MSVCFindCompilerPaths -->
<PropertyGroup Condition="$([MSBuild]::IsOsPlatform('Windows'))">
<MSVCPlatform>x64</MSVCPlatform>
<MSVCPlatform Condition="$(NETCoreSDKRuntimeIdentifier.Contains('x86'))">x86</MSVCPlatform>
</PropertyGroup>
<ItemGroup>
<NativeSource Include="nativehost.cpp" />
<Clean Include="$(NativeBinDir)/$(NativeOutputName).*" />
<Clean Include="$(NativeObjDir)/*.*" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CompilerPaths"
Version="[1.0.2, )"
Condition="$([MSBuild]::IsOsPlatform('Windows'))" />
</ItemGroup>
<!-- Targets to build the native project. The output goes directly to the bin directory -->
<Target Name="PrepareForNativeBuild">
<PropertyGroup>
<NativeOutputExtension Condition="$([MSBuild]::IsOsPlatform('Linux'))"></NativeOutputExtension>
<NativeOutputExtension Condition="$([MSBuild]::IsOsPlatform('OSX'))"></NativeOutputExtension>
<NativeOutputExtension Condition="$([MSBuild]::IsOsPlatform('Windows'))">.exe</NativeOutputExtension>
<NativeOutputFilePath>$(NativeBinDir)/$(NativeOutputName)$(NativeOutputExtension)</NativeOutputFilePath>
<SourceFiles>@(NativeSource-> '"%(RootDir)%(Directory)%(Filename)%(Extension)"', ' ')</SourceFiles>
<NetHostDir>$(NetCoreTargetingPackRoot)/Microsoft.NETCore.App.Host.$(NETCoreSdkRuntimeIdentifier)/$(BundledNETCoreAppPackageVersion)/runtimes/$(NETCoreSdkRuntimeIdentifier)/native</NetHostDir>
<NetHostName Condition="$([MSBuild]::IsOsPlatform('Windows'))">nethost.dll</NetHostName>
<NetHostName Condition="$([MSBuild]::IsOsPlatform('Linux'))">libnethost.so</NetHostName>
<NetHostName Condition="$([MSBuild]::IsOsPlatform('OSX'))">libnethost.dylib</NetHostName>
</PropertyGroup>
<MakeDir Directories="$(NativeBinDir)" />
<MakeDir Directories="$(NativeObjDir)" />
</Target>
<Target Name="BuildNativeProjectUnix"
AfterTargets="Build"
DependsOnTargets="PrepareForNativeBuild"
Condition="$([MSBuild]::IsOsPlatform('Linux')) OR $([MSBuild]::IsOsPlatform('OSX'))">
<PropertyGroup>
<IncPaths>-I$(NativeHostDirectory)inc -I"$(NetHostDir)"</IncPaths>
<CompilerArgs>-g</CompilerArgs>
</PropertyGroup>
<PropertyGroup Condition="$([MSBuild]::IsOsPlatform('Linux'))">
<PreprocessorDefines>-D LINUX</PreprocessorDefines>
<LinkArgs>-ldl -lnethost -lpthread -L"$(NetHostDir)" -Wl,-rpath,'$ORIGIN',--disable-new-dtags</LinkArgs>
</PropertyGroup>
<PropertyGroup Condition="$([MSBuild]::IsOsPlatform('OSX'))">
<PreprocessorDefines>-D OSX</PreprocessorDefines>
<LinkArgs>-ldl -lnethost -lpthread -L"$(NetHostDir)" -Wl,-rpath,'@loader_path'</LinkArgs>
</PropertyGroup>
<Exec Command="g++ $(SourceFiles) $(IncPaths) $(PreprocessorDefines) -std=c++11 -o "$(NativeOutputFilePath)" $(CompilerArgs) $(LinkArgs)"
WorkingDirectory="$(NativeObjDir)"
ConsoleToMsBuild="true" />
<Copy SourceFiles="$(NetHostDir)/$(NetHostName)"
DestinationFolder="$(NativeBinDir)"
SkipUnchangedFiles="True" />
</Target>
<Target Name="BuildNativeProjectWindows"
AfterTargets="Build"
DependsOnTargets="PrepareForNativeBuild;MSVCFindCompilerPaths"
Condition="$([MSBuild]::IsOsPlatform('Windows'))">
<PropertyGroup>
<IncPaths>@(MSVCIncludePaths-> '/I "%(RootDir)%(Directory)%(Filename)"', ' ')</IncPaths>
<IncPaths>$(IncPaths) /I inc /I "$(NetHostDir)"</IncPaths>
<CompilerArgs>/EHsc /Od /GS /sdl /Zi</CompilerArgs>
<PreprocessorDefines>/D WINDOWS</PreprocessorDefines>
<LibPaths>@(MSVCLibPaths-> '/LIBPATH:"%(RootDir)%(Directory)%(Filename)"', ' ')</LibPaths>
<LibPaths>$(LibPaths) "$(NetHostDir)\nethost.lib"</LibPaths>
</PropertyGroup>
<Exec Command=""$(MSVCCompilerPath)" $(SourceFiles) $(IncPaths) $(PreprocessorDefines) $(CompilerArgs) /link $(LibPaths) /out:"$(NativeOutputFilePath)""
WorkingDirectory="$(NativeObjDir)"
ConsoleToMsBuild="true" />
<Copy SourceFiles="$(NetHostDir)/$(NetHostName)"
DestinationFolder="$(NativeBinDir)"
SkipUnchangedFiles="True" />
</Target>
</Project>