Skip to content

Commit ef509a7

Browse files
feat: shared compiled; ui base; memory detections
1 parent 9a77956 commit ef509a7

55 files changed

Lines changed: 5121 additions & 78 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@ BLUEPRINT.md
88
out/
99

1010
# .vscode
11-
.vscode
11+
.vscode
12+
13+
# third_party dependencies (downloaded during configuration)
14+
third_party/*/
15+
!third_party/.gitkeep

CMakeLists.txt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,44 @@ message("Including Requested CMake Dependencies OK")
1212
include(cmake/check_toolchain.cmake)
1313
project(CFDesktop VERSION 0.0.1 LANGUAGES CXX)
1414

15+
# ------ Build Type Configuration ------
16+
# Validate and set build type
17+
if(NOT CMAKE_BUILD_TYPE)
18+
message(FATAL_ERROR "CMAKE_BUILD_TYPE is not set. Please specify build_type in build_*.config.ini")
19+
endif()
20+
21+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "RelWithDebInfo")
22+
23+
# Set compiler flags for each build type (use CACHE FORCE to override CMake defaults)
24+
# Debug: No optimization (-O0), full debug info (-g)
25+
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g" CACHE STRING "Flags used by the C++ compiler during Debug builds" FORCE)
26+
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "" CACHE STRING "Linker flags used during Debug builds" FORCE)
27+
28+
# Release: Maximum optimization (-O3), no debug info
29+
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "Flags used by the C++ compiler during Release builds" FORCE)
30+
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-s" CACHE STRING "Linker flags used during Release builds" FORCE)
31+
32+
# RelWithDebInfo: Optimization (-O2) + full debug info
33+
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG" CACHE STRING "Flags used by the C++ compiler during RelWithDebInfo builds" FORCE)
34+
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "" CACHE STRING "Linker flags used during RelWithDebInfo builds" FORCE)
35+
36+
string(TOUPPER "${CMAKE_BUILD_TYPE}" _build_type_upper)
37+
38+
# Log build type and compiler flags (use variable indirection for nested expansion)
39+
set(_cxx_flags_var "CMAKE_CXX_FLAGS_${_build_type_upper}")
40+
set(_link_flags_var "CMAKE_EXE_LINKER_FLAGS_${_build_type_upper}")
41+
42+
log_info("BuildSettings" "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
43+
log_info("BuildSettings" "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
44+
log_info("BuildSettings" "CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}: ${${_cxx_flags_var}}")
45+
log_info("BuildSettings" "CMAKE_EXE_LINKER_FLAGS: ${CMAKE_EXE_LINKER_FLAGS}")
46+
log_info("BuildSettings" "CMAKE_EXE_LINKER_FLAGS_${CMAKE_BUILD_TYPE}: ${${_link_flags_var}}")
47+
1548
# ------ Build Settings ------
49+
# Set output directories for all targets to ensure DLLs and executables are together
50+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
51+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
52+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
1653
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
1754
# Disable response files in compile_commands.json for better clangd compatibility
1855
set(CMAKE_CXX_RESPONSE_FILE_FLAG "@")
@@ -48,15 +85,25 @@ include(cmake/generate_develop_helpers.cmake)
4885
log_info("DevHelpers" "Will Generate VSCode clangd configuration")
4986
generate_vscode_clangd()
5087

88+
log_info("DevHelpers" "Will Generate VSCode debug configuration")
89+
generate_vscode_debug_config()
90+
5191
# Print build configuration
5292
log_config_summary()
5393
log_qt_dir()
94+
5495
# Log base module start
5596
log_module_start("base")
5697
add_subdirectory(base)
5798
# Log base module end
5899
log_module_end("base")
59100

101+
# Log base module start
102+
log_module_start("ui")
103+
add_subdirectory(ui)
104+
# Log base module end
105+
log_module_end("ui")
106+
60107

61108
log_module_start("example")
62109
add_subdirectory("example")

README.md

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,49 @@
4444
✓ 自动生成 clangd 配置
4545
✓ 保证与 QtCreator 几乎一致的丝滑开发体验
4646
✓ 支持 C++23 语法高亮和代码补全
47+
✓ 自动生成 launch.json 和 tasks.json(支持 GDB/LLDB 调试)
4748

4849
+3. 自动化构建脚本
4950
✓ Windows PowerShell 构建脚本
5051
✓ Linux Bash 构建脚本
5152
✓ 支持多种工具链配置(LLVM/GCC)
5253
✓ 部署(deploy)与开发(develop)双模式构建
53-
为后续开发打下坚实的基础
54+
新增测试运行脚本(windows_run_tests.ps1 / linux_run_tests.sh)
5455

5556
+4. CMake 基础设施
5657
✓ 模块化 CMake 架构
5758
✓ 自定义日志输出系统
5859
✓ 工具链检测与配置管理
5960
✓ 编译命令生成(compile_commands.json)
61+
✓ 第三方依赖管理(third_party_helper.cmake)
62+
✓ 自动化输出目录配置(bin/lib 分离)
63+
64+
+5. 硬件探针模块(Phase 1)
65+
✓ CPU 信息检测(型号、核心数、频率)
66+
✓ CPU Profile 和 Features 检测
67+
✓ 内存信息检测(Windows 平台完成)
68+
69+
+6. Base 基础库(Phase 2)
70+
✓ 统一 cfbase.dll 动态库架构
71+
✓ expected 类型(std::expected 风格的错误处理)
72+
✓ scope_guard(RAII 风格的资源管理)
73+
74+
+7. UI 组件库(Phase 4 - 提前启动)
75+
✓ Material Design 规范文档(MaterialRules.md)
76+
✓ 基础数学工具(math_helper)
77+
✓ 颜色处理工具(color_helper, color)
78+
✓ 缓动曲线封装(easing)
79+
✓ 几何图形工具(geometry_helper)
80+
✓ 设备像素转换(device_pixel)
6081
```
6182

6283
### 🚧 开发中
6384

6485
| 模块 | 状态 | 阶段 |
6586
|:---|:---:|:---:|
6687
| 🔍 硬件探针模块 | ⏳ 进行中 | Phase 1 |
67-
| 📦 Base 基础库 | 📋 计划中 | Phase 2 |
88+
| 📦 Base 基础库 | ⏳ 进行中 | Phase 2 |
89+
| 🎨 UI 组件库 | ⏳ 进行中 | Phase 4 |
6890
| ⌨️ 输入抽象层 | 📋 计划中 | Phase 3 |
6991

7092
---
@@ -121,6 +143,9 @@
121143
# 完整构建(包含完整清理流程)
122144
.\scripts\build_helpers\windows_develop_build.ps1
123145
.\scripts\build_helpers\windows_deploy_build.ps1
146+
147+
# 运行测试
148+
.\scripts\build_helpers\windows_run_tests.ps1
124149
```
125150

126151
### 🐧 Linux 构建
@@ -132,6 +157,9 @@
132157
# 快速构建(推荐日常开发)
133158
./scripts/build_helpers/linux_fast_develop_build.sh
134159
./scripts/build_helpers/linux_fast_deploy_build.sh
160+
161+
# 运行测试
162+
./scripts/build_helpers/linux_run_tests.sh
135163
```
136164

137165
### ⚙️ 构建配置
@@ -157,12 +185,20 @@
157185

158186
### 🤝 VSCode + Clangd
159187

160-
项目已配置自动生成 clangd 配置。首次运行 CMake 配置后,会在项目根目录生成 `.clangd` 配置文件,提供:
188+
项目已配置自动生成 VSCode 开发配置。首次运行 CMake 配置后:
189+
190+
**在构建目录生成:**
191+
- `.vscode/launch.json` - 调试配置(自动检测 GDB/LLDB)
192+
- `.vscode/tasks.json` - 构建任务(CMake Configure/Build/Clean/CTest)
193+
- `.clangd` - Clangd 语言服务器配置
161194

195+
**提供的功能:**
162196
- ✨ 精准的代码补全
163197
- ✔️ 实时语法检查
164198
- 🔍 跳转到定义
165199
- 🔧 重构支持
200+
- 🐛 一键调试(F5)
201+
- 📦 快速构建(Ctrl+Shift+B)
166202

167203
### 🎨 QtCreator
168204

@@ -261,7 +297,7 @@ graph LR
261297

262298
**Made with ❤️ for embedded devices**
263299

264-
*最后更新: 2026-02-21*
300+
*最后更新: 2026-02-23*
265301

266302
[⬆ 返回顶部](#-cfdesktop)
267303

base/CMakeLists.txt

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,36 @@
11
# Base library - fundamental utilities and platform abstractions
22
cmake_minimum_required(VERSION 3.16)
33

4-
# Include subdirectory CMakeLists
4+
# Include subdirectory CMakeLists (OBJECT libraries)
55
add_subdirectory(system/cpu)
66
add_subdirectory(system/memory)
77

88
# ============================================================
9-
# Unified Base Library
9+
# Unified Base Library - Single DLL: cfbase.dll
1010
# ============================================================
1111

12-
# Create interface library that merges all sub-libraries
13-
add_library(cfbase INTERFACE)
12+
# Create the unified shared library
13+
add_library(cfbase SHARED)
1414

15-
# Link all CPU and memory modules
16-
target_link_libraries(cfbase INTERFACE
17-
cfbase_cpu_info
18-
cfbase_cpu_profile
19-
cfbase_cpu_bonus
20-
cfbase_cpu_features
21-
cfbase_memory_info
15+
# Merge all object files from sub-modules
16+
target_sources(cfbase PRIVATE
17+
$<TARGET_OBJECTS:cfbase_cpu>
18+
$<TARGET_OBJECTS:cfbase_memory>
19+
)
20+
21+
# Set include directories
22+
target_include_directories(cfbase PUBLIC
23+
${CMAKE_CURRENT_SOURCE_DIR}/include
24+
)
25+
26+
# Link dependencies
27+
target_link_libraries(cfbase PUBLIC
2228
Qt6::Core
2329
)
2430

25-
# Platform-specific link for unified library
31+
# Platform-specific link libraries
2632
if(WIN32)
27-
target_link_libraries(cfbase INTERFACE
33+
target_link_libraries(cfbase PUBLIC
2834
wbemuuid
2935
PowrProf
3036
pdh
@@ -36,3 +42,6 @@ endif()
3642
# Aliases
3743
# ============================================================
3844
add_library(CFDesktop::base ALIAS cfbase)
45+
# For backward compatibility
46+
add_library(CFDesktop::base_cpu ALIAS cfbase)
47+
add_library(CFDesktop::base_memory ALIAS cfbase)

base/include/base/expected/expected.hpp

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,13 +1248,34 @@ template <typename T, typename E> class expected {
12481248
} else if (!has_val_ && !o.has_val_) {
12491249
swap(storage_.err, o.storage_.err);
12501250
} else {
1251-
expected* src = has_val_ ? this : &o;
1252-
expected* dst = has_val_ ? &o : this;
1253-
::new (&dst->storage_.val) T(std::move(src->storage_.val));
1254-
src->storage_.val.~T();
1255-
::new (&src->storage_.err) E(std::move(dst->storage_.err));
1256-
dst->storage_.err.~E();
1257-
swap(src->has_val_, dst->has_val_);
1251+
// Swap between value-holding and error-holding expected
1252+
if (has_val_) {
1253+
// this has value, o has error
1254+
T tmp_val(std::move(storage_.val));
1255+
storage_.val.~T();
1256+
1257+
::new (&storage_.err) E(std::move(o.storage_.err));
1258+
o.storage_.err.~E();
1259+
1260+
::new (&o.storage_.val) T(std::move(tmp_val));
1261+
// tmp_val is destroyed here
1262+
1263+
has_val_ = false;
1264+
o.has_val_ = true;
1265+
} else {
1266+
// this has error, o has value
1267+
E tmp_err(std::move(storage_.err));
1268+
storage_.err.~E();
1269+
1270+
::new (&storage_.val) T(std::move(o.storage_.val));
1271+
o.storage_.val.~T();
1272+
1273+
::new (&o.storage_.err) E(std::move(tmp_err));
1274+
// tmp_err is destroyed here
1275+
1276+
has_val_ = true;
1277+
o.has_val_ = false;
1278+
}
12581279
}
12591280
}
12601281

base/include/base/scope_guard/scope_guard.hpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ class ScopeGuard {
6060
* @since 0.1
6161
* @ingroup base_utilities
6262
*/
63-
explicit ScopeGuard(std::function<void()> f) : fn_(std::move(f)) {}
63+
template <typename F>
64+
explicit ScopeGuard(F&& f) : fn_(std::forward<F>(f)) {}
6465

