Skip to content

Commit 651dddb

Browse files
committed
update config
1 parent 2af9c27 commit 651dddb

4 files changed

Lines changed: 202 additions & 0 deletions

File tree

‎.vscode/launch.json‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
5+
{
6+
"name": "g++ - Build and debug active file",
7+
"type": "cppdbg",
8+
"request": "launch",
9+
"program": "${fileDirname}/${fileBasenameNoExtension}",
10+
"args": [],
11+
"stopAtEntry": false,
12+
"cwd": "${fileDirname}",
13+
"environment": [],
14+
"externalConsole": false,
15+
"MIMode": "gdb",
16+
"setupCommands": [
17+
{
18+
"description": "Enable pretty-printing for gdb",
19+
"text": "-enable-pretty-printing",
20+
"ignoreFailures": true
21+
}
22+
],
23+
"preLaunchTask": "C/C++: g++ build active file",
24+
"miDebuggerPath": "/usr/bin/gdb"
25+
}
26+
]
27+
}

‎.vscode/tasks.json‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"type": "cppbuild",
6+
"label": "C/C++: g++ build active file",
7+
"command": "/usr/bin/g++",
8+
"args": [
9+
"-g",
10+
"${file}",
11+
"-o",
12+
"${fileDirname}/${fileBasenameNoExtension}"
13+
],
14+
"options": {
15+
"cwd": "${fileDirname}"
16+
},
17+
"problemMatcher": [
18+
"$gcc"
19+
],
20+
"group": {
21+
"kind": "build",
22+
"isDefault": true
23+
},
24+
"detail": "compiler: /usr/bin/g++"
25+
}
26+
]
27+
}

‎LICENSE‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"License" shall mean the terms and conditions for use, reproduction,
1010
and distribution as defined by Sections 1 through 9 of this document.
1111

12+
1213
"Licensor" shall mean the copyright owner or entity authorized by
1314
the copyright owner that is granting the License.
1415

