当前位置: 首页 > article >正文

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

背景:新开发一个算法时,总会新建一系列文件,这里汇总成一个脚本,方便使用。此次,分享给大家。环境,ubuntu20.04

一、一键工程模板

脚本名称,create_project.sh

#!/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


http://www.kler.cn/a/349882.html

相关文章:

  • 大模型本地部署流程介绍
  • (学习总结21)C++11 异常与智能指针
  • Julia Distributed(分布式计算)详解
  • Oracle之Merge into函数使用
  • Padas进行MongoDB数据库CRUD
  • 浅谈Linux 权限、压缩、进程与服务
  • 2015年-2016年 软件工程程序设计题(算法题)实战_c语言程序设计数据结构程序设计分析
  • Spring Security自定义登录接口处理JSON请求体
  • 开源OpenStack
  • 施磊C++ | 进阶学习笔记 | 5.设计模式
  • H3Linux部署iMC智能管理中心平台PLAT-7.3_E0706实验
  • 基于java SpringBoot和Vue校园食堂网站管理系统设计
  • 51 | 适配器模式:代理、适配器、桥接、装饰,这四个模式有何区别?
  • 【数据结构】之学习路线
  • 【Sceneform-EQR】(手势优化)通过手势事件实现在AR/VR等三维场景中的控制模型旋转、平移与缩放
  • linux_find命令
  • SQL分类中的DCL
  • [LeetCode 题1] 两数之和
  • uni-app中添加自定义相机(微信小程序+app)
  • 三、账号密码存储
  • 企业资产安全之数据防泄密要领
  • 农作物柑橘病虫害识别数据集
  • 双十一数码好物怎么入手最划算?这五款数码好物闭眼入也不踩雷
  • 炸锅了!大语言模型直言能替代 20 种人类工作,你需不需要转行?速看!
  • 数制转换及交换机
  • 数据结构-顺序栈