@@ -16,21 +16,34 @@ if [[ "$(uname -s)" == "Darwin" ]]; then
1616 exit 1
1717fi
1818
19- if [[ -z ${QNN_SDK_ROOT} ]]; then
20- echo " Please export QNN_SDK_ROOT=/path/to/qnn_sdk"
21- exit -1
22- fi
19+ SCRIPT_DIR=" $( cd " $( dirname " $0 " ) " ; pwd -P) "
20+
21+ # If QNN_SDK_ROOT is set, pass it to cmake. Otherwise cmake will
22+ # auto-download the SDK via download_qnn_sdk.py during configure.
23+ if [[ -n ${QNN_SDK_ROOT} ]]; then
24+ QNN_SDK_CMAKE_FLAG=" -DQNN_SDK_ROOT=${QNN_SDK_ROOT} "
2325
26+ # Ensure LD_LIBRARY_PATH includes QNN SDK libs
27+ QNN_LIB_DIR=" ${QNN_SDK_ROOT} /lib/x86_64-linux-clang"
28+ if [[ -d " ${QNN_LIB_DIR} " ]] && [[ " :${LD_LIBRARY_PATH:- } :" != * " :${QNN_LIB_DIR} :" * ]]; then
29+ export LD_LIBRARY_PATH=" ${QNN_LIB_DIR} :${LD_LIBRARY_PATH:- } "
30+ fi
31+ else
32+ QNN_SDK_CMAKE_FLAG=" "
33+ echo " [QNN] QNN_SDK_ROOT not set. SDK will be auto-downloaded during cmake configure."
34+ fi
2435
2536set -o xtrace
2637
2738usage () {
2839 echo " Usage: Build the aarch64 version of executor runner or the python interface of Qnn Manager"
29- echo " First, you need to set the environment variable for QNN_SDK_ROOT"
30- echo " , and if you want to build the android version of executor runner"
31- echo " , you need to export ANDROID_NDK_ROOT=/path/to/android_ndkXX"
40+ echo " "
41+ echo " QNN SDK and Android NDK will be auto-downloaded if not set."
42+ echo " To use a custom SDK, export QNN_SDK_ROOT=/path/to/qnn_sdk"
43+ echo " To use a custom NDK, export ANDROID_NDK_ROOT=/path/to/android_ndkXX"
3244 echo " (or export TOOLCHAIN_ROOT_HOST=/path/to/sysroots/xx_host, "
3345 echo " TOOLCHAIN_ROOT_TARGET=/path/to/sysroots/xx_target for linux embedded with --enable_linux_embedded)"
46+ echo " "
3447 echo " e.g.: executorch$ ./backends/qualcomm/scripts/build.sh --skip_x86_64"
3548 exit 1
3649}
@@ -51,13 +64,13 @@ BUILD_TYPE="RelWithDebInfo"
5164BUILD_JOB_NUMBER=" 16"
5265
5366# Default to use CDSP for now
54- DSP_TYPE=3
67+ DSP_TYPE=3
5568
56- if [ -z PYTHON_EXECUTABLE ]; then
69+ if [ -z " $ PYTHON_EXECUTABLE" ]; then
5770 PYTHON_EXECUTABLE=" python3"
5871fi
5972
60- if [ -z BUCK2 ]; then
73+ if [ -z " $ BUCK2" ]; then
6174 BUCK2=" buck2"
6275fi
6376
@@ -85,8 +98,14 @@ PRJ_ROOT="$( cd "$(dirname "$0")/../../.." ; pwd -P)"
8598
8699if [ " $BUILD_ANDROID " = true ]; then
87100 if [[ -z ${ANDROID_NDK_ROOT} ]]; then
88- echo " Please export ANDROID_NDK_ROOT=/path/to/android_ndkXX"
89- exit -1
101+ echo " [QNN] ANDROID_NDK_ROOT not set. Auto-downloading Android NDK..."
102+ source " ${SCRIPT_DIR} /install_qnn_sdk.sh"
103+ setup_android_ndk
104+ if [[ -z ${ANDROID_NDK_ROOT} ]]; then
105+ echo " [QNN] Error: Failed to download Android NDK."
106+ echo " [QNN] Set ANDROID_NDK_ROOT manually."
107+ exit 1
108+ fi
90109 fi
91110
92111 BUILD_ROOT=$PRJ_ROOT /$CMAKE_ANDROID
@@ -112,7 +131,7 @@ if [ "$BUILD_ANDROID" = true ]; then
112131 -DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \
113132 -DEXECUTORCH_ENABLE_EVENT_TRACER=ON \
114133 -DEXECUTORCH_ENABLE_LOGGING=ON \
115- -DQNN_SDK_ROOT= $QNN_SDK_ROOT \
134+ ${QNN_SDK_CMAKE_FLAG} \
116135 -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_ROOT /build/cmake/android.toolchain.cmake \
117136 -DANDROID_ABI=' arm64-v8a' \
118137 -DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
@@ -126,7 +145,7 @@ if [ "$BUILD_ANDROID" = true ]; then
126145 CMAKE_PREFIX_PATH=" ${BUILD_ROOT} ;${BUILD_ROOT} /third-party/gflags;"
127146
128147 # DSP_TYPE variable only matters when building direct_mode.
129- # Ignore the variable for traditional mode.
148+ # Ignore the variable for traditional mode.
130149
131150 if [ " $BUILD_HEXAGON " = " true" ]; then
132151 DIRECT_MODE_FLAG=" -DBUILD_DIRECT_MODE=ON"
@@ -274,7 +293,7 @@ if [ "$BUILD_OE_LINUX" = true ]; then
274293 -DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \
275294 -DEXECUTORCH_ENABLE_EVENT_TRACER=ON \
276295 -DEXECUTORCH_ENABLE_LOGGING=ON \
277- -DQNN_SDK_ROOT= $QNN_SDK_ROOT \
296+ ${QNN_SDK_CMAKE_FLAG} \
278297 -DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
279298 -DPYTHON_EXECUTABLE=$PYTHON_EXECUTABLE \
280299 -B$BUILD_ROOT
@@ -335,7 +354,7 @@ if [ "$BUILD_X86_64" = true ]; then
335354 cmake \
336355 -DCMAKE_BUILD_TYPE=$BUILD_TYPE \
337356 -DCMAKE_INSTALL_PREFIX=$BUILD_ROOT \
338- -DQNN_SDK_ROOT= ${QNN_SDK_ROOT } \
357+ ${QNN_SDK_CMAKE_FLAG } \
339358 -DEXECUTORCH_BUILD_QNN=ON \
340359 -DEXECUTORCH_BUILD_DEVTOOLS=ON \
341360 -DEXECUTORCH_BUILD_EXTENSION_LLM=ON \
0 commit comments