杂记9---C++工程目录一键生成脚本分享

背景:新开发一个算法时,总会新建一系列文件,这里汇总成一个脚本,方便使用。此次,分享给大家。环境,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

相关推荐
南巷逸清风25 分钟前
LeetCode 101.对称二叉树
c++·python·算法·leetcode
七月巫山晴38 分钟前
QChart中柱形图的简单使用并实现【Qt】
开发语言·数据结构·c++·qt·算法·排序算法
风清扬_jd44 分钟前
Chromium HTML5 新的 Input 类型time对应c++
java·c++·html5
风清扬_jd44 分钟前
Chromium HTML5 新的 Input 类型search对应c++
前端·c++·html5
yy_xzz2 小时前
QLineEdit 控件在设置了 QDoubleValidator 之后无法正确输入小数
c++·qt
ya888g3 小时前
信息学奥赛复赛复习19-CSP-J2023-02公路-贪心算法、向上取整、向下取整
c++·算法
#Y清墨3 小时前
STL映射
数据结构·c++
无职转生真好看3 小时前
数据结构:利用队列的基本操作,模拟病人到医院排队看病过程。
数据结构·c++·算法
Death2005 小时前
PCL库中的算法封装详解
c++·qt·算法·3d
勇敢滴勇5 小时前
【C++】继承和多态常见的面试问题
java·c++·面试