build_ios.sh 7.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
#!/bin/bash
set +x

#####################################################################################################
# 1. global variables, you can change them according to your requirements
#####################################################################################################
# armv7 or armv8, default armv8.
ARM_ABI=armv8
# ON or OFF, default OFF.
WITH_EXTRA=OFF
# controls whether to compile cv functions into lib, default is OFF.
WITH_CV=OFF
# controls whether to hide log information, default is ON.
14
WITH_LOG=ON
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
# absolute path of Paddle-Lite.
workspace=$PWD/$(dirname $0)/../../
# options of striping lib according to input model.
OPTMODEL_DIR=""
WITH_STRIP=OFF
# num of threads used during compiling..
readonly NUM_PROC=${LITE_BUILD_THREADS:-4}
#####################################################################################################


#####################################################################################################
# 2. local variables, these variables should not be changed.
#####################################################################################################
# on mac environment, we should expand the maximum file num to compile successfully
os_name=`uname -s`
if [ ${os_name} == "Darwin" ]; then
   ulimit -n 1024
fi
#####################################################################################################

####################################################################################################
# 3. compiling functions
####################################################################################################
function make_ios {
    local abi=$1

    if [ ${abi} == "armv8" ]; then
        local os=ios64
    elif [ ${abi} == "armv7" ]; then
        local os=ios
    else
        echo -e "Error: unsupported arm_abi: ${abi} \t --arm_abi: armv8|armv7"
        exit 1
    fi

    build_dir=$workspace/build.ios.${os}.${abi}
    if [ -d $build_dir ]
    then
        rm -rf $build_dir
    fi
    echo "building ios target into $build_dir"
    echo "target abi: $abi"
    mkdir -p ${build_dir}
    cd ${build_dir}
    GEN_CODE_PATH_PREFIX=lite/gen_code
    mkdir -p ./${GEN_CODE_PATH_PREFIX}
    touch ./${GEN_CODE_PATH_PREFIX}/__generated_code__.cc

    cmake $workspace \
            -DWITH_LITE=ON \
            -DLITE_WITH_ARM=ON \
            -DLITE_ON_TINY_PUBLISH=ON \
            -DLITE_WITH_OPENMP=OFF \
            -DWITH_ARM_DOTPROD=OFF \
            -DLITE_WITH_LIGHT_WEIGHT_FRAMEWORK=ON \
70
            -DLITE_WITH_LOG=$WITH_LOG \
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
            -DLITE_BUILD_TAILOR=$WITH_STRIP \
            -DLITE_OPTMODEL_DIR=$OPTMODEL_DIR \
            -DARM_TARGET_ARCH_ABI=$abi \
            -DLITE_BUILD_EXTRA=$WITH_EXTRA \
            -DLITE_WITH_CV=$WITH_CV \
            -DARM_TARGET_OS=$os

    make publish_inference -j$NUM_PROC
    cd -
}


function print_usage {
    echo "----------------------------------------------------------------------------------------------------------------------------------------"
    echo -e "| Methods of compiling Padddle-Lite iOS library:                                                                                       |"
    echo "----------------------------------------------------------------------------------------------------------------------------------------"
    echo -e "|  compile iOS armv8 library:                                                                                                          |"
    echo -e "|     ./lite/tools/build_ios.sh                                                                                                        |"
    echo -e "|  compile iOS armv7 library:                                                                                                          |"
    echo -e "|     ./lite/tools/build_ios.sh  --arm_abi=armv7                                                                                       |"
    echo -e "|  print help information:                                                                                                             |"
    echo -e "|     ./lite/tools/build_ios.sh help                                                                                                   |"
    echo -e "|                                                                                                                                      |"
    echo -e "|  optional argument:                                                                                                                  |"
    echo -e "|     --arm_abi: (armv8|armv7), default is armv8                                                                                       |"
    echo -e "|     --with_cv: (OFF|ON); controls whether to compile cv functions into lib, default is OFF                                           |"
97
    echo -e "|     --with_log: (OFF|ON); controls whether to print log information, default is ON                                                |"
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
    echo -e "|     --with_extra: (OFF|ON); controls whether to publish extra operators and kernels for (sequence-related model such as OCR or NLP)  |"
    echo -e "|                                                                                                                                      |"
    echo -e "|  arguments of striping lib according to input model:(armv8, gcc, c++_static)                                                         |"
    echo -e "|     ./lite/tools/build_android.sh --with_strip=ON --opt_model_dir=YourOptimizedModelDir                                              |"
    echo -e "|     --with_strip: (OFF|ON); controls whether to strip lib accrding to input model, default is OFF                                    |"
    echo -e "|     --opt_model_dir: (absolute path to optimized model dir) required when compiling striped library                                  |"
    echo -e "|  detailed information about striping lib:  https://paddle-lite.readthedocs.io/zh/latest/user_guides/library_tailoring.html           |"
    echo "----------------------------------------------------------------------------------------------------------------------------------------"

}

function main {
    if [ -z "$1" ]; then
        make_ios $ARM_ABI
        exit -1
    fi

    # Parse command line.
    for i in "$@"; do
        case $i in
            --arm_abi=*)
                ARM_ABI="${i#*=}"
                make_ios $ARM_ABI
                shift
                ;;
            --with_extra=*)
                WITH_EXTRA="${i#*=}"
                shift
                ;;
            --with_cv=*)
                WITH_CV="${i#*=}"
                shift
                ;;
            --opt_model_dir=*)
                OPTMODEL_DIR="${i#*=}"
                shift
                ;;
            --with_strip=*)
                WITH_STRIP="${i#*=}"
                shift
                ;;
139 140
            --with_log=*)
                WITH_LOG="${i#*=}"
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
                shift
                ;;
            help)
                print_usage
                exit 0
                ;;
            *)
                # unknown option
                print_usage
                exit 1
                ;;
        esac
        make_ios $ARM_ABI
    done
}

main $@