@chengzhao-dev/dsh-cpp-workflow 0.6.20 → 0.7.1

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.
Files changed (173) hide show
  1. package/README.en.md +10 -25
  2. package/README.md +12 -27
  3. package/cordis.patch.yml +1 -1
  4. package/lib/client.js +33 -21
  5. package/lib/comment-policy.js +15 -6
  6. package/lib/workspace.js +0 -15
  7. package/package.json +7 -7
  8. package/skills/building-cpp/SKILL.md +23 -23
  9. package/skills/building-cpp/assets/templates/projects/common/running-build.sh +5 -1
  10. package/skills/building-cpp/project/vscode/01-extensions.md +6 -0
  11. package/skills/building-cpp/project/vscode/02-settings.md +7 -1
  12. package/skills/building-cpp/references/build-script.md +10 -3
  13. package/skills/building-cpp/references/environment.md +8 -1
  14. package/skills/building-cpp/steps/01-build.md +4 -4
  15. package/skills/building-cpp/steps/02-tooling.md +10 -10
  16. package/skills/building-cpp/steps/03-check.md +13 -11
  17. package/skills/developing-cpp/SKILL.md +32 -36
  18. package/skills/developing-cpp/references/comments/comment-rules.md +181 -0
  19. package/skills/developing-cpp/references/comments/comment-style.md +80 -0
  20. package/skills/developing-cpp/{source/07-comments → references/comments}/examples/declaration-class.md +24 -2
  21. package/skills/developing-cpp/references/comments/examples/declaration-constructor.md +22 -0
  22. package/skills/developing-cpp/references/comments/examples/declaration-enum.md +48 -0
  23. package/skills/developing-cpp/{source/07-comments → references/comments}/examples/declaration-file.md +3 -3
  24. package/skills/developing-cpp/references/comments/examples/declaration-function.md +127 -0
  25. package/skills/developing-cpp/{source/07-comments → references/comments}/examples/declaration-member.md +7 -9
  26. package/skills/developing-cpp/{source/07-comments → references/comments}/examples/declaration-predicate.md +2 -1
  27. package/skills/developing-cpp/references/comments/examples/declaration-struct.md +18 -0
  28. package/skills/developing-cpp/references/comments/examples/implementation-body.md +64 -0
  29. package/skills/developing-cpp/references/comments/glossary/comment-terms.md +93 -0
  30. package/skills/developing-cpp/references/design/examples/move-result.md +39 -0
  31. package/skills/developing-cpp/{source/03-design → references/design}/examples/preview-read.md +7 -7
  32. package/skills/developing-cpp/{source/03-design/01-project-design.md → references/design/project-design.md} +57 -5
  33. package/skills/developing-cpp/{source/01-editing → references/editing}/01-edit-operations.md +4 -2
  34. package/skills/developing-cpp/{source/01-editing → references/editing}/02-rule-priority.md +2 -2
  35. package/skills/developing-cpp/{source/08-exceptions → references/exceptions}/examples/throw-build-mode.md +2 -2
  36. package/skills/developing-cpp/{source/08-exceptions → references/exceptions}/examples/throw-message.md +2 -3
  37. package/skills/developing-cpp/{source/08-exceptions/01-throw-rules.md → references/exceptions/throw-rules.md} +74 -21
  38. package/skills/developing-cpp/{source/05-language → references/language}/glossary/language-terms.md +2 -2
  39. package/skills/developing-cpp/{source/05-language/01-language-basics → references/language/language-basics}/01-objects.md +7 -1
  40. package/skills/developing-cpp/{source/05-language/01-language-basics → references/language/language-basics}/02-initialization.md +8 -1
  41. package/skills/developing-cpp/{source/05-language/01-language-basics → references/language/language-basics}/03-deduction.md +6 -0
  42. package/skills/developing-cpp/references/language/language-basics/04-const.md +25 -0
  43. package/skills/developing-cpp/references/language/language-basics/05-expressions.md +23 -0
  44. package/skills/developing-cpp/{source/05-language/01-language-basics → references/language/language-basics}/06-functions.md +7 -1
  45. package/skills/developing-cpp/{source/05-language/01-language-basics → references/language/language-basics}/07-classes.md +7 -1
  46. package/skills/developing-cpp/references/language/language-basics/08-raii.md +15 -0
  47. package/skills/developing-cpp/{source/05-language/01-language-basics → references/language/language-basics}/09-templates.md +6 -0
  48. package/skills/developing-cpp/{source/05-language/01-language-basics → references/language/language-basics}/10-checklist.md +2 -1
  49. package/skills/developing-cpp/references/language/performance/01-measure.md +22 -0
  50. package/skills/developing-cpp/{source/05-language/04-performance → references/language/performance}/02-complexity.md +6 -0
  51. package/skills/developing-cpp/{source/05-language/04-performance → references/language/performance}/03-memory.md +7 -1
  52. package/skills/developing-cpp/{source/05-language/04-performance → references/language/performance}/04-undefined-behavior.md +9 -1
  53. package/skills/developing-cpp/{source/05-language/04-performance → references/language/performance}/05-pitfalls.md +6 -0
  54. package/skills/developing-cpp/references/language/performance/06-false-optimizations.md +13 -0
  55. package/skills/developing-cpp/{source/05-language/03-standard-library → references/language/standard-library}/01-containers.md +6 -0
  56. package/skills/developing-cpp/{source/05-language/03-standard-library → references/language/standard-library}/02-access.md +7 -1
  57. package/skills/developing-cpp/{source/05-language/03-standard-library → references/language/standard-library}/03-iteration.md +6 -0
  58. package/skills/developing-cpp/{source/05-language/03-standard-library → references/language/standard-library}/04-algorithms.md +6 -0
  59. package/skills/developing-cpp/{source/05-language/03-standard-library → references/language/standard-library}/05-string.md +6 -0
  60. package/skills/developing-cpp/references/language/standard-library/06-format.md +106 -0
  61. package/skills/developing-cpp/references/language/standard-library/07-time.md +13 -0
  62. package/skills/developing-cpp/references/language/standard-library/08-random.md +13 -0
  63. package/skills/developing-cpp/references/language/standard-library/09-files.md +14 -0
  64. package/skills/developing-cpp/{source/05-language/02-value-types → references/language/value-types}/01-width.md +6 -0
  65. package/skills/developing-cpp/{source/05-language/02-value-types → references/language/value-types}/02-signed.md +7 -1
  66. package/skills/developing-cpp/references/language/value-types/03-integer-roles.md +38 -0
  67. package/skills/developing-cpp/references/language/value-types/04-enum.md +24 -0
  68. package/skills/developing-cpp/{source/05-language/02-value-types → references/language/value-types}/06-const-method.md +5 -0
  69. package/skills/developing-cpp/{source/05-language/02-value-types → references/language/value-types}/07-nodiscard.md +6 -0
  70. package/skills/developing-cpp/references/language/value-types/08-comparison.md +10 -0
  71. package/skills/developing-cpp/{source/05-language/02-value-types → references/language/value-types}/09-subscript.md +2 -1
  72. package/skills/developing-cpp/{source/05-language/02-value-types → references/language/value-types}/10-float-bool.md +6 -0
  73. package/skills/developing-cpp/{source/05-language/02-value-types → references/language/value-types}/11-checklist.md +1 -1
  74. package/skills/developing-cpp/{source/04-layout → references/layout}/01-source-layout.md +8 -2
  75. package/skills/developing-cpp/{source/04-layout → references/layout}/02-file-template.md +10 -4
  76. package/skills/developing-cpp/references/layout/03-declaration-order.md +138 -0
  77. package/skills/developing-cpp/references/naming/examples/naming-basic.md +3 -0
  78. package/skills/developing-cpp/{source/06-naming → references/naming}/examples/naming-lower-layer.md +9 -9
  79. package/skills/developing-cpp/references/naming/examples/naming-player-value.md +16 -0
  80. package/skills/developing-cpp/references/naming/examples/naming-state-change.md +57 -0
  81. package/skills/developing-cpp/{source/06-naming/01-identifier-names.md → references/naming/identifier-names.md} +34 -8
  82. package/skills/developing-cpp/{source/02-style/01-google-cpp-style.md → references/style/google-cpp-style.md} +11 -10
  83. package/skills/developing-cpp/scripts/checking-comments.mjs +71 -14
  84. package/skills/developing-cpp/scripts/checking-declaration-order.mjs +357 -0
  85. package/skills/developing-cpp/steps/01-behavior.md +5 -5
  86. package/skills/developing-cpp/steps/02-boundary.md +9 -9
  87. package/skills/developing-cpp/steps/03-declaration.md +16 -14
  88. package/skills/developing-cpp/steps/04-implementation.md +21 -17
  89. package/skills/engineering/SKILL.md +41 -38
  90. package/skills/engineering/{cmake → references/cmake}/assets/CompileSettings.cmake +2 -0
  91. package/skills/engineering/{cmake → references/cmake}/linking/01-libraries.md +6 -0
  92. package/skills/engineering/references/cmake/linking/02-rpath.md +25 -0
  93. package/skills/engineering/{cmake → references/cmake}/linking/03-undefined-reference.md +6 -0
  94. package/skills/engineering/{cmake → references/cmake}/linking/04-inspect.md +6 -0
  95. package/skills/engineering/{cmake/02-modules/01-functions.md → references/cmake/modules/functions.md} +8 -5
  96. package/skills/engineering/{cmake/03-standard/01-cxx-standard.md → references/cmake/standard/cxx-standard.md} +5 -4
  97. package/skills/engineering/{cmake/03-standard → references/cmake/standard}/standards/README.md +8 -8
  98. package/skills/engineering/{cmake/01-targets → references/cmake/targets}/examples/target.md +1 -1
  99. package/skills/engineering/{cmake/01-targets/01-rules.md → references/cmake/targets/rules.md} +18 -11
  100. package/skills/engineering/{cmake → references/cmake}/testing/ctest.md +9 -2
  101. package/skills/engineering/{formatting → references/formatting}/01-encoding.md +1 -1
  102. package/skills/engineering/{formatting → references/formatting}/02-clang-format.md +6 -0
  103. package/skills/engineering/{formatting → references/formatting}/03-clang-tidy.md +7 -0
  104. package/skills/engineering/{formatting → references/formatting}/04-clangd.md +7 -0
  105. package/skills/engineering/references/formatting/examples/clang-format.md +38 -0
  106. package/skills/engineering/{formatting → references/formatting}/examples/clang-tidy.md +0 -21
  107. package/skills/engineering/{cmake/steps → steps}/01-targets.md +6 -6
  108. package/skills/engineering/{cmake/steps → steps}/02-modules.md +4 -4
  109. package/skills/engineering/{cmake/steps → steps}/03-check.md +3 -2
  110. package/skills/developing-cpp/source/03-design/examples/move-result.md +0 -39
  111. package/skills/developing-cpp/source/04-layout/03-declaration-order.md +0 -118
  112. package/skills/developing-cpp/source/05-language/01-language-basics/04-const.md +0 -15
  113. package/skills/developing-cpp/source/05-language/01-language-basics/05-expressions.md +0 -8
  114. package/skills/developing-cpp/source/05-language/01-language-basics/08-raii.md +0 -9
  115. package/skills/developing-cpp/source/05-language/02-value-types/03-integer-roles.md +0 -23
  116. package/skills/developing-cpp/source/05-language/02-value-types/04-enum.md +0 -17
  117. package/skills/developing-cpp/source/05-language/02-value-types/08-comparison.md +0 -4
  118. package/skills/developing-cpp/source/05-language/03-standard-library/06-format.md +0 -44
  119. package/skills/developing-cpp/source/05-language/03-standard-library/07-time.md +0 -3
  120. package/skills/developing-cpp/source/05-language/03-standard-library/08-random.md +0 -3
  121. package/skills/developing-cpp/source/05-language/03-standard-library/09-files.md +0 -4
  122. package/skills/developing-cpp/source/05-language/04-performance/01-measure.md +0 -15
  123. package/skills/developing-cpp/source/05-language/04-performance/06-false-optimizations.md +0 -6
  124. package/skills/developing-cpp/source/06-naming/examples/naming-basic.md +0 -3
  125. package/skills/developing-cpp/source/06-naming/examples/naming-player-mark.md +0 -17
  126. package/skills/developing-cpp/source/06-naming/examples/naming-state-change.md +0 -57
  127. package/skills/developing-cpp/source/07-comments/01-comment-rules.md +0 -239
  128. package/skills/developing-cpp/source/07-comments/examples/declaration-constructor.md +0 -22
  129. package/skills/developing-cpp/source/07-comments/examples/declaration-enum.md +0 -24
  130. package/skills/developing-cpp/source/07-comments/examples/declaration-function.md +0 -100
  131. package/skills/developing-cpp/source/07-comments/examples/declaration-struct.md +0 -18
  132. package/skills/developing-cpp/source/07-comments/examples/implementation-body.md +0 -42
  133. package/skills/developing-cpp/source/07-comments/glossary/comment-terms.md +0 -75
  134. package/skills/engineering/cmake/linking/02-rpath.md +0 -17
  135. package/skills/engineering/formatting/examples/clang-format.md +0 -17
  136. /package/skills/developing-cpp/{source/07-comments → references/comments}/examples/implementation-todo.md +0 -0
  137. /package/skills/developing-cpp/{source/03-design → references/design}/examples/behavior-sentence.md +0 -0
  138. /package/skills/developing-cpp/{source/03-design → references/design}/examples/coordinate-table.md +0 -0
  139. /package/skills/developing-cpp/{source/03-design → references/design}/examples/header-place.md +0 -0
  140. /package/skills/developing-cpp/{source/03-design → references/design}/examples/library-boundary.md +0 -0
  141. /package/skills/developing-cpp/{source/03-design → references/design}/examples/library-split.md +0 -0
  142. /package/skills/developing-cpp/{source/08-exceptions → references/exceptions}/examples/throw-boundary.md +0 -0
  143. /package/skills/developing-cpp/{source/08-exceptions → references/exceptions}/examples/throw-catch.md +0 -0
  144. /package/skills/developing-cpp/{source/08-exceptions → references/exceptions}/examples/throw-destructor.md +0 -0
  145. /package/skills/developing-cpp/{source/08-exceptions → references/exceptions}/examples/throw-format.md +0 -0
  146. /package/skills/developing-cpp/{source/08-exceptions → references/exceptions}/examples/throw-when.md +0 -0
  147. /package/skills/developing-cpp/{source/05-language/04-performance → references/language/performance}/07-checklist.md +0 -0
  148. /package/skills/developing-cpp/{source/05-language/03-standard-library → references/language/standard-library}/10-checklist.md +0 -0
  149. /package/skills/developing-cpp/{source/05-language/02-value-types → references/language/value-types}/05-strong-type.md +0 -0
  150. /package/skills/developing-cpp/{source/06-naming → references/naming}/examples/naming-accessor.md +0 -0
  151. /package/skills/developing-cpp/{source/06-naming → references/naming}/examples/naming-current-prefix.md +0 -0
  152. /package/skills/developing-cpp/{source/06-naming → references/naming}/examples/naming-lookup.md +0 -0
  153. /package/skills/developing-cpp/{source/06-naming → references/naming}/examples/naming-multiple-return.md +0 -0
  154. /package/skills/developing-cpp/{source/06-naming → references/naming}/examples/naming-predicate.md +0 -0
  155. /package/skills/developing-cpp/{source/06-naming → references/naming}/examples/naming-rename.md +0 -0
  156. /package/skills/developing-cpp/{source/06-naming → references/naming}/examples/naming-responsibility.md +0 -0
  157. /package/skills/developing-cpp/{source/06-naming → references/naming}/examples/naming-role.md +0 -0
  158. /package/skills/engineering/{cmake → references/cmake}/assets/LinkSettings.cmake +0 -0
  159. /package/skills/engineering/{cmake/03-standard → references/cmake/standard}/examples/standard.md +0 -0
  160. /package/skills/engineering/{cmake/03-standard → references/cmake/standard}/standards/c++11/README.md +0 -0
  161. /package/skills/engineering/{cmake/03-standard → references/cmake/standard}/standards/c++11/cmake-snippet.cmake +0 -0
  162. /package/skills/engineering/{cmake/03-standard → references/cmake/standard}/standards/c++14/README.md +0 -0
  163. /package/skills/engineering/{cmake/03-standard → references/cmake/standard}/standards/c++14/cmake-snippet.cmake +0 -0
  164. /package/skills/engineering/{cmake/03-standard → references/cmake/standard}/standards/c++17/README.md +0 -0
  165. /package/skills/engineering/{cmake/03-standard → references/cmake/standard}/standards/c++17/cmake-snippet.cmake +0 -0
  166. /package/skills/engineering/{cmake/03-standard → references/cmake/standard}/standards/c++20/README.md +0 -0
  167. /package/skills/engineering/{cmake/03-standard → references/cmake/standard}/standards/c++20/cmake-snippet.cmake +0 -0
  168. /package/skills/engineering/{cmake/03-standard → references/cmake/standard}/standards/c++23/README.md +0 -0
  169. /package/skills/engineering/{cmake/03-standard → references/cmake/standard}/standards/c++23/cmake-snippet.cmake +0 -0
  170. /package/skills/engineering/{cmake/01-targets → references/cmake/targets}/examples/glob.md +0 -0
  171. /package/skills/engineering/{cmake/01-targets → references/cmake/targets}/examples/rpath.md +0 -0
  172. /package/skills/engineering/{formatting → references/formatting}/examples/clangd.md +0 -0
  173. /package/skills/engineering/{formatting → references/formatting}/scripts/checking-encoding.mjs +0 -0
