forked from dotnet/samples
/
MarshalingSampleNative.csproj
94 lines (80 loc) · 4.13 KB
/
MarshalingSampleNative.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
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<NativeBinDir>$(BinRoot)/$(Configuration)</NativeBinDir>
<NativeOutputName>MarshalingSampleNative</NativeOutputName>
<NativePlatform>$([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture)</NativePlatform>
<NativeObjDir>$(MSBuildThisFileDirectory)obj/$(Configuration)/$(NativePlatform)/</NativeObjDir>
</PropertyGroup>
<!-- Properties for MSVCFindCompilerPaths -->
<PropertyGroup Condition="$([MSBuild]::IsOsPlatform('Windows'))">
<MSVCPlatform>$(NativePlatform)</MSVCPlatform>
</PropertyGroup>
<ItemGroup>
<NativeSource Include="MarshalingSampleNative.cpp" />
<Clean Include="$(NativeBinDir)/$(NativeOutputName).*" />
<Clean Include="$(NativeObjDir)/*.*" />
</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>
</ItemGroup>
<ItemGroup>
<PackageReference Include="CompilerPaths"
Version="[1.0.1, )"
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'))">.so</NativeOutputExtension>
<NativeOutputExtension Condition="$([MSBuild]::IsOsPlatform('OSX'))">.dylib</NativeOutputExtension>
<NativeOutputExtension Condition="$([MSBuild]::IsOsPlatform('Windows'))">.dll</NativeOutputExtension>
<NativeOutputFilePath>$(NativeBinDir)/$(NativeOutputName)$(NativeOutputExtension)</NativeOutputFilePath>
<SourceFiles>@(NativeSource-> '"%(RootDir)%(Directory)%(Filename)%(Extension)"', ' ')</SourceFiles>
</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>-Iinc</IncPaths>
<CompilerArgs>-g -shared -fPIC </CompilerArgs>
</PropertyGroup>
<PropertyGroup Condition="$([MSBuild]::IsOsPlatform('Linux'))">
<PreprocessorDefines>-D LINUX</PreprocessorDefines>
<LinkArgs>-ldl -Wl,-rpath,'$ORIGIN',--disable-new-dtags</LinkArgs>
</PropertyGroup>
<PropertyGroup Condition="$([MSBuild]::IsOsPlatform('OSX'))">
<PreprocessorDefines>-D OSX</PreprocessorDefines>
<LinkArgs>-ldl -Wl,-rpath,'@loader_path'</LinkArgs>
</PropertyGroup>
<Exec Command="g++ $(SourceFiles) $(IncPaths) $(PreprocessorDefines) -std=c++11 -o "$(NativeOutputFilePath)" $(CompilerArgs) $(LinkArgs)"
WorkingDirectory="$(NativeObjDir)"
ConsoleToMsBuild="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</IncPaths>
<CompilerArgs>/EHsc /Od /GS /sdl /Zi</CompilerArgs>
<PreprocessorDefines>/D WINDOWS</PreprocessorDefines>
<LibPaths>@(MSVCLibPaths-> '/LIBPATH:"%(RootDir)%(Directory)%(Filename)"', ' ')</LibPaths>
</PropertyGroup>
<Exec Command=""$(MSVCCompilerPath)" $(SourceFiles) $(IncPaths) $(PreprocessorDefines) $(CompilerArgs) /link $(LibPaths) ole32.lib /DLL /out:"$(NativeOutputFilePath)""
WorkingDirectory="$(NativeObjDir)"
ConsoleToMsBuild="true" />
</Target>
</Project>