杂记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

相关推荐
charlie1145141911 分钟前
C++ STL CookBook
开发语言·c++·stl·c++20
小林熬夜学编程12 分钟前
【Linux网络编程】第十四弹---构建功能丰富的HTTP服务器:从状态码处理到服务函数扩展
linux·运维·服务器·c语言·网络·c++·http
倔强的石头10623 分钟前
【C++指南】类和对象(九):内部类
开发语言·c++
A懿轩A2 小时前
C/C++ 数据结构与算法【数组】 数组详细解析【日常学习,考研必备】带图+详细代码
c语言·数据结构·c++·学习·考研·算法·数组
机器视觉知识推荐、就业指导2 小时前
C++设计模式:享元模式 (附文字处理系统中的字符对象案例)
c++
半盏茶香2 小时前
在21世纪的我用C语言探寻世界本质 ——编译和链接(编译环境和运行环境)
c语言·开发语言·c++·算法
Ronin3053 小时前
11.vector的介绍及模拟实现
开发语言·c++
✿ ༺ ོIT技术༻3 小时前
C++11:新特性&右值引用&移动语义
linux·数据结构·c++
字节高级特工3 小时前
【C++】深入剖析默认成员函数3:拷贝构造函数
c语言·c++
唐诺9 小时前
几种广泛使用的 C++ 编译器
c++·编译器