Skip to content

Commit

Permalink
Build Emgu.TF.runtime.maui.android nuget package
Browse files Browse the repository at this point in the history
  • Loading branch information
emgucv committed Aug 24, 2023
1 parent 94c4f6a commit 064e4c7
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 42 deletions.
42 changes: 41 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ IF(HAVE_ANDROID)
#IF ("${LICENSE_TYPE}" STREQUAL "Commercial")
# SET(EMGUTF_ANDROID_NUGET_ID "${EMGUTF_ANDROID_NUGET_ID}-CR")
#ENDIF()
SET(EMGUTF_XAMARIN_ANDROID_NUGET_TITLE "Native runtime of ${EMGUTF_NUGET_TITLE} for Xamarin Android")
SET(EMGUTF_XAMARIN_ANDROID_NUGET_TITLE "Native Android runtime of ${EMGUTF_NUGET_TITLE} for Xamarin")
SET(EMGUTF_XAMARIN_ANDROID_NUGET_FILE_LIST "
<file src=\"..\\..\\..\\lib\\Emgu.TF.Platform.Xamarin.Android.dll\" target=\"lib\\MonoAndroid10\" />
<file src=\"..\\..\\..\\lib\\Emgu.TF.Platform.Xamarin.Android.xml\" target=\"lib\\MonoAndroid10\" />
Expand All @@ -591,6 +591,46 @@ IF(HAVE_ANDROID)
<dependency id=\"Xamarin.Android.Support.v7.AppCompat\" version=\"28.0.0.3\" />
</group>
</dependencies>")

SET(EMGUTF_MAUI_ANDROID_NUGET_ID "${EMGUTF_NUGET_BASE_ID}.runtime.maui.android")
#IF ("${LICENSE_TYPE}" STREQUAL "Commercial")
# SET(EMGUTF_ANDROID_NUGET_ID "${EMGUTF_ANDROID_NUGET_ID}-CR")
#ENDIF()
SET(EMGUTF_MAUI_ANDROID_NUGET_TITLE "Native Android runtime of ${EMGUTF_NUGET_TITLE} for MAUI")

# Sign and copy the binary
SET(EMGUTF_MAUI_ANDROID_POST_PROCESS_BINARY "<Target Name=\"PostProcessBinary\" AfterTargets=\"PostBuildEvent\">")
IF(EMGU_SIGN_FOUND AND WIN32)
file(TO_NATIVE_PATH ${EMGU_SIGN_EXECUTABLE} EMGU_SIGN_EXECUTABLE_NATIVE_PATH)
file(TO_NATIVE_PATH ${SIGNTOOL_EXECUTABLE} SIGNTOOL_EXECUTABLE_NATIVE_PATH)
SET(EMGUTF_MAUI_ANDROID_POST_PROCESS_BINARY "${EMGUTF_MAUI_ANDROID_POST_PROCESS_BINARY}
<Message Text=\"Signing $(OutputPath)$(AssemblyName).dll\" Importance=\"high\" />
<MakeDir Directories=\"$(OutputPath)\\signed\"/>
<Exec Command='${EMGU_SIGN_EXECUTABLE_NATIVE_PATH} \"$(OutputPath)$(AssemblyName).dll\" \"$(OutputPath)signed\" \"${SIGNTOOL_EXECUTABLE_NATIVE_PATH}\"' WorkingDirectory=\"$(OutputPath)\" />
")
ENDIF()
SET(EMGUTF_MAUI_ANDROID_POST_PROCESS_BINARY "${EMGUTF_MAUI_ANDROID_POST_PROCESS_BINARY}
<Message Text=\"Copying $(OutputPath)$(AssemblyName).dll, $(OutputPath)$(AssemblyName).xml to $(TfBinaryDir)\" Importance=\"high\" />
<Copy SourceFiles=\"$(OutputPath)$(AssemblyName).dll\" DestinationFolder=\"$(TfBinaryDir)\" ContinueOnError=\"true\" />
<Copy SourceFiles=\"$(OutputPath)$(AssemblyName).xml\" DestinationFolder=\"$(TfBinaryDir)\" ContinueOnError=\"true\" />
</Target>")

# Sign the nuget package
SET(EMGUTF_MAUI_ANDROID_POST_PROCESS_NUGET "")
IF(EMGU_NUGET_SIGN_FOUND AND WIN32)
file(TO_NATIVE_PATH ${EMGU_NUGET_SIGN_EXECUTABLE} EMGU_NUGET_SIGN_EXECUTABLE_NATIVE_PATH)
file(TO_NATIVE_PATH ${NUGET_EXECUTABLE} NUGET_EXECUTABLE_NATIVE_PATH)
SET(EMGUTF_MAUI_ANDROID_POST_PROCESS_NUGET "${EMGUTF_MAUI_ANDROID_POST_PROCESS_NUGET}
<Target Name=\"PostProcessNuget\" AfterTargets=\"Pack\">
<Message Text=\"Signing $(PackageOutputPath)\\$(PackageId).$(PackageVersion).nupkg\" Importance=\"high\" />
<MakeDir Directories=\"$(PackageOutputPath)\\signed\"/>
<Exec Command='${EMGU_NUGET_SIGN_EXECUTABLE_NATIVE_PATH} \"$(PackageOutputPath)\\$(PackageId).$(PackageVersion).nupkg\" \"$(PackageOutputPath)\\signed\" \"${NUGET_EXECUTABLE_NATIVE_PATH}\"' WorkingDirectory=\"$(PackageOutputPath)\" />
</Target>")
ENDIF()

CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.TF.runtime.maui.android.Directory.Build.props.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.TF.Platform/Maui/Android/Full/Directory.Build.props)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Emgu.TF.runtime.maui.android.Package.README.md.in ${CMAKE_CURRENT_SOURCE_DIR}/Emgu.TF.Platform/Maui/Android/Full/docs/README.md)

ENDIF()

IF(HAVE_OSX)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-android</TargetFramework>
<TargetFramework>net7.0-android</TargetFramework>
<SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<PropertyGroup>
<PropertyGroup>
<TfBinaryDir>$([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)..\..\..\..\lib))</TfBinaryDir>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand Down Expand Up @@ -109,4 +109,5 @@
<Message Text="Emgu TF MAUI Android Compiling with $(EmguTfMauiAndroidDeployMessage)binary" Condition="'$(EmguTfMauiAndroidDeployMessage)'!=''" Importance="High" />
<Message Text="Native binary is NOT deployed by the project." Condition="'$(EmguTfMauiAndroidDeployMessage)'==''" Importance="High" />
</Target>

</Project>
74 changes: 38 additions & 36 deletions Emgu.TF/Emgu.TF.Netstandard/Emgu.TF.Netstandard.csproj
Original file line number Diff line number Diff line change
@@ -1,42 +1,44 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AssemblyName>Emgu.TF.Netstandard</AssemblyName>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
<PropertyGroup>
<TfBinaryDir>$([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)..\..\lib))</TfBinaryDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>$(TfBinaryDir)\Build\$(AssemblyName)\$(Platform)\$(Configuration)\</OutputPath>
<DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
<DefineConstants>TRACE;__NETSTANDARD_2_0__</DefineConstants>
</PropertyGroup>

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AssemblyName>Emgu.TF.Netstandard</AssemblyName>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>..\..\lib\Build\$(AssemblyName)\$(Platform)\$(Configuration)\</OutputPath>
<DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
<DefineConstants>TRACE;__NETSTANDARD_2_0__</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutputPath>..\..\lib\Build\$(AssemblyName)\$(Platform)\$(Configuration)\</OutputPath>
<DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
<DefineConstants>TRACE;__NETSTANDARD_2_0__</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutputPath>$(TfBinaryDir)\Build\$(AssemblyName)\$(Platform)\$(Configuration)\</OutputPath>
<DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
<DefineConstants>TRACE;__NETSTANDARD_2_0__</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<OutputPath>..\..\lib\Build\$(AssemblyName)\$(Platform)\$(Configuration)\</OutputPath>
<DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
<DefineConstants>TRACE;__NETSTANDARD_2_0__</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<OutputPath>$(TfBinaryDir)\Build\$(AssemblyName)\$(Platform)\$(Configuration)\</OutputPath>
<DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
<DefineConstants>TRACE;__NETSTANDARD_2_0__</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutputPath>..\..\lib\Build\$(AssemblyName)\$(Platform)\$(Configuration)\</OutputPath>
<DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
<DefineConstants>TRACE;__NETSTANDARD_2_0__</DefineConstants>
</PropertyGroup>

