Skip to content

Commit

Permalink
Added option to link maui ios project with xcframework
Browse files Browse the repository at this point in the history
  • Loading branch information
emgucv committed Nov 11, 2024
1 parent 16969b9 commit c141553
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
43 changes: 22 additions & 21 deletions Emgu.TF.Runtime/Maui/iOS/Emgu.TF.Lite.runtime.maui.ios.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,31 @@
<ImplicitUsings>true</ImplicitUsings>
<IsBindingProject>true</IsBindingProject>
<PlatformTarget>AnyCPU</PlatformTarget>
<NoBindingEmbedding>false</NoBindingEmbedding>
<UseXCFramework>true</UseXCFramework>
<NoBindingEmbedding>$(UseXCFramework)</NoBindingEmbedding>
</PropertyGroup>
<PropertyGroup>
<EmguTfLiteIOSLinkTarget>MAUI IOS Library</EmguTfLiteIOSLinkTarget>
<TfLiteBinaryDir>$([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)..\..\..\lib))</TfLiteBinaryDir>
<EmguTfLiteNativeIOSBinary>$(TfLiteBinaryDir)\ios\libtfliteextern.a</EmguTfLiteNativeIOSBinary>
<EmguTfLiteMauiIOSErrorMessage Condition="!Exists('$(EmguTfLiteNativeIOSBinary)')">This package do not contain necessary binary for $(EmguTfLiteIOSLinkTarget). Emgu TF Lite for iOS Commercial License is required. iOS is targeted, but file $(EmguTfLiteNativeIOSBinary) is missing.</EmguTfLiteMauiIOSErrorMessage>
<EmguTfLiteNativeIOSFramework>$(TfLiteBinaryDir)\ios\libtfliteextern_ios.xcframework</EmguTfLiteNativeIOSFramework>
<EmguTfLiteNativeIOSBinary>$(TfLiteBinaryDir)\ios\libtfliteextern.a</EmguTfLiteNativeIOSBinary>
<UseEmguTfLiteNativeIOSFramework Condition="('$(UseXCFramework)'=='true') And Exists('$(EmguTfLiteNativeIOSFramework)')">true</UseEmguTfLiteNativeIOSFramework>
<UseEmguTfLiteNativeIOSBinary Condition="('$(UseXCFramework)'!='true') And Exists('$(EmguTfLiteNativeIOSBinary)')">true</UseEmguTfLiteNativeIOSBinary>
<IOSFrameworkUsed Condition="'$(UseEmguTfLiteNativeIOSFramework)'=='true'">$(EmguTfLiteNativeIOSFramework);$(IOSFrameworkUsed)</IOSFrameworkUsed>
<IOSFrameworkUsed Condition="'$(UseEmguTfLiteNativeIOSBinary)'=='true'">$(EmguTfLiteNativeIOSBinary);$(IOSFrameworkUsed)</IOSFrameworkUsed>
<EmguTfLiteMauiIOSErrorMessage Condition="('$(UseXCFramework)'!='true') And ('$(UseEmguTfLiteNativeIOSBinary)'!='true')">This package do not contain necessary binary for $(EmguTfLiteIOSLinkTarget). Emgu TF Lite for iOS Commercial License is required. iOS is targeted, but file $(EmguTfLiteNativeIOSBinary) is missing.</EmguTfLiteMauiIOSErrorMessage>
<EmguTfLiteMauiIOSErrorMessage Condition="('$(UseXCFramework)'=='true') And ('$(UseEmguTfLiteNativeIOSFramework)'!='true')">This package do not contain necessary binary for $(EmguTfLiteIOSLinkTarget). Emgu TF Lite for iOS Commercial License is required. iOS is targeted, but file $(EmguTfLiteNativeIOSFramework) is missing.</EmguTfLiteMauiIOSErrorMessage>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<WarningLevel>4</WarningLevel>
<OutputPath>$(TfLiteBinaryDir)\Build\$(AssemblyName)\$(Platform)\$(Configuration)\</OutputPath>
<OutputPath>$(TfLiteBinaryDir)\Build\$(AssemblyName)\$(Platform)\$(Configuration)\</OutputPath>
<DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
<MtouchLink>SdkOnly</MtouchLink>
<MtouchHttpClientHandler>HttpClientHandler</MtouchHttpClientHandler>
<PlatformTarget>anycpu</PlatformTarget>
<!-- <PlatformTarget>anycpu</PlatformTarget> -->
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<OutputPath>$(TfLiteBinaryDir)\Build\$(AssemblyName)\$(Platform)\$(Configuration)\</OutputPath>
<OutputPath>$(TfLiteBinaryDir)\Build\$(AssemblyName)\$(Platform)\$(Configuration)\</OutputPath>
<DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
<MtouchLink>SdkOnly</MtouchLink>
<MtouchHttpClientHandler>HttpClientHandler</MtouchHttpClientHandler>
Expand All @@ -32,41 +39,35 @@
<ObjcBindingApiDefinition Include="ApiDefinition.cs" />
<ObjcBindingCoreSource Include="StructsAndEnums.cs" />
</ItemGroup>

