@chengzhao-dev/dsh-cpp-workflow 0.1.0 → 0.2.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/LICENSE +20 -20
- package/README.en.md +18 -16
- package/README.md +18 -16
- package/cordis.patch.yml +2 -5
- package/lib/index.js +7 -8
- package/lib/workspace.js +14 -14
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +5 -5
- package/skills/building-cpp/SKILL.md +6 -6
- package/skills/building-cpp/assets/config/.clang-format +3 -38
- package/skills/building-cpp/assets/config/.clang-tidy +8 -39
- package/skills/building-cpp/assets/config/.clangd +2 -5
- package/skills/building-cpp/assets/config/.vscode/extensions.json +2 -1
- package/skills/building-cpp/assets/config/.vscode/settings.json +16 -1
- package/skills/building-cpp/assets/templates/projects/common/running-build.sh +29 -18
- package/skills/building-cpp/assets/templates/projects/multi/CMakeLists.txt +9 -5
- package/skills/building-cpp/assets/templates/projects/multi/include/greeting.h +5 -3
- package/skills/building-cpp/assets/templates/projects/multi/src/greeting.cc +18 -0
- package/skills/building-cpp/assets/templates/projects/multi/src/main.cc +8 -0
- package/skills/building-cpp/assets/templates/projects/shared-library/CMakeLists.txt +8 -3
- package/skills/building-cpp/assets/templates/projects/shared-library/greeting/CMakeLists.txt +15 -5
- package/skills/building-cpp/assets/templates/projects/shared-library/greeting/include/greeting.h +5 -3
- package/skills/building-cpp/assets/templates/projects/shared-library/greeting/src/greeting.cc +18 -0
- package/skills/building-cpp/assets/templates/projects/shared-library/src/main.cc +8 -0
- package/skills/building-cpp/assets/templates/projects/single/CMakeLists.txt +7 -3
- package/skills/building-cpp/assets/templates/projects/single/src/main.cc +15 -0
- package/skills/building-cpp/assets/templates/projects/static-library/CMakeLists.txt +8 -3
- package/skills/building-cpp/assets/templates/projects/static-library/greeting/CMakeLists.txt +15 -5
- package/skills/building-cpp/assets/templates/projects/static-library/greeting/include/greeting.h +5 -3
- package/skills/building-cpp/assets/templates/projects/static-library/greeting/src/greeting.cc +18 -0
- package/skills/building-cpp/assets/templates/projects/static-library/src/main.cc +8 -0
- package/skills/building-cpp/examples/cmake.md +17 -17
- package/skills/building-cpp/examples/environment.md +4 -3
- package/skills/building-cpp/examples/tooling.md +31 -16
- package/skills/building-cpp/references/build-script.md +2 -2
- package/skills/building-cpp/references/cmake.md +35 -17
- package/skills/building-cpp/references/environment.md +17 -13
- package/skills/building-cpp/references/linking.md +6 -6
- package/skills/building-cpp/references/standards/README.md +165 -0
- package/skills/building-cpp/references/standards/c++11/README.md +50 -0
- package/skills/building-cpp/references/standards/c++11/cmake-snippet.cmake +7 -0
- package/skills/building-cpp/references/standards/c++14/README.md +48 -0
- package/skills/building-cpp/references/standards/c++14/cmake-snippet.cmake +7 -0
- package/skills/building-cpp/references/standards/c++17/README.md +49 -0
- package/skills/building-cpp/references/standards/c++17/cmake-snippet.cmake +7 -0
- package/skills/building-cpp/references/standards/c++20/README.md +49 -0
- package/skills/building-cpp/references/standards/c++20/cmake-snippet.cmake +7 -0
- package/skills/building-cpp/references/standards/c++23/README.md +50 -0
- package/skills/building-cpp/references/standards/c++23/cmake-snippet.cmake +7 -0
- package/skills/building-cpp/references/static-analysis.md +27 -15
- package/skills/building-cpp/scripts/checking-environment.mjs +21 -21
- package/skills/building-cpp/steps/01-build.md +78 -76
- package/skills/building-cpp/steps/02-tooling.md +43 -41
- package/skills/building-cpp/steps/03-check.md +60 -60
- package/skills/developing-cpp/SKILL.md +6 -6
- package/skills/developing-cpp/examples/comments.md +10 -8
- package/skills/developing-cpp/examples/exceptions.md +64 -45
- package/skills/developing-cpp/examples/naming.md +2 -2
- package/skills/developing-cpp/examples/structure.md +12 -9
- package/skills/developing-cpp/references/comments.md +10 -8
- package/skills/developing-cpp/references/declaration-order.md +7 -4
- package/skills/developing-cpp/references/exceptions.md +83 -46
- package/skills/developing-cpp/references/glossary.md +6 -6
- package/skills/developing-cpp/references/google-cpp-style.md +27 -37
- package/skills/developing-cpp/references/language.md +4 -4
- package/skills/developing-cpp/references/layout.md +14 -14
- package/skills/developing-cpp/references/naming.md +7 -6
- package/skills/developing-cpp/references/project-design.md +3 -3
- package/skills/developing-cpp/references/standard-library.md +1 -1
- package/skills/developing-cpp/steps/02-boundary.md +7 -7
- package/skills/developing-cpp/steps/03-declaration.md +9 -8
- package/skills/developing-cpp/steps/04-implementation.md +11 -7
- package/templates/cpp-workflow-project/SKILL.md +1 -1
- package/templates/cpp-workflow-project/environment.json +2 -1
- package/skills/building-cpp/assets/templates/projects/multi/src/greeting.cpp +0 -13
- package/skills/building-cpp/assets/templates/projects/multi/src/main.cpp +0 -8
- package/skills/building-cpp/assets/templates/projects/shared-library/greeting/src/greeting.cpp +0 -13
- package/skills/building-cpp/assets/templates/projects/shared-library/src/main.cpp +0 -8
- package/skills/building-cpp/assets/templates/projects/single/src/main.cpp +0 -9
- package/skills/building-cpp/assets/templates/projects/static-library/greeting/src/greeting.cpp +0 -13
- package/skills/building-cpp/assets/templates/projects/static-library/src/main.cpp +0 -8
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
|
|
3
|
-
# 配置、构建、格式化、静态检查、测试并运行当前 C++
|
|
2
|
+
#===------------------------------------------------------------------------===#
|
|
3
|
+
# 配置、构建、格式化、静态检查、测试并运行当前 C++11–C++23 工程(默认 C++23)。
|
|
4
4
|
#
|
|
5
5
|
# 用法:./running-build.sh [clang|gcc];省略时用 clang。
|
|
6
|
-
# 构建目录:build/<compiler
|
|
7
|
-
#
|
|
8
|
-
|
|
6
|
+
# 构建目录:build/<compiler>;
|
|
7
|
+
# 编译数据库:build/<compiler>/compile_commands.json
|
|
8
|
+
# 适用于 Linux、macOS 和 Windows + WSL;
|
|
9
|
+
# 本版本不支持 Windows 原生壳。
|
|
10
|
+
#===------------------------------------------------------------------------===#
|
|
9
11
|
|
|
10
12
|
set -euo pipefail
|
|
11
13
|
cd "$(dirname "$0")"
|
|
@@ -29,9 +31,9 @@ esac
|
|
|
29
31
|
readonly COMPILER CXX
|
|
30
32
|
readonly BUILD_DIR="${BUILD_ROOT}/${COMPILER}"
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
#===------------------------------------------------------------------------===#
|
|
33
35
|
# 输出辅助
|
|
34
|
-
|
|
36
|
+
#===------------------------------------------------------------------------===#
|
|
35
37
|
|
|
36
38
|
header() {
|
|
37
39
|
printf '\n== %s ==\n' "$1"
|
|
@@ -41,23 +43,29 @@ err() {
|
|
|
41
43
|
printf '错误: %s\n' "$1" >&2
|
|
42
44
|
}
|
|
43
45
|
|
|
44
|
-
|
|
46
|
+
on_error() {
|
|
47
|
+
local status=$?
|
|
48
|
+
printf '失败(退出码 %s):%s\n' "${status}" "${BASH_COMMAND}" >&2
|
|
49
|
+
}
|
|
50
|
+
trap on_error ERR
|
|
45
51
|
|
|
46
|
-
|
|
52
|
+
#===------------------------------------------------------------------------===#
|
|
47
53
|
# 项目源码
|
|
48
|
-
|
|
54
|
+
#===------------------------------------------------------------------------===#
|
|
49
55
|
|
|
50
56
|
collect_sources() {
|
|
51
57
|
find . \
|
|
52
58
|
\( -type d \( -name .git -o -name .cache -o -name node_modules \
|
|
53
59
|
-o -name third_party -o -name external -o -name vendor \
|
|
54
60
|
-o -name build -o -name temp -o -name templates \) -prune \) -o \
|
|
55
|
-
-type f \( -name '*.c' -o -name '*.cc' -o -name '*.cpp'
|
|
56
|
-
-o -name '*.
|
|
61
|
+
-type f \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' \
|
|
62
|
+
-o -name '*.cxx' -o -name '*.h' -o -name '*.hh' \
|
|
63
|
+
-o -name '*.hpp' -o -name '*.hxx' \) -print0
|
|
57
64
|
}
|
|
58
65
|
|
|
59
|
-
#
|
|
60
|
-
#
|
|
66
|
+
# 只让项目自身目录的头文件诊断进入结果。
|
|
67
|
+
# 顶层目录从项目文件推导,不硬编码 include/src;
|
|
68
|
+
# 项目根同时覆盖 clang-tidy 输出的绝对路径。
|
|
61
69
|
# 第三方头即使被包含,也不在项目根 + 顶层目录的白名单里。
|
|
62
70
|
header_filter_for() {
|
|
63
71
|
local tops=()
|
|
@@ -77,12 +85,14 @@ header_filter_for() {
|
|
|
77
85
|
printf '^(%s/)?[^/]+$' "${root}"
|
|
78
86
|
return 0
|
|
79
87
|
fi
|
|
80
|
-
|
|
88
|
+
local top_pattern
|
|
89
|
+
top_pattern="$(printf '%s\n' "${tops[@]}" | sort -u | paste -sd '|' -)"
|
|
90
|
+
printf '^(%s/)?((%s)/|[^/]+$)' "${root}" "${top_pattern}"
|
|
81
91
|
}
|
|
82
92
|
|
|
83
|
-
|
|
93
|
+
#===------------------------------------------------------------------------===#
|
|
84
94
|
# 主流程
|
|
85
|
-
|
|
95
|
+
#===------------------------------------------------------------------------===#
|
|
86
96
|
|
|
87
97
|
main() {
|
|
88
98
|
header "配置 (${COMPILER})"
|
|
@@ -97,7 +107,8 @@ main() {
|
|
|
97
107
|
|
|
98
108
|
header "编译数据库"
|
|
99
109
|
rm -f "${BUILD_ROOT}/compile_commands.json"
|
|
100
|
-
ln -s "${COMPILER}/compile_commands.json"
|
|
110
|
+
ln -s "${COMPILER}/compile_commands.json" \
|
|
111
|
+
"${BUILD_ROOT}/compile_commands.json"
|
|
101
112
|
|
|
102
113
|
local format_sources=()
|
|
103
114
|
local tidy_sources=()
|
|
@@ -7,12 +7,16 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
|
|
7
7
|
enable_testing()
|
|
8
8
|
|
|
9
9
|
add_executable(app
|
|
10
|
-
src/main.
|
|
11
|
-
src/greeting.
|
|
10
|
+
src/main.cc
|
|
11
|
+
src/greeting.cc
|
|
12
|
+
)
|
|
13
|
+
target_include_directories(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
|
14
|
+
target_compile_features(app PRIVATE cxx_std_23)
|
|
15
|
+
set_target_properties(app PROPERTIES
|
|
16
|
+
CXX_STANDARD 23
|
|
17
|
+
CXX_STANDARD_REQUIRED ON
|
|
18
|
+
CXX_EXTENSIONS OFF
|
|
12
19
|
)
|
|
13
|
-
target_include_directories(app PRIVATE include)
|
|
14
|
-
target_compile_features(app PRIVATE cxx_std_20)
|
|
15
|
-
set_target_properties(app PROPERTIES CXX_EXTENSIONS OFF)
|
|
16
20
|
target_compile_options(app PRIVATE -Wall -Wextra -Werror)
|
|
17
21
|
|
|
18
22
|
add_test(NAME app_smoke COMMAND app)
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
#
|
|
1
|
+
#ifndef CPP_WORKFLOW_TEMPLATE_MULTI_INCLUDE_GREETING_H_
|
|
2
|
+
#define CPP_WORKFLOW_TEMPLATE_MULTI_INCLUDE_GREETING_H_
|
|
2
3
|
|
|
3
4
|
#include <string>
|
|
4
|
-
#include <string_view>
|
|
5
5
|
|
|
6
6
|
namespace greeting {
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
std::string MakeGreeting(const std::string& name);
|
|
9
9
|
|
|
10
10
|
} // namespace greeting
|
|
11
|
+
|
|
12
|
+
#endif // CPP_WORKFLOW_TEMPLATE_MULTI_INCLUDE_GREETING_H_
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#include "include/greeting.h"
|
|
2
|
+
|
|
3
|
+
#include <string>
|
|
4
|
+
#if __cplusplus >= 202002L
|
|
5
|
+
#include <format>
|
|
6
|
+
#endif
|
|
7
|
+
|
|
8
|
+
namespace greeting {
|
|
9
|
+
|
|
10
|
+
std::string MakeGreeting(const std::string& name) {
|
|
11
|
+
#if __cplusplus >= 202002L
|
|
12
|
+
return std::format("Hello, {}!", name);
|
|
13
|
+
#else
|
|
14
|
+
return "Hello, " + name + "!";
|
|
15
|
+
#endif
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
} // namespace greeting
|
|
@@ -9,9 +9,14 @@ enable_testing()
|
|
|
9
9
|
|
|
10
10
|
add_subdirectory(greeting)
|
|
11
11
|
|
|
12
|
-
add_executable(app src/main.
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
add_executable(app src/main.cc)
|
|
13
|
+
target_include_directories(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
|
14
|
+
target_compile_features(app PRIVATE cxx_std_23)
|
|
15
|
+
set_target_properties(app PROPERTIES
|
|
16
|
+
CXX_STANDARD 23
|
|
17
|
+
CXX_STANDARD_REQUIRED ON
|
|
18
|
+
CXX_EXTENSIONS OFF
|
|
19
|
+
)
|
|
15
20
|
target_link_libraries(app PRIVATE greeting)
|
|
16
21
|
target_compile_options(app PRIVATE -Wall -Wextra -Werror)
|
|
17
22
|
|
package/skills/building-cpp/assets/templates/projects/shared-library/greeting/CMakeLists.txt
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
add_library(greeting SHARED src/greeting.
|
|
2
|
-
target_include_directories(greeting PUBLIC
|
|
3
|
-
target_compile_features(greeting PUBLIC
|
|
4
|
-
set_target_properties(greeting PROPERTIES
|
|
5
|
-
|
|
1
|
+
add_library(greeting SHARED src/greeting.cc)
|
|
2
|
+
target_include_directories(greeting PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/..)
|
|
3
|
+
target_compile_features(greeting PUBLIC cxx_std_23)
|
|
4
|
+
set_target_properties(greeting PROPERTIES
|
|
5
|
+
CXX_STANDARD 23
|
|
6
|
+
CXX_STANDARD_REQUIRED ON
|
|
7
|
+
CXX_EXTENSIONS OFF
|
|
8
|
+
)
|
|
9
|
+
target_compile_options(greeting PRIVATE
|
|
10
|
+
-Wall
|
|
11
|
+
-Wextra
|
|
12
|
+
-Werror
|
|
13
|
+
-Wold-style-cast
|
|
14
|
+
-Wshadow
|
|
15
|
+
)
|
package/skills/building-cpp/assets/templates/projects/shared-library/greeting/include/greeting.h
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
#
|
|
1
|
+
#ifndef CPP_WORKFLOW_TEMPLATE_GREETING_INCLUDE_GREETING_H_
|
|
2
|
+
#define CPP_WORKFLOW_TEMPLATE_GREETING_INCLUDE_GREETING_H_
|
|
2
3
|
|
|
3
4
|
#include <string>
|
|
4
|
-
#include <string_view>
|
|
5
5
|
|
|
6
6
|
namespace greeting {
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
std::string MakeGreeting(const std::string& name);
|
|
9
9
|
|
|
10
10
|
} // namespace greeting
|
|
11
|
+
|
|
12
|
+
#endif // CPP_WORKFLOW_TEMPLATE_GREETING_INCLUDE_GREETING_H_
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#include "greeting/include/greeting.h"
|
|
2
|
+
|
|
3
|
+
#include <string>
|
|
4
|
+
#if __cplusplus >= 202002L
|
|
5
|
+
#include <format>
|
|
6
|
+
#endif
|
|
7
|
+
|
|
8
|
+
namespace greeting {
|
|
9
|
+
|
|
10
|
+
std::string MakeGreeting(const std::string& name) {
|
|
11
|
+
#if __cplusplus >= 202002L
|
|
12
|
+
return std::format("Hello, {}!", name);
|
|
13
|
+
#else
|
|
14
|
+
return "Hello, " + name + "!";
|
|
15
|
+
#endif
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
} // namespace greeting
|
|
@@ -6,9 +6,13 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
|
|
6
6
|
|
|
7
7
|
enable_testing()
|
|
8
8
|
|
|
9
|
-
add_executable(app src/main.
|
|
10
|
-
target_compile_features(app PRIVATE
|
|
11
|
-
set_target_properties(app PROPERTIES
|
|
9
|
+
add_executable(app src/main.cc)
|
|
10
|
+
target_compile_features(app PRIVATE cxx_std_23)
|
|
11
|
+
set_target_properties(app PROPERTIES
|
|
12
|
+
CXX_STANDARD 23
|
|
13
|
+
CXX_STANDARD_REQUIRED ON
|
|
14
|
+
CXX_EXTENSIONS OFF
|
|
15
|
+
)
|
|
12
16
|
target_compile_options(app PRIVATE -Wall -Wextra -Werror)
|
|
13
17
|
|
|
14
18
|
add_test(NAME app_smoke COMMAND app)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#include <iostream>
|
|
2
|
+
#include <string>
|
|
3
|
+
#if __cplusplus >= 202002L
|
|
4
|
+
#include <format>
|
|
5
|
+
#endif
|
|
6
|
+
|
|
7
|
+
int main() {
|
|
8
|
+
const std::string name = "C++";
|
|
9
|
+
#if __cplusplus >= 202002L
|
|
10
|
+
std::cout << std::format("Hello, {}!\n", name);
|
|
11
|
+
#else
|
|
12
|
+
std::cout << "Hello, " << name << "!\n";
|
|
13
|
+
#endif
|
|
14
|
+
return 0;
|
|
15
|
+
}
|
|
@@ -9,9 +9,14 @@ enable_testing()
|
|
|
9
9
|
|
|
10
10
|
add_subdirectory(greeting)
|
|
11
11
|
|
|
12
|
-
add_executable(app src/main.
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
add_executable(app src/main.cc)
|
|
13
|
+
target_include_directories(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
|
14
|
+
target_compile_features(app PRIVATE cxx_std_23)
|
|
15
|
+
set_target_properties(app PROPERTIES
|
|
16
|
+
CXX_STANDARD 23
|
|
17
|
+
CXX_STANDARD_REQUIRED ON
|
|
18
|
+
CXX_EXTENSIONS OFF
|
|
19
|
+
)
|
|
15
20
|
target_link_libraries(app PRIVATE greeting)
|
|
16
21
|
target_compile_options(app PRIVATE -Wall -Wextra -Werror)
|
|
17
22
|
|
package/skills/building-cpp/assets/templates/projects/static-library/greeting/CMakeLists.txt
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
add_library(greeting STATIC src/greeting.
|
|
2
|
-
target_include_directories(greeting PUBLIC
|
|
3
|
-
target_compile_features(greeting PUBLIC
|
|
4
|
-
set_target_properties(greeting PROPERTIES
|
|
5
|
-
|
|
1
|
+
add_library(greeting STATIC src/greeting.cc)
|
|
2
|
+
target_include_directories(greeting PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/..)
|
|
3
|
+
target_compile_features(greeting PUBLIC cxx_std_23)
|
|
4
|
+
set_target_properties(greeting PROPERTIES
|
|
5
|
+
CXX_STANDARD 23
|
|
6
|
+
CXX_STANDARD_REQUIRED ON
|
|
7
|
+
CXX_EXTENSIONS OFF
|
|
8
|
+
)
|
|
9
|
+
target_compile_options(greeting PRIVATE
|
|
10
|
+
-Wall
|
|
11
|
+
-Wextra
|
|
12
|
+
-Werror
|
|
13
|
+
-Wold-style-cast
|
|
14
|
+
-Wshadow
|
|
15
|
+
)
|
package/skills/building-cpp/assets/templates/projects/static-library/greeting/include/greeting.h
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
#
|
|
1
|
+
#ifndef CPP_WORKFLOW_TEMPLATE_GREETING_INCLUDE_GREETING_H_
|
|
2
|
+
#define CPP_WORKFLOW_TEMPLATE_GREETING_INCLUDE_GREETING_H_
|
|
2
3
|
|
|
3
4
|
#include <string>
|
|
4
|
-
#include <string_view>
|
|
5
5
|
|
|
6
6
|
namespace greeting {
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
std::string MakeGreeting(const std::string& name);
|
|
9
9
|
|
|
10
10
|
} // namespace greeting
|
|
11
|
+
|
|
12
|
+
#endif // CPP_WORKFLOW_TEMPLATE_GREETING_INCLUDE_GREETING_H_
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#include "greeting/include/greeting.h"
|
|
2
|
+
|
|
3
|
+
#include <string>
|
|
4
|
+
#if __cplusplus >= 202002L
|
|
5
|
+
#include <format>
|
|
6
|
+
#endif
|
|
7
|
+
|
|
8
|
+
namespace greeting {
|
|
9
|
+
|
|
10
|
+
std::string MakeGreeting(const std::string& name) {
|
|
11
|
+
#if __cplusplus >= 202002L
|
|
12
|
+
return std::format("Hello, {}!", name);
|
|
13
|
+
#else
|
|
14
|
+
return "Hello, " + name + "!";
|
|
15
|
+
#endif
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
} // namespace greeting
|
|
@@ -10,14 +10,14 @@ 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
|
-
add_library(greeting STATIC greeting/src/greeting.
|
|
13
|
+
add_library(greeting STATIC greeting/src/greeting.cc)
|
|
14
14
|
target_include_directories(greeting PUBLIC greeting/include)
|
|
15
|
-
target_compile_features(greeting PUBLIC
|
|
15
|
+
target_compile_features(greeting PUBLIC cxx_std_23)
|
|
16
16
|
set_target_properties(greeting PROPERTIES CXX_EXTENSIONS OFF)
|
|
17
17
|
target_compile_options(greeting PRIVATE -Wall -Wextra -Werror)
|
|
18
18
|
|
|
19
|
-
add_executable(app src/main.
|
|
20
|
-
target_compile_features(app PRIVATE
|
|
19
|
+
add_executable(app src/main.cc)
|
|
20
|
+
target_compile_features(app PRIVATE cxx_std_23)
|
|
21
21
|
set_target_properties(app PROPERTIES CXX_EXTENSIONS OFF)
|
|
22
22
|
target_link_libraries(app PRIVATE greeting)
|
|
23
23
|
```
|
|
@@ -30,7 +30,7 @@ target_link_libraries(app PRIVATE greeting)
|
|
|
30
30
|
|
|
31
31
|
```cmake
|
|
32
32
|
include_directories(include greeting/include)
|
|
33
|
-
add_executable(app src/main.
|
|
33
|
+
add_executable(app src/main.cc greeting/src/greeting.cc)
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
问题:所有 target 共享 include,边界消失;程序直接编译库源码,测试无法只链接库。
|
|
@@ -47,7 +47,7 @@ target_link_libraries(app PRIVATE greeting)
|
|
|
47
47
|
**差**:
|
|
48
48
|
|
|
49
49
|
```cmake
|
|
50
|
-
file(GLOB SOURCES "src/*.
|
|
50
|
+
file(GLOB SOURCES "src/*.cc")
|
|
51
51
|
add_executable(app ${SOURCES})
|
|
52
52
|
```
|
|
53
53
|
|
|
@@ -57,9 +57,9 @@ add_executable(app ${SOURCES})
|
|
|
57
57
|
|
|
58
58
|
```cmake
|
|
59
59
|
add_executable(app
|
|
60
|
-
src/main.
|
|
61
|
-
src/task_list.
|
|
62
|
-
src/task_parser.
|
|
60
|
+
src/main.cc
|
|
61
|
+
src/task_list.cc
|
|
62
|
+
src/task_parser.cc
|
|
63
63
|
)
|
|
64
64
|
```
|
|
65
65
|
|
|
@@ -70,15 +70,15 @@ add_executable(app
|
|
|
70
70
|
**差**:
|
|
71
71
|
|
|
72
72
|
```cmake
|
|
73
|
-
add_library(core STATIC src/main.
|
|
74
|
-
add_executable(app src/main.
|
|
73
|
+
add_library(core STATIC src/main.cc src/core.cc)
|
|
74
|
+
add_executable(app src/main.cc) # 重复定义
|
|
75
75
|
```
|
|
76
76
|
|
|
77
77
|
**好**:
|
|
78
78
|
|
|
79
79
|
```cmake
|
|
80
|
-
add_library(core STATIC src/core.
|
|
81
|
-
add_executable(app src/main.
|
|
80
|
+
add_library(core STATIC src/core.cc)
|
|
81
|
+
add_executable(app src/main.cc)
|
|
82
82
|
target_link_libraries(app PRIVATE core)
|
|
83
83
|
```
|
|
84
84
|
|
|
@@ -93,7 +93,7 @@ target_link_libraries(app PRIVATE core)
|
|
|
93
93
|
```
|
|
94
94
|
|
|
95
95
|
```bash
|
|
96
|
-
clang-tidy src/main.
|
|
96
|
+
clang-tidy src/main.cc # 没有编译参数,头路径和标准都不对
|
|
97
97
|
```
|
|
98
98
|
|
|
99
99
|
**好**:
|
|
@@ -106,7 +106,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
|
106
106
|
cmake -S . -B build/clang -G Ninja -DCMAKE_CXX_COMPILER=clang++
|
|
107
107
|
rm -f build/compile_commands.json
|
|
108
108
|
ln -s clang/compile_commands.json build/compile_commands.json
|
|
109
|
-
clang-tidy -p build/clang src/main.
|
|
109
|
+
clang-tidy -p build/clang src/main.cc
|
|
110
110
|
```
|
|
111
111
|
|
|
112
112
|
## 共享库运行时路径
|
|
@@ -120,11 +120,11 @@ LD_LIBRARY_PATH=build/clang/lib ./build/clang/bin/app # 每次运行都要包
|
|
|
120
120
|
**好**:
|
|
121
121
|
|
|
122
122
|
```cmake
|
|
123
|
-
add_library(greeting SHARED greeting/src/greeting.
|
|
123
|
+
add_library(greeting SHARED greeting/src/greeting.cc)
|
|
124
124
|
set_target_properties(greeting PROPERTIES
|
|
125
125
|
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
|
|
126
126
|
|
|
127
|
-
add_executable(app src/main.
|
|
127
|
+
add_executable(app src/main.cc)
|
|
128
128
|
target_link_libraries(app PRIVATE greeting)
|
|
129
129
|
if(APPLE)
|
|
130
130
|
set_target_properties(app PROPERTIES BUILD_RPATH "@loader_path/../lib")
|
|
@@ -70,13 +70,14 @@ WSL 只对 `host=windows` 合法;不要通过改 `host` 来绕过,先确认
|
|
|
70
70
|
}
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
这不是「合法但暂时不能构建」,而是本版本直接拒绝的组合。声明校验返回:
|
|
74
74
|
|
|
75
75
|
```text
|
|
76
|
-
|
|
76
|
+
ok: false
|
|
77
|
+
issues: ["本版本不能在 Windows 原生壳里构建"]
|
|
77
78
|
```
|
|
78
79
|
|
|
79
|
-
|
|
80
|
+
停在这里。不要建议改 `build_host` 为 `wsl` 来绕过,也不要补 PowerShell 脚本。
|
|
80
81
|
|
|
81
82
|
## GCC 模式不比较 GCC 主版本
|
|
82
83
|
|
|
@@ -33,6 +33,27 @@ CompileFlags:
|
|
|
33
33
|
}
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
+
## `.clangd` 写死标准
|
|
37
|
+
|
|
38
|
+
**差**:
|
|
39
|
+
|
|
40
|
+
```yaml
|
|
41
|
+
# 工程已经在 CMake 里声明 C++23
|
|
42
|
+
CompileFlags:
|
|
43
|
+
CompilationDatabase: build/clang
|
|
44
|
+
Add:
|
|
45
|
+
- -std=c++20 # 覆盖 compile_commands.json,C++23 补全/诊断全部降级
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**好**:
|
|
49
|
+
|
|
50
|
+
```yaml
|
|
51
|
+
CompileFlags:
|
|
52
|
+
CompilationDatabase: build/clang
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
标准只来自 `compile_commands.json`。没有数据库时先回到定构建生成,不要在 `.clangd` 里猜一个 `-std`。
|
|
56
|
+
|
|
36
57
|
## 编译数据库指错目录
|
|
37
58
|
|
|
38
59
|
**差**:
|
|
@@ -64,11 +85,13 @@ ColumnLimit: 100
|
|
|
64
85
|
**好**:
|
|
65
86
|
|
|
66
87
|
```yaml
|
|
67
|
-
#
|
|
68
|
-
|
|
88
|
+
# 全部取 Google 预设:80 列、2 空格、不用 tab、包含顺序。
|
|
89
|
+
Language: Cpp
|
|
90
|
+
BasedOnStyle: Google
|
|
91
|
+
Standard: Latest
|
|
69
92
|
```
|
|
70
93
|
|
|
71
|
-
|
|
94
|
+
配置只选预设和语言版本,不重复策略;列宽、缩进、包含顺序都由 Google 预设决定。需要新规则时先改技能文档并说明理由,不要在手写配置里堆本地约定。
|
|
72
95
|
|
|
73
96
|
## 整族关闭检查
|
|
74
97
|
|
|
@@ -87,26 +110,18 @@ Checks: >
|
|
|
87
110
|
```yaml
|
|
88
111
|
Checks: >
|
|
89
112
|
-*,
|
|
90
|
-
clang-analyzer-*,
|
|
91
|
-
bugprone-*,
|
|
92
|
-
cppcoreguidelines-*,
|
|
93
113
|
google-*,
|
|
94
|
-
|
|
95
|
-
performance-*,
|
|
96
|
-
readability-*
|
|
97
|
-
CheckOptions:
|
|
98
|
-
# 团队用 100 列,tidy 的列宽判断跟随 clang-format。
|
|
99
|
-
readability-identifier-length.MinimumVariableNameLength: 2
|
|
114
|
+
readability-identifier-naming
|
|
100
115
|
```
|
|
101
116
|
|
|
102
|
-
|
|
117
|
+
保留 Google 检查主体和项目命名规则;关闭项逐条写理由,不整族关闭。不设 `FunctionCase`,Google 允许 `count()` / `set_count()` 这类访问器。
|
|
103
118
|
|
|
104
119
|
## tidy 扫描系统头
|
|
105
120
|
|
|
106
121
|
**差**:
|
|
107
122
|
|
|
108
123
|
```bash
|
|
109
|
-
clang-tidy -p build/clang --system-headers src/main.
|
|
124
|
+
clang-tidy -p build/clang --system-headers src/main.cc
|
|
110
125
|
```
|
|
111
126
|
|
|
112
127
|
系统头也参与诊断,出现大量第三方告警。
|
|
@@ -115,7 +130,7 @@ clang-tidy -p build/clang --system-headers src/main.cpp
|
|
|
115
130
|
|
|
116
131
|
```bash
|
|
117
132
|
clang-tidy -p build/clang --header-filter="^$(pwd -P)/(include|src)/" \
|
|
118
|
-
--warnings-as-errors='*' src/main.
|
|
133
|
+
--warnings-as-errors='*' src/main.cc
|
|
119
134
|
```
|
|
120
135
|
|
|
121
136
|
`--header-filter` 只列项目顶层目录,避免把第三方头纳入;系统头默认排除。工程有别的顶层目录时按实际替换。
|
|
@@ -125,7 +140,7 @@ clang-tidy -p build/clang --header-filter="^$(pwd -P)/(include|src)/" \
|
|
|
125
140
|
**差**:
|
|
126
141
|
|
|
127
142
|
```bash
|
|
128
|
-
clang-format -i src/*.
|
|
143
|
+
clang-format -i src/*.cc # 构建时悄悄改源码
|
|
129
144
|
```
|
|
130
145
|
|
|
131
146
|
**好**:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# 构建脚本
|
|
2
2
|
|
|
3
|
-
`assets/templates/projects/common/running-build.sh` 是 POSIX build-host 脚本,适用于 Linux、macOS 和 Windows + WSL
|
|
3
|
+
`assets/templates/projects/common/running-build.sh` 是 POSIX build-host 脚本,适用于 Linux、macOS 和 Windows + WSL。`host=windows` + `build_host=native` 不是本版本支持的组合:声明校验会直接拒绝,脚本也不会在原生 Windows 壳里运行。
|
|
4
4
|
|
|
5
5
|
## 用法
|
|
6
6
|
|
|
@@ -60,4 +60,4 @@
|
|
|
60
60
|
- 从工程根直接 `./build/clang/bin/app` 能启动(共享库场景由 RPATH 保证)。
|
|
61
61
|
- 切换编译器后 `build/compile_commands.json` 指向新数据库。
|
|
62
62
|
- 调用者的 `LD_LIBRARY_PATH` 在脚本结束后不变。
|
|
63
|
-
- Windows
|
|
63
|
+
- Windows 原生:声明校验已拒绝该组合;不要伪造 PowerShell 脚本,也不要绕过声明。
|