[Tizen] separate PIC and PIE to fix x86_64 build error
[platform/upstream/dotnet/runtime.git] / Directory.Build.targets
1 <Project InitialTargets="ValidateTargetOSLowercase">
2   <PropertyGroup>
3     <!--
4     For non-SDK projects that import this file and then import Microsoft.Common.targets,
5     tell Microsoft.Common.targets not to import Directory.Build.targets again
6     -->
7     <ImportDirectoryBuildTargets>false</ImportDirectoryBuildTargets>
8   </PropertyGroup>
9
10   <Import Project="$(RepositoryEngineeringDir)Analyzers.targets" />
11   <Import Project="Sdk.targets" Sdk="Microsoft.DotNet.Arcade.Sdk" />
12   <Import Project="$(RepositoryEngineeringDir)liveBuilds.targets" />
13   <Import Project="$(RepositoryEngineeringDir)generators.targets" />
14   <Import Project="$(RepositoryEngineeringDir)python.targets" />
15   <Import Project="$(RepositoryEngineeringDir)generatorProjects.targets" Condition="'$(IsGeneratorProject)' == 'true'" />
16   <Import Project="$(RepositoryEngineeringDir)resolveContract.targets" Condition="'$(IsSourceProject)' == 'true'" />
17   <Import Project="$(RepositoryEngineeringDir)packaging.targets" Condition="'$(IsPackable)' == 'true' and '$(MSBuildProjectExtension)' != '.pkgproj'" />
18
19   <!--
20   When .NET gets built from source, make the SDK aware there are bootstrap packages
21   for Microsoft.NETCore.App.Runtime.<rid> and Microsoft.NETCore.App.Crossgen2.<rid>.
22   -->
23   <ItemGroup Condition="'$(DotNetBuildFromSource)' == 'true'">
24     <KnownFrameworkReference Update="@(KnownFrameworkReference->WithMetadataValue('Identity', 'Microsoft.NETCore.App')->WithMetadataValue('TargetFramework', '$(NetCoreAppCurrent)'))">
25       <RuntimePackRuntimeIdentifiers>$(PackageRID)</RuntimePackRuntimeIdentifiers>
26     </KnownFrameworkReference>
27     <KnownCrossgen2Pack Update="@(KnownCrossgen2Pack->WithMetadataValue('Identity', 'Microsoft.NETCore.App.Crossgen2')->WithMetadataValue('TargetFramework', '$(NetCoreAppCurrent)'))">
28       <Crossgen2RuntimeIdentifiers>$(PackageRID)</Crossgen2RuntimeIdentifiers>
29     </KnownCrossgen2Pack>
30     <!-- Avoid references to Microsoft.AspNetCore.App.Runtime.<rid> -->
31     <KnownFrameworkReference Remove="Microsoft.AspNetCore.App" />
32   </ItemGroup>
33
34   <PropertyGroup>
35     <!--
36       Define this here (not just in Versions.props) because the SDK resets it
37       unconditionally in Microsoft.NETCoreSdk.BundledVersions.props.
38     -->
39     <NETCoreAppMaximumVersion>$(MajorVersion).$(MinorVersion)</NETCoreAppMaximumVersion>
40     <!-- SDK sets product to assembly but we want it to be our product name -->
41     <Product>Microsoft%AE .NET</Product>
42     <!-- Use the .NET product branding version for informational version description -->
43     <InformationalVersion Condition="'$(InformationalVersion)' == '' and '$(VersionSuffix)' == ''">$(ProductVersion)</InformationalVersion>
44     <InformationalVersion Condition="'$(InformationalVersion)' == '' and '$(PreReleaseVersionLabel)' == 'servicing'">$(ProductVersion)</InformationalVersion>
45     <InformationalVersion Condition="'$(InformationalVersion)' == '' and '$(VersionSuffix)' != ''">$(ProductVersion)-$(VersionSuffix)</InformationalVersion>
46   </PropertyGroup>
47
48   <ItemGroup>
49     <SupportedNETCoreAppTargetFramework Include=".NETCoreApp,Version=v$(NETCoreAppMaximumVersion)" DisplayName=".NET $(NETCoreAppMaximumVersion)" Alias="net$(NETCoreAppMaximumVersion)" />
50   </ItemGroup>
51
52   <!-- The Default behavior in VS is to show files for the first target framework in TargetFrameworks property.
53        This is required to show all the files corresponding to all target frameworks in VS. -->
54   <ItemGroup Condition="'$(DefaultLanguageSourceExtension)' != '' and
55                         ('$(BuildingInsideVisualStudio)' == 'true' or '$(DesignTimeBuild)' == 'true')">
56     <None Include="$(MSBuildProjectDirectory)\**\*$(DefaultLanguageSourceExtension)"
57           Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder);@(Compile)" />
58   </ItemGroup>
59
60   <!-- Packaging -->
61   <ItemGroup Condition="'$(IsPackable)' == 'true'">
62     <!-- The sfxproj files add the license themselves. -->
63     <None Include="$(LicenseFile)"
64           PackagePath="$([System.IO.Path]::GetFileName('$(LicenseFile)'))"
65           Pack="true"
66           Condition="'$(MSBuildProjectExtension)' != '.sfxproj' and '$(MSBuildProjectFile)' != 'msi.csproj'" />
67     <None Include="$(PackageThirdPartyNoticesFile)"
68           PackagePath="$([System.IO.Path]::GetFileName('$(PackageThirdPartyNoticesFile)'))"
69           Pack="true" />
70   </ItemGroup>
71
72   <PropertyGroup>
73     <PackageDescription Condition="'$(PackageDescription)' == '' and '$(Description)' != ''">$(Description)</PackageDescription>
74     <RuntimePackageDisclaimer>Internal implementation package not meant for direct consumption. Please do not reference directly.</RuntimePackageDisclaimer>
75     <UseRuntimePackageDisclaimer Condition="'$(UseRuntimePackageDisclaimer)' == '' and
76                                             ($(MSBuildProjectName.StartsWith('runtime.native')) or '$(PackageTargetRuntime)' != '')">true</UseRuntimePackageDisclaimer>
77     <PackageDescription Condition="'$(PackageDescription)' != '' and '$(UseRuntimePackageDisclaimer)' == 'true'">$(RuntimePackageDisclaimer) %0A$(PackageDescription)</PackageDescription>
78     <PackageDescription Condition="'$(PackageDescription)' == '' and '$(UseRuntimePackageDisclaimer)' == 'true'">$(RuntimePackageDisclaimer)</PackageDescription>
79     <!-- Keep in sync as required by the Packaging SDK in Arcade. -->
80     <Description>$(PackageDescription)</Description>
81   </PropertyGroup>
82
83   <Target Name="ValidateTargetOSLowercase"
84           Condition="!$(TargetOS.Equals($(TargetOS.ToLower()), StringComparison.InvariantCulture))">
85     <Error Text="The passed-in TargetOS property value '$(TargetOS)' must be lowercase." />
86   </Target>
87
88   <ItemDefinitionGroup>
89     <TargetPathWithTargetPlatformMoniker>
90       <IsReferenceAssemblyProject>$(IsReferenceAssemblyProject)</IsReferenceAssemblyProject>
91     </TargetPathWithTargetPlatformMoniker>
92   </ItemDefinitionGroup>
93
94   <Target Name="ValidateReferenceAssemblyProjectReferencesAndTargetFramework"
95           AfterTargets="ResolveReferences"
96           Condition="'$(IsReferenceAssemblyProject)' == 'true' and
97                      '$(SkipValidateReferenceAssemblyProjectReferences)' != 'true'">
98     <Error Text="Reference assemblies must only reference other reference assemblies and '%(ReferencePath.ProjectReferenceOriginalItemSpec)' is not a reference assembly project and does not set 'ProduceReferenceAssembly'."
99            Condition="'%(ReferencePath.ReferenceSourceTarget)' == 'ProjectReference' and '%(ReferencePath.IsReferenceAssemblyProject)' != 'true' and '%(ReferencePath.ReferenceAssembly)' == ''" />
100     <Error Text="Reference assemblies must be TargetPlatform agnostic. $(MSBuildProjectName) incorrectly targets $(TargetFramework), platform: $(TargetPlatformIdentifier)."
101            Condition="'$(TargetPlatformIdentifier)' != ''" />
102   </Target>
103
104   <!-- For experimental ref assemblies (which typically have the same name as a regular ref
105        assembly), bump their minor file version by 100 to make it distinguishable from the regular
106        ref assembly. -->
107   <Target Name="UpdateExperimentalRefAssemblyFileVersion"
108           AfterTargets="_InitializeAssemblyVersion"
109                 Condition="'$(IsReferenceAssemblyProject)' == 'true' and '$(IsExperimentalRefAssembly)' == 'true'">
110     <PropertyGroup>
111       <_FileVersionMaj>$(FileVersion.Split('.')[0])</_FileVersionMaj>
112       <_FileVersionMin>$(FileVersion.Split('.')[1])</_FileVersionMin>
113       <_FileVersionBld>$(FileVersion.Split('.')[2])</_FileVersionBld>
114       <_FileVersionRev>$(FileVersion.Split('.')[3])</_FileVersionRev>
115       <FileVersion>$(_FileVersionMaj).$([MSBuild]::Add($(_FileVersionMin), 100)).$(_FileVersionBld).$(_FileVersionRev)</FileVersion>
116     </PropertyGroup>
117   </Target>
118
119   <!-- Allows building against source assemblies when the 'SkipUseReferenceAssembly' attribute is present on ProjectReference items. -->
120   <Target Name="HandleReferenceAssemblyAttributeForProjectReferences"
121           AfterTargets="ResolveProjectReferences"
122           BeforeTargets="FindReferenceAssembliesForReferences"
123           Condition="'@(ProjectReference)' != '' and '@(_ResolvedProjectReferencePaths)' != ''">
124     <!-- If we have a ProjectReference to CoreLib, we need to compile against implementation assemblies, 
125          and ignore architecture mismatches in those implementation assemblies. -->
126     <PropertyGroup Condition="@(_ResolvedProjectReferencePaths->AnyHaveMetadataValue('MSBuildSourceProjectFile', '$(CoreLibProject)'))">
127       <CompileUsingReferenceAssemblies Condition="'$(CompileUsingReferenceAssemblies)' == ''">false</CompileUsingReferenceAssemblies>
128       <ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
129     </PropertyGroup>
130
131     <!-- Clear the ReferenceAssembly attribute on resolved P2Ps that set SkipUseReferenceAssembly to true. -->
132     <ItemGroup>
133       <_ResolvedProjectReferencePaths Condition="'%(_ResolvedProjectReferencePaths.SkipUseReferenceAssembly)' == 'true'"
134                                       ReferenceAssembly="" />
135     </ItemGroup>
136   </Target>
137
138   <!-- Filter out transitive P2Ps which should be excluded. -->
139   <Target Name="FilterTransitiveProjectReferences"
140           AfterTargets="IncludeTransitiveProjectReferences"
141           Condition="'$(DisableTransitiveProjectReferences)' != 'true' and
142                      '@(DefaultReferenceExclusion)' != ''">
143     <ItemGroup>
144       <_transitiveProjectReferenceWithProjectName Include="@(ProjectReference->Metadata('NuGetPackageId'))"
145                                                   OriginalIdentity="%(Identity)" />
146       <_transitiveIncludedProjectReferenceWithProjectName Include="@(_transitiveProjectReferenceWithProjectName)"
147                                                           Exclude="@(DefaultReferenceExclusion)" />
148       <_transitiveExcludedProjectReferenceWithProjectName Include="@(_transitiveProjectReferenceWithProjectName)"
149                                                           Exclude="@(_transitiveIncludedProjectReferenceWithProjectName)" />
150       <ProjectReference Remove="@(_transitiveExcludedProjectReferenceWithProjectName->Metadata('OriginalIdentity'))" />
151     </ItemGroup>
152   </Target>
153
154   <!-- Filter out conflicting implicit assembly references. -->
155   <Target Name="FilterImplicitAssemblyReferences"
156           Condition="'$(DisableImplicitFrameworkReferences)' != 'true'"
157           DependsOnTargets="ResolveProjectReferences"
158           AfterTargets="ResolveTargetingPackAssets">
159     <ItemGroup>
160       <_targetingPackReferenceExclusion Include="$(TargetName)" />
161       <_targetingPackReferenceExclusion Include="@(_ResolvedProjectReferencePaths->Metadata('Filename'))" />
162       <_targetingPackReferenceExclusion Include="@(DefaultReferenceExclusion)" />
163     </ItemGroup>
164
165     <!-- Filter out shims from the targeting pack references as an opt-in. -->
166     <ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and
167                           '$(SkipTargetingPackShimReferences)' == 'true'">
168       <_targetingPackReferenceExclusion Include="@(NetFxReference)" />
169       <_targetingPackReferenceExclusion Include="netstandard" />
170     </ItemGroup>
171
172     <ItemGroup>
173       <_targetingPackReferenceWithProjectName Include="@(Reference->WithMetadataValue('ExternallyResolved', 'true')->Metadata('Filename'))"
174                                               OriginalIdentity="%(Identity)" />
175       <_targetingPackIncludedReferenceWithProjectName Include="@(_targetingPackReferenceWithProjectName)"
176                                                       Exclude="@(_targetingPackReferenceExclusion)" />
177       <_targetingPackExcludedReferenceWithProjectName Include="@(_targetingPackReferenceWithProjectName)"
178                                                       Exclude="@(_targetingPackIncludedReferenceWithProjectName)" />
179       <Reference Remove="@(_targetingPackExcludedReferenceWithProjectName->Metadata('OriginalIdentity'))" />
180     </ItemGroup>
181
182     <ItemGroup>
183       <_targetingPackAnalyzerReferenceWithProjectName Include="@(Analyzer->WithMetadataValue('ExternallyResolved', 'true')->Metadata('Filename'))"
184                                                       OriginalIdentity="%(Identity)" />
185       <_targetingPackIncludedAnalyzerReferenceWithProjectName Include="@(_targetingPackAnalyzerReferenceWithProjectName)"
186                                                               Exclude="@(_targetingPackReferenceExclusion)" />
187       <_targetingPackExcludedAnalyzerReferenceWithProjectName Include="@(_targetingPackAnalyzerReferenceWithProjectName)"
188                                                               Exclude="@(_targetingPackIncludedAnalyzerReferenceWithProjectName)" />
189       <Analyzer Remove="@(_targetingPackExcludedAnalyzerReferenceWithProjectName->Metadata('OriginalIdentity'))" />
190     </ItemGroup>
191   </Target>
192
193   <!--
194     Arcade SDK versioning is defined by static properties in a targets file: work around this by
195     moving properties based on versioning into a target.
196   -->
197   <Target Name="GetProductVersions">
198     <PropertyGroup>
199       <IncludePreReleaseLabelInPackageVersion Condition="'$(DotNetFinalVersionKind)' != 'release'">true</IncludePreReleaseLabelInPackageVersion>
200       <IncludePreReleaseLabelInPackageVersion Condition="'$(SuppressFinalPackageVersion)' == 'true'">true</IncludePreReleaseLabelInPackageVersion>
201       <IncludePreReleaseLabelInPackageVersion Condition="'$(IsShipping)' != 'true'">true</IncludePreReleaseLabelInPackageVersion>
202
203       <IncludeBuildNumberInPackageVersion Condition="'$(StabilizePackageVersion)' != 'true'">true</IncludeBuildNumberInPackageVersion>
204       <IncludeBuildNumberInPackageVersion Condition="'$(SuppressFinalPackageVersion)' == 'true'">true</IncludeBuildNumberInPackageVersion>
205       <IncludeBuildNumberInPackageVersion Condition="'$(IsShipping)' != 'true'">true</IncludeBuildNumberInPackageVersion>
206
207       <ProductVersionSuffix Condition="'$(IncludePreReleaseLabelInPackageVersion)' == 'true'">-$(VersionSuffix)</ProductVersionSuffix>
208       <ProductBandVersion Condition="'$(ProductBandVersion)' == ''">$(MajorVersion).$(MinorVersion)</ProductBandVersion>
209       <ProductionVersion Condition="'$(ProductionVersion)' == ''">$(ProductBandVersion).$(PatchVersion)</ProductionVersion>
210       <ProductVersion>$(ProductionVersion)$(ProductVersionSuffix)</ProductVersion>
211
212       <SharedFrameworkNugetVersion>$(ProductVersion)</SharedFrameworkNugetVersion>
213       <NuGetVersion>$(SharedFrameworkNugetVersion)</NuGetVersion>
214       <InstallersRelativePath>Runtime/$(SharedFrameworkNugetVersion)/</InstallersRelativePath>
215
216       <!--
217         By default, we are always building the nuget packages for HostPolicy, HostFXR and
218         Dotnet/AppHost. Thus, the properties (below) are always set to $(ProductVersion).
219         However, there are scenarios when only some of these components will change (e.g. during
220         servicing, we may only change HostPolicy but not HostFXR and Dotnet/AppHost). In such cases,
221         pass the appropriate version value(s) as argument to the build command in order to override;
222         e.g. 'build -p:HostPolicyVersion=x.y.z ...'
223       -->
224       <HostVersion Condition="'$(HostVersion)' == ''">$(ProductVersion)</HostVersion>
225       <AppHostVersion Condition="'$(AppHostVersion)' == ''">$(ProductVersion)</AppHostVersion>
226       <HostResolverVersion Condition="'$(HostResolverVersion)' == ''">$(ProductVersion)</HostResolverVersion>
227       <HostPolicyVersion Condition="'$(HostPolicyVersion)' == ''">$(ProductVersion)</HostPolicyVersion>
228     </PropertyGroup>
229   </Target>
230 </Project>