1 Star 0 Fork 17

enwa/xege

forked from xege/xege 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
tasks.sh 4.19 KB
一键复制 编辑 原始数据 按行查看 历史
Wang Yang 提交于 2024-07-14 02:17 . 完善release脚本, 方便版本发布
#!/usr/bin/env bash
cd "$(dirname "$0")"
PROJECT_DIR=$(pwd)
CMAKE_VS_DIR="$PROJECT_DIR/build"
# 如果是在 vscode 里面调用, 那么不给错误码, 否则会导致 vscode tasks 无法正常执行任务并显示错误.
if [[ "$TERM_PROGRAM" =~ vscode ]]; then
export EXIT_WHEN_FAILED=false
else
export EXIT_WHEN_FAILED=true
fi
export BUILD_TARGET="xege" # 默认只构建 xege 静态库
# 默认开Release模式
export CMAKE_BUILD_TYPE="Release"
if [[ -z "$WIN_CMAKE_BUILD_DEFINE" ]]; then
export WIN_CMAKE_BUILD_DEFINE=""
fi
if [[ -z "$CMAKE_CONFIG_DEFINE" ]]; then
export CMAKE_CONFIG_DEFINE=""
fi
function MY_CMAKE_BUILD_DEFINE() {
echo "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} ${CMAKE_CONFIG_DEFINE}"
}
if ! command -v grealpath && command -v realpath; then
function grealpath() {
realpath $@
}
fi
function isWindows() {
# check mingw and cygwin
[[ -d "/c" ]] || [[ -d "/cygdrive/c" ]]
}
function loadCMakeProject() {
echo "Run cmake command: cmake "$(MY_CMAKE_BUILD_DEFINE)" .."
if mkdir -p "$CMAKE_VS_DIR" &&
cd "$CMAKE_VS_DIR" &&
cmake $(MY_CMAKE_BUILD_DEFINE) ..; then
echo "CMake Project Loaded: MY_CMAKE_BUILD_DEFINE=$(MY_CMAKE_BUILD_DEFINE)"
else
echo "CMake Project Load Failed!"
exit 1
fi
}
function cmakeCleanAll() {
pushd $PROJECT_DIR
git clean -ffdx build
popd
}
function reloadCMakeProject() {
cmakeCleanAll && loadCMakeProject
}
function cmakeBuildAll() {
pushd "$CMAKE_VS_DIR"
if isWindows; then
if [[ -n "$CMAKE_BUILD_TYPE" ]]; then
export WIN_CMAKE_BUILD_DEFINE="$WIN_CMAKE_BUILD_DEFINE --config $CMAKE_BUILD_TYPE"
fi
echo start: cmake.exe --build . --target "$BUILD_TARGET" $WIN_CMAKE_BUILD_DEFINE -- /m
# ref: https://stackoverflow.com/questions/11865085/out-of-a-git-console-how-do-i-execute-a-batch-file-and-then-return-to-git-conso
if ! cmd "/C cmake.exe --build . --target "$BUILD_TARGET" $WIN_CMAKE_BUILD_DEFINE -- /m" && $EXIT_WHEN_FAILED; then
exit 1
fi
echo end: cmake.exe --build . --target "$BUILD_TARGET" $WIN_CMAKE_BUILD_DEFINE -- /m
else
if ! cmake --build . --target "$BUILD_TARGET" $(test -n "$CMAKE_BUILD_TYPE" && echo --config $CMAKE_BUILD_TYPE) -- -j $(nproc) && $EXIT_WHEN_FAILED; then
exit 1
fi
fi
popd
}
if [[ $# -eq 0 ]]; then
echo "usage: [--load] [--reload] [--clean] [--build]"
fi
while [[ $# > 0 ]]; do
PARSE_KEY="$1"
case "$PARSE_KEY" in
--load)
echo "loadCMakeProject"
loadCMakeProject
shift # past argument
;;
--reload)
echo "reloadCMakeProject"
reloadCMakeProject
shift # past argument
;;
--clean)
echo "clean"
cmakeCleanAll
shift # past argument
;;
--build)
echo "build"
if [[ ! -f "$CMAKE_VS_DIR/CMakeCache.txt" ]]; then
loadCMakeProject
fi
cmakeBuildAll
shift # past argument
;;
--debug)
echo "enable debug mode"
export CMAKE_BUILD_TYPE="Debug"
shift
;;
--release)
echo "enable release mode"
export CMAKE_BUILD_TYPE="Release"
shift # past argument
;;
--target)
echo "set build target to $2"
export BUILD_TARGET="$2"
shift
shift
;;
--toolset)
echo "set toolset to $2"
export CMAKE_CONFIG_DEFINE="$CMAKE_CONFIG_DEFINE -T $2"
shift
shift
;;
--arch)
echo "set arch to $2"
export CMAKE_CONFIG_DEFINE="$CMAKE_CONFIG_DEFINE -A $2"
shift
shift
;;
--run)
if isWindows; then
echo "run $CMAKE_VS_DIR/$CMAKE_BUILD_TYPE/$2"
"$CMAKE_VS_DIR/$CMAKE_BUILD_TYPE/$2"
else
echo run "$CMAKE_VS_DIR/$2"
if command -v wine64 &>/dev/null; then
wine64 "$CMAKE_VS_DIR/$2"
else
echo "Command 'wine64' not found, please install wine first."
fi
fi
shift
shift
;;
*)
echo "unknown option $PARSE_KEY..."
exit 1
;;
esac
done
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/enwa/xege.git
git@gitee.com:enwa/xege.git
enwa
xege
xege
master

搜索帮助