@@ -7,17 +7,19 @@ metadata:
7
7
 
8
8
  # engineering
9
9
 
10
- ## 适用场景
11
-
12
- 本技能管两件事:CMake 文件与 target 契约(`CMakeLists.txt`、`cmake/` 模块、`target_*` 命令、目标属性、include 与链接边界、输出目录、共享库运行时路径、`FetchContent`、preset 与安装导出),以及编码与排版工具配置(UTF-8/LF、clang-format、clang-tidy、clangd)。函数体、类型、命名、异常和源码注释只开 `developing-cpp`;构建目录、编译器、入口脚本与运行检查开 `building-cpp`。
10
+ 本技能管两件事:CMake 文件与 target 契约,以及编码与排版工具配置。函数体、类型、命名、异常与源码注释只开 `developing-cpp`;构建目录、编译器、入口脚本与运行检查开 `building-cpp`。
13
11
 
14
- 一次改动同时碰到源码和 CMake 时先开 `developing-cpp` 定行为与边界,再用本技能把源文件、库和程序写进 target,最后到 `building-cpp` 跑检查。只改一个 target 的 include、链接或标准时走单点修正;新工程、新组件、换语言标准或抽公共函数时走整段重构。
12
+ ## 适用场景
15
13
 
16
- 存在项目技能 `cpp-workflow-project` 时先读它的 `SKILL.md`、`environment.json` 和 `stages/stage-table.md`。`environment.json` 的 `standard` 是 target 标准的唯一来源;缺失、非法或与现有 target 不一致时停在定 target,不猜标准。构建目录、编译器和工具版本由 `building-cpp` 的定构建负责,本技能只写 target 契约与工具配置;target 图与 CMake 写法以本技能为权威,`building-cpp` 只读不修改。
14
+ - **负责**:`CMakeLists.txt`、`references/cmake/` 模块、`target_*` 命令、目标属性、include 与链接边界、输出目录、共享库运行时路径、`FetchContent`、preset 与安装导出;UTF-8/LF、clang-format、clang-tidy、clangd 的配置条文。
15
+ - **不负责**:源码语义与注释开 `developing-cpp`;`environment.json`、`running-build.sh`、构建目录、编译器与 CTest 运行开 `building-cpp`。
16
+ - **交接**:一次改动同时碰到源码和 CMake 时先开 `developing-cpp` 定行为与边界,再用本技能把源文件、库和程序写进 target,最后到 `building-cpp` 跑检查。只改一个 target 的 include、链接或标准时走单点修正;新工程、新组件、换语言标准或抽公共函数时走整段重构。
17
+ - **前置**:存在项目技能 `cpp-workflow-project` 时先读它的 `SKILL.md`、`environment.json` 和 `stages/stage-table.md`。`environment.json` 的 `standard` 是 target 标准的唯一来源;缺失、非法或与现有 target 不一致时停在定 target,不猜标准。
18
+ - **边界**:target 图与 CMake 写法以本技能为权威,`building-cpp` 只读不修改;构建目录、编译器和工具版本由 `building-cpp` 的定构建负责,本技能只写 target 契约与工具配置。
17
19
 
