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

相关推荐
我们的五年11 分钟前
【Linux课程学习】:进程描述---PCB(Process Control Block)
linux·运维·c++
程序猿阿伟27 分钟前
《C++ 实现区块链:区块时间戳的存储与验证机制解析》
开发语言·c++·区块链
爱摸鱼的孔乙己1 小时前
【数据结构】链表(leetcode)
c语言·数据结构·c++·链表·csdn
烦躁的大鼻嘎2 小时前
模拟算法实例讲解:从理论到实践的编程之旅
数据结构·c++·算法·leetcode
IU宝2 小时前
C/C++内存管理
java·c语言·c++
fhvyxyci2 小时前
【C++之STL】摸清 string 的模拟实现(下)
开发语言·c++·string
C++忠实粉丝2 小时前
计算机网络socket编程(4)_TCP socket API 详解
网络·数据结构·c++·网络协议·tcp/ip·计算机网络·算法
古月居GYH2 小时前
在C++上实现反射用法
java·开发语言·c++
Betty’s Sweet2 小时前
[C++]:IO流
c++·文件·fstream·sstream·iostream
敲上瘾2 小时前
操作系统的理解
linux·运维·服务器·c++·大模型·操作系统·aigc