背景:新开发一个算法时,总会新建一系列文件,这里汇总成一个脚本,方便使用。此次,分享给大家。环境,ubuntu20.04
一、一键工程模板
脚本名称,create_project.sh
powershell
#!/bin/bash
#edit by ylh 2024.10.16
# Ask for the project name
read -p "Enter project name: " project_name
# Check if the project name is empty
if [ -z "$project_name" ]; then
echo "Project name cannot be empty."
exit 1
fi
# Check if the project name already exists
if [ -d "$project_name" ]; then
echo "Project name already exists."
exit 1
fi
# Create the project directory
mkdir -p "$project_name"
# Create basic directory structure
mkdir -p "$project_name/src"
mkdir -p "$project_name/include"
mkdir -p "$project_name/thirdparty"
mkdir -p "$project_name/test"
mkdir -p "$project_name/script"
mkdir -p "$project_name/data"
mkdir -p "$project_name/config"
# Create demo files
touch "$project_name/src/demo.cpp"
touch "$project_name/include/demo.h"
touch "$project_name/test/test_demo.cpp"
# Create a CMakeLists.txt file
echo "cmake_minimum_required(VERSION 3.10)" > "$project_name/CMakeLists.txt"
echo "project($project_name)" >> "$project_name/CMakeLists.txt"
echo "set(CMAKE_RUNTIME_OUTPUT_DIRECTORY \${PROJECT_SOURCE_DIR}/bin)" >> "$project_name/CMakeLists.txt"
echo "set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY \${PROJECT_SOURCE_DIR}/lib)" >> "$project_name/CMakeLists.txt"
echo "add_executable(\${PROJECT_NAME} src/main.cpp)" >> "$project_name/CMakeLists.txt"
# create build.sh file
echo "#!/bin/bash" > "$project_name/build.sh"
echo "rm -r ./build ./bin" >> "$project_name/build.sh"
echo "rm -r ./build ./bin" >> "$project_name/build.sh"
echo "mkdir build && cd build" >> "$project_name/build.sh"
echo "cmake .. && make -j24" >> "$project_name/build.sh"
# create clear.sh file
echo "#!/bin/bash" > "$project_name/clear.sh"
echo "rm -r ./build ./bin" >> "$project_name/clear.sh"
# Create a README file
echo "# $project_name" > "$project_name/README.md"
echo "This is a new project : $project_name ." >> "$project_name/README.md"
echo "Project $project_name created successfully!"
二、小结
每个文件作用,老司机应该一眼看懂!不清出的,可以评论留言。
#############
积跬步期千里
觉得不错的话,点赞收藏
20241016