18
20
  ## 三种操作
19
21
 
20
- 一次只选一种,范围(单点、整段)是任务属性。操作与域的判据、边界和交接见 `../developing-cpp/source/01-editing/01-edit-operations.md`;四类改动是域,不是操作。
22
+ 一次只选一种,范围(单点、整段)是任务属性;判据、边界与交接见 `../developing-cpp/references/editing/01-edit-operations.md`。四类改动是域,不是操作。
21
23
 
22
24
  | 操作 | 什么时候用 | 从哪步进 |
23
25
  | --- | --- | --- |
@@ -25,60 +27,61 @@ metadata:
25
27
  | 改写 | target 图与标准不变,模块、函数或目录结构不对 | 从第 2 步重走,可到第 3 步 |
26
28
  | 润色 | 只改函数名、注释措辞或错误消息 | 第 2 步 |
27
29
 
28
- 三种操作共用这些约束:不发明项目没有声明的 target、标准、编译器或目录;不覆盖已有 `CMakeLists.txt`;不用全局 `include_directories()`、`add_definitions()`、`CMAKE_CXX_FLAGS` 给所有 target 加料;不写 `file(GLOB ...)`;不把 `main()` 编进库;库与程序不下载依赖,只有测试需要时调用 `LinkSettings_FetchGoogleTest`。后一步发现前一步没做完,退回那一步。排版工具配置只改本技能点名的三份文件,不顺手改项目其他文件。
30
+ - 不发明项目没有声明的 target、标准、编译器或目录;不覆盖已有 `CMakeLists.txt`。
31
+ - 不用全局 `include_directories()`、`add_definitions()`、`CMAKE_CXX_FLAGS` 给所有 target 加料;不写 `file(GLOB ...)`;不把 `main()` 编进库。
32
+ - 库与程序不下载依赖;只有测试需要时调用 `LinkSettings_FetchGoogleTest`。排版工具配置只改本技能点名的三份文件,不顺手改项目其他文件。
33
+ - 后一步发现前一步没做完,退回那一步;拿不准先单点修正,target 图或标准要改则整段退回。
29
34
 
30
35
  ## 步骤
31
36
 
32
37
  | 步 | 名称 | 文件 | 一句话 |
33
38
  | --- | --- | --- | --- |
34
- | 1 | 定 target 与标准 | `cmake/steps/01-targets.md` | target 图、PUBLIC/PRIVATE、标准、输出目录与编译数据库 |
35
- | 2 | 定模块与函数 | `cmake/steps/02-modules.md` | 何时抽函数、文件与命名、导入、注释与 2 空格排版 |
36
- | 3 | 通过检查 | `cmake/steps/03-check.md` | configure、构建、编译数据库与实际 `-std` 核对 |
39
+ | 1 | 定 target 与标准 | `steps/01-targets.md` | target 图、PUBLIC/PRIVATE、标准、输出目录与编译数据库 |
40
+ | 2 | 定模块与函数 | `steps/02-modules.md` | 何时抽函数、文件与命名、导入、注释与 2 空格排版 |
41
+ | 3 | 通过检查 | `steps/03-check.md` | configure、构建、编译数据库与实际 `-std` 核对 |
37
42
 
38
- 每步只打开同号的一个步骤文件。步骤只覆盖 CMake;编码与 clang 工具没有步骤,按下面的入口表直接打开那一份文件。
43
+ 每步只打开同号的一个步骤文件。步骤只覆盖 CMake;编码与 clang 工具没有步骤,按入口表直接打开那一份文件。
39
44
 
40
- ### 入口表
45
+ ## 入口表
41
46
 
42
47
  | 要做的事 | 打开 |
43
48
  | --- | --- |
44
- | 定 target、include、链接、输出目录与警告 | `cmake/01-targets/01-rules.md`;案例在 `cmake/01-targets/examples/` |
45
- | 定语言标准与档位 | `cmake/03-standard/01-cxx-standard.md`;五档细节在 `cmake/03-standard/standards/` |
46
- | 抽 CMake 函数与模块 | `cmake/02-modules/01-functions.md` |
47
- | 链接方式、rpath、undefined reference、产物核对 | 按问题只开一份:`cmake/linking/01-libraries.md`、`02-rpath.md`、`03-undefined-reference.md`、`04-inspect.md` |
48
- | CTest 注册、断言与用例拆分 | `cmake/testing/ctest.md` |
49
- | 编码、BOM 与行尾 | `formatting/01-encoding.md` |
50
- | clang-format | `formatting/02-clang-format.md`;案例 `formatting/examples/clang-format.md` |
51
- | clang-tidy 与检查分级 | `formatting/03-clang-tidy.md`;案例 `formatting/examples/clang-tidy.md` |
52
- | clangd 与编辑器补全 | `formatting/04-clangd.md`;案例 `formatting/examples/clangd.md` |
53
- | 可复制的 CMake 函数 | `cmake/assets/CompileSettings.cmake`、`cmake/assets/LinkSettings.cmake` |
54
-
55
- 本轮激活按三条上限走:
56
-
57
- - 只开当前步对应的一个步骤文件;同一改动域内不同时展开两个技能的步骤。跨域按 `源码 → engineering → building-cpp` 的顺序逐段进入,前一段结论落下再开下一段。
58
- - 条文只开该步点名的一份;同号案例留到下一次激活。排版工具一次只开入口表里的那一份。
49
+ | 定 target、include、链接、输出目录与警告 | `references/cmake/targets/rules.md`;案例在 `references/cmake/targets/examples/` |
50
+ | 定语言标准与档位 | `references/cmake/standard/cxx-standard.md`;五档细节在 `references/cmake/standard/standards/` |
51
+ | 抽 CMake 函数与模块 | `references/cmake/modules/functions.md` |
52
+ | 链接方式、rpath、undefined reference、产物核对 | 按问题只开一份:`references/cmake/linking/01-libraries.md`、`02-rpath.md`、`03-undefined-reference.md`、`04-inspect.md` |
53
+ | CTest 注册、断言与用例拆分 | `references/cmake/testing/ctest.md` |
54
+ | 编码、BOM 与行尾 | `references/formatting/01-encoding.md` |
55
+ | clang-format | `references/formatting/02-clang-format.md`;案例 `references/formatting/examples/clang-format.md` |
56
+ | clang-tidy 与检查分级 | `references/formatting/03-clang-tidy.md`;案例 `references/formatting/examples/clang-tidy.md` |
57
+ | clangd 与编辑器补全 | `references/formatting/04-clangd.md`;案例 `references/formatting/examples/clangd.md` |
58
+ | 可复制的 CMake 函数 | `references/cmake/assets/CompileSettings.cmake`、`references/cmake/assets/LinkSettings.cmake` |
59
+
60
+ ## 加载预算
61
+
62
+ - 只开当前步对应的一个步骤文件;同一改动域内不同时展开两个技能的步骤。
63
+ - 条文只开该步点名的一份;同号案例留到下一次激活;排版工具一次只开入口表里的那一份。
59
64
  - 标准档只打开项目技能声明的那一档,没有声明时用本技能已有的新工程默认,不把其余标准档读进来。