6566
/**
6667
* @brief Destroys the scope guard and executes the cleanup function.
@@ -78,7 +79,7 @@ class ScopeGuard {
7879
* @since 0.1
7980
* @ingroup base_utilities
8081
*/
81-
~ScopeGuard() {
82+
~ScopeGuard() noexcept(false) {
8283
if (active_)
8384
fn_();
8485
}
@@ -99,6 +100,22 @@ class ScopeGuard {
99100
*/
100101
ScopeGuard& operator=(const ScopeGuard&) = delete;
101102

103+
/**
104+
* @brief Move constructor is deleted.
105+
*
106+
* @since 0.1
107+
* @ingroup base_utilities
108+
*/
109+
ScopeGuard(ScopeGuard&&) = delete;
110+
111+
/**
112+
* @brief Move assignment operator is deleted.
113+
*
114+
* @since 0.1
115+
* @ingroup base_utilities
116+
*/
117+
ScopeGuard& operator=(ScopeGuard&&) = delete;
118+
102119
/**
103120
* @brief Dismisses the scope guard.
104121
*

base/system/cpu/CMakeLists.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# CPU Module Library
1+
# CPU Module - compiled as OBJECT library for merging into cfbase.dll
22
cmake_minimum_required(VERSION 3.16)
33

4-
add_library(cfbase_cpu STATIC)
4+
add_library(cfbase_cpu OBJECT)
55
target_include_directories(cfbase_cpu
66
PUBLIC
77
${CMAKE_CURRENT_SOURCE_DIR}/../../include
@@ -24,7 +24,6 @@ if(WIN32)
2424
target_include_directories(cfbase_cpu PRIVATE
2525
${CMAKE_CURRENT_SOURCE_DIR}/private
2626
)
27-
target_link_libraries(cfbase_cpu PUBLIC wbemuuid PowrProf pdh)
2827
elseif(UNIX)
2928
target_sources(cfbase_cpu PRIVATE
3029
private/linux_impl/cpu_profile.cpp
@@ -34,5 +33,3 @@ elseif(UNIX)
3433
../../utils/linux/proc_parser.cpp
3534
)
3635
endif()
37-
38-
add_library(CFDesktop::base_cpu ALIAS cfbase_cpu)

base/system/memory/CMakeLists.txt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# Memory Module Library
1+
# Memory Module - compiled as OBJECT library for merging into cfbase.dll
22
cmake_minimum_required(VERSION 3.16)
33

4-
add_library(cfbase_memory STATIC)
4+
add_library(cfbase_memory OBJECT)
55
target_include_directories(cfbase_memory
66
PUBLIC
77
${CMAKE_CURRENT_SOURCE_DIR}/../../include
@@ -20,15 +20,8 @@ if(WIN32)
2020
private/win_impl/process_memory.cpp
2121
private/win_impl/dimm_info.cpp
2222
)
23-
target_link_libraries(cfbase_memory PUBLIC psapi)
2423
elseif(UNIX)
2524
target_sources(cfbase_memory PRIVATE
2625
private/linux_impl/memory_info.cpp
2726
)
2827
endif()
29-
30-
# Link Qt Core for QtGlobal header
31-
find_package(Qt6 COMPONENTS Core REQUIRED)
32-
target_link_libraries(cfbase_memory PRIVATE Qt6::Core)
33-
34-
add_library(CFDesktop::base_memory ALIAS cfbase_memory)

0 commit comments

Comments
 (0)