<ItemGroup>
<NativeReference Condition="Exists('$(EmguTfLiteNativeIOSBinary)')" Include="$(EmguTfLiteNativeIOSBinary)">

<ItemGroup>

<NativeReference Condition="'$(UseEmguTfLiteNativeIOSBinary)'=='true'" Include="$(EmguTfLiteNativeIOSBinary)">
<Kind>Static</Kind>
<SmartLink>True</SmartLink>
<ForceLoad>True</ForceLoad>
<IsCxx>True</IsCxx>
<LinkerFlags>-stdlib=libc++ -ObjC -lc++</LinkerFlags>
<Frameworks>Foundation Accelerate CoreFoundation CoreGraphics AssetsLibrary AVFoundation CoreImage CoreMedia CoreVideo QuartzCore ImageIO UIKit CoreText</Frameworks>
</NativeReference>
<!--
<NativeReference Include="$(TfLiteBinaryDir)\iOS\libcvextern_simulator.a">

<NativeReference Condition="'$(UseEmguTfLiteNativeIOSFramework)'=='true'" Include="$(EmguTfLiteNativeIOSFramework)">
<Kind>Static</Kind>
<SmartLink>True</SmartLink>
<ForceLoad>True</ForceLoad>
<IsCxx>True</IsCxx>
<LinkerFlags>-stdlib=libc++ -ObjC -lc++</LinkerFlags>
<Frameworks>Foundation Accelerate CoreFoundation CoreGraphics AssetsLibrary AVFoundation CoreImage CoreMedia CoreVideo QuartzCore ImageIO UIKit CoreText</Frameworks>
</NativeReference>
-->

</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Emgu.TF.Lite\NetStandard\Emgu.TF.Lite.csproj" />
</ItemGroup>

<!--
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Message Text="Copying $(OutputPath)$(AssemblyName).dll and $(OutputPath)$(AssemblyName).xml to $(TfLiteBinaryDir)" Importance="high" />
<Copy SourceFiles="$(OutputPath)$(AssemblyName).dll" DestinationFolder="$(TfLiteBinaryDir)" ContinueOnError="true" />
<Copy SourceFiles="$(OutputPath)$(AssemblyName).xml" DestinationFolder="$(TfLiteBinaryDir)" ContinueOnError="true" />
</Target>
-->


<Target Name="EmguTfLiteMauiIOSPackageBuildImports" BeforeTargets="PrepareForBuild">
<Message Text="IOS native binary linked: '$(IOSFrameworkUsed)'" Importance="high" />
<Warning Text="'$(EmguTfLiteMauiIOSErrorMessage)'" Condition="'$(EmguTfLiteMauiIOSErrorMessage)'!=''" />
</Target>
</Project>
5 changes: 3 additions & 2 deletions platforms/ios/bazel_build_tflite_ios
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
if [ \( -n "$1" \) ]; then
echo "Building with config $1"
else
echo "Please specify the ios config and architecture to build. e.g. $0 ios_fat; $0 x86_64; $0 ios_sim_arm64; $0 arm64; $0 armv7; $0 i386;"
echo "Please specify the ios config and architecture to build. e.g. $0 ios_fat; $0 ios_x86_64; $0 ios_sim_arm64; $0 ios_arm64; $0 ios_armv7"
exit 1
fi

Expand Down Expand Up @@ -59,7 +59,8 @@ rm -rf bazel-bin/tensorflow/lite/ios/TensorFlowLiteC_framework.zip
#alias python="/usr/local/bin/python3"
#bazel --output_user_root=$BAZEL_OUTPUT_USER_ROOT build --verbose_failures --config=ios_fat --copt="-DCL_DELEGATE_NO_GL" --copt="-D__IOS__" -c opt --action_env PATH="$PATH" //tensorflow/lite/ios:TensorFlowLiteC_framework
bazel --output_user_root=$BAZEL_OUTPUT_USER_ROOT build --verbose_failures --incompatible_run_shell_command_string=false --config=$1 --copt="-DCL_DELEGATE_NO_GL" --copt="-D__IOS__" -c opt ${@:2} //tensorflow/lite/ios:TensorFlowLiteC_framework
unzip -o bazel-bin/tensorflow/lite/ios/TensorFlowLiteC_framework.zip TensorFlowLiteC.framework/TensorFlowLiteC ../lib/ios/libtfliteextern_$1.a
unzip -o bazel-bin/tensorflow/lite/ios/TensorFlowLiteC_framework.zip TensorFlowLiteC.framework/TensorFlowLiteC -d ../lib/ios
mv ../lib/ios/TensorFlowLiteC.framework/TensorFlowLiteC ../lib/ios/libtfliteextern_$1.a
#cp -r TensorFlowLiteC.framework/TensorFlowLiteC ../lib/ios/libtfliteextern.a
cd ..

Expand Down

0 comments on commit c141553

Please sign in to comment.