60
65
 
61
- 项目技能列出了检查命令时只跑那一条,没有时跑插件根目录的 `npm test`;退出码为 0 后在同一轮结束 goal,不再继续走没有失败的步骤。
62
-
63
- 五档标准的语言设施、工具映射与降档由 `cmake/03-standard/standards/` 维护;本技能只负责这些标准在 CMake 里怎么写,以及三份工具配置各自的最低版本。
66
+ 项目技能列出了检查命令时只跑那一条,没有时按 `steps/03-check.md` 的 configure 与构建命令跑;退出码为 0 后停在这一步,不再继续走没有失败的步骤。五档标准的语言设施、工具映射与降档由 `references/cmake/standard/standards/` 维护;本技能只负责这些标准在 CMake 里怎么写,以及三份工具配置各自的最低版本。
64
67
 
65
- ### 四类改动
68
+ ## 四类改动
66
69
 
67
- 四类改动是操作内部的域:操作定入口,域定层次。四域的定义、边界与次序见 `../developing-cpp/source/01-editing/01-edit-operations.md`;一次改动混了两类时,按「内容 → 结构 → 版式 → 措辞」拆开做,前一类落定并经检查再进下一类。
70
+ 四类改动是操作内部的域:操作定入口,域定层次。四域的定义、边界与次序见 `../developing-cpp/references/editing/01-edit-operations.md`;一次改动混了两类时,按「内容 → 结构 → 版式 → 措辞」拆开做,前一类落定并经检查再进下一类。
68
71
 
69
72
  | 类型 | 典型请求 | 入口步骤 |
70
73
  | --- | --- | --- |
71
- | 内容 | 新增 target、改公共 include 或链接边界、换语言标准 | `cmake/steps/01-targets.md` |
72
- | 结构 | 抽函数、拆模块、调导入位置 | `cmake/steps/02-modules.md` |
73
- | 版式 | 只改 2 空格、行宽、注释形态或工具配置 | `cmake/steps/02-modules.md`;工具配置见 `formatting/02-clang-format.md` |
74
- | 措辞 | 只改函数名、注释措辞或错误消息 | `cmake/steps/02-modules.md` |
74
+ | 内容 | 新增 target、改公共 include 或链接边界、换语言标准 | `steps/01-targets.md` |
75
+ | 结构 | 抽函数、拆模块、调导入位置 | `steps/02-modules.md` |
76
+ | 版式 | 只改 2 空格、行宽、注释形态或工具配置 | `steps/02-modules.md`;工具配置见 `references/formatting/02-clang-format.md` |
77
+ | 措辞 | 只改函数名、注释措辞或错误消息 | `steps/02-modules.md` |
75
78
 
76
79
  ## 完成判据
77
80
 
78
81
  - [ ] target 图显式:程序 target 叫 `app`,库 target 用组件名,程序链接库,库的公共 include 用 `PUBLIC`;没有全局 include、全局编译选项或 GLOB。
79
82
  - [ ] 每个 target 的标准来自 `environment.json`;`target_compile_features` 与 `CXX_STANDARD`、`CXX_STANDARD_REQUIRED ON`、`CXX_EXTENSIONS OFF` 同时存在,live 的 `compile_commands.json` 最后一条 `-std=` 与声明一致,不是 `gnu++NN`。
80
- - [ ] 复用的 CMake 函数放在 `cmake/` 模块里,文件名用 UpperCamelCase,函数名用 `<ModuleName>_` 加 PascalCase,有目标与参数校验,根 `CMakeLists.txt` 通过 `CMAKE_MODULE_PATH` 导入;没有重复片段和未使用的旧模块。
81
- - [ ] 公开函数上方写中文 `#` 契约:一句功能、空行、边界,再用 `:param` / `:keyword` 标参数;不写 `#[[.rst:` 与 `.. command::`,完整写法见 `cmake/01-targets/01-rules.md`;函数组之间用 `#---`,不画 `#===...===#` 方框。
83
+ - [ ] 复用的 CMake 函数放在工程根的 `cmake/` 模块里(模板源在 `references/cmake/assets/`),文件名用 UpperCamelCase,函数名用 `<ModuleName>_` 加 PascalCase,有目标与参数校验,根 `CMakeLists.txt` 通过 `CMAKE_MODULE_PATH` 导入;没有重复片段和未使用的旧模块。
84
+ - [ ] 公开函数上方写中文 `#` 契约:一句功能、空行、边界,再用 `:param` / `:keyword` 标参数;不写 `#[[.rst:` 与 `.. command::`,完整写法见 `references/cmake/targets/rules.md`;函数组之间用 `#---`,不画 `#===...===#` 方框。
82
85
  - [ ] `CMakeLists.txt` 与 `*.cmake` 用 UTF-8 无 BOM、LF、2 空格缩进、不用 tab;行宽按团队约定,默认 80 列。
83
86
  - [ ] 编码与排版工具各管一段:`.clang-format` 管空白与包含顺序,`.clang-tidy` 管检查分级,`.clangd` 管编辑器补全;三份都不把标准写死成与 `environment.json` 冲突的值,也不把 clang-format 塞进构建脚本。
84
87
  - [ ] configure 与构建通过,构建产物不落在源码目录;没有改源码语义,也没有覆盖已有工程文件。
@@ -11,6 +11,8 @@ include_guard(GLOBAL)
11
11
  #
12
12
  # :param target: 已经存在的 CMake 目标。
13
13
  # :param visibility: 取 PUBLIC、PRIVATE 或 INTERFACE。
14
+ # INTERFACE 只传播 compile feature(最低标准),不能锁死 CXX_STANDARD
15
+ # 与 CXX_EXTENSIONS;纯头文件 target 的消费者仍需自己调用一次。
14
16
  # :param standard: 取 c++11、c++14、c++17、c++20 或 c++23。
15
17
  function(CompileSettings_SetCxxStandard target visibility standard)
16
18
  if(NOT TARGET "${target}")
@@ -52,3 +52,9 @@
52
52
  - [ ] 静态库/共享库选择有理由,没有混用两套标准库。
53
53
  - [ ] 产物在 `bin/` 与 `lib/`,RPATH 指向相对位置。
54
54
  - [ ] `file` 与 `ldd` 检查过,程序能最小启动。
