<Project Sdk="Microsoft.NET.Sdk">
	<PropertyGroup>
		<AssemblyName>Kyoo.Core</AssemblyName>
		<RootNamespace>Kyoo.Core</RootNamespace>
		<TranscoderRoot>../Kyoo.Transcoder/</TranscoderRoot>
	</PropertyGroup>

	<PropertyGroup>
		<TranscoderBinary Condition="$(IsWindows) == true">transcoder.dll</TranscoderBinary>
		<TranscoderBinary Condition="$(IsOSX) == true">libtranscoder.dylib</TranscoderBinary>
		<TranscoderBinary Condition="$(IsLinux) == true">libtranscoder.so</TranscoderBinary>
	</PropertyGroup>

	<ItemGroup>
		<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
		<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.8" />
		<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
	</ItemGroup>

	<ItemGroup>
		<ProjectReference Include="../Kyoo.Abstractions/Kyoo.Abstractions.csproj" />
		<ProjectReference Include="../Kyoo.Database/Kyoo.Database.csproj" />
	</ItemGroup>

	<Target Name="BuildTranscoder" BeforeTargets="BeforeBuild" Condition="'$(SkipTranscoder)' != 'true' And !Exists('$(TranscoderRoot)/build/$(TranscoderBinary)')">
		<Exec WorkingDirectory="$(TranscoderRoot)" Condition="'$(IsWindows)' != 'true'" Command="mkdir -p build %26%26 cd build %26%26 cmake .. %26%26 make -j" ContinueOnError="true">
			<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
		</Exec>
		<Exec WorkingDirectory="$(TranscoderRoot)" Condition="'$(IsWindows)' == 'true'" Command="(if not exist build mkdir build) %26%26 cd build %26%26 cmake .. -G &quot;NMake Makefiles&quot; %26%26 nmake" ContinueOnError="true">
			<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
		</Exec>
		<Error Condition="'$(ErrorCode)' != '0'" Text="An environement capable of building the transcoder was not found. Appropriate tools are not installed, not available in the $PATH or not correctly configured. To fix this you can ether:&#xA; - Fix your tools&#xA; - Skip the transcoder via the '-p:SkipTranscoder=true'&#xA; - Download an already built transcoder and put it in ./Kyoo.Transcoder/build" />
	</Target>

	<ItemGroup Condition="'$(SkipTranscoder)' != 'true'">
		<None Include="$(TranscoderRoot)/build/$(TranscoderBinary)">
			<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
			<Visible>false</Visible>
		</None>
	</ItemGroup>
</Project>