<Import Project="..\..\Emgu.TF.Util\Emgu.TF.Util.Shared.projitems" Label="Shared" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutputPath>$(TfBinaryDir)\Build\$(AssemblyName)\$(Platform)\$(Configuration)\</OutputPath>
<DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
<DefineConstants>TRACE;__NETSTANDARD_2_0__</DefineConstants>
</PropertyGroup>

<Import Project="..\Emgu.TF.Shared.projitems" Label="Shared" />
<Target Name="DeployBinary" AfterTargets="AfterBuild">
<Message Text="Copying $(OutputPath)$(AssemblyName).dll, $(OutputPath)$(AssemblyName).xml to ..\..\lib" Importance="high" />
<Copy SourceFiles="$(OutputPath)$(AssemblyName).dll" DestinationFolder="..\..\lib" ContinueOnError="true" />
<Copy SourceFiles="$(OutputPath)$(AssemblyName).xml" DestinationFolder="..\..\lib" ContinueOnError="true" />
</Target>
<Import Project="..\..\Emgu.TF.Util\Emgu.TF.Util.Shared.projitems" Label="Shared" />

<Import Project="..\Emgu.TF.Shared.projitems" Label="Shared" />

<Target Name="DeployBinary" AfterTargets="AfterBuild">
<Message Text="Copying $(OutputPath)$(AssemblyName).dll, $(OutputPath)$(AssemblyName).xml to $(TfBinaryDir)" Importance="high" />
<Copy SourceFiles="$(OutputPath)$(AssemblyName).dll" DestinationFolder="$(TfBinaryDir)" ContinueOnError="true" />
<Copy SourceFiles="$(OutputPath)$(AssemblyName).xml" DestinationFolder="$(TfBinaryDir)" ContinueOnError="true" />
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<summary>Android runtime package of Emgu TF Lite for MAUI</summary>
<Description>This package contains the native Android runtime of Emgu TF Lite for MAUI</Description>
<PackageReleaseNotes>This is the ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH} release of Emgu TF Lite. For online documentation please visit
${NUGET_EMGU_URL}/wiki/files/emgutf/${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}/document/index.html
${NUGET_EMGU_URL}/wiki/files/emgutf/${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}/document-lite/index.html
</PackageReleaseNotes>

