cmake(dotnet): Add UNIVERSAL_DOTNET_PACKAGE option

This commit is contained in:
Corentin Le Molgat
2022-02-28 15:13:14 +01:00
parent 1cce03f851
commit 674a0d6f77
4 changed files with 191 additions and 12 deletions

View File

@@ -221,6 +221,11 @@ message(STATUS "CPLEX support: ${USE_CPLEX}")
option(USE_XPRESS "Use the XPRESS solver" OFF)
message(STATUS "XPRESS support: ${USE_XPRESS}")
if(BUILD_DOTNET)
option(UNIVERSAL_DOTNET_PACKAGE "Build a .Net multi OS Package" OFF)
message(STATUS ".Net: Create multiple os package: ${UNIVERSAL_DOTNET_PACKAGE}")
endif()
if(BUILD_JAVA)
option(BUILD_FAT_JAR "Create single .jar with all dependencies (including native binaries)" OFF)
message(STATUS "Java: Build single fat .jar: ${BUILD_FAT_JAR}")

View File

@@ -213,10 +213,17 @@ add_custom_target(dotnet_native_package
####################
## .Net Package ##
####################
configure_file(
${PROJECT_SOURCE_DIR}/ortools/dotnet/${DOTNET_PROJECT}.csproj.in
${DOTNET_PROJECT_DIR}/${DOTNET_PROJECT}.csproj.in
@ONLY)
if(UNIVERSAL_DOTNET_PACKAGE)
configure_file(
${PROJECT_SOURCE_DIR}/ortools/dotnet/${DOTNET_PROJECT}-full.csproj.in
${DOTNET_PROJECT_DIR}/${DOTNET_PROJECT}.csproj.in
@ONLY)
else()
configure_file(
${PROJECT_SOURCE_DIR}/ortools/dotnet/${DOTNET_PROJECT}-local.csproj.in
${DOTNET_PROJECT_DIR}/${DOTNET_PROJECT}.csproj.in
@ONLY)
endif()
add_custom_command(
OUTPUT ${DOTNET_PROJECT_DIR}/${DOTNET_PROJECT}.csproj

View File

@@ -96,14 +96,14 @@
<RuntimeOsx Include="@DOTNET_PACKAGES_DIR@/@DOTNET_PROJECT@.runtime.osx-x64.*.nupkg"/>
<RuntimeWin Include="@DOTNET_PACKAGES_DIR@/@DOTNET_PROJECT@.runtime.win-x64.*.nupkg"/>
</ItemGroup>
<Message Importance="high" Text="------- $(OS)"/>
<Message Importance="high" Text="Package @DOTNET_PROJECT@.runtime.linux-x64: found" Condition="Exists('@(RuntimeLinux)')"/>
<Message Importance="high" Text="------- $(OS) "/>
<Message Importance="high" Text="Package @DOTNET_PROJECT@.runtime.linux-x64: not found" Condition="!Exists('@(RuntimeLinux)')"/>
<Message Importance="high" Text="Package @DOTNET_PROJECT@.runtime.osx-x64: found" Condition="Exists('@(RuntimeOsx)')"/>
<Message Importance="high" Text="Package @DOTNET_PROJECT@.runtime.osx-x64: not found" Condition="!Exists('@(RuntimeOsx)')"/>
<Message Importance="high" Text="Package @DOTNET_PROJECT@.runtime.win-x64: found" Condition="Exists('@(RuntimeWin)')"/>
<Message Importance="high" Text="Package @DOTNET_PROJECT@.runtime.win-x64: not found" Condition="!Exists('@(RuntimeWin)')"/>
<Error Text="You must locally 'dotnet pack' at least one @DOTNET_PROJECT@.runtime.{rid} Project." Condition="!Exists('@(RuntimeLinux)') AND !Exists('@(RuntimeOsx)') AND !Exists('@(RuntimeWin)')"/>
<Error Text="You must have locally all runtime packages." Condition="!Exists('@(RuntimeLinux)') OR !Exists('@(RuntimeOsx)') OR !Exists('@(RuntimeWin)')"/>
</Target>
<!-- Copy all .proto file(s) -->
@@ -170,12 +170,9 @@
</PropertyGroup>
<ItemGroup>
<RuntimeLinux Include="@DOTNET_PACKAGES_DIR@/@DOTNET_PROJECT@.runtime.linux-x64.*.nupkg"/>
<RuntimeOsx Include="@DOTNET_PACKAGES_DIR@/@DOTNET_PROJECT@.runtime.osx-x64.*.nupkg"/>
<RuntimeWin Include="@DOTNET_PACKAGES_DIR@/@DOTNET_PROJECT@.runtime.win-x64.*.nupkg"/>
<PackageReference Include="@DOTNET_PROJECT@.runtime.linux-x64" Version="@PROJECT_VERSION@" Condition="Exists('@(RuntimeLinux)')"/>
<PackageReference Include="@DOTNET_PROJECT@.runtime.osx-x64" Version="@PROJECT_VERSION@" Condition="Exists('@(RuntimeOsx)')" />
<PackageReference Include="@DOTNET_PROJECT@.runtime.win-x64" Version="@PROJECT_VERSION@" Condition="Exists('@(RuntimeWin)')" />
<PackageReference Include="@DOTNET_PROJECT@.runtime.linux-x64" Version="@PROJECT_VERSION@"/>
<PackageReference Include="@DOTNET_PROJECT@.runtime.osx-x64" Version="@PROJECT_VERSION@"/>
<PackageReference Include="@DOTNET_PROJECT@.runtime.win-x64" Version="@PROJECT_VERSION@"/>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,170 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<LangVersion>9.0</LangVersion>
<TargetFrameworks>netcoreapp3.1;net6.0</TargetFrameworks>
<RuntimeIdentifier>@RUNTIME_IDENTIFIER@</RuntimeIdentifier>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AssemblyName>@DOTNET_PROJECT@</AssemblyName>
<Version>@PROJECT_VERSION@</Version>
<!-- Nuget Properties -->
<Description>.NET wrapper for the Operations Research Tools project</Description>
<!-- Pack Option -->
<Title>@DOTNET_PROJECT@ v@PROJECT_VERSION@</Title>
<PackageId>@DOTNET_PROJECT@</PackageId>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<!-- Signing -->
<AssemblyOriginatorKeyFile>../or-tools.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign>false</PublicSign>
<DelaySign>false</DelaySign>
</PropertyGroup>
<!-- On windows we can build cross-platform netstandard and windows-only netframework.-->
<PropertyGroup Condition=" '$(OS)' != 'Windows_NT' And '$(OS)' != 'Windows' ">
<TargetFrameworks>netcoreapp3.1;net6.0</TargetFrameworks>
</PropertyGroup>
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT' Or '$(OS)' == 'Windows' ">
<TargetFrameworks>netcoreapp3.1;net6.0;net452</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<Compile Include="@DOTNET_PROJECT_DIR@/ortools/algorithms/*.cs">
<Link>algorithms/%(Filename)%(Extension)</Link>
</Compile>
<Compile Include="@DOTNET_PROJECT_DIR@/ortools/bop/*.cs">
<Link>bop/%(Filename)%(Extension)</Link>
</Compile>
<Compile Include="@DOTNET_PROJECT_DIR@/ortools/glop/*.cs">
<Link>graph/%(Filename)%(Extension)</Link>
</Compile>
<Compile Include="@DOTNET_PROJECT_DIR@/ortools/graph/*.cs">
<Link>graph/%(Filename)%(Extension)</Link>
</Compile>
<Compile Include="@PROJECT_SOURCE_DIR@/ortools/graph/csharp/*.cs">
<Link>graph/%(Filename)%(Extension)</Link>
</Compile>
<Compile Include="@DOTNET_PROJECT_DIR@/ortools/linear_solver/*.cs">
<Link>linear_solver/%(Filename)%(Extension)</Link>
</Compile>
<Compile Include="@PROJECT_SOURCE_DIR@/ortools/linear_solver/csharp/*.cs">
<Link>linear_solver/%(Filename)%(Extension)</Link>
</Compile>
<Compile Include="@DOTNET_PROJECT_DIR@/ortools/constraint_solver/*.cs">
<Link>constraint_solver/%(Filename)%(Extension)</Link>
</Compile>
<Compile Include="@PROJECT_SOURCE_DIR@/ortools/constraint_solver/csharp/*.cs">
<Link>constraint_solver/%(Filename)%(Extension)</Link>
</Compile>
<Compile Include="@DOTNET_PROJECT_DIR@/ortools/init/*.cs">
<Link>init/%(Filename)%(Extension)</Link>
</Compile>
<Compile Include="@DOTNET_PROJECT_DIR@/ortools/pdlp/*.cs">
<Link>sat/%(Filename)%(Extension)</Link>
</Compile>
<Compile Include="@DOTNET_PROJECT_DIR@/ortools/sat/*.cs">
<Link>sat/%(Filename)%(Extension)</Link>
</Compile>
<Compile Include="@PROJECT_SOURCE_DIR@/ortools/sat/csharp/*.cs">
<Link>sat/%(Filename)%(Extension)</Link>
</Compile>
<Compile Include="@DOTNET_PROJECT_DIR@/ortools/util/*.cs">
<Link>util/%(Filename)%(Extension)</Link>
</Compile>
<Compile Include="@PROJECT_SOURCE_DIR@/ortools/util/csharp/*.cs">
<Link>util/%(Filename)%(Extension)</Link>
</Compile>
</ItemGroup>
<!-- Validate at least one runtime package has been generated -->
<Target Name="ValidateRuntimePackage" BeforeTargets="GenerateNuspec">
<ItemGroup>
<RuntimePackage Include="@DOTNET_PACKAGES_DIR@/@DOTNET_PROJECT@.runtime.@RUNTIME_IDENTIFIER@.*.nupkg"/>
</ItemGroup>
<Message Importance="high" Text="------- $(OS)"/>
<Message Importance="high" Text="Package @DOTNET_PROJECT@.runtime.@RUNTIME_IDENTIFIER@: found" Condition="Exists('@(RuntimePackage)')"/>
<Message Importance="high" Text="Package @DOTNET_PROJECT@.runtime.@RUNTIME_IDENTIFIER@: not found" Condition="!Exists('@(RuntimePackage)')"/>
<Error Text="You must locally 'dotnet pack' the @DOTNET_PROJECT@.runtime.@RUNTIME_IDENTIFIER@ Project." Condition="!Exists('@(RuntimePackage)')"/>
</Target>
<!-- Copy all .proto file(s) -->
<ItemGroup>
<Content Include="@PROJECT_SOURCE_DIR@/ortools/algorithms/*.proto">
<PackagePath>content/algorithms</PackagePath>
<Pack>true</Pack>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="@PROJECT_SOURCE_DIR@/ortools/bop/*.proto">
<PackagePath>content/bop</PackagePath>
<Pack>true</Pack>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="@PROJECT_SOURCE_DIR@/ortools/constraint_solver/*.proto">
<PackagePath>content/constraint_solver</PackagePath>
<Pack>true</Pack>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="@PROJECT_SOURCE_DIR@/ortools/data/*.proto">
<PackagePath>content/data</PackagePath>
<Pack>true</Pack>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="@PROJECT_SOURCE_DIR@/ortools/glop/*.proto">
<PackagePath>content/glop</PackagePath>
<Pack>true</Pack>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="@PROJECT_SOURCE_DIR@/ortools/graph/*.proto">
<PackagePath>content/graph</PackagePath>
<Pack>true</Pack>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="@PROJECT_SOURCE_DIR@/ortools/linear_solver/*.proto">
<PackagePath>content/linear_solver</PackagePath>
<Pack>true</Pack>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="@PROJECT_SOURCE_DIR@/ortools/pdlp/*.proto">
<PackagePath>content/pdlp</PackagePath>
<Pack>true</Pack>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="@PROJECT_SOURCE_DIR@/ortools/sat/*.proto">
<PackagePath>content/sat</PackagePath>
<Pack>true</Pack>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="@PROJECT_SOURCE_DIR@/ortools/util/*.proto">
<PackagePath>content/util</PackagePath>
<Pack>true</Pack>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.19.4"/>
</ItemGroup>
<!-- Need to add required runtime dependencies so Meta-Project will pull runtime Nuget(s) -->
<PropertyGroup>
<RestoreSources>@DOTNET_PACKAGES_DIR@;$(RestoreSources);https://api.nuget.org/v3/index.json</RestoreSources>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="@DOTNET_PROJECT@.runtime.@RUNTIME_IDENTIFIER@" Version="@PROJECT_VERSION@"/>
</ItemGroup>
</Project>