Files
RCS-3000/build.sh
CaiXiang 7b6c956b6a initial
2025-11-27 15:20:21 +08:00

146 lines
4.1 KiB
Bash
Raw Permalink 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
# ============================================
# AGV 项目快速构建脚本
# ============================================
#
# 功能:
# 1. 自动设置环境并编译项目
# 2. 自动复制 Qt/MinGW 依赖到 build 目录
# 3. 编译后可直接双击 build/agv_qt_gui.exe 运行
#
# 使用:./build.sh [clean]
#
# ============================================
set -e # 遇到错误立即退出
# ==================== 配置区域 ====================
# Qt 和 MinGW 路径
QT_DIR="/c/Qt/6.10.1/mingw_64"
MINGW_DIR="/c/Qt/Tools/mingw1310_64"
# 项目路径
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BUILD_DIR="$PROJECT_ROOT/build"
# 颜色定义
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# ==================== 函数定义 ====================
print_step() {
echo -e "${GREEN}[✓]${NC} $1"
}
print_info() {
echo -e "${BLUE}[→]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[!]${NC} $1"
}
# ==================== 主流程 ====================
echo ""
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE} AGV 项目构建脚本${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
# 检查参数
if [ "$1" == "clean" ]; then
print_info "清理 build 目录..."
rm -rf "$BUILD_DIR"
print_step "清理完成"
echo ""
fi
# 创建 build 目录
if [ ! -d "$BUILD_DIR" ]; then
print_info "创建 build 目录..."
mkdir -p "$BUILD_DIR"
fi
# 设置 PATH
print_info "设置 MinGW 环境..."
export PATH="$MINGW_DIR/bin:$PATH"
# CMake 配置
print_info "运行 CMake 配置..."
cd "$BUILD_DIR"
cmake -G "MinGW Makefiles" -DCMAKE_PREFIX_PATH="$QT_DIR" ..
print_step "CMake 配置完成"
echo ""
# 编译
print_info "开始编译项目..."
cmake --build . -j4
echo ""
print_step "编译完成!"
echo ""
# 复制依赖到 build 目录,使得可以直接双击运行
print_info "正在复制运行时依赖到 build 目录..."
# 复制 Qt 核心库
cp "$QT_DIR/bin/Qt6Core.dll" "$BUILD_DIR/" 2>/dev/null || true
cp "$QT_DIR/bin/Qt6Gui.dll" "$BUILD_DIR/" 2>/dev/null || true
cp "$QT_DIR/bin/Qt6Widgets.dll" "$BUILD_DIR/" 2>/dev/null || true
cp "$QT_DIR/bin/Qt6Network.dll" "$BUILD_DIR/" 2>/dev/null || true
cp "$QT_DIR/bin/Qt6Svg.dll" "$BUILD_DIR/" 2>/dev/null || true
# 复制 MinGW 运行时
cp "$MINGW_DIR/bin/libgcc_s_seh-1.dll" "$BUILD_DIR/" 2>/dev/null || true
cp "$MINGW_DIR/bin/libstdc++-6.dll" "$BUILD_DIR/" 2>/dev/null || true
cp "$MINGW_DIR/bin/libwinpthread-1.dll" "$BUILD_DIR/" 2>/dev/null || true
# 复制 Qt 平台插件
mkdir -p "$BUILD_DIR/platforms"
cp "$QT_DIR/plugins/platforms/qwindows.dll" "$BUILD_DIR/platforms/" 2>/dev/null || true
# 复制样式插件
mkdir -p "$BUILD_DIR/styles"
cp "$QT_DIR/plugins/styles/qmodernwindowsstyle.dll" "$BUILD_DIR/styles/" 2>/dev/null || true
# 复制图标引擎
mkdir -p "$BUILD_DIR/iconengines"
cp "$QT_DIR/plugins/iconengines/qsvgicon.dll" "$BUILD_DIR/iconengines/" 2>/dev/null || true
# 复制图像格式插件
mkdir -p "$BUILD_DIR/imageformats"
cp "$QT_DIR/plugins/imageformats/qgif.dll" "$BUILD_DIR/imageformats/" 2>/dev/null || true
cp "$QT_DIR/plugins/imageformats/qjpeg.dll" "$BUILD_DIR/imageformats/" 2>/dev/null || true
cp "$QT_DIR/plugins/imageformats/qsvg.dll" "$BUILD_DIR/imageformats/" 2>/dev/null || true
# 复制 OpenGL 软件渲染器
cp "$QT_DIR/bin/opengl32sw.dll" "$BUILD_DIR/" 2>/dev/null || true
# 复制项目特定库
if [ -f "$PROJECT_ROOT/lib/ControlCAN.dll" ]; then
cp "$PROJECT_ROOT/lib/ControlCAN.dll" "$BUILD_DIR/" 2>/dev/null || true
fi
print_step "依赖库已复制到 build 目录"
echo ""
# 显示生成的可执行文件
echo "生成的可执行文件:"
echo " • build/agv_qt_gui.exe (Qt6 图形界面)"
echo " • build/curtis_demo.exe (Curtis 控制器演示)"
echo " • build/curtis_path_tracking_demo.exe (Curtis 路径跟踪)"
echo " • build/agv_demo.exe (控制台演示)"
echo ""
echo -e "${YELLOW}下一步:${NC}"
echo " 1. 运行 Qt GUI 双击 build/agv_qt_gui.exe 或 cd build && ./agv_qt_gui.exe"
echo " 2. 部署应用: ./deploy_windows.sh"
echo ""