55
+
56
+ ## 依据
57
+
58
+ - [CMake: `target_link_libraries`](https://cmake.org/cmake/help/latest/command/target_link_libraries.html):链接依赖的传递与顺序。
59
+ - [CMake: `BUILD_SHARED_LIBS`](https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html):`add_library` 未写类型时的默认库类型。
60
+ - [CMake: `POSITION_INDEPENDENT_CODE`](https://cmake.org/cmake/help/latest/prop_tgt/POSITION_INDEPENDENT_CODE.html):共享库与 PIE 的编译要求。
@@ -0,0 +1,25 @@
1
+ # 输出目录与 RPATH
2
+
3
+ 推荐布局:
4
+
5
+ ```text
6
+ build/<compiler>/
7
+ bin/app
8
+ lib/libgame.so
9
+ compile_commands.json
10
+ ```
11
+
12
+ - 可执行文件在 `bin/`,共享库在 `lib/`;不要把库和可执行文件混在同一层。
13
+ - 运行时动态加载器默认不搜索可执行文件旁边的 `lib/`;需要 RPATH:
14
+ - Linux:`-Wl,-rpath,'$ORIGIN/../lib'`
15
+ - macOS:`-Wl,-rpath,@loader_path/../lib`
16
+ - CMake 用 `BUILD_RPATH` / `INSTALL_RPATH` 设置,不要手工拼链接命令;见 [`LinkSettings.cmake`](../assets/LinkSettings.cmake)。
17
+ - CMake 字符串里直接写 `"$ORIGIN/../lib"`:`$ORIGIN` 不是 CMake 变量(CMake 只展开 `${...}`),CMake 也不经过 shell。实测 `"$ORIGIN/../lib"` 与 `"\$ORIGIN/../lib"` 生成的 RUNPATH 都是 `$ORIGIN/../lib`;只有把路径交给 shell 命令时才需要 shell 引号。
18
+ - `BUILD_RPATH_USE_ORIGIN` 让 CMake 为构建树里的绝对路径自动生成 `$ORIGIN` 相对形式,不是转义开关。
19
+
20
+ ## 依据
21
+
22
+ - [CMake: `BUILD_RPATH`](https://cmake.org/cmake/help/latest/prop_tgt/BUILD_RPATH.html):构建树中的运行时搜索路径。
23
+ - [CMake: `INSTALL_RPATH`](https://cmake.org/cmake/help/latest/prop_tgt/INSTALL_RPATH.html):安装后的运行时搜索路径。
24
+ - [CMake: `BUILD_RPATH_USE_ORIGIN`](https://cmake.org/cmake/help/latest/prop_tgt/BUILD_RPATH_USE_ORIGIN.html):用 `$ORIGIN` 生成相对 RPATH。
25
+ - [Linux `ld.so(8)`](https://man7.org/linux/man-pages/man8/ld.so.8.html):`$ORIGIN` 与 RPATH 的展开规则。
@@ -12,3 +12,9 @@
12
12
  | 静态库中的目标文件没被拉入 | 链接器只取被引用符号所在的目标文件 | 确认符号确实被引用,或改用对象库/共享库 |
13
13
 
14
14
  先看链接器报的完整符号名和来源文件,不要只看第一行。
15
+
16
+ ## 依据
17
+
18
+ - [CMake: `target_link_libraries`](https://cmake.org/cmake/help/latest/command/target_link_libraries.html):链接依赖与顺序。
19
+ - [CMake: `target_sources`](https://cmake.org/cmake/help/latest/command/target_sources.html):把实现文件加入 target。
20
+ - [GCC: Link Options](https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html):链接器参数与库顺序。
@@ -13,3 +13,9 @@ ldd build/clang/bin/app
13
13
  - `ldd` 确认每个共享库都能解析到实际路径;出现 `not found` 就是加载期会失败。
14
14
  - 运行 `app` 做一次最小启动;动态库缺失会在启动时暴露,而不是链接时。
15
15
  - macOS 用 `otool -L` 代替 `ldd`;Windows 用 `dumpbin /dependents`。
16
+
17
+ ## 依据
18
+
19
+ - [`file(1)`](https://man7.org/linux/man-pages/man1/file.1.html):识别文件格式、架构与位数。
20
+ - [`ldd(1)`](https://man7.org/linux/man-pages/man1/ldd.1.html):动态库依赖解析与 `not found` 的含义。
21
+ - [CMake: `add_custom_command`](https://cmake.org/cmake/help/latest/command/add_custom_command.html):把产物检查接进构建流程。
@@ -30,7 +30,7 @@ project/
30
30
  - 文件名用 UpperCamelCase,与 CMake 官方 `Modules/` 一致;按职责命名,例如 `CompileSettings.cmake`、`LinkSettings.cmake`。不用 kebab-case,也不用现在分词。
31
31
  - 函数名用 `<ModuleName>_` 加 PascalCase:`CompileSettings_SetCxxStandard`、`LinkSettings_FetchGoogleTest`。前缀取模块文件名的原样大小写,复制到工程后不改名。
32
32
  - 工程自己新增、不准备回流的函数才用项目前缀加 snake_case,例如 `my_project_do_something`。
33
- - 只有项目真的需要时才建 `cmake/`;一个函数都没有时不建空目录。
33
+ - 只有项目真的需要时才建 `references/cmake/`;一个函数都没有时不建空目录。
34
34
 
35
35
  ## 导入
36
36
 
@@ -59,8 +59,9 @@ function(CompileSettings_SetCxxStandard target visibility standard)
59
59
  endfunction()
60
60
 
61
61
  # 同一文件的第二组函数前再放一条 #--- 分隔线。
62
- function(CompileSettings_SetWarnings target visibility level)
63
- # 校验 LEVEL,再调用 target_compile_options。
62
+ function(CompileSettings_SetWarnings target visibility)
63
+ cmake_parse_arguments(PARSE_ARGV 2 arg "" "LEVEL" "")
64
+ # 校验 LEVEL 与可见性,再调用 target_compile_options。
64
65
  endfunction()
65
66
  ```
66
67
 
@@ -74,7 +75,7 @@ endfunction()
74
75
 
75
76
  ## 契约注释
76
77
 
77
- 公开函数上方写中文 `#` 契约:一句功能、空行、边界,再用 `:param` 标位置参数、`:keyword` 标关键字参数;不写 `#[[.rst:` 与 `.. command::`,那是进 CMake 手册的模块才用的标记。同一文件的函数组之间用一条 `#---` 分隔,行注释只写原因,不画 `#===...===#` 方框。完整写法见 `../01-targets/01-rules.md`。
78
+ 公开函数上方写中文 `#` 契约:一句功能、空行、边界,再用 `:param` 标位置参数、`:keyword` 标关键字参数;不写 `#[[.rst:` 与 `.. command::`,那是进 CMake 手册的模块才用的标记。同一文件的函数组之间用一条 `#---` 分隔,行注释只写原因,不画 `#===...===#` 方框。完整写法见 `../targets/rules.md`。
78
79
 
79
80
  ## 测试
80
81
 
@@ -86,7 +87,7 @@ endfunction()
86
87
  4. 重复 `include()` 不报函数重定义。
87
88
  5. `compile_commands.json` 出现对应 `-std=`。
88
89
 
89
- 测试完删除临时工程;不把测试用 `CMakeLists.txt` 留在仓库。真实工程里的验证由 `../steps/03-check.md` 完成。
90
+ 测试完删除临时工程;不把测试用 `CMakeLists.txt` 留在仓库。真实工程里的验证由 `../../../steps/03-check.md` 完成。
90
91
 
91
92
  ## 迁移旧模块
92
93
 
@@ -98,6 +99,8 @@ endfunction()
98
99
  ## 官方依据
99
100
 
100
101
  - [`function()`](https://cmake.org/cmake/help/latest/command/function.html):函数在调用时执行,拥有自己的作用域。
102
+ - [`macro()`](https://cmake.org/cmake/help/latest/command/macro.html):宏是文本替换,没有函数作用域。
103
+ - [`include()`](https://cmake.org/cmake/help/latest/command/include.html):模块搜索路径与 `CMAKE_MODULE_PATH`。
101
104
  - [`include_guard()`](https://cmake.org/cmake/help/latest/command/include_guard.html):按目录或全局防止重复导入。
102
105
  - [`CMAKE_MODULE_PATH`](https://cmake.org/cmake/help/latest/variable/CMAKE_MODULE_PATH.html):`include()` 的模块搜索路径。
103
106
  - [CMake Source Code Guide](https://github.com/Kitware/CMake/blob/master/Help/dev/source.rst):只规定 C++ 风格,没有 CMake 语言风格章节。
@@ -21,7 +21,7 @@ CMake 有两套相关机制,必须同时写:
21
21
 
22
22
  ## 通用函数
23
23
 
24
- `../assets/cmake/CompileSettings.cmake` 提供:
24
+ `../assets/CompileSettings.cmake` 提供:
25
25
 
26
26
  ```cmake
27
27
  CompileSettings_SetCxxStandard(app PRIVATE c++23)
@@ -34,9 +34,10 @@ CompileSettings_SetCxxStandard(greeting PUBLIC c++20)
34
34
 
35
35
  ## 可见性
36
36
 
37
- - 库的公共接口需要该标准时用 `PUBLIC`,链接者自动继承。
37
+ - 库的公共接口需要该标准时用 `PUBLIC`:`target_compile_features` 只把“至少 C++NN”传给链接者;`CXX_STANDARD`、`CXX_STANDARD_REQUIRED` 与 `CXX_EXTENSIONS` 不随 `PUBLIC` / `INTERFACE` 传播。
38
38
  - 程序、测试、实现文件用 `PRIVATE`。
39
- - `INTERFACE` 只用于纯头文件 target;不要用它绕过「标准应写在有源文件的目标上」。
39
+ - `INTERFACE` 只用于纯头文件 target;它没有编译单元,只能传播最低标准,不能锁死精确的 `-std=c++NN`。
40
+ - 因此每个会编译的 target 都要自己调用一次函数;只靠库的 `PUBLIC`,消费者可能得到 `-std=gnu++NN`,甚至没有 `-std=`。
40
41
  - `target_compile_features` 重复调用会追加特性;同一目标不要同时写两个不同标准。
41
42
 
42
43
  ## 常见错误
@@ -58,7 +59,7 @@ configure 后读 `build/<compiler>/compile_commands.json`,取最后一条 `-st
58
59
  grep -o -- '-std=[^ ]*' build/clang/compile_commands.json | sort -u
59
60
  ```
60
61
 
61
- 输出必须只有一条,且等于 `-std=c++NN`;出现 `gnu++NN`、两条不同值或没有 `-std=` 都回第 1 步。`CXX_STANDARD_REQUIRED ON` 与 `CXX_EXTENSIONS OFF` 同时存在时,主流编译器会给出精确的 `-std=c++NN`;仍以数据库为准,不靠猜。
62
+ 每个编译 target 的输出都应只有一条,且等于 `-std=c++NN`;出现 `gnu++NN`、两条不同值或没有 `-std=` 都回第 1 步。`CXX_STANDARD_REQUIRED ON` 与 `CXX_EXTENSIONS OFF` 同时存在时,该 target 会得到精确的 `-std=c++NN`;只链接了 `PUBLIC` / `INTERFACE` 库的消费者不继承这两项,要自己调用函数。仍以数据库为准,不靠猜。
62
63
 
63
64
  ## 官方依据
64
65
 
@@ -1,10 +1,10 @@
1
1
  # 语言标准档案
2
2
 
3
- 本工作流默认 **C++23**,但一个工程只选一个 `standard`,不为同一份源码承诺“同时兼容 C++11–C++23”。标准是项目级事实,写在 `.agents/skills/cpp-workflow-project/environment.json`。
3
+ 本工作流默认 **C++23**,但一个工程只选一个 `standard`,不为同一份源码承诺“同时兼容 C++11–C++23”。标准是项目级事实,写在项目的 `environment.json`(本书在 `.agents/skills/cpp-workflow-project/environment.json`)。
4
4
 
5
5
  每个标准单独一个目录:`c++11/`、`c++14/`、`c++17/`、`c++20/`、`c++23/`。目录里放这一档自己的编译器下限、语言/库设施、CMake 片段和工具映射;模板仍然只有一套公共骨架,靠 `__cplusplus` 条件选择实现,不复制五份模板。
6
6
 
7
- Google C++ Style Guide 上游仍写 “target C++20”,本工作流默认 C++23 是一处明确偏离;Google 的排版、命名、头文件和异常之外的规则不变。异常政策仍按 [exceptions.md](../../../../developing-cpp/source/08-exceptions/01-throw-rules.md)。
7
+ Google C++ Style Guide 上游仍写 “target C++20”,本工作流默认 C++23 是一处明确偏离;Google 的排版、命名、头文件和异常之外的规则不变。异常政策仍按 [exceptions.md](../../../../../developing-cpp/references/exceptions/throw-rules.md)。
8
8
 
9
9
  ## 选择标准
10
10
 
@@ -72,7 +72,7 @@ set_target_properties(app PROPERTIES
72
72
  - `CXX_STANDARD` 是请求值;`CXX_STANDARD_REQUIRED ON` 防止编译器不支持时静默 decay。
73
73
  - `CXX_EXTENSIONS OFF` 把 `-std=gnu++23` 收成 `-std=c++23`。
74
74
  - configure 后读 `compile_commands.json` 的最后一个 `-std=`;必须是 `-std=c++NN`,不能是 `gnu++NN`。
75
- - CMake 最低 3.20(模板统一要求);只单独使用低档片段时,C++11/14 的 `cxx_std_*` meta-feature 最低 3.8,C++20 为 3.12。C++23 的 `CXX_STANDARD 23` 自 3.20 才有。
75
+ - CMake 最低 3.20(模板统一要求);只单独使用低档片段时,C++11/14 的 `cxx_std_*` meta-feature 最低 3.1,C++17 为 3.8,C++20 为 3.12。C++23 的 `CXX_STANDARD 23` 自 3.20 才有。
76
76
 
77
77
  ### clang-format
78
78
 
@@ -104,7 +104,7 @@ CompileFlags:
104
104
  `.clang-tidy` 不写标准,标准来自编译数据库。检查项保持 Google 基线:
105
105
 
106
106
  ```yaml
107
- Checks: '-*, google-*, readability-identifier-naming'
107
+ Checks: '-*, google-*, portability-avoid-pragma-once, readability-identifier-naming'
108
108
  WarningsAsErrors: '*'
109
109
  FormatStyle: file
110
110
  ```
@@ -145,7 +145,7 @@ target_link_options(app PRIVATE -stdlib=libc++)
145
145
  | `c++20` | 必测 | 必测 | 必测 | `c++20` | `c++20` | 读 DB |
146
146
  | `c++23` | 必测 | 必测 | 必测 | `c++23` | `Latest` | 读 DB |
147
147
 
148
- 本仓库在 WSL(clang 21.1.8、CMake 4.2.3、Ninja 1.13.2)上跑过四套模板 × 五档共 20 个构建:single、multi、static-library、shared-library 全部 configure/build/CTest 通过,`compile_commands.json` 都得到精确的 `-std=c++11/14/17/20/23`。模板用 `__cplusplus` 条件选择 `std::format` 或字符串拼接,默认仍交付 C++23。可复现脚本:[checking-standard-matrix.sh](../../../../../scripts/checking-standard-matrix.sh)。
148
+ 本仓库在 WSL(clang 21.1.8、CMake 4.2.3、Ninja 1.13.2)上跑过四套模板 × 五档共 20 个构建:single、multi、static-library、shared-library 全部 configure/build/CTest 通过,`compile_commands.json` 都得到精确的 `-std=c++11/14/17/20/23`。模板用 `__cplusplus` 条件选择 `std::format` 或字符串拼接,默认仍交付 C++23。可复现脚本:`scripts/checking-standard-matrix.sh`(仓库开发脚本,不随 npm 包发布)。
149
149
 
150
150
  ## 新增标准
151
151
 
@@ -159,7 +159,7 @@ target_link_options(app PRIVATE -stdlib=libc++)
159
159
 
160
160
  ## 相关文件
161
161
 
162
- - [environment.md](../../../../building-cpp/references/environment.md):四轴声明与校验。
163
- - [cxx-standard.md](../01-cxx-standard.md):C++11–C++23 在 CMake 里的两层声明与验证。
162
+ - [environment.md](../../../../../building-cpp/references/environment.md):四轴声明与校验。
163
+ - [cxx-standard.md](../cxx-standard.md):C++11–C++23 在 CMake 里的两层声明与验证。
164
164
  - [clang-tidy.md](../../../formatting/03-clang-tidy.md):clang-format / clang-tidy / clangd 分工。
165
- - [01-build.md](../../../../building-cpp/steps/01-build.md):定构建步骤。
165
+ - [01-build.md](../../../../../building-cpp/steps/01-build.md):定构建步骤。
@@ -10,7 +10,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
10
10
  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
11
11
  set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
12
12
 
13
- # 先把 assets/cmake/ 里的 CompileSettings.cmake 复制到工程的 cmake/。
13
+ # 先把 assets/ 里的 CompileSettings.cmake 复制到工程的 cmake/。
14
14
  include(CompileSettings)
15
15
 
16
16
  add_library(greeting STATIC greeting/src/greeting.cpp)
@@ -1,6 +1,6 @@
1
1
  # CMake
2
2
 
3
- 目标:一个编译器、Ninja、target-based 规则、可用的编译数据库。下面是最小形状和常见边界;工程模板仍由 `building-cpp` 提供,在 `../../../building-cpp/assets/templates/projects/`,可复用的 CMake 函数在本技能的 `assets/cmake/`:`CompileSettings.cmake` 收标准与警告,`LinkSettings.cmake` 收构建期 RPATH 与 GoogleTest 依赖。
3
+ 目标:一个编译器、Ninja、target-based 规则、可用的编译数据库。下面是最小形状和常见边界;工程模板仍由 `building-cpp` 提供,在 `../../../../building-cpp/assets/templates/projects/`,可复用的 CMake 函数在本技能的 `assets/`:`CompileSettings.cmake` 收标准与警告,`LinkSettings.cmake` 收构建期 RPATH 与 GoogleTest 依赖。
4
4
 
5
5
  ## 排版
6
6
 
@@ -21,7 +21,7 @@ project({{PROJECT_NAME}} VERSION 0.1.0 LANGUAGES CXX)
21
21
  set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
22
22
  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
23
23
 
24
- # 先把 assets/cmake/ 里的 CompileSettings.cmake 复制到工程的 cmake/。
24
+ # 先把 assets/ 里的 CompileSettings.cmake 复制到工程的 cmake/。
25
25
  include(CompileSettings)
26
26
 
27
27
  add_executable(app src/main.cpp)
@@ -40,7 +40,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
40
40
  set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
41
41
  set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
42
42
 
43
- # 先把 assets/cmake/ 里的 CompileSettings.cmake 复制到工程的 cmake/。
43
+ # 先把 assets/ 里的 CompileSettings.cmake 复制到工程的 cmake/。
44
44
  include(CompileSettings)
45
45
 
46
46
  add_subdirectory(greeting)
@@ -60,36 +60,36 @@ CompileSettings_SetWarnings(greeting PRIVATE LEVEL standard)
60
60
  ```
61
61
 
62
62
  - 库的 `PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include` 让程序与链接它的测试写 `#include "greeting.h"` 就能找到公共头,不需要各自再写 include 路径。
63
- - 标准用 `CompileSettings_SetCxxStandard`:库用 `PUBLIC` 传播,程序用 `PRIVATE`;函数内部同时写 `target_compile_features` 与 `CXX_STANDARD` 三属性。
63
+ - 标准用 `CompileSettings_SetCxxStandard`:库用 `PUBLIC` 传播“至少 C++NN”,程序用 `PRIVATE`;`CXX_STANDARD`/`CXX_EXTENSIONS` 不传播,每个会编译的 target 都要自己调用一次。
64
64
  - `CXX_STANDARD_REQUIRED ON` 防止 CMake 在编译器不支持时静默 decay;`CXX_EXTENSIONS OFF` 把 `-std=gnu++NN` 收成 `-std=c++NN`。configure 后检查 `compile_commands.json` 的最后一条 `-std=`。
65
65
  - 程序 target 固定 `app`;库 target 用组件名。
66
66
 
67
67
  ## 标准与复用
68
68
 
69
- C++11–C++23 的两层声明、可见性、常见错误与验证见 `../03-standard/01-cxx-standard.md`。通用函数 `CompileSettings_SetCxxStandard(target visibility c++NN)` 在 `../assets/cmake/CompileSettings.cmake`:
69
+ C++11–C++23 的两层声明、可见性、常见错误与验证见 `../standard/cxx-standard.md`。通用函数 `CompileSettings_SetCxxStandard(target visibility c++NN)` 在 `../assets/CompileSettings.cmake`:
70
70
 
71
71
  ```cmake
72
72
  CompileSettings_SetCxxStandard(app PRIVATE c++23)
73
73
  CompileSettings_SetCxxStandard(greeting PUBLIC c++20)
74
74
  ```
75
75
 
76
- 函数名不绑定单一标准;新增档位只改函数里的支持列表。模块何时抽、文件怎么放、怎么导入与测试见 `../02-modules/01-functions.md`。
76
+ 函数名不绑定单一标准;新增档位只改函数里的支持列表。模块何时抽、文件怎么放、怎么导入与测试见 `../modules/functions.md`。
77
77
 
78
78
  ## 警告等级
79
79
 
80
- `cmake/CompileSettings.cmake` 的 `CompileSettings_SetWarnings(<target> <visibility> LEVEL basic|standard|strict)` 把常用 flag 收成三档;`visibility` 用 `PRIVATE` 或 `INTERFACE`,`PRIVATE` 不向使用方传播。警告与标准写在同一份编译设置模块里。
80
+ `references/cmake/assets/CompileSettings.cmake` 的 `CompileSettings_SetWarnings(<target> <visibility> LEVEL basic|standard|strict)` 把常用 flag 收成三档;`visibility` 用 `PRIVATE` 或 `INTERFACE`,`PRIVATE` 不向使用方传播。警告与标准写在同一份编译设置模块里。
81
81
 
82
82
  - `basic`:`-Wall -Wextra`;适合刚开始接 CI 的旧代码。
83
83
  - `standard`:`basic` 加 `-Werror`、`-Wshadow`、`-Wold-style-cast`、`-Wpedantic`、`-Wnon-virtual-dtor`、`-Woverloaded-virtual`;默认档。
84
84
  - `strict`:`standard` 加 `-Wconversion`、`-Wsign-conversion`、`-Wcast-align`、`-Wcast-qual`、`-Wformat=2`、`-Wundef`、`-Wdouble-promotion`、`-Wimplicit-fallthrough`、`-Wnull-dereference`;适合新代码或质量闸门。
85
85
 
86
- MSVC 分支用 `/W4`、`/permissive-`、`/WX`;其他编译器直接报错,避免静默地没有警告。警告是 target 的 `PRIVATE` 选项,库不把自己的策略强加给消费者。
86
+ MSVC 分支用 `/W4`、`/permissive-`、`/WX`;其他编译器直接报错,避免静默地没有警告。警告默认走 `PRIVATE`,库不把自己的策略强加给消费者;只有纯头文件库需要把同一档警告传给使用方时才用 `INTERFACE`。
87
87
 
88
88
  ## target-based 规则
89
89
 
90
90
  - 每个 target 自己声明 include、标准、编译选项、链接库;不要用全局 `include_directories()`、`add_definitions()`、`CMAKE_CXX_FLAGS` 给所有 target 加料。
91
91
  - `target_include_directories(<target> PUBLIC|PRIVATE <dir>)`:公共头给 `PUBLIC`,私有实现目录给 `PRIVATE`。
92
- - `target_compile_features(<target> PUBLIC cxx_std_NN)`:标准是 target 属性,不是全局开关;优先调用项目 `cmake/` 里的标准函数。
92
+ - `target_compile_features(<target> PUBLIC|PRIVATE cxx_std_NN)`:只传播“至少 C++NN”的最低要求;精确 `-std` 由 `CompileSettings_SetCxxStandard` 在会编译的 target 上设置,不靠这一步锁死。
93
93
  - `target_link_libraries(<target> PRIVATE|PUBLIC <lib>)`:实现依赖用 `PRIVATE`,接口依赖用 `PUBLIC`。
94
94
  - 不要 `file(GLOB ...)`;显式列源文件,新增文件时改 CMake,构建系统才知道。`CONFIGURE_DEPENDS` 依赖构建系统每次检查目录,跨生成器行为也不完全一致,不作为工程规则。
95
95
  - 不把 `main()` 编进库;程序只做装配和 I/O。
@@ -140,7 +140,7 @@ LinkSettings_SetBuildRpath(app)
140
140
  - 函数按平台写 `BUILD_RPATH`:Linux 用 `$ORIGIN/../lib`,Apple 用 `@loader_path/../lib`。
141
141
  - 只对需要直接运行构建产物的程序设置;安装规则另算。
142
142
  - 不要用全局 `LD_LIBRARY_PATH` 包装所有命令;共享库的运行时路径由 target 的 RPATH 设置,不在脚本里全局改寻库路径。
143
- - `$ORIGIN` 在 CMake 双引号里不是 `${...}`,不会被展开,保持字面量;若遇到展开问题,用 `"\$ORIGIN/../lib"`。
143
+ - `$ORIGIN` 在 CMake 双引号里不是 `${...}`,不会被展开,保持字面量,不需要 `\$` 转义;`\$` 只在把字符串交给 shell 时使用。
144
144
 
145
145
  ## 标准库与编译器一致
146
146
 
@@ -152,7 +152,7 @@ LinkSettings_SetBuildRpath(app)
152
152
 
153
153
  ## 警告与静态检查
154
154
 
155
- - 警告选项统一:`-Wall -Wextra -Werror`;库额外 `-Wold-style-cast -Wshadow`。
155
+ - 警告选项统一由 `CompileSettings_SetWarnings` 按 `basic` / `standard` / `strict` 施加,不要另写一套 `-Wall -Wextra -Werror` 列表;各档的具体 flag 见上文「警告等级」。
156
156
  - 不要把警告选项加到全局 `CMAKE_CXX_FLAGS`;每个 target 显式加,或用一个函数统一施加。
157
157
  - `clang-tidy` 在构建后单独跑,不挂进 CMake 的编译命令;这样编译数据库稳定,诊断可复现。
158
158
  - 需要 `clang-tidy` 集成时用 `CMAKE_CXX_CLANG_TIDY`,但本项目默认不启用,避免构建与检查耦合。
@@ -190,3 +190,10 @@ LinkSettings_FetchGoogleTest()
190
190
  - 同时设 `CMAKE_CXX_COMPILER` 和 `CXX` 环境变量,互相覆盖。
191
191
  - 在 `CMakeLists.txt` 里 `execute_process` 下载依赖或改源码。
192
192
  - 用 `CMAKE_CXX_FLAGS` 加 `-std=c++23` 之类与声明不符的标准。
193
+
194
+ ## 依据
195
+
196
+ - [CMake: `add_library`](https://cmake.org/cmake/help/latest/command/add_library.html):库 target 的类型与作用域。
197
+ - [CMake: `target_include_directories`](https://cmake.org/cmake/help/latest/command/target_include_directories.html):`PUBLIC` / `PRIVATE` / `INTERFACE` 的传递。
198
+ - [CMake: `CMAKE_EXPORT_COMPILE_COMMANDS`](https://cmake.org/cmake/help/latest/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html):生成 `compile_commands.json`。
199
+ - [CMake: `CMAKE_CXX_STANDARD`](https://cmake.org/cmake/help/latest/variable/CMAKE_CXX_STANDARD.html):标准版本与 `CXX_STANDARD_REQUIRED`。
@@ -5,7 +5,7 @@
5
5
  ## 先决定测什么
6
6
 
7
7
  - 一个公开入口至少一条成功用例、一条拒绝用例;拒绝路径核对返回值、异常类型与状态没有被改坏。
8
- - 一条测试只核对一件事。用例名写行为,不写实现:`PlaceCellRejectsOccupiedCell`,不是 `TestPlaceCell2`。
8
+ - 一条测试只核对一件事。用例名写行为,不写实现:`PlaceRejectsOccupiedSquare`,不是 `TestPlace2`。
9
9
  - 测试直接链接库、包含公共头,不经过 `main()`、终端或文件系统;要进程、端口、临时目录的用例归集成测试,单列标签。
10
10
  - 不测私有成员与内部调用次数;测试锁定可观察行为,重构不该改测试。
11
11
 
@@ -44,7 +44,7 @@ gtest_discover_tests(tictactoe_test
44
44
  | 找不到测试 target 或 `gtest` | CMake 的 `enable_testing()`、`add_subdirectory(tests)`、链接目标 | `engineering` |
45
45
  | 断言失败但行为符合预期 | 测试期望是否写错、是否依赖未初始化状态 | 本文件 |
46
46
  | 断言失败且行为不对 | 被测函数的实现与契约 | `developing-cpp` |
47
- | 用例数比预期少 | `gtest_discover_tests` 的发现超时、测试是否在正确 target | 本文件与 `../steps/03-check.md` |
47
+ | 用例数比预期少 | `gtest_discover_tests` 的发现超时、测试是否在正确 target | 本文件与 `../../../steps/03-check.md` |
48
48
  | 偶发失败 | 共享临时文件、固定端口、执行顺序依赖 | 本文件 |
49
49
 
50
50
  ## 不做什么
@@ -52,3 +52,10 @@ gtest_discover_tests(tictactoe_test
52
52
  - 不为凑覆盖率写没有断言的测试;不用 `sleep` 等待异步结果。
53
53
  - 不在测试里复制一份被测实现来对照。
54
54
  - 不把测试输出、`Testing/` 目录或生成的可执行文件入库。
55
+
56
+ ## 依据
57
+
58
+ - [CMake: `add_test`](https://cmake.org/cmake/help/latest/command/add_test.html):注册测试与参数。
59
+ - [CMake: `gtest_discover_tests`](https://cmake.org/cmake/help/latest/module/GoogleTest.html#command:gtest_discover_tests):构建后发现 GoogleTest 用例。
60
+ - [CTest](https://cmake.org/cmake/help/latest/manual/ctest.1.html):`-R`、`-L`、`--output-on-failure`、`--no-tests=error`。
61
+ - [GoogleTest Primer](https://google.github.io/googletest/primer.html):断言、fixture 与用例命名。
@@ -32,7 +32,7 @@ MSVC 默认按 BOM 判断源码编码。源码没有 BOM 时,它按当前用
32
32
  在仓库根运行:
33
33
 
34
34
  ```bash
35
- node "<skill-dir>/scripts/checking-encoding.mjs" --profile portable
35
+ node "<skill-dir>/references/formatting/scripts/checking-encoding.mjs" --profile portable
36
36
  ```
37
37
 
38
38
  - `portable`(默认)要求所有文本文件 UTF-8 无 BOM、LF、末尾换行。
@@ -12,3 +12,9 @@ clang-format --dry-run --Werror src/*.cpp include/*.h tests/*.cpp
12
12
  - 配置文件在工程根 `.clang-format`;不要依赖用户主目录或编辑器内置配置。
13
13
  - `BasedOnStyle: Google`、`Standard: Latest`;clang-format 21/22 不接受 `c++23`,`Latest` 按工具支持的最高标准解析。列宽、缩进与包含顺序以工程根 `.clang-format` 为准;工程显式写 `ColumnLimit` 时按工程值执行,模板资产不写 `ColumnLimit`。
14
14
  - 格式化失败就是失败,不要用 `// clang-format off` 绕过;确需关闭时只包住无法排版的宏或表格,并写一句理由。
15
+
16
+ ## 依据
17
+
18
+ - [ClangFormat: Style Options](https://clang.llvm.org/docs/ClangFormatStyleOptions.html):`BasedOnStyle`、`Standard`、`ColumnLimit` 等选项。
19
+ - [ClangFormat](https://clang.llvm.org/docs/ClangFormat.html):`--dry-run`、`--Werror` 与 `-i` 的用法。
20
+ - [Google C++ Style Guide: Formatting](https://google.github.io/styleguide/cppguide.html#Formatting):Google 基线的排版约定。
@@ -49,3 +49,10 @@ clang-tidy -p build/clang \
49
49
  | tidy 报系统头 | 加了 `--system-headers` 或 header-filter 过宽 | 去掉 `--system-headers`,用项目头目录白名单 |
50
50
  | 大量 `readability-*` | 代码风格未统一 | 回到 `developing-cpp` 的定声明 / 定实现修声明与实现,不要批量 NOLINT |
51
51
  | clangd 与 tidy 诊断不一致 | 两者读的数据库/版本不同 | 统一 `CompilationDatabase` 与工具版本 |
52
+
53
+ ## 依据
54
+
55
+ - [clang-tidy](https://clang.llvm.org/extra/clang-tidy/):命令行、`-p` 与 `--warnings-as-errors`。
56
+ - [clang-tidy Checks](https://clang.llvm.org/extra/clang-tidy/checks/list.html):`google-*`、`bugprone-*` 与 `readability-identifier-naming` 的语义。
57
+ - [Clang-Tidy: `.clang-tidy`](https://clang.llvm.org/extra/clang-tidy/#using-clang-tidy):配置继承、`Checks` 与 `CheckOptions`。
58
+ - [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html):Google 检查族的规则来源。
@@ -81,3 +81,10 @@ Diagnostics:
81
81
  - 不推荐与 clangd 冲突的 C++ 智能提示插件;只保留一个语言服务。
82
82
  - 不把 `compile_commands.json` 提交进仓库;它是构建产物。
83
83
  - 切换编译器时同时改 `.clangd`、`settings.json` 和构建目录;三处不一致会让诊断指向旧代码。GCC 模式把 `MIMode` 改为 `gdb`、`miDebuggerPath` 改为 `/usr/bin/gdb`。
84
+
85
+ ## 依据
86
+
87
+ - [clangd: Configuration](https://clangd.llvm.org/config):`.clangd` 的 `CompileFlags`、`Diagnostics` 与 `CompilationDatabase`。
88
+ - [clangd: `--query-driver`](https://clangd.llvm.org/design/compile-commands#query-driver):允许读取系统头的驱动白名单。
89
+ - [clangd: Editor Plugins](https://clangd.llvm.org/installation#editor-plugins):VS Code 扩展与语言服务配置。
90
+ - [CMake Tools for VS Code](https://github.com/microsoft/vscode-cmake-tools/blob/main/docs/README.md):`cmake.buildDirectory`、`cmake.generator` 与调试配置。
@@ -0,0 +1,38 @@
1
+ # 正反例:clang-format
2
+
3
+ ## 构建脚本里自动格式化
4
+
5
+ **差**:
6
+
7
+ ```bash
8
+ clang-format -i src/*.cpp # 构建时悄悄改源码
9
+ ```
10
+
11
+ **好**:
12
+
13
+ ```bash
14
+ clang-format --dry-run --Werror "${sources[@]}" # 只检查
15
+ ```
16
+
17
+ 需要自动修复时单独运行 `clang-format -i`,由人确认 diff。
18
+
19
+ ## 配置文件堆策略头
20
+
21
+ **差**:
22
+
23
+ ```yaml
24
+ # 本项目遵循 Google C++ Style Guide,详见 docs/...
25
+ # 所有检查必须通过,禁止 NOLINT,禁止 ...
26
+ ColumnLimit: 100
27
+ ```
28
+
29
+ **好**:
30
+
31
+ ```yaml
32
+ # 全部取 Google 预设:80 列、2 空格、不用 tab、包含顺序。
33
+ Language: Cpp
34
+ BasedOnStyle: Google
35
+ Standard: Latest
36
+ ```
37
+
38
+ 配置只选预设和语言版本,不重复策略;列宽、缩进、包含顺序都由 Google 预设决定。需要新规则时先改技能文档并说明理由,不要在手写配置里堆本地约定。
@@ -1,26 +1,5 @@
1
1
  # 正反例:clang-tidy
2
2
 
3
- ## 配置文件堆策略头
4
-
5
- **差**:
6
-
7
- ```yaml
8
- # 本项目遵循 Google C++ Style Guide,详见 docs/...
9
- # 所有检查必须通过,禁止 NOLINT,禁止 ...
10
- ColumnLimit: 100
11
- ```
12
-
13
- **好**:
14
-
15
- ```yaml
16
- # 全部取 Google 预设:80 列、2 空格、不用 tab、包含顺序。
17
- Language: Cpp
18
- BasedOnStyle: Google
19
- Standard: Latest
20
- ```
21
-
22
- 配置只选预设和语言版本,不重复策略;列宽、缩进、包含顺序都由 Google 预设决定。需要新规则时先改技能文档并说明理由,不要在手写配置里堆本地约定。
23
-
24
3
  ## 整族关闭检查
25
4
 
26
5
  **差**: