@chengzhao-dev/dsh-cpp-workflow 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +14 -11
- package/README.md +14 -11
- package/lib/index.js +4 -4
- package/lib/workspace.js +1 -56
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +2 -2
- package/skills/building-cpp/SKILL.md +25 -12
- package/skills/building-cpp/assets/config/.clang-tidy +1 -0
- package/skills/building-cpp/assets/templates/projects/multi/CMakeLists.txt +2 -2
- package/skills/building-cpp/assets/templates/projects/shared-library/CMakeLists.txt +1 -1
- package/skills/building-cpp/assets/templates/projects/shared-library/greeting/CMakeLists.txt +1 -1
- package/skills/building-cpp/assets/templates/projects/single/CMakeLists.txt +1 -1
- package/skills/building-cpp/assets/templates/projects/static-library/CMakeLists.txt +1 -1
- package/skills/building-cpp/assets/templates/projects/static-library/greeting/CMakeLists.txt +1 -1
- package/skills/building-cpp/examples/tooling.md +3 -3
- package/skills/building-cpp/references/build-script.md +11 -0
- package/skills/building-cpp/references/linking.md +7 -7
- package/skills/building-cpp/references/standards/README.md +1 -1
- package/skills/building-cpp/references/static-analysis.md +3 -3
- package/skills/building-cpp/steps/01-build.md +22 -35
- package/skills/building-cpp/steps/02-tooling.md +2 -2
- package/skills/configuring-cmake/SKILL.md +57 -0
- package/skills/configuring-cmake/assets/cmake/CompileSettings.cmake +126 -0
- package/skills/configuring-cmake/assets/cmake/LinkSettings.cmake +48 -0
- package/skills/configuring-cmake/examples/cmake.md +224 -0
- package/skills/{building-cpp → configuring-cmake}/references/cmake.md +54 -48
- package/skills/configuring-cmake/references/cxx-standard.md +67 -0
- package/skills/configuring-cmake/references/modules.md +105 -0
- package/skills/configuring-cmake/steps/01-targets.md +53 -0
- package/skills/configuring-cmake/steps/02-modules.md +37 -0
- package/skills/configuring-cmake/steps/03-check.md +39 -0
- package/skills/developing-cpp/SKILL.md +17 -3
- package/skills/developing-cpp/examples/comments.md +173 -136
- package/skills/developing-cpp/examples/exceptions.md +38 -19
- package/skills/developing-cpp/examples/structure.md +75 -4
- package/skills/developing-cpp/references/comments.md +82 -99
- package/skills/developing-cpp/references/declaration-order.md +4 -2
- package/skills/developing-cpp/references/exceptions.md +12 -13
- package/skills/developing-cpp/references/file-template.md +131 -0
- package/skills/developing-cpp/references/glossary.md +3 -3
- package/skills/developing-cpp/references/google-cpp-style.md +8 -8
- package/skills/developing-cpp/references/language.md +4 -3
- package/skills/developing-cpp/references/layout.md +21 -12
- package/skills/developing-cpp/references/naming.md +5 -4
- package/skills/developing-cpp/references/project-design.md +1 -1
- package/skills/developing-cpp/references/standard-library.md +2 -1
- package/skills/developing-cpp/references/types.md +1 -2
- package/skills/developing-cpp/scripts/checking-comments.mjs +371 -0
- package/skills/developing-cpp/steps/01-behavior.md +1 -1
- package/skills/developing-cpp/steps/02-boundary.md +4 -4
- package/skills/developing-cpp/steps/03-declaration.md +7 -7
- package/skills/developing-cpp/steps/04-implementation.md +6 -5
- package/skills/building-cpp/assets/cmake/applying-warnings.cmake +0 -10
- package/skills/building-cpp/assets/cmake/fetching-googletest.cmake +0 -15
- package/skills/building-cpp/assets/cmake/setting-rpath.cmake +0 -8
- package/skills/building-cpp/examples/cmake.md +0 -150
- /package/skills/building-cpp/assets/templates/projects/multi/src/{greeting.cc → greeting.cpp} +0 -0
- /package/skills/building-cpp/assets/templates/projects/multi/src/{main.cc → main.cpp} +0 -0
- /package/skills/building-cpp/assets/templates/projects/shared-library/greeting/src/{greeting.cc → greeting.cpp} +0 -0
- /package/skills/building-cpp/assets/templates/projects/shared-library/src/{main.cc → main.cpp} +0 -0
- /package/skills/building-cpp/assets/templates/projects/single/src/{main.cc → main.cpp} +0 -0
- /package/skills/building-cpp/assets/templates/projects/static-library/greeting/src/{greeting.cc → greeting.cpp} +0 -0
- /package/skills/building-cpp/assets/templates/projects/static-library/src/{main.cc → main.cpp} +0 -0
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
# 正反例:CMake
|
|
2
|
-
|
|
3
|
-
## 最小可用形状
|
|
4
|
-
|
|
5
|
-
```cmake
|
|
6
|
-
cmake_minimum_required(VERSION 3.20)
|
|
7
|
-
project(greeter VERSION 0.1.0 LANGUAGES CXX)
|
|
8
|
-
|
|
9
|
-
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
10
|
-
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
|
11
|
-
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
|
|
12
|
-
|
|
13
|
-
add_library(greeting STATIC greeting/src/greeting.cc)
|
|
14
|
-
target_include_directories(greeting PUBLIC greeting/include)
|
|
15
|
-
target_compile_features(greeting PUBLIC cxx_std_23)
|
|
16
|
-
set_target_properties(greeting PROPERTIES CXX_EXTENSIONS OFF)
|
|
17
|
-
target_compile_options(greeting PRIVATE -Wall -Wextra -Werror)
|
|
18
|
-
|
|
19
|
-
add_executable(app src/main.cc)
|
|
20
|
-
target_compile_features(app PRIVATE cxx_std_23)
|
|
21
|
-
set_target_properties(app PROPERTIES CXX_EXTENSIONS OFF)
|
|
22
|
-
target_link_libraries(app PRIVATE greeting)
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
程序只写 `#include "greeting.h"`;公共 include 根由库的 `PUBLIC` 传过来。
|
|
26
|
-
|
|
27
|
-
## 全局 include
|
|
28
|
-
|
|
29
|
-
**差**:
|
|
30
|
-
|
|
31
|
-
```cmake
|
|
32
|
-
include_directories(include greeting/include)
|
|
33
|
-
add_executable(app src/main.cc greeting/src/greeting.cc)
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
问题:所有 target 共享 include,边界消失;程序直接编译库源码,测试无法只链接库。
|
|
37
|
-
|
|
38
|
-
**好**:
|
|
39
|
-
|
|
40
|
-
```cmake
|
|
41
|
-
target_include_directories(greeting PUBLIC greeting/include)
|
|
42
|
-
target_link_libraries(app PRIVATE greeting)
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
## GLOB
|
|
46
|
-
|
|
47
|
-
**差**:
|
|
48
|
-
|
|
49
|
-
```cmake
|
|
50
|
-
file(GLOB SOURCES "src/*.cc")
|
|
51
|
-
add_executable(app ${SOURCES})
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
新增文件不触发重新配置;不同机器上的文件集合可能不同。
|
|
55
|
-
|
|
56
|
-
**好**:
|
|
57
|
-
|
|
58
|
-
```cmake
|
|
59
|
-
add_executable(app
|
|
60
|
-
src/main.cc
|
|
61
|
-
src/task_list.cc
|
|
62
|
-
src/task_parser.cc
|
|
63
|
-
)
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
显式列表,新增文件时改 CMake;diff 能看出变化。
|
|
67
|
-
|
|
68
|
-
## 把 `main()` 编进库
|
|
69
|
-
|
|
70
|
-
**差**:
|
|
71
|
-
|
|
72
|
-
```cmake
|
|
73
|
-
add_library(core STATIC src/main.cc src/core.cc)
|
|
74
|
-
add_executable(app src/main.cc) # 重复定义
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
**好**:
|
|
78
|
-
|
|
79
|
-
```cmake
|
|
80
|
-
add_library(core STATIC src/core.cc)
|
|
81
|
-
add_executable(app src/main.cc)
|
|
82
|
-
target_link_libraries(app PRIVATE core)
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
库不依赖 `main()`;测试链接库时不会碰到入口。
|
|
86
|
-
|
|
87
|
-
## 编译数据库
|
|
88
|
-
|
|
89
|
-
**差**:
|
|
90
|
-
|
|
91
|
-
```cmake
|
|
92
|
-
# 没开导出
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
```bash
|
|
96
|
-
clang-tidy src/main.cc # 没有编译参数,头路径和标准都不对
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
**好**:
|
|
100
|
-
|
|
101
|
-
```cmake
|
|
102
|
-
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
```bash
|
|
106
|
-
cmake -S . -B build/clang -G Ninja -DCMAKE_CXX_COMPILER=clang++
|
|
107
|
-
rm -f build/compile_commands.json
|
|
108
|
-
ln -s clang/compile_commands.json build/compile_commands.json
|
|
109
|
-
clang-tidy -p build/clang src/main.cc
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
## 共享库运行时路径
|
|
113
|
-
|
|
114
|
-
**差**:
|
|
115
|
-
|
|
116
|
-
```bash
|
|
117
|
-
LD_LIBRARY_PATH=build/clang/lib ./build/clang/bin/app # 每次运行都要包一层
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
**好**:
|
|
121
|
-
|
|
122
|
-
```cmake
|
|
123
|
-
add_library(greeting SHARED greeting/src/greeting.cc)
|
|
124
|
-
set_target_properties(greeting PROPERTIES
|
|
125
|
-
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
|
|
126
|
-
|
|
127
|
-
add_executable(app src/main.cc)
|
|
128
|
-
target_link_libraries(app PRIVATE greeting)
|
|
129
|
-
if(APPLE)
|
|
130
|
-
set_target_properties(app PROPERTIES BUILD_RPATH "@loader_path/../lib")
|
|
131
|
-
else()
|
|
132
|
-
set_target_properties(app PROPERTIES BUILD_RPATH "$ORIGIN/../lib")
|
|
133
|
-
endif()
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
从 `build/<compiler>/bin/app` 直接启动即可找到同级 `../lib` 下的共享库;安装场景另配 RPATH。
|
|
137
|
-
|
|
138
|
-
## 输出目录
|
|
139
|
-
|
|
140
|
-
**差**:可执行文件生成在源码根,`git status` 出现 `app`、`*.o`。
|
|
141
|
-
|
|
142
|
-
**好**:
|
|
143
|
-
|
|
144
|
-
```cmake
|
|
145
|
-
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
|
146
|
-
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
|
|
147
|
-
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
构建产物全在 `build/<compiler>/` 下。
|
/package/skills/building-cpp/assets/templates/projects/multi/src/{greeting.cc → greeting.cpp}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/skills/building-cpp/assets/templates/projects/shared-library/src/{main.cc → main.cpp}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/skills/building-cpp/assets/templates/projects/static-library/src/{main.cc → main.cpp}
RENAMED
|
File without changes
|