From c05056a2bc565a3e2642a76f232d88d25c82d6fa Mon Sep 17 00:00:00 2001 From: Canming Huang Date: Thu, 22 Apr 2021 12:26:58 -0400 Subject: [PATCH] Split libcvextern.a into two files (device & simulator) --- CMakeLists.txt | 16 +++++++- Emgu.CV.Extern/CMakeLists.txt | 40 +++++++++++++++---- .../iOS/Emgu.CV.Platform.IOS.csproj | 6 +-- platforms/ios/build.sh | 24 +++++------ platforms/ios/configure_xcode.sh | 19 +++------ 5 files changed, 68 insertions(+), 37 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f578ba34..b1a0e5d28 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -370,9 +370,21 @@ ELSEIF("${EMGUCV_ARCH}" STREQUAL "ubuntu_arm") ELSEIF("${EMGUCV_ARCH}" STREQUAL "raspbian_arm") SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/arm") ELSEIF("${EMGUCV_ARCH}" STREQUAL "arm64") - SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/arm64") + IF(IPHONEOS) + SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/iphoneos_arm64") + ELSEIF(IPHONESIMULATOR) + SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/simulator_arm64") + ELSE() + SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/arm64") + ENDIF() ELSEIF("${EMGUCV_ARCH}" STREQUAL "arm") - SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/arm") + IF(IPHONEOS) + SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/iphoneos_arm") + ELSEIF(IPHONESIMULATOR) + SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/simulator_arm") + ELSE() + SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "/arm") + ENDIF() ELSE() SET(UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER "") ENDIF() diff --git a/Emgu.CV.Extern/CMakeLists.txt b/Emgu.CV.Extern/CMakeLists.txt index 101d881d6..8c69a1ca3 100644 --- a/Emgu.CV.Extern/CMakeLists.txt +++ b/Emgu.CV.Extern/CMakeLists.txt @@ -3642,11 +3642,13 @@ IF (IOS) SET(IOS_RELEASE_FOLDER "") IF (IPHONESIMULATOR) SET(IOS_RELEASE_FOLDER "Release-iphonesimulator") + SET(IOS_RELEASE_FILENAME "libcvextern_simulator_${IOS_ARCH}.a") ELSEIF(IPHONEOS) SET(IOS_RELEASE_FOLDER "Release-iphoneos") + SET(IOS_RELEASE_FILENAME "libcvextern_iphoneos_${IOS_ARCH}.a") ENDIF() #MESSAGE(STATUS "<<<<<< IOS_RELEASE_FOLDER: ${IOS_RELEASE_FOLDER} >>>>>>") - SET(LIBTOOL_LINKING_COMMAND libtool -static -o ${CMAKE_SOURCE_DIR}/libs/iOS/libcvextern_${IOS_ARCH}.a bin${UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER}/Release/*.a opencv/3rdparty/lib/Release/*.a ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Release/*.a) + SET(LIBTOOL_LINKING_COMMAND libtool -static -o ${CMAKE_SOURCE_DIR}/libs/iOS/${IOS_RELEASE_FILENAME} bin${UNMANAGED_LIBRARY_OUTPUT_SUBFOLDER}/Release/*.a opencv/3rdparty/lib/Release/*.a ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Release/*.a) IF (EMGU_CV_WITH_TESSERACT) LIST(APPEND LIBTOOL_LINKING_COMMAND libs/Release/*.a) ENDIF() @@ -3658,13 +3660,37 @@ IF (IOS) COMMAND ${LIBTOOL_LINKING_COMMAND} WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" COMMENT "Linking target for ${IOS_ARCH}") - add_custom_command(TARGET ${the_target} - POST_BUILD - COMMAND lipo -create -output ${CMAKE_SOURCE_DIR}/libs/iOS/libcvextern.a ${CMAKE_SOURCE_DIR}/libs/iOS/libcvextern_*.a - WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" - COMMENT "Linking multiple arch into a single file") + + SET(IPHONEOS_STATIC_LIB_FILE ${CMAKE_SOURCE_DIR}/libs/iOS/libcvextern_iphoneos.a) + SET(IPHONESIMULATOR_STATIC_LIB_FILE ${CMAKE_SOURCE_DIR}/libs/iOS/libcvextern_simulator.a) + + IF (IPHONESIMULATOR) + IF (EXISTS ${IPHONEOS_STATIC_LIB_FILE}) + ELSE() + FILE(WRITE ${IPHONEOS_STATIC_LIB_FILE} "") + ENDIF() + add_custom_command(TARGET ${the_target} + POST_BUILD + COMMAND lipo -create -output ${IPHONESIMULATOR_STATIC_LIB_FILE} ${CMAKE_SOURCE_DIR}/libs/iOS/libcvextern_simulator_*.a + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + COMMENT "Linking multiple arch into a single file for iOS simulator") + ELSEIF(IPHONEOS) + IF (EXISTS ${IPHONESIMULATOR_STATIC_LIB_FILE}) + ELSE() + FILE(WRITE ${IPHONESIMULATOR_STATIC_LIB_FILE} "") + ENDIF() + add_custom_command(TARGET ${the_target} + POST_BUILD + COMMAND lipo -create -output ${IPHONEOS_STATIC_LIB_FILE} ${CMAKE_SOURCE_DIR}/libs/iOS/libcvextern_iphoneos_*.a + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + COMMENT "Linking multiple arch into a single file for iOS device") + ENDIF() + INSTALL(FILES + "${IPHONEOS_STATIC_LIB_FILE}" + DESTINATION "libs/iOS/" + COMPONENT emgucv_binary) INSTALL(FILES - "${CMAKE_SOURCE_DIR}/libs/iOS/libcvextern.a" + "${IPHONESIMULATOR_STATIC_LIB_FILE}" DESTINATION "libs/iOS/" COMPONENT emgucv_binary) ELSEIF (ANDROID) diff --git a/Emgu.CV.Platform/iOS/Emgu.CV.Platform.IOS.csproj b/Emgu.CV.Platform/iOS/Emgu.CV.Platform.IOS.csproj index 89ea97039..2d2414b80 100644 --- a/Emgu.CV.Platform/iOS/Emgu.CV.Platform.IOS.csproj +++ b/Emgu.CV.Platform/iOS/Emgu.CV.Platform.IOS.csproj @@ -71,7 +71,7 @@ Xamarin iOS Native Binding Library - $(OpenCVBinaryDir)\iOS\libcvextern.a + $(OpenCVBinaryDir)\iOS\libcvextern_iphoneos.a This package do not contain necessary binary for $(EmguCVLinkTarget). Emgu CV for iOS Commercial License is required. Missing $(EmguCVNativeFile) $(EmguCVDeployMessage)ios @@ -99,7 +99,7 @@ - + Static True True @@ -118,4 +118,4 @@ - \ No newline at end of file + diff --git a/platforms/ios/build.sh b/platforms/ios/build.sh index ec5153863..1ba8a9126 100755 --- a/platforms/ios/build.sh +++ b/platforms/ios/build.sh @@ -24,36 +24,36 @@ fi JOB_COUNT=1 if [ \( "$1" != "simulator" \) -a \( "$1" != "simulator_x86_64" \) ]; then - mkdir -p platforms/ios/armv7s - cd platforms/ios/armv7s + mkdir -p platforms/ios/iphoneos_armv7s + cd platforms/ios/iphoneos_armv7s ../configure_xcode.sh $CV_CONTRIB_OPTION device armv7s ${@:3} - ./xcodebuild_wrapper BITCODE_GENERATION_MODE=bitcode -parallelizeTargets -jobs ${JOB_COUNT} -configuration Release -target ALL_BUILD build + ./xcodebuild_wrapper -parallelizeTargets -jobs ${JOB_COUNT} -configuration Release -target ALL_BUILD build cd ../../.. - mkdir -p platforms/ios/armv7 + mkdir -p platforms/ios/iphoneos_armv7 cd platforms/ios/armv7 ../configure_xcode.sh $CV_CONTRIB_OPTION device armv7 ${@:3} - ./xcodebuild_wrapper BITCODE_GENERATION_MODE=bitcode -parallelizeTargets -jobs ${JOB_COUNT} -configuration Release -target ALL_BUILD build + ./xcodebuild_wrapper -parallelizeTargets -jobs ${JOB_COUNT} -configuration Release -target ALL_BUILD build cd ../../.. - mkdir -p platforms/ios/arm64 + mkdir -p platforms/ios/iphoneos_arm64 cd platforms/ios/arm64 ../configure_xcode.sh $CV_CONTRIB_OPTION device arm64 ${@:3} - ./xcodebuild_wrapper BITCODE_GENERATION_MODE=bitcode -parallelizeTargets -jobs ${JOB_COUNT} -configuration Release -target ALL_BUILD build + ./xcodebuild_wrapper -parallelizeTargets -jobs ${JOB_COUNT} -configuration Release -target ALL_BUILD build cd ../../.. fi #if [ "$1" != "simulator_x86_64" ]; then -# mkdir -p platforms/ios/arm64_simulator -# cd platforms/ios/arm64_simulator +# mkdir -p platforms/ios/simulator_arm64 +# cd platforms/ios/simulator_arm64 # #skip the first two parameter # ../configure_xcode.sh $CV_CONTRIB_OPTION simulator arm64 -DBUILD_IPP_IW:BOOL=FALSE -DWITH_IPP:BOOL=FALSE ${@:3} # ./xcodebuild_wrapper -parallelizeTargets -jobs ${JOB_COUNT} -configuration Release -target ALL_BUILD build # cd ../../.. #fi -mkdir -p platforms/ios/x86_64_simulator -cd platforms/ios/x86_64_simulator +mkdir -p platforms/ios/simulator_x86_64 +cd platforms/ios/simulator_x86_64 #skip the first two parameter ../configure_xcode.sh $CV_CONTRIB_OPTION simulator x86_64 -DBUILD_IPP_IW:BOOL=FALSE -DWITH_IPP:BOOL=FALSE ${@:3} @@ -64,7 +64,7 @@ cd ../../.. cd Emgu.CV.Platform/iOS #compile Emgu.CV.World.iOS.dll msbuild /p:Configuration=Release -cd ../../platforms/ios/x86_64_simulator +cd ../../platforms/ios/simulator_x86_64 #build the package this time ./xcodebuild_wrapper WARNING_CFLAGS=-Wno-implicit-function-declaration -parallelizeTargets -jobs ${JOB_COUNT} -configuration Release -target package build diff --git a/platforms/ios/configure_xcode.sh b/platforms/ios/configure_xcode.sh index bb536afbb..fddddbb97 100755 --- a/platforms/ios/configure_xcode.sh +++ b/platforms/ios/configure_xcode.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env bash -v set -e set -x CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" @@ -24,6 +24,7 @@ fi INSTALL_PREFIX_OPTION=( -DCMAKE_INSTALL_PREFIX=$INSTALL_FOLDER ) +CMAKE_COMMON_OPTION=( -DIOS_ARCH="$3" -DCMAKE_XCODE_ATTRIBUTE_BITCODE_GENERATION_MODE:STRING="bitcode" -DCMAKE_FIND_ROOT_PATH:STRING="$INSTALL_FOLDER" -DIPHONEOS_DEPLOYMENT_TARGET:STRING=9.0 ) pushd $CURRENT_SCRIPT_DIR/../../eigen mkdir -p build_$3 @@ -33,9 +34,7 @@ cmake \ -GXcode \ ${CV_TOOLCHAIN_OPTION[@]} \ ${INSTALL_PREFIX_OPTION[@]} \ - -DIOS_ARCH="$3"\ - -DCMAKE_FIND_ROOT_PATH:STRING="$INSTALL_FOLDER" \ - -DIPHONEOS_DEPLOYMENT_TARGET:STRING=9.0 \ + ${CMAKE_COMMON_OPTION[@]} \ ${@:4} \ .. cmake --build . --config Release --target install @@ -48,9 +47,7 @@ cmake \ -GXcode \ ${CV_TOOLCHAIN_OPTION[@]} \ ${INSTALL_PREFIX_OPTION[@]} \ - -DIOS_ARCH="$3"\ - -DCMAKE_FIND_ROOT_PATH:STRING="$INSTALL_FOLDER" \ - -DIPHONEOS_DEPLOYMENT_TARGET:STRING=9.0 \ + ${CMAKE_COMMON_OPTION[@]} \ -DCMAKE_DISABLE_FIND_PACKAGE_ZLIB:BOOL=TRUE \ -DCMAKE_DISABLE_FIND_PACKAGE_BZip2:BOOL=TRUE \ -DCMAKE_DISABLE_FIND_PACKAGE_PNG:BOOL=TRUE \ @@ -67,10 +64,8 @@ cmake \ -GXcode \ ${CV_TOOLCHAIN_OPTION[@]} \ ${INSTALL_PREFIX_OPTION[@]} \ - -DIOS_ARCH="$3"\ + ${CMAKE_COMMON_OPTION[@]} \ -DHB_HAVE_FREETYPE:BOOL=TRUE \ - -DCMAKE_FIND_ROOT_PATH:STRING="$INSTALL_FOLDER" \ - -DIPHONEOS_DEPLOYMENT_TARGET:STRING=9.0 \ ${@:4} \ .. cmake --build . --config Release --target install @@ -82,8 +77,7 @@ cmake \ ${CV_TOOLCHAIN_OPTION[@]} \ ${CV_CONTRIB_OPTION[@]} \ ${INSTALL_PREFIX_OPTION[@]} \ --DIOS_ARCH="$3" \ --DCMAKE_FIND_ROOT_PATH:STRING="$INSTALL_FOLDER" \ +${CMAKE_COMMON_OPTION[@]} \ -DWITH_EIGEN:BOOL=ON \ -DEigen3_DIR:STRING="$EIGEN_DIR" \ -DBUILD_SHARED_LIBS:BOOL=FALSE \ @@ -92,6 +86,5 @@ ${INSTALL_PREFIX_OPTION[@]} \ -DBUILD_opencv_apps:BOOL=FALSE \ -DBUILD_opencv_java_bindings_generator:BOOL=FALSE \ -DBUILD_opencv_python_bindings_generator:BOOL=FALSE \ --DIPHONEOS_DEPLOYMENT_TARGET:STRING=9.0 \ ${@:4} $CURRENT_SCRIPT_DIR/../..