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

相关推荐
Merokes3 小时前
关于Gstreamer+MPP硬件加速推流问题:视频输入video0被占用
c++·音视频·rk3588
请来次降维打击!!!4 小时前
优选算法系列(5.位运算)
java·前端·c++·算法
别NULL4 小时前
机试题——统计最少媒体包发送源个数
c++·算法·媒体
嘤国大力士5 小时前
C++11&QT复习 (七)
java·c++·qt
背影疾风5 小时前
C++学习之路:指针基础
c++·学习
x-cmd5 小时前
[250331] Paozhu 发布 1.9.0:C++ Web 框架,比肩脚本语言 | DeaDBeeF 播放器发布 1.10.0
android·linux·开发语言·c++·web·音乐播放器·脚本语言
myloveasuka5 小时前
[Linux]从硬件到软件理解操作系统
linux·开发语言·c++
UpUpUp……5 小时前
特殊类的设计/单例模式
开发语言·c++·笔记·单例模式
苏克贝塔6 小时前
CMake学习--Window下VSCode 中 CMake C++ 代码调试操作方法
c++·vscode·学习
嘤国大力士6 小时前
C++11&QT复习 (十一)
开发语言·c++·qt