<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
Expand Down
75 changes: 75 additions & 0 deletions cmake/Emgu.TF.runtime.maui.android.Directory.Build.props.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0"?>
<Project>
<!-- https://learn.microsoft.com/en-us/visualstudio/msbuild/customize-by-directory?view=vs-2022 -->
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />

<PropertyGroup>
<PackageId>${EMGUTF_MAUI_ANDROID_NUGET_ID}</PackageId>

<title>${EMGUTF_MAUI_ANDROID_NUGET_TITLE}</title>
<version>${CPACK_PACKAGE_VERSION}</version>
<authors>${CPACK_PACKAGE_VENDOR}</authors>
<owners>${CPACK_PACKAGE_VENDOR}</owners>
<summary>Android runtime package of Emgu TF for MAUI</summary>
<Description>This package contains the native Android runtime of Emgu TF for MAUI</Description>
<PackageReleaseNotes>This is the ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH} release of Emgu TF. For online documentation please visit
${NUGET_EMGU_URL}/wiki/files/emgutf/${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}/document/index.html
</PackageReleaseNotes>

<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageIcon>nuget_icon.png</PackageIcon>
<PackageReadmeFile>docs/README.md</PackageReadmeFile>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<RepositoryUrl>https://github.com/emgucv/emgutf</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
<PackageOutputPath>$([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)..\..\..\platforms\nuget))</PackageOutputPath>
<PackageTags>tensorflow;emgu;emgutf;ai;image;android;maui</PackageTags>
<PackageProjectUrl>${NUGET_EMGU_URL}</PackageProjectUrl>
<copyright>© ${CPACK_PACKAGE_VENDOR} ${CURRENT_YEAR}. All rights reserved.</copyright>

