@chengzhao-dev/dsh-cpp-workflow 0.7.6 → 0.7.7
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 +2 -2
- package/README.md +2 -2
- package/package.json +1 -1
- package/skills/building-cpp/SKILL.md +2 -2
- package/skills/building-cpp/assets/config/.clang-format +8 -8
- package/skills/building-cpp/assets/config/.clang-tidy +0 -4
- package/skills/building-cpp/assets/templates/projects/common/running-build.sh +42 -42
- package/skills/building-cpp/assets/templates/projects/multi/CMakeLists.txt +5 -5
- package/skills/building-cpp/assets/templates/projects/multi/include/greeting.h +1 -4
- package/skills/building-cpp/assets/templates/projects/multi/src/greeting.cpp +2 -2
- package/skills/building-cpp/assets/templates/projects/multi/src/main.cpp +2 -2
- package/skills/building-cpp/assets/templates/projects/shared-library/CMakeLists.txt +5 -5
- package/skills/building-cpp/assets/templates/projects/shared-library/greeting/CMakeLists.txt +8 -8
- package/skills/building-cpp/assets/templates/projects/shared-library/greeting/include/greeting.h +1 -4
- package/skills/building-cpp/assets/templates/projects/shared-library/greeting/src/greeting.cpp +2 -2
- package/skills/building-cpp/assets/templates/projects/shared-library/src/main.cpp +2 -2
- package/skills/building-cpp/assets/templates/projects/single/CMakeLists.txt +3 -3
- package/skills/building-cpp/assets/templates/projects/single/src/main.cpp +4 -4
- package/skills/building-cpp/assets/templates/projects/static-library/CMakeLists.txt +3 -3
- package/skills/building-cpp/assets/templates/projects/static-library/greeting/CMakeLists.txt +8 -8
- package/skills/building-cpp/assets/templates/projects/static-library/greeting/include/greeting.h +1 -4
- package/skills/building-cpp/assets/templates/projects/static-library/greeting/src/greeting.cpp +2 -2
- package/skills/building-cpp/assets/templates/projects/static-library/src/main.cpp +2 -2
- package/skills/building-cpp/references/02-environment.md +4 -4
- package/skills/building-cpp/steps/01-build.md +1 -1
- package/skills/building-cpp/steps/02-tooling.md +2 -2
- package/skills/building-cpp/steps/03-check.md +2 -0
- package/skills/building-cpp/steps/04-vscode.md +1 -1
- package/skills/developing-cpp/SKILL.md +2 -2
- package/skills/developing-cpp/references/comments/02-style.md +3 -2
- package/skills/developing-cpp/references/design/session-layer.md +10 -10
- package/skills/developing-cpp/references/index.md +4 -4
- package/skills/developing-cpp/references/language/glossary/01-language-terms.md +1 -1
- package/skills/developing-cpp/references/layout/01-source-layout.md +1 -1
- package/skills/developing-cpp/references/layout/02-file-template.md +24 -38
- package/skills/developing-cpp/references/layout/03-declaration-order.md +3 -6
- package/skills/developing-cpp/references/naming/01-identifier-names.md +7 -1
- package/skills/developing-cpp/references/style/01-google-cpp-style.md +4 -4
- package/skills/developing-cpp/scripts/checking-comments.mjs +23 -2
- package/skills/developing-cpp/steps/03-declaration.md +1 -1
- package/skills/engineering/SKILL.md +5 -5
- package/skills/engineering/references/cmake/assets/CompileSettings.cmake +100 -100
- package/skills/engineering/references/cmake/assets/LinkSettings.cmake +25 -25
- package/skills/engineering/references/cmake/assets/OutputSettings.cmake +38 -0
- package/skills/engineering/references/cmake/linking/01-libraries.md +1 -1
- package/skills/engineering/references/cmake/modules/01-functions.md +3 -2
- package/skills/engineering/references/cmake/standards/c++11/cmake-snippet.cmake +3 -3
- package/skills/engineering/references/cmake/standards/c++14/cmake-snippet.cmake +3 -3
- package/skills/engineering/references/cmake/standards/c++17/cmake-snippet.cmake +3 -3
- package/skills/engineering/references/cmake/standards/c++20/cmake-snippet.cmake +3 -3
- package/skills/engineering/references/cmake/standards/c++23/cmake-snippet.cmake +3 -3
- package/skills/engineering/references/cmake/standards/index.md +2 -2
- package/skills/engineering/references/cmake/standards/versions.md +1 -1
- package/skills/engineering/references/cmake/targets/01-target-rules.md +7 -7
- package/skills/engineering/references/formatting/01-encoding.md +4 -1
- package/skills/engineering/references/formatting/02-clang-format.md +1 -1
- package/skills/engineering/references/formatting/03-clang-tidy.md +2 -2
- package/skills/engineering/references/formatting/04-clangd.md +2 -2
- package/skills/engineering/references/formatting/examples/01-clang-format.md +2 -2
- package/skills/engineering/references/index.md +2 -2
- package/skills/engineering/steps/01-targets.md +3 -3
- package/skills/engineering/steps/02-modules.md +1 -1
- package/skills/engineering/steps/03-check.md +1 -1
- package/templates/cpp-workflow-project/SKILL.md +3 -2
|
@@ -51,107 +51,107 @@ Commands
|
|
|
51
51
|
include_guard(GLOBAL)
|
|
52
52
|
|
|
53
53
|
function(set_target_cxx_standard target visibility standard)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
54
|
+
set(supported_standards c++11 c++14 c++17 c++20 c++23)
|
|
55
|
+
|
|
56
|
+
if(NOT TARGET "${target}")
|
|
57
|
+
message(FATAL_ERROR
|
|
58
|
+
"set_target_cxx_standard: target '${target}' does not exist")
|
|
59
|
+
endif()
|
|
60
|
+
|
|
61
|
+
if(NOT visibility MATCHES "^(PUBLIC|PRIVATE|INTERFACE)$")
|
|
62
|
+
message(FATAL_ERROR
|
|
63
|
+
"set_target_cxx_standard: visibility must be "
|
|
64
|
+
"PUBLIC, PRIVATE, or INTERFACE")
|
|
65
|
+
endif()
|
|
66
|
+
|
|
67
|
+
if(NOT standard IN_LIST supported_standards)
|
|
68
|
+
message(FATAL_ERROR
|
|
69
|
+
"set_target_cxx_standard: standard must be one of "
|
|
70
|
+
"${supported_standards}")
|
|
71
|
+
endif()
|
|
72
|
+
|
|
73
|
+
string(SUBSTRING "${standard}" 3 -1 number)
|
|
74
|
+
|
|
75
|
+
target_compile_features("${target}" "${visibility}" "cxx_std_${number}")
|
|
76
|
+
|
|
77
|
+
set_target_properties("${target}" PROPERTIES
|
|
78
|
+
CXX_STANDARD "${number}"
|
|
79
|
+
CXX_STANDARD_REQUIRED ON
|
|
80
|
+
CXX_EXTENSIONS OFF
|
|
81
|
+
)
|
|
82
82
|
endfunction()
|
|
83
83
|
|
|
84
84
|
function(set_target_warnings target visibility)
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
85
|
+
cmake_parse_arguments(PARSE_ARGV 2 arg "" "LEVEL" "")
|
|
86
|
+
|
|
87
|
+
if(arg_UNPARSED_ARGUMENTS)
|
|
88
|
+
message(FATAL_ERROR
|
|
89
|
+
"set_target_warnings: unexpected arguments: "
|
|
90
|
+
"${arg_UNPARSED_ARGUMENTS}")
|
|
91
|
+
endif()
|
|
92
|
+
|
|
93
|
+
if(NOT TARGET "${target}")
|
|
94
|
+
message(FATAL_ERROR
|
|
95
|
+
"set_target_warnings: target '${target}' does not exist")
|
|
96
|
+
endif()
|
|
97
|
+
|
|
98
|
+
if(NOT visibility MATCHES "^(PRIVATE|INTERFACE)$")
|
|
99
|
+
message(FATAL_ERROR
|
|
100
|
+
"set_target_warnings: visibility must be PRIVATE or INTERFACE")
|
|
101
|
+
endif()
|
|
102
|
+
|
|
103
|
+
if(NOT arg_LEVEL)
|
|
104
|
+
set(arg_LEVEL standard)
|
|
105
|
+
endif()
|
|
106
|
+
|
|
107
|
+
if(MSVC)
|
|
108
|
+
set(basic_warnings /W4)
|
|
109
|
+
set(standard_warnings ${basic_warnings} /permissive- /WX)
|
|
110
|
+
set(strict_warnings
|
|
111
|
+
${standard_warnings}
|
|
112
|
+
/w14242 /w14254 /w14263 /w14265 /w14287 /w14296
|
|
113
|
+
/w14311 /w14545 /w14546 /w14547 /w14549 /w14555
|
|
114
|
+
/w14619 /w14640 /w14826
|
|
115
|
+
)
|
|
116
|
+
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
|
|
117
|
+
set(basic_warnings -Wall -Wextra)
|
|
118
|
+
set(standard_warnings
|
|
119
|
+
${basic_warnings}
|
|
120
|
+
-Werror
|
|
121
|
+
-Wshadow
|
|
122
|
+
-Wold-style-cast
|
|
123
|
+
-Wpedantic
|
|
124
|
+
-Wnon-virtual-dtor
|
|
125
|
+
-Woverloaded-virtual
|
|
126
|
+
)
|
|
127
|
+
set(strict_warnings
|
|
128
|
+
${standard_warnings}
|
|
129
|
+
-Wcast-align
|
|
130
|
+
-Wcast-qual
|
|
131
|
+
-Wconversion
|
|
132
|
+
-Wsign-conversion
|
|
133
|
+
-Wdouble-promotion
|
|
134
|
+
-Wformat=2
|
|
135
|
+
-Wimplicit-fallthrough
|
|
136
|
+
-Wnull-dereference
|
|
137
|
+
-Wundef
|
|
138
|
+
)
|
|
139
|
+
else()
|
|
140
|
+
message(FATAL_ERROR
|
|
141
|
+
"set_target_warnings: unsupported compiler "
|
|
142
|
+
"'${CMAKE_CXX_COMPILER_ID}'")
|
|
143
|
+
endif()
|
|
144
|
+
|
|
145
|
+
if(arg_LEVEL STREQUAL "basic")
|
|
146
|
+
set(warnings ${basic_warnings})
|
|
147
|
+
elseif(arg_LEVEL STREQUAL "standard")
|
|
148
|
+
set(warnings ${standard_warnings})
|
|
149
|
+
elseif(arg_LEVEL STREQUAL "strict")
|
|
150
|
+
set(warnings ${strict_warnings})
|
|
151
|
+
else()
|
|
152
|
+
message(FATAL_ERROR
|
|
153
|
+
"set_target_warnings: LEVEL must be basic, standard, or strict")
|
|
154
|
+
endif()
|
|
155
|
+
|
|
156
|
+
target_compile_options("${target}" "${visibility}" ${warnings})
|
|
157
157
|
endfunction()
|
|
@@ -36,32 +36,32 @@ Commands
|
|
|
36
36
|
include_guard(GLOBAL)
|
|
37
37
|
|
|
38
38
|
function(set_target_build_rpath target)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
39
|
+
if(NOT TARGET "${target}")
|
|
40
|
+
message(FATAL_ERROR
|
|
41
|
+
"set_target_build_rpath: target '${target}' does not exist")
|
|
42
|
+
endif()
|
|
43
|
+
|
|
44
|
+
if(APPLE)
|
|
45
|
+
set_target_properties("${target}" PROPERTIES
|
|
46
|
+
BUILD_RPATH "@loader_path/../lib")
|
|
47
|
+
else()
|
|
48
|
+
set_target_properties("${target}" PROPERTIES BUILD_RPATH "$ORIGIN/../lib")
|
|
49
|
+
endif()
|
|
50
50
|
endfunction()
|
|
51
51
|
|
|
52
52
|
function(fetch_googletest)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
53
|
+
include(FetchContent)
|
|
54
|
+
|
|
55
|
+
if(POLICY CMP0135)
|
|
56
|
+
cmake_policy(SET CMP0135 NEW)
|
|
57
|
+
endif()
|
|
58
|
+
|
|
59
|
+
FetchContent_Declare(
|
|
60
|
+
googletest
|
|
61
|
+
URL https://codeload.github.com/google/googletest/tar.gz/refs/tags/v1.17.0
|
|
62
|
+
URL_HASH
|
|
63
|
+
SHA256=65fab701d9829d38cb77c14acdc431d2108bfdbf8979e40eb8ae567edf10b27c
|
|
64
|
+
)
|
|
65
|
+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
|
66
|
+
FetchContent_MakeAvailable(googletest)
|
|
67
67
|
endfunction()
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#[=======================================================================[.rst:
|
|
2
|
+
OutputSettings
|
|
3
|
+
--------------
|
|
4
|
+
|
|
5
|
+
把构建产物输出到固定目录,便于脚本与文档按固定路径引用。
|
|
6
|
+
|
|
7
|
+
.. code-block:: cmake
|
|
8
|
+
|
|
9
|
+
include(OutputSettings)
|
|
10
|
+
|
|
11
|
+
Commands
|
|
12
|
+
^^^^^^^^
|
|
13
|
+
|
|
14
|
+
.. command:: set_output_directories
|
|
15
|
+
|
|
16
|
+
.. code-block:: cmake
|
|
17
|
+
|
|
18
|
+
set_output_directories()
|
|
19
|
+
|
|
20
|
+
在顶层 ``CMakeLists.txt`` 中调用一次,且要早于目标的创建(通常放在
|
|
21
|
+
``add_subdirectory()`` 之前)。函数把
|
|
22
|
+
``CMAKE_<TYPE>_OUTPUT_DIRECTORY`` 这类变量设为固定的输出目录;之后创建
|
|
23
|
+
目标时,CMake 用这些变量初始化目标的输出目录属性:
|
|
24
|
+
|
|
25
|
+
- ``RUNTIME`` 目标的产物输出到 ``build/bin``。
|
|
26
|
+
- ``LIBRARY`` 目标的产物输出到 ``build/lib``。
|
|
27
|
+
- ``ARCHIVE`` 目标的产物输出到 ``build/lib``。
|
|
28
|
+
#]=======================================================================]
|
|
29
|
+
|
|
30
|
+
include_guard(GLOBAL)
|
|
31
|
+
|
|
32
|
+
function(set_output_directories)
|
|
33
|
+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" PARENT_SCOPE)
|
|
34
|
+
|
|
35
|
+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" PARENT_SCOPE)
|
|
36
|
+
|
|
37
|
+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" PARENT_SCOPE)
|
|
38
|
+
endfunction()
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
- 普通函数的定义放 `.cpp`;在头文件里写非 `inline` 函数定义,多个翻译单元包含时会重复定义。
|
|
23
23
|
- 类定义放头文件;成员函数在类外定义时写 `ClassName::`,定义放 `.cpp`。
|
|
24
24
|
- 只用到声明时不要包含完整定义;前置声明可以减少编译依赖,但不能替代需要完整类型的场景(继承、成员对象、按值返回)。
|
|
25
|
-
- 每个头文件自包含:单独编译一个只包含该头文件的 `.cpp`
|
|
25
|
+
- 每个头文件自包含:单独编译一个只包含该头文件的 `.cpp` 应通过。这是编译单元边界的要求,不是链接要求。用 `#pragma once` 防止重复包含,不写 `#define` 宏守卫;宏名会把头文件绑死在项目路径上。
|
|
26
26
|
|
|
27
27
|
## 静态库与共享库
|
|
28
28
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<!-- 读取时机:配 CMake 或工具链时;读完能回答:CMake 模块与函数;预算:一次只开这一份(
|
|
1
|
+
<!-- 读取时机:配 CMake 或工具链时;读完能回答:CMake 模块与函数;预算:一次只开这一份(118 行),不自动串联。 -->
|
|
2
2
|
# CMake 模块与函数
|
|
3
3
|
|
|
4
4
|
目标:同一段构建逻辑只有一份权威,函数可导入、可校验、可测试,目标目录只表达差异。
|
|
@@ -21,6 +21,7 @@ project/
|
|
|
21
21
|
cmake/
|
|
22
22
|
CompileSettings.cmake
|
|
23
23
|
LinkSettings.cmake
|
|
24
|
+
OutputSettings.cmake
|
|
24
25
|
component/
|
|
25
26
|
CMakeLists.txt
|
|
26
27
|
app/
|
|
@@ -28,7 +29,7 @@ project/
|
|
|
28
29
|
```
|
|
29
30
|
|
|
30
31
|
- 一个文件放一组语义相近的函数,不为每个函数建单独文件;文件过大或出现无关职责时再拆。
|
|
31
|
-
- 文件名用 UpperCamelCase,与 CMake 官方 `Modules/` 一致;按职责命名,例如 `CompileSettings.cmake`、`LinkSettings.cmake`。不用 kebab-case,也不用现在分词。
|
|
32
|
+
- 文件名用 UpperCamelCase,与 CMake 官方 `Modules/` 一致;按职责命名,例如 `CompileSettings.cmake`、`LinkSettings.cmake`、`OutputSettings.cmake`。不用 kebab-case,也不用现在分词。
|
|
32
33
|
- 函数名用 snake_case,按“动词 + 对象”直接描述动作,例如
|
|
33
34
|
`set_target_cxx_standard`、`set_target_warnings`、`set_output_directories`;
|
|
34
35
|
不要机械重复模块名。CMake 没有命名空间,函数全局可见;确有重名风险时
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# c++11:把 target 名换成实际 target;与 environment.json 的 standard 一致。
|
|
2
2
|
target_compile_features(app PRIVATE cxx_std_11)
|
|
3
3
|
set_target_properties(app PROPERTIES
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
CXX_STANDARD 11
|
|
5
|
+
CXX_STANDARD_REQUIRED ON
|
|
6
|
+
CXX_EXTENSIONS OFF
|
|
7
7
|
)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# c++14:把 target 名换成实际 target;与 environment.json 的 standard 一致。
|
|
2
2
|
target_compile_features(app PRIVATE cxx_std_14)
|
|
3
3
|
set_target_properties(app PROPERTIES
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
CXX_STANDARD 14
|
|
5
|
+
CXX_STANDARD_REQUIRED ON
|
|
6
|
+
CXX_EXTENSIONS OFF
|
|
7
7
|
)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# c++17:把 target 名换成实际 target;与 environment.json 的 standard 一致。
|
|
2
2
|
target_compile_features(app PRIVATE cxx_std_17)
|
|
3
3
|
set_target_properties(app PROPERTIES
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
CXX_STANDARD 17
|
|
5
|
+
CXX_STANDARD_REQUIRED ON
|
|
6
|
+
CXX_EXTENSIONS OFF
|
|
7
7
|
)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# c++20:把 target 名换成实际 target;与 environment.json 的 standard 一致。
|
|
2
2
|
target_compile_features(app PRIVATE cxx_std_20)
|
|
3
3
|
set_target_properties(app PROPERTIES
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
CXX_STANDARD 20
|
|
5
|
+
CXX_STANDARD_REQUIRED ON
|
|
6
|
+
CXX_EXTENSIONS OFF
|
|
7
7
|
)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# c++23:把 target 名换成实际 target;与 environment.json 的 standard 一致。
|
|
2
2
|
target_compile_features(app PRIVATE cxx_std_23)
|
|
3
3
|
set_target_properties(app PROPERTIES
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
CXX_STANDARD 23
|
|
5
|
+
CXX_STANDARD_REQUIRED ON
|
|
6
|
+
CXX_EXTENSIONS OFF
|
|
7
7
|
)
|
|
@@ -46,7 +46,7 @@ Google C++ Style Guide 上游仍写 “target C++20”,本工作流默认 C++2
|
|
|
46
46
|
| --- | --- | --- |
|
|
47
47
|
| `std::string_view`、`std::optional`、`std::variant`、`if constexpr` | C++17 | 随语言核心 |
|
|
48
48
|
| `std::format` | C++20 | libstdc++ 13+;libc++ 14+(特性宏到 19 才稳定) |
|
|
49
|
-
| `std::print`、`std::expected`、`std::stacktrace` | C++23 | `std::print`:libstdc++ 14+、libc++
|
|
49
|
+
| `std::print`、`std::expected`、`std::stacktrace` | C++23 | `std::print`:libstdc++ 14+、libc++ 18+;`std::expected` 随各库 C++23 实现;`std::stacktrace` 还要链接对应库 |
|
|
50
50
|
|
|
51
51
|
Clang/GCC 的 “Partial” 状态意味着 C++23 不是全量实现。用到具体设施前,先查:
|
|
52
52
|
|
|
@@ -105,7 +105,7 @@ CompileFlags:
|
|
|
105
105
|
`.clang-tidy` 不写标准,标准来自编译数据库。检查项保持 Google 基线:
|
|
106
106
|
|
|
107
107
|
```yaml
|
|
108
|
-
Checks: '-*, google-*,
|
|
108
|
+
Checks: '-*, google-*, readability-identifier-naming'
|
|
109
109
|
WarningsAsErrors: '*'
|
|
110
110
|
FormatStyle: file
|
|
111
111
|
```
|
|
@@ -39,6 +39,6 @@
|
|
|
39
39
|
|
|
40
40
|
- 能用:C++20 的全部内容;`std::print`/`std::println`、`std::expected`、`std::stacktrace`、`if consteval`、显式对象参数(deducing this)、`std::mdspan`、`std::flat_map`、ranges 的 C++23 增补(工具链实现为准)。
|
|
41
41
|
- 不能假设:C++23 在 GCC/Clang 上仍是 Partial,具体设施要查编译器状态页;`std::print` 的库门槛是 libstdc++ 14+ / libc++ 19+;`std::stacktrace` 还要链接对应库;`std::expected` 的 monadic 接口、`std::flat_map` 等设施在旧标准库上可能缺失;模板只用 `std::format`,不因为默认 C++23 就强依赖 `print`/`stacktrace`。
|
|
42
|
-
- 降档/升级:从 C++23 降到 C++20 见上一节;升级到 C++26 前先确认 CMake 3.
|
|
42
|
+
- 降档/升级:从 C++23 降到 C++20 见上一节;升级到 C++26 前先确认 CMake 3.30+(首次接受 CXX_STANDARD 26/cxx_std_26)、编译器/标准库支持、clang-format 的 `c++26` 枚举,并按 [index.md](index.md#新增标准) 的流程新增片段与矩阵行。
|
|
43
43
|
- 验证:`compile_commands.json` 的最后一个 `-std=` 必须是 `-std=c++23`;模板在 C++23 下走 `std::format` 分支;若使用 `print`/`stacktrace`,另做链接测试。
|
|
44
44
|
- 片段:[cmake-snippet.cmake](c++23/cmake-snippet.cmake)。
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
## 排版
|
|
7
7
|
|
|
8
|
-
CMake 没有单独的官方风格指南文档,官方仓库的 [.editorconfig](https://raw.githubusercontent.com/Kitware/CMake/master/.editorconfig) 规定 `CMakeLists.txt`、`*.cmake`、`*.rst` 使用 `indent_size = 2`、`indent_style = space`;本机 `cmake 4.2` 的 359 个官方模块没有一个文件含 tab
|
|
8
|
+
CMake 没有单独的官方风格指南文档,官方仓库的 [.editorconfig](https://raw.githubusercontent.com/Kitware/CMake/master/.editorconfig) 规定 `CMakeLists.txt`、`*.cmake`、`*.rst` 使用 `indent_size = 2`、`indent_style = space`;本机 `cmake 4.2` 的 359 个官方模块没有一个文件含 tab。本仓与 C++ 源码统一为 4 个空格缩进,行内对齐也用空格;官方文档块内部仍按 RST 的 2 空格。行宽上限取 120 列,中文字符按 2 列计,既有 Tab 按 4 列展开后计宽;命令行、列表和注释一视同仁,官方文档块的分隔行固定 79 列,不跟着加宽。
|
|
9
9
|
|
|
10
10
|
注释用官方文档块。CMake 官方模块在文件开头放一个 `#[=======================================================================[.rst:` 块:模块名下一行画标题线,命令用 `.. command::`,签名用 `.. code-block:: cmake`,参数在正文里用双反引号包住(Kitware 的 [documentation.rst](https://github.com/Kitware/CMake/blob/master/Help/dev/documentation.rst) 与 [GoogleTest.cmake](https://github.com/Kitware/CMake/blob/master/Modules/GoogleTest.cmake) 都是这个形)。本仓照这个形写,块内散文用中文:模块名、`Commands`、`.. command::`、`.. code-block::` 这些标记保留英文,功能、边界与参数说明写中文句子。签名仍留在 `function()` 那一行,块里只抄调用形式,不重复参数表;CMake 函数没有返回值,不写 `:return:`,也不把 C++ 的 `@param`、`@return` 搬进来。模块文件不再画 `#---` 函数分隔线,一个文件的多个命令在 `Commands` 段落里逐个列出。`CMakeLists.txt` 以文件头开头:标题一行、`#` 一行、再用 1–2 行写用途,空一行后接命令;命令之间空一行,按“项目、模块、产物、子目录”的顺序自然分组,不画框线、不写段落标题;小文件可只留一行标题;工程模板提供最小形状,从 `cmake_minimum_required` 开始,注释保持最少,使用者按本段补齐;`CMakeLists.txt` 在每条命令上方写一句说明,子目录文件同样;同一文件保持同一句式,句子的主语按命令的实际对象(工程、目标、产物)写,不要每条都以「本工程」「本项目」开头。中文注释用全角标点,用书面语,避免口语词与网络用语;中文与英文、数字之间留一个空格,句子写完整并说明职责或原因,不复述命令名与模块名。模块文件(`*.cmake`)把说明写进 RST 文档块,函数体内不写行注释;子目录 `CMakeLists.txt` 用普通 `#` 注释。官方 [GoogleTest.cmake](https://github.com/Kitware/CMake/blob/master/Modules/GoogleTest.cmake) 在一个文件里放多个测试命令,可作“文件按职责聚合”的参照;社区 [CompilerWarnings.cmake](https://github.com/cpp-best-practices/cmake_template/blob/main/cmake/CompilerWarnings.cmake) 在每个警告 flag 后写它抓什么问题;本仓把这类说明收进文档块,函数体内不留行注释。
|
|
11
11
|
|
|
12
|
-
Shell 脚本同样用
|
|
12
|
+
Shell 脚本同样用 4 个空格缩进;Google Shell Style Guide 用 2 个空格,本仓为单仓统一而有意偏离。
|
|
13
13
|
|
|
14
14
|
## 最小可用形状
|
|
15
15
|
|
|
@@ -61,9 +61,9 @@ set_target_warnings(greeting PRIVATE LEVEL standard)
|
|
|
61
61
|
```
|
|
62
62
|
|
|
63
63
|
- 库的 `PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include` 让程序与链接它的测试写 `#include "greeting.h"` 就能找到公共头,不需要各自再写 include 路径。
|
|
64
|
-
- 标准用 `set_target_cxx_standard`:库用 `PUBLIC` 传播“至少 C++NN”,程序用 `PRIVATE`;`CXX_STANDARD`/`CXX_EXTENSIONS`
|
|
64
|
+
- 标准用 `set_target_cxx_standard`:库用 `PUBLIC` 传播“至少 C++NN”,程序用 `PRIVATE`;`CXX_STANDARD`/`CXX_EXTENSIONS` 是 target 属性,不是 INTERFACE 属性,不会跨 target 传播;每个会编译的 target 都要自己调用一次。
|
|
65
65
|
- `CXX_STANDARD_REQUIRED ON` 防止 CMake 在编译器不支持时静默降级;`CXX_EXTENSIONS OFF` 把 `-std=gnu++NN` 收成 `-std=c++NN`。configure 后检查 `compile_commands.json` 的最后一条 `-std=`。
|
|
66
|
-
- 程序 target
|
|
66
|
+
- 程序 target 用项目技能点名的名字(模板默认 `app`,本书 `terminal`);库 target 用组件名。
|
|
67
67
|
|
|
68
68
|
## 标准与复用
|
|
69
69
|
|
|
@@ -91,7 +91,7 @@ MSVC 分支用 `/W4`、`/permissive-`、`/WX`;其他编译器直接报错,
|
|
|
91
91
|
- 每个 target 自己声明 include、标准、编译选项、链接库;不要用全局 `include_directories()`、`add_definitions()`、`CMAKE_CXX_FLAGS` 给所有 target 加料。
|
|
92
92
|
- `target_include_directories(<target> PUBLIC|PRIVATE <dir>)`:公共头给 `PUBLIC`,私有实现目录给 `PRIVATE`。
|
|
93
93
|
- `target_compile_features(<target> PUBLIC|PRIVATE cxx_std_NN)`:只传播“至少 C++NN”的最低要求;精确 `-std` 由 `set_target_cxx_standard` 在会编译的 target 上设置,不靠这一步锁死。
|
|
94
|
-
- `target_link_libraries(<target> PRIVATE|PUBLIC <lib>)`:实现依赖用 `PRIVATE`,接口依赖用 `PUBLIC
|
|
94
|
+
- `target_link_libraries(<target> PRIVATE|PUBLIC <lib>)`:实现依赖用 `PRIVATE`,接口依赖用 `PUBLIC`。官方文档只保证第一个参数已创建;当前 CMake 实现能解析稍后定义的库,但这不是文档承诺,拼错库名还会退化成 `-lname`。工程约定先定义库、再定义程序,不依赖隐式排序。
|
|
95
95
|
- 不要 `file(GLOB ...)`;显式列源文件,新增文件时改 CMake,构建系统才知道。`CONFIGURE_DEPENDS` 依赖构建系统每次检查目录,跨生成器行为也不完全一致,不作为工程规则。
|
|
96
96
|
- 不把 `main()` 编进库;程序只做装配和 I/O。
|
|
97
97
|
- 头文件不参与编译时,不需要 `target_sources` 列出;需要 IDE 展示时再列。
|
|
@@ -109,7 +109,7 @@ MSVC 分支用 `/W4`、`/permissive-`、`/WX`;其他编译器直接报错,
|
|
|
109
109
|
project(TaskList VERSION 0.1.0 LANGUAGES CXX)
|
|
110
110
|
```
|
|
111
111
|
|
|
112
|
-
目录 `task-list/` 对应 `project(TaskList ...)`。派生规则是「按 `-` 切分、每段首字母大写、其余保留」,不要直接照抄目录名,也不要把 `{{PROJECT_NAME}}` 留在模板里。库 target 用组件名的小写形式(`task_list` 或 `tasks`),程序 target
|
|
112
|
+
目录 `task-list/` 对应 `project(TaskList ...)`。派生规则是「按 `-` 切分、每段首字母大写、其余保留」,不要直接照抄目录名,也不要把 `{{PROJECT_NAME}}` 留在模板里。库 target 用组件名的小写形式(`task_list` 或 `tasks`),程序 target 由项目技能点名,模板默认 `app`。
|
|
113
113
|
|
|
114
114
|
## 编译数据库
|
|
115
115
|
|
|
@@ -242,4 +242,4 @@ function(set_target_warnings target visibility)
|
|
|
242
242
|
- [CMake: `CMAKE_EXPORT_COMPILE_COMMANDS`](https://cmake.org/cmake/help/latest/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html):生成 `compile_commands.json`。
|
|
243
243
|
- [CMake: `CMAKE_CXX_STANDARD`](https://cmake.org/cmake/help/latest/variable/CMAKE_CXX_STANDARD.html):标准版本与 `CXX_STANDARD_REQUIRED`。
|
|
244
244
|
- [CMake `documentation.rst`](https://github.com/Kitware/CMake/blob/master/Help/dev/documentation.rst):官方文档块、`.. command::` 与参数段的写法。
|
|
245
|
-
- [CMake `.editorconfig`](https://raw.githubusercontent.com/Kitware/CMake/master/.editorconfig):官方取 2 个空格、不用 tab
|
|
245
|
+
- [CMake `.editorconfig`](https://raw.githubusercontent.com/Kitware/CMake/master/.editorconfig):官方取 2 个空格、不用 tab;本仓改为 4 个空格,仍不用 tab。
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<!-- 读取时机:排版或工具配置时;读完能回答:编码与行尾;预算:一次只开这一份(
|
|
1
|
+
<!-- 读取时机:排版或工具配置时;读完能回答:编码与行尾;预算:一次只开这一份(52 行),不自动串联。 -->
|
|
2
2
|
# 编码与行尾
|
|
3
3
|
|
|
4
4
|
默认组合是 UTF-8 无 BOM、LF。机器规则以仓库根 `.gitattributes` 与 `.editorconfig` 为准,本文件只记决定、MSVC 例外与检查方法。
|
|
@@ -26,6 +26,8 @@ MSVC 默认按 BOM 判断源码编码。源码没有 BOM 时,它按当前用
|
|
|
26
26
|
|
|
27
27
|
- `.gitattributes` 决定 Git 入库和检出;它覆盖贡献者自己的 `core.autocrlf`。
|
|
28
28
|
- `.editorconfig` 决定编辑器保存;`charset` 与 `end_of_line` 必须和 `.gitattributes` 同一档。
|
|
29
|
+
- `.editorconfig` 的边界:`[*]` 给 2 空格默认,C++、CMake、shell 覆盖成 4 个空格;`max_line_length`
|
|
30
|
+
不是核心键,VS Code 不读,C++ 的 120 由 `.clang-format` 的 `ColumnLimit` 强制,CMake 与 shell 只是参考线。
|
|
29
31
|
- `.clang-format` 写 `LineEnding: LF`,避免格式化把行尾改回 CRLF。
|
|
30
32
|
|
|
31
33
|
## 检查
|
|
@@ -39,6 +41,7 @@ node "<skill-dir>/scripts/checking-encoding.mjs" --profile portable
|
|
|
39
41
|
- `portable`(默认)要求所有文本文件 UTF-8 无 BOM、LF、末尾换行。
|
|
40
42
|
- `msvc` 只放宽 MSVC 编译的 C/C++ 源文件:允许 UTF-8 BOM 与 CRLF;Markdown、配置与脚本仍按 `portable` 检查。
|
|
41
43
|
- 退出码:0 无问题,1 有问题,2 参数或 Git 错误。加 `--json` 输出机器可读结果。
|
|
44
|
+
- 脚本只写 stdout,不生成报告文件;不要把输出重定向成仓库根下的日志。要留证据写 `temp/`,否则只引用终端输出。
|
|
42
45
|
|
|
43
46
|
再跑 `git diff --check`,确认没有空白错误。不要用 `git add --renormalize` 把行尾改动混进功能改动;确需规范化时单独提交并说明。
|
|
44
47
|
|
|
@@ -11,7 +11,7 @@ clang-format --dry-run --Werror src/*.cpp include/*.h app/*.cpp tests/*.cpp
|
|
|
11
11
|
- 工程必须有根 `.clang-format`;缺失时先复制配置,不要回退到内置风格,回退会掩盖配置缺失。
|
|
12
12
|
- 只扫描项目源码:`src/`、`include/`、`app/`、`tests/` 等实际存在的目录;不扫描 `build/`、第三方、生成文件。
|
|
13
13
|
- 配置文件在工程根 `.clang-format`;不要依赖用户主目录或编辑器内置配置。
|
|
14
|
-
- `BasedOnStyle: Google`、`Standard: Latest
|
|
14
|
+
- `BasedOnStyle: Google`、`Standard: Latest`;clang-format 21/22 不认 `c++23`,直接写会报 `error: unknown enumerated scalar`;23 起支持,但统一用 `Latest` 兼容旧版,由工具取它支持的最高标准。列宽、缩进与包含分块以工程根 `.clang-format` 为准;模板资产固定 `UseTab: Never`、`TabWidth: 4`、`IndentWidth: 4`、`ContinuationIndentWidth: 8`、`AccessModifierOffset: -4`、`ColumnLimit: 120` 与 `IncludeBlocks: Preserve`,不覆盖 `IncludeCategories`;工程显式写 `ColumnLimit` 时按工程值执行。
|
|
15
15
|
- 构造函数初始化列表写 `PackConstructorInitializers: BinPack`:放得下时并入一行,超出列宽再按成员换行。Google 预设逐项换行,成员一多就占五六行,与「列宽内保持一行」冲突;这条只在配置里定,不在条文里规定手写位置。
|
|
16
16
|
- 格式化失败就是失败,不要用 `// clang-format off` 绕过;确需关闭时只包住无法排版的宏或表格,并写一句理由。
|
|
17
17
|
|
|
@@ -12,11 +12,11 @@ clang-tidy -p build/clang \
|
|
|
12
12
|
|
|
13
13
|
- `-p` 指向当前编译器的构建目录,读取 `compile_commands.json`。
|
|
14
14
|
- `--header-filter` 控制哪些头文件的诊断被显示,不改变 clang-tidy 实际解析哪些头;模板实例化可能让一条根因产生多条警告,警告条数不等于缺陷条数。按根因修,不要按条数修。
|
|
15
|
-
- `--header-filter` 用项目头目录的白名单,不要用 `.*`
|
|
15
|
+
- `--header-filter` 用项目头目录的白名单,不要用 `.*` 把系统头和第三方头一并纳入。`--header-filter` 是对头文件名的正则;上面用 `$(pwd -P)` 前缀只是让正则匹配绝对路径的一种写法,不是文档强制。上面的目录是常见布局,工程用别的顶层目录时按实际替换。`--exclude-header-filter` 到 clang-tidy 19 才加入,16/17/18 都没有,不要依赖它。
|
|
16
16
|
- 系统头默认被排除,不要加 `--system-headers`。
|
|
17
17
|
- 只扫描项目源文件;不要把 `build/` 或第三方源码传给 clang-tidy。
|
|
18
18
|
- `--warnings-as-errors='*'` 把警告当失败;修代码,不要新增 `NOLINT`。确需抑制时写 `// NOLINT(检查名): 理由`,理由必须具体。
|
|
19
|
-
- 配置在工程根 `.clang-tidy`;默认集合是 `google
|
|
19
|
+
- 配置在工程根 `.clang-tidy`;默认集合是 `google-*` 与 `readability-identifier-naming`,不启用 `portability-avoid-pragma-once`(工程统一用 `#pragma once`)。关闭某条时逐条写理由,不整族关闭;命名规则只配项目确实统一的项,不设 `FunctionCase`。
|
|
20
20
|
- 没有编译数据库时先回到 `building-cpp` 的定构建生成;不要用 `--` 手工拼编译参数绕过。
|
|
21
21
|
- `clang-tidy` 的诊断可能指向头文件;修头文件里的声明或实现,不要只改调用点。
|
|
22
22
|
|
|
@@ -41,7 +41,7 @@ Diagnostics:
|
|
|
41
41
|
|
|
42
42
|
## 编辑器
|
|
43
43
|
|
|
44
|
-
`.vscode/extensions.json`
|
|
44
|
+
`.vscode/extensions.json` 推荐(`ms-vscode.cpptools` 只作调试后端,关闭 IntelliSense 与格式化;clangd 安装文档要求不装它,是针对 IntelliSense 冲突的默认建议,这里是明确的本地例外):
|
|
45
45
|
|
|
46
46
|
```json
|
|
47
47
|
{
|
|
@@ -64,7 +64,7 @@ Diagnostics:
|
|
|
64
64
|
],
|
|
65
65
|
"cmake.buildDirectory": "${workspaceFolder}/build/clang",
|
|
66
66
|
"cmake.generator": "Ninja",
|
|
67
|
-
"cmake.configureOnOpen":
|
|
67
|
+
"cmake.configureOnOpen": false,
|
|
68
68
|
"cmake.buildBeforeRun": true,
|
|
69
69
|
"cmake.exportCompileCommandsFile": true,
|
|
70
70
|
"cmake.debugConfig": {
|
|
@@ -30,7 +30,7 @@ BasedOnStyle: Google
|
|
|
30
30
|
**好**:
|
|
31
31
|
|
|
32
32
|
```yaml
|
|
33
|
-
# Google 基线;本工程用
|
|
33
|
+
# Google 基线;本工程用 4 个空格缩进、120 列。
|
|
34
34
|
Language: Cpp
|
|
35
35
|
BasedOnStyle: Google
|
|
36
36
|
Standard: Latest
|
|
@@ -38,7 +38,7 @@ IncludeBlocks: Preserve
|
|
|
38
38
|
ColumnLimit: 120
|
|
39
39
|
IndentWidth: 4
|
|
40
40
|
TabWidth: 4
|
|
41
|
-
UseTab:
|
|
41
|
+
UseTab: Never
|
|
42
42
|
ContinuationIndentWidth: 8
|
|
43
43
|
AccessModifierOffset: -4
|
|
44
44
|
PackConstructorInitializers: BinPack
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
| `cmake/linking/02-rpath.md` | 输出目录与 RPATH | 一次只开这一份(25 行),不自动串联。 |
|
|
12
12
|
| `cmake/linking/03-undefined-reference.md` | undefined reference 分诊 | 一次只开这一份(20 行),不自动串联。 |
|
|
13
13
|
| `cmake/linking/04-inspect.md` | 验收:file 与 ldd | 一次只开这一份(20 行),不自动串联。 |
|
|
14
|
-
| `cmake/modules/01-functions.md` | CMake 模块与函数 | 一次只开这一份(
|
|
14
|
+
| `cmake/modules/01-functions.md` | CMake 模块与函数 | 一次只开这一份(118 行),不自动串联。 |
|
|
15
15
|
| `cmake/standards/01-cxx-standard.md` | C++ 标准与 CMake | 一次只开这一份(68 行),不自动串联。 |
|
|
16
16
|
| `cmake/standards/versions.md` | C++11–C++23 各档差异 | 一次只开这一份(43 行),不自动串联。 |
|
|
17
17
|
| `cmake/standards/examples/01-standard.md` | 正反例:标准只写一半 | 一次只开这一份(19 行),不自动串联。 |
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
|
|
24
24
|
| 文件 | 读完能回答 | 预算 |
|
|
25
25
|
| --- | --- | --- |
|
|
26
|
-
| `formatting/01-encoding.md` | 编码与行尾 | 一次只开这一份(
|
|
26
|
+
| `formatting/01-encoding.md` | 编码与行尾 | 一次只开这一份(52 行),不自动串联。 |
|
|
27
27
|
| `formatting/02-clang-format.md` | clang-format | 一次只开这一份(23 行),不自动串联。 |
|
|
28
28
|
| `formatting/03-clang-tidy.md` | clang-tidy 与静态检查门禁 | 一次只开这一份(58 行),不自动串联。 |
|
|
29
29
|
| `formatting/04-clangd.md` | clangd 与编辑器 | 一次只开这一份(91 行),不自动串联。 |
|
|
@@ -18,13 +18,13 @@
|
|
|
18
18
|
|
|
19
19
|
target 规则:
|
|
20
20
|
|
|
21
|
-
- 程序 target
|
|
21
|
+
- 程序 target 用项目技能点名的名字(模板默认 `app`,本书 `terminal`);库 target 用组件名,程序链接库;不把 `main()` 编进库。
|
|
22
22
|
- 每个 target 自己声明 include、标准、编译选项和链接库;公共头用 `PUBLIC`,实现目录用 `PRIVATE`。
|
|
23
23
|
- 用 `target_include_directories`、`target_compile_features`、`target_link_libraries`;禁止全局 `include_directories()`、`add_definitions()`、`CMAKE_CXX_FLAGS`。target 内的命令按 `../references/cmake/targets/01-target-rules.md` 的块顺序写,标准与警告放在链接之前。
|
|
24
24
|
- 源文件显式列出;不写 `file(GLOB ...)`,新增文件时改 CMake。
|
|
25
25
|
- `set(CMAKE_EXPORT_COMPILE_COMMANDS ON)`;可执行文件输出到 `build/<compiler>/bin`,库到 `build/<compiler>/lib`。
|
|
26
26
|
- 需要直接运行构建产物的共享库程序,调用 `set_target_build_rpath(app)`;函数在 Linux 写 `$ORIGIN/../lib`,Apple 写 `@loader_path/../lib`。
|
|
27
|
-
- 标准用工程根 `cmake/` 里的 `set_target_cxx_standard(target visibility c++NN)
|
|
27
|
+
- 标准用工程根 `cmake/` 里的 `set_target_cxx_standard(target visibility c++NN)`;模板为了脱离插件可直接复制而内联三属性,复制进工程后应改回函数。没有这个函数时先从 `../references/cmake/assets/CompileSettings.cmake` 复制到工程根 `cmake/` 并导入,不要在每个 target 重复三属性。需要 `set_target_build_rpath` 或 `fetch_googletest` 时,把同目录的 `LinkSettings.cmake` 一并复制并 `include(LinkSettings)`。
|
|
28
28
|
- 警告用同一份 `CompileSettings.cmake` 里的 `set_target_warnings(target visibility LEVEL basic|standard|strict)`;`visibility` 用 `PRIVATE` 或 `INTERFACE`,不要在每个 target 重复 `-Wall` 列表。
|
|
29
29
|
|
|
30
30
|
## 命令形状
|
|
@@ -41,7 +41,7 @@ GCC 模式把目录和编译器换成 `build/gcc`、`g++`(C 驱动换成 `gcc`
|
|
|
41
41
|
|
|
42
42
|
## 情况
|
|
43
43
|
|
|
44
|
-
**新工程**:工程模板仍由 `building-cpp` 提供,从 `../../building-cpp/assets/templates/projects/` 选形态,只复制目标工程缺的文件;模板里的三属性与 `-Wall -Wextra -Werror` 只是可运行的最小形状,接管时按本节换成 `
|
|
44
|
+
**新工程**:工程模板仍由 `building-cpp` 提供,从 `../../building-cpp/assets/templates/projects/` 选形态,只复制目标工程缺的文件;模板里的三属性与 `-Wall -Wextra -Werror` 只是可运行的最小形状,接管时按本节换成 `set_target_cxx_standard`;需要警告时再加 `set_target_warnings`;模板里的 `{{PROJECT_NAME}}` 换成真实工程名,再按本节改 target 与标准。
|
|
45
45
|
|
|
46
46
|
**已有工程**:先读现有 `CMakeLists.txt`,找出全局设置、GLOB、输出目录和 target 命名;只改与当前任务相关的一处。大改前先让现有构建跑通,保留可回退点。
|
|
47
47
|
|