‎README.md‎

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,149 @@
11
# cppdev
22
my template for cpp
3+
4+
from: https://github.com/hattonl/cpp-project-structure.git
5+
6+
7+
8+
9+
# 顶层目录结构
10+
11+
```shell
12+
project_name
13+
├── deploy
14+
├── build
15+
├── doc
16+
├── 3rdparty
17+
├── include
18+
│ └── project_name
19+
├── project_name
20+
├── tools
21+
├── scripts
22+
├── platforms
23+
├── test
24+
├── LICENSE
25+
├── CMakeLists.txt
26+
├── build.sh
27+
├── toolchain.cmake
28+
├── .gitignore
29+
├── readme.md
30+
└── sample
31+
```
32+
33+
- **deploy :** 用于存放部署、交付的文件,其包含子目录bin、lib、include分别存放本项目最总生成的可执行文件、库文件以及对外所提供的头文件。
34+
- **build :** 用于存放build时cmake产生的中间文件,其包含子目录release和debug。
35+
- **doc :** 用于存放项目的相关文档。
36+
- **3rdparty :** 用于存放第三方库,每个第三库以单独目录的形式组织在3rdparty目录下。其中每个第三方目录下又有 `include` 和 `lib` 分别存放第三方库的头文件和库文件。
37+
- **include/project_name :** 用于存放每个模块以及整个工程对外的头文件。具体格式如下文。
38+
- **project_name :** 存放源码文件,以及内部头文件。具体格式如下文。
39+
- **tools :** 包含一些支持项目构建的工具,如编译器等,一般情况下使用软链接。
40+
- **scripts :** 包含一些脚本文件,如使用Jenkins进行自动化构建时所需要的脚本文件,以及一些用于预处理的脚本文件。
41+
- **platforms :** 用于一些交叉编译时所需要的工具链等文件,按照平台进行划分来组织子目录。每个子目录下存放 `toolchain.cmake` 等用于指定平台的文件。
42+
- **test :** 分模块存放测试代码。
43+
- **LICENSE :** 版权信息说明。
44+
- **CMakeLists.txt :** cmake文件。
45+
- **build.sh :** build脚本文件。
46+
- **.gitignore :** 指明git忽略规则。
47+
- **readme.md :** 存放工程说明文件。
48+
- **sample :** 存放示例代码。
49+
50+
# 源文件目录结构说明
51+
52+
结构示例:
53+
54+
```shell
55+
# example modules tree
56+
project_name
57+
├── module_1
58+
│   ├── dir_1
59+
│ │   ├── something.cc
60+
│ │   └── something.h
61+
│   ├── dir_2
62+
│   ├── module_1.cc
63+
│   ├── CMakeLists.txt
64+
│   └── README.md
65+
├── module_2
66+
│   ├── dir_1
67+
│   ├── dir_2
68+
│   ├── module_2.cc
69+
│   ├── CMakeLists.txt
70+
│   └── README.md
71+
├── module_3
72+
├── main.cc
73+
└── CMakeLists.txt
74+
```
75+
76+
1. 总源码文件目录以 `project_name` 命名,即与项目同名,存放在项目根目录下。
77+
2. 源码文件分模块进行组织,分别以各个模块进行命名存放在 `project_name` 目录下,如示例中的 `module_1` 、`module_2`。
78+
3. 在每个子模块目录下,只包含源文件以及该模块内部所调用的头文件。
79+
4. 每个子模块的根目录下存放该模块的主要功能逻辑代码,如 `module_1.cc`。另外,可按照功能再划分子目录进行源码组织,但不可以出现模块嵌套的情况。
80+
5. 若要包含内部头文件时,包含路径要从 `project_name` 开始路径要完整,如`#include "project_name/module1/dir_1/somthing.h"`,以防止头文件名称冲突的情况,同时遵循了[Google C++编码规范](https://zh-google-styleguide.readthedocs.io/en/latest/google-cpp-styleguide/contents/)。
81+
82+
# 头文件目录结构说明
83+
84+
```shell
85+
# example include tree
86+
include
87+
└── project_name
88+
├── module_1
89+
│   ├── module_1_header_1.h
90+
│   └── module_1_header_2.h
91+
├── module_2
92+
│   └── module_2.h
93+
└── project_name.h
94+
```
95+
96+
1. (公共)头文件目录以 `include/project_name` 命名,即文件目录为两级,存放在项目根目录下。该目录只包含所有对外的头文件。
97+
2. 头文件同样分模块进行组织,分别以各个模块进行命名存放在 `include/project_name` 目录下,如示例中的 `module_1` 、`module_1`。
98+
3. `include/project_name` 目录下最多只包含一级子目录,即最多按照模块再划分一级,模块内的功能头文件不再以功能进行划分。
99+
4. 若要包含外部头文件时,包含路径同样要从 `project_name` 开始路径要完整,如`#include "project_name/module_2/module_2.h"`。
100+
101+
# 其他
102+
103+
1. 针对头文件的包含,顶层 `CMakeLists.txt` 只指定 `${CMAKE_SOURCE_DIR}\include` 和 `${CMAKE_SOURCE_DIR}`,以保证所有的包含规则都是从工程根目录开始包含。
104+
2. 添加 `include` 目录使得公共头文件和对内部文件可以分离开,使多个模块之间合作开发时项目内部结构更加清晰。
105+
5. (暂时)在 `3rdparty` 下存放的工程中用到的第三方库和第三方源码。第三方库尽量不要直接把静态连接库直接放到git仓库中,应该另外提供链接以便下载,或者提供文档说明库的名称和版本自行安装下载,或者提供git仓库自行编译。第三方源码一般为开源的,只提供git链接。
106+
107+
# TODO
108+
109+
1. 添加cmake示例。
110+
2. 添加简单工程示例。
111+
112+
# 参考
113+
114+
大型项目CMakeLIsts.txt的编写规范
115+
https://blog.csdn.net/dongfang1984/article/details/55105537
116+
117+
CmakeLists.txt书写规范
118+
https://blog.csdn.net/csdnhuaong/article/details/80895679
119+
120+
cmake简介与编写规范
121+
http://675816156.github.io/2016/06/26/cmake%E7%AE%80%E4%BB%8B%E4%B8%8E%E7%BC%96%E5%86%99%E8%A7%84%E8%8C%83/
122+
123+
C++工程目录架构推荐
124+
https://www.cnblogs.com/kuliuheng/p/5729559.html
125+
126+
A Simple C++ Project Structure
127+
https://hiltmon.com/blog/2013/07/03/a-simple-c-plus-plus-project-structure/
128+
129+
Directory Structure for a C++ Project
130+
https://mariuszbartosik.com/directory-structure-for-a-c-project/
131+
132+
C++ application development ( Part 1 — Project structure )
133+
https://medium.com/heuristics/c-application-development-part-1-project-structure-454b00f9eddc
134+
135+
AakashMallik/C++ project structure (与上个参考重)
136+
https://gist.github.com/AakashMallik/f7451b09a0807ed7203fb97cd125bff5#file-c-project-structure
137+
138+
Filesystem Hierarchy Standard
139+
http://www.pathname.com/fhs/pub/fhs-2.3.html
140+
141+
How to structure your project
142+
https://cliutils.gitlab.io/modern-cmake/chapters/basics/structure.html
143+
144+
kigster/cmake-project-template
145+
https://github.com/kigster/cmake-project-template
146+
147+
opencv/opencv
148+
https://github.com/opencv/opencv
149+

0 commit comments

Comments
 (0)