<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
    <!-- Enable all optional code analyzers -->
    <AnalysisMode>All</AnalysisMode>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <!-- Warnings that are suppressed for the entire assembly.
         Consider suppressing inline before adding to this list -->
    <NoWarn>
      CA5392; <!-- P/Invoke missing DefaultDllImportSearchPathsAttribute (system default is OK) -->
      CA1032; <!-- Standard exception constructors missing (exception are only meant to be thrown by this assembly) -->
      CA1063; <!-- Implement full dispose pattern (derived classes would not own unmanaged resources) -->
      CA1819; <!-- Properties should not return array (this is a data-centric library so arrays are expected) -->
    </NoWarn>
    <AssemblyName>CanteraDotNet</AssemblyName>
    <IsPackable>false</IsPackable>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>

    <RootDir>$([MSBuild]::NormalizePath($(MSBuildProjectDirectory)/../../..))</RootDir>
    <LibDir>$([MSBuild]::NormalizePath($(RootDir)/build/lib))</LibDir>
    <DataDir>$([MSBuild]::NormalizePath($(RootDir)/data))</DataDir>
    <!-- Don’t use BaseIntermediateOutputPath because it may not have been calculated yet -->
    <SourceGenDir>$([MSBuild]::NormalizePath($(MSBuildProjectDirectory)/obj/sourcegen))</SourceGenDir>
  </PropertyGroup>

  <ItemGroup>
    <InternalsVisibleTo Include="Cantera.Tests" />

    <None Include="$(DataDir)/*" CopyToOutputDirectory="PreserveNewest" LinkBase="data/" />

    <SourceGenFiles Include="$(SourceGenDir)/*" />
  </ItemGroup>

  <ItemGroup Condition="$([MSBuild]::IsOsPlatform(Windows))">
    <None Include="$(LibDir)/cantera_shared.dll" CopyToOutputDirectory="PreserveNewest"/>
  </ItemGroup>
  <ItemGroup Condition="$([MSBuild]::IsOsPlatform(OSX))">
    <None Include="$(LibDir)/libcantera_shared.dylib" CopyToOutputDirectory="PreserveNewest"/>
  </ItemGroup>
  <ItemGroup Condition="$([MSBuild]::IsOsPlatform(Linux))">
    <None Include="$(LibDir)/libcantera_shared.so" CopyToOutputDirectory="PreserveNewest"/>
  </ItemGroup>

  <Target Name="GenerateInterop" BeforeTargets="CoreCompile">
    <Exec Command="python3 -m interfaces.sourcegen.src.sourcegen --api=csharp --output=$(SourceGenDir)"
      WorkingDirectory="$(RootDir)"
      Condition="$(GenerateInterop) == 'true' Or !Exists(@(SourceGenFiles))"/>

    <ItemGroup>
      <!-- Recalculate list of SourceGen files to capture what may have just been created -->
      <Compile Include="$(SourceGenDir)/*" />
    </ItemGroup>
  </Target>

  <Target Name="CleanSourceGen" BeforeTargets="CoreClean">
    <Delete Files="@(SourceGenFiles)" />
  </Target>
</Project>
