diff --git a/Emgu.TF.Runtime/Maui/Mac/ApiDefinition.cs b/Emgu.TF.Runtime/Maui/Mac/ApiDefinition.cs new file mode 100644 index 00000000..5b4fea28 --- /dev/null +++ b/Emgu.TF.Runtime/Maui/Mac/ApiDefinition.cs @@ -0,0 +1,70 @@ +namespace Emgu.TF.Lite.Platform.Maui.iOS +{ + +// The first step to creating a binding is to add your native framework ("MyLibrary.xcframework") +// to the project. +// Open your binding csproj and add a section like this +// +// +// Framework +// +// +// +// +// Once you've added it, you will need to customize it for your specific library: +// - Change the Include to the correct path/name of your library +// - Change Kind to Static (.a) or Framework (.framework/.xcframework) based upon the library kind and extension. +// - Dynamic (.dylib) is a third option but rarely if ever valid, and only on macOS and Mac Catalyst +// - If your library depends on other frameworks, add them inside +// Example: +// +// Framework +// CoreLocation ModelIO +// +// +// Once you've done that, you're ready to move on to binding the API... +// +// Here is where you'd define your API definition for the native Objective-C library. +// +// For example, to bind the following Objective-C class: +// +// @interface Widget : NSObject { +// } +// +// The C# binding would look like this: +// +// [BaseType (typeof (NSObject))] +// interface Widget { +// } +// +// To bind Objective-C properties, such as: +// +// @property (nonatomic, readwrite, assign) CGPoint center; +// +// You would add a property definition in the C# interface like so: +// +// [Export ("center")] +// CGPoint Center { get; set; } +// +// To bind an Objective-C method, such as: +// +// -(void) doSomething:(NSObject *)object atIndex:(NSInteger)index; +// +// You would add a method definition to the C# interface like so: +// +// [Export ("doSomething:atIndex:")] +// void DoSomething (NSObject object, nint index); +// +// Objective-C "constructors" such as: +// +// -(id)initWithElmo:(ElmoMuppet *)elmo; +// +// Can be bound as: +// +// [Export ("initWithElmo:")] +// NativeHandle Constructor (ElmoMuppet elmo); +// +// For more information, see https://aka.ms/ios-binding +// + +} diff --git a/Emgu.TF.Runtime/Maui/Mac/CMakeLists.txt b/Emgu.TF.Runtime/Maui/Mac/CMakeLists.txt new file mode 100644 index 00000000..aa5221e8 --- /dev/null +++ b/Emgu.TF.Runtime/Maui/Mac/CMakeLists.txt @@ -0,0 +1,39 @@ +# -------------------------------------------------------- +# Copyright (C) 2004-2024 by EMGU Corporation. All rights reserved. +# -------------------------------------------------------- + +IF(HAVE_MAUI_MAC_LITE) + + INSTALL( + DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + DESTINATION Emgu.TF.Runtime/Maui + COMPONENT emgutf_source + FILES_MATCHING + PATTERN "*.csproj" + PATTERN "*.cs" + PATTERN "Directory.Build.props" + PATTERN "README.md" + PATTERN ".svn" EXCLUDE + PATTERN "obj" EXCLUDE + PATTERN "CMakeFiles" EXCLUDE + PATTERN "${PROJECT_NAME}.dir" EXCLUDE + ) + + IF (APPLE) + PROJECT(Emgu.TF.Lite.runtime.maui.macos) + SET(EXTRA_BUILD_FLAGS "/p:Platform=\"AnyCPU\"") + BUILD_DOTNET_PROJ(${PROJECT_NAME} "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.csproj" "${EXTRA_BUILD_FLAGS}" ALL) + + ADD_DEPENDENCIES(${PROJECT_NAME} Emgu.TF.Lite) + if(ENABLE_SOLUTION_FOLDERS) + set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER "emgu") + endif() + ENDIF() + + INSTALL( + DIRECTORY + ${LIBRARY_OUTPUT_PATH}/Build/Emgu.TF.Lite.runtime.maui.macos + DESTINATION ${CPACK_PACKAGE_CLI_FOLDER} + COMPONENT emgutf_binary) + +ENDIF() diff --git a/Emgu.TF.Runtime/Maui/Mac/Emgu.TF.Lite.runtime.maui.macos.csproj b/Emgu.TF.Runtime/Maui/Mac/Emgu.TF.Lite.runtime.maui.macos.csproj new file mode 100644 index 00000000..09cfb650 --- /dev/null +++ b/Emgu.TF.Runtime/Maui/Mac/Emgu.TF.Lite.runtime.maui.macos.csproj @@ -0,0 +1,50 @@ + + + net9.0-maccatalyst + enable + true + true + Emgu.TF.Lite.runtime.maui.macos + True + $([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)..\..\..\lib)) + $(TfLiteBinaryDir)\ios + $(EmguTfLiteCatalystBinaryDir)\libtfliteextern_darwin_x86_64.a + $(EmguTfLiteCatalystBinaryDir)\libtfliteextern_darwin_arm64.a + MAUI MacCatalyst Library + This package do not contains necessary binary for $(EmguTfLiteLinkTarget). Emgu TF for MacOS Commercial license is required, Mac Catalyst x86_64 is targeted, but file $(EmguTfLiteCatalystNativeFileX64) is missing. + This package do not contains necessary binary for $(EmguTfLiteLinkTarget). Emgu TF for MacOS Commercial license is required, Mac Catalyst ARM64 is targeted, but file $(EmguTfLiteCatalystNativeFileARM64) is missing. + $(TfLiteBinaryDir)\Build\$(AssemblyName)\$(Platform)\ + + + + + + + + + + Static + True + True + True + -stdlib=libc++ -ObjC -lc++ + Foundation Accelerate CoreFoundation CoreGraphics AssetsLibrary AVFoundation CoreImage CoreMedia CoreVideo QuartzCore ImageIO UIKit CoreText + + + + + Static + True + True + True + -stdlib=libc++ -ObjC -lc++ + Foundation Accelerate CoreFoundation CoreGraphics AssetsLibrary AVFoundation CoreImage CoreMedia CoreVideo QuartzCore ImageIO UIKit CoreText + + + + + + + + + diff --git a/Emgu.TF.Runtime/Maui/Mac/StructsAndEnums.cs b/Emgu.TF.Runtime/Maui/Mac/StructsAndEnums.cs new file mode 100644 index 00000000..6b6e0eef --- /dev/null +++ b/Emgu.TF.Runtime/Maui/Mac/StructsAndEnums.cs @@ -0,0 +1,4 @@ +namespace Emgu.TF.Lite.Platform.Maui.iOS +{ + +} diff --git a/platforms/ios/bazel_build_tflite_catalyst b/platforms/ios/bazel_build_tflite_catalyst deleted file mode 100755 index bac3cc57..00000000 --- a/platforms/ios/bazel_build_tflite_catalyst +++ /dev/null @@ -1,67 +0,0 @@ -#!/bin/bash -v - -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 ios_x86_64; $0 ios_sim_arm64; $0 ios_arm64; $0 ios_armv7" - exit 1 -fi - -cd "$(dirname "$0")" -cd ../../ -mkdir -p lib/ios -cd tensorflow - -#check for x86_64 version of python3 from homebew -if test -f "/usr/local/bin/python3"; then - if test -d "/usr/local/lib/python3.9/site-packages"; then - export PYTHON_BIN_PATH="/usr/local/bin/python3" - export PYTHON_LIB_PATH="/usr/local/lib/python3.9/site-packages" - fi -fi - -#check for arm64 version of python3, if it is available, use this instead. -if test -f "/opt/homebrew/bin/python3"; then - if test -d "/opt/homebrew/lib/python3.9/site-packages"; then - export PYTHON_BIN_PATH="/opt/homebrew/bin/python3" - export PYTHON_LIB_PATH="/opt/homebrew/lib/python3.9/site-packages" - fi -fi - -#The python3 comes with Xcode seems to have issues when compiling for tflite using bazel, will disable it now. - -#if test -f "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/Current/bin/python3"; then -# if test -d "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/Current/lib/python3.8/site-packages"; then -# export PYTHON_BIN_PATH="/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/Current/bin/python3" -# export PYTHON_LIB_PATH="/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/Current/lib/python3.8/site-packages" -# fi -#fi - -echo PYTHON_BIN_PATH=$PYTHON_BIN_PATH -echo PYTHON_LIB_PATH=$PYTHON_LIB_PATH - -export TF_CONFIGURE_IOS='1' -export TF_ENABLE_XLA=1 -export TF_NEED_CUDA=0 -export TF_NEED_ROCM=0 -export TF_NEED_OPENCL_SYCL=0 -export TF_DOWNLOAD_CLANG=0 -export CC_OPT_FLAGS="-match=native -Wno-sign-compare" -export TF_SET_ANDROID_WORKSPACE=0 - -BAZEL_OUTPUT_USER_ROOT="$(pwd)/../bazel_output_$1" - -cp -f tensorflow/lite/ios/BUILD.apple tensorflow/lite/ios/BUILD - -rm -rf bazel-bin/tensorflow/lite/ios/TensorFlowLiteC_framework.zip - -./configure -#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 --apple_platform_type=macos --cpu==$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 -d ../lib/ios -mv ../lib/ios/TensorFlowLiteC.framework/TensorFlowLiteC ../lib/ios/libtfliteextern_$1.a -#cp -r TensorFlowLiteC.framework/TensorFlowLiteC ../lib/ios/libtfliteextern.a -cd .. - -