Files
HSP_demo/build.sh
2026-04-10 18:10:51 +08:00

52 lines
1.2 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
set -euo pipefail
ACTION="${1:-}"
LINK_MODE="${2:-static}"
BUILD_DIR="build"
usage() {
echo "用法:"
echo " ./build.sh all [static|shared|embed] 配置并编译整个工程"
echo " ./build.sh run 运行 build/test"
echo " ./build.sh clean 清理 build 目录"
}
check_link_mode() {
case "$1" in
static|shared|embed)
;;
*)
echo "错误: 无效的 has_platform 接入模式 '$1'"
usage
exit 1
;;
esac
}
case "${ACTION}" in
all)
check_link_mode "${LINK_MODE}"
mkdir -p "${BUILD_DIR}"
rm -rf "${BUILD_DIR:?}/"*
cmake -S . -B "${BUILD_DIR}" \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DHAS_PLATFORM_LINK_MODE="${LINK_MODE}"
cmake --build "${BUILD_DIR}" -j"$(nproc)"
;;
run)
if [ ! -x "${BUILD_DIR}/test" ]; then
echo "错误: 未找到 ${BUILD_DIR}/test请先执行 ./build.sh all"
exit 1
fi
"${BUILD_DIR}/test"
;;
clean)
rm -rf "${BUILD_DIR}"
;;
*)
usage
exit 1
;;
esac