</PropertyGroup>

<ItemGroup>
<None Include="..\..\..\..\LICENSE.txt">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
<None Include="..\..\..\..\miscellaneous\nuget_icon.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>
<ItemGroup>
<None Include="docs\README.md">
<Pack>True</Pack>
<PackagePath>docs\</PackagePath>
</None>
</ItemGroup>
<ItemGroup Condition="Exists('${TfBinaryDir}\android\arm64-v8a\arm64-v8a_version_string.inc')">
<None Include="${TfBinaryDir}\android\arm64-v8a\arm64-v8a_version_string.inc">
<Pack>True</Pack>
<PackagePath>docs\</PackagePath>
</None>
</ItemGroup>
<ItemGroup Condition="Exists('${TfBinaryDir}\libs\android\arm64-v8a\armeabi-v7a_version_string.inc')">
<None Include="${TfBinaryDir}\libs\android\arm64-v8a\armeabi-v7a_version_string.inc">
<Pack>True</Pack>
<PackagePath>docs\</PackagePath>
</None>
</ItemGroup>
<ItemGroup Condition="Exists('${TfBinaryDir}\libs\android\x86\x86_version_string.inc')">
<None Include="${TfBinaryDir}\libs\android\x86\x86_version_string.inc">
<Pack>True</Pack>
<PackagePath>docs\</PackagePath>
</None>
</ItemGroup>
<ItemGroup Condition="Exists('${TfBinaryDir}\libs\android\x86_64\x86_64_version_string.inc')">
<None Include="${TfBinaryDir}\libs\android\x86_64\x86_64_version_string.inc">
<Pack>True</Pack>
<PackagePath>docs\</PackagePath>
</None>
</ItemGroup>
${EMGUTF_MAUI_ANDROID_POST_PROCESS_BINARY}
${EMGUTF_MAUI_ANDROID_POST_PROCESS_NUGET}
</Project>
13 changes: 13 additions & 0 deletions cmake/Emgu.TF.runtime.maui.android.Package.README.md.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## About this package

This package is part of the ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH} release of Emgu CV.

For online documentation please visit
<${NUGET_EMGU_URL}/wiki/files/${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}/document/index.html>

Release note can be found at
<${NUGET_EMGU_URL}/wiki/index.php/Version_History#Emgu.CV-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}>

## Setup

Please make sure to call Emgu.CV.CvInvokeAndroid.Init() before making any other calls to Emgu CV library on Android.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ IF ( HAVE_ANDROID )
)

IF (EMGU_NUGET_SIGN_FOUND)
EMGU_SIGN_NUGET(${PROJECT_NAME} "${NUGET_OUTPUT_DIR}/${EMGUTF_ANDROID_NUGET_ID}.${CPACK_PACKAGE_VERSION}${TENSORFLOW_VERSION_SUFFIX}.nupkg")
EMGU_SIGN_NUGET(${PROJECT_NAME} "${NUGET_OUTPUT_DIR}/${EMGUTF_XAMARIN_ANDROID_NUGET_ID}.${CPACK_PACKAGE_VERSION}${TENSORFLOW_VERSION_SUFFIX}.nupkg")
ENDIF()

ADD_DEPENDENCIES(${PROJECT_NAME} Emgu.TF.Platform.Xamarin.Android Emgu.TF.nuget)
Expand Down

0 comments on commit 064e4c7

Please sign in to comment.