初版可用

This commit is contained in:
2026-03-31 15:34:09 +08:00
commit 9b00ecb585
14 changed files with 366 additions and 0 deletions

20
.clang-format Normal file
View File

@@ -0,0 +1,20 @@
BasedOnStyle: LLVM
IndentWidth: 4
PointerAlignment: Left
AccessModifierOffset: -4
ReflowComments: true
SpacesBeforeTrailingComments: 3
AllowShortFunctionsOnASingleLine: None
AllowShortEnumsOnASingleLine: false
BreakBeforeBraces: Custom
BraceWrapping:
AfterFunction: true
AfterClass: true
TabWidth: 4
ColumnLimit: 130
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<.*>'
Priority: 1
- Regex: '^".*"'
Priority: 2

12
.clangd Normal file
View File

@@ -0,0 +1,12 @@
Hover:
ShowAKA: Yes
Diagnostics:
UnusedIncludes: None # 禁用未使用头文件提示
Suppress: [
anon_type_definition, # 禁用匿名的typedef提示
unused-variable, # 禁用未使用变量提示
unused-function, # 禁用未使用函数提示
unused-includes,
]
ClangTidy:
Remove: misc-unused-alias-decls

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
.cache/
.qtcreator/
build*

8
.zed/keymap.json Normal file
View File

@@ -0,0 +1,8 @@
[
{
"context": "Editor",
"bindings": {
"alt-g": "editor::GoToDefinition",
},
},
]

26
.zed/settings.json Normal file
View File

@@ -0,0 +1,26 @@
// Folder-specific settings
//
// For a full list of overridable settings, and general information on folder-specific settings,
// see the documentation: https://zed.dev/docs/configuring-zed#settings-files
{
"tab_size": 4,
"ensure_final_newline_on_save": true,
"lsp": {
"clangd": {
"binary": {
"arguments": [
"--header-insertion=never",
"--all-scopes-completion",
"--completion-style=detailed",
"--clang-tidy",
"-j=4",
"--pch-storage=memory",
"--compile-commands-dir=build",
"--background-index",
"--ranking-model=heuristics",
"--function-arg-placeholders=false",
],
},
},
},
}

54
.zed/tasks.json Normal file
View File

@@ -0,0 +1,54 @@
[
{
"label": "Debug-Config",
"command": "cmd",
"shell": {
"program": "C:\\Windows\\System32\\cmd.exe",
},
"env": {
"EXT_ARGS": "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_PREFIX_PATH=C:/local",
"CC": "clang",
"CXX": "clang++",
},
"args": [
"/c",
"cmake -Bbuild -S . -G Ninja %EXT_ARGS% -DCMAKE_BUILD_TYPE=Debug",
],
"cwd": "$ZED_WORKTREE_ROOT",
},
{
"label": "Debug-Build",
"command": "cmd",
"shell": {
"program": "C:\\Windows\\System32\\cmd.exe",
},
"args": ["/c", "cmake --build build --config Debug"],
"cwd": "$ZED_WORKTREE_ROOT",
},
{
"label": "Release-Config",
"command": "cmd",
"shell": {
"program": "C:\\Windows\\System32\\cmd.exe",
},
"env": {
"EXT_ARGS": "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_PREFIX_PATH=C:/local",
"CC": "clang",
"CXX": "clang++",
},
"args": [
"/c",
"cmake -Bbuild -S . -G Ninja %EXT_ARGS% -DCMAKE_BUILD_TYPE=Release",
],
"cwd": "$ZED_WORKTREE_ROOT",
},
{
"label": "Release-Build",
"command": "cmd",
"shell": {
"program": "C:\\Windows\\System32\\cmd.exe",
},
"args": ["/c", "cmake --build build --config Release"],
"cwd": "$ZED_WORKTREE_ROOT",
},
]

20
CMakeLists.txt Normal file
View File

@@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.16)
project(hello-cmake LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib/${CMAKE_BUILD_TYPE})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE})
find_package(cxxLibrary CONFIG REQUIRED)
if (MSVC)
add_compile_options(/utf-8)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()
add_executable(hello-cmake main.cpp)
target_link_libraries(hello-cmake PRIVATE cxxLibrary::cxxLibrary)
install(TARGETS hello-cmake DESTINATION bin)
install(DIRECTORY template DESTINATION bin)

111
main.cpp Normal file
View File

@@ -0,0 +1,111 @@
#include <boost/algorithm/string.hpp>
#include <boost/nowide/fstream.hpp>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <zoost/zoost.h>
namespace fs = std::filesystem;
bool CopyDirectory(const std::string& from, const std::string& to)
{
try {
fs::path source_path(from);
fs::path target_path(to);
if (!fs::exists(source_path) || !fs::is_directory(source_path)) {
std::cerr << "源目录不存在或不是目录: " << from << std::endl;
return false;
}
if (!fs::exists(target_path)) {
fs::create_directories(target_path);
}
for (const auto& entry : fs::recursive_directory_iterator(source_path)) {
try {
fs::path relative_path = entry.path().lexically_relative(source_path);
fs::path full_target_path = target_path / relative_path;
if (fs::is_directory(entry.status())) {
fs::create_directories(full_target_path);
} else if (fs::is_regular_file(entry.status())) {
fs::create_directories(full_target_path.parent_path());
fs::copy_file(entry.path(), full_target_path, fs::copy_options::overwrite_existing);
}
} catch (const std::exception& e) {
std::cerr << "处理文件时出错: " << entry.path() << " - " << e.what() << std::endl;
continue;
}
}
return true;
} catch (const std::exception& e) {
std::cerr << "复制目录时出错: " << e.what() << std::endl;
return false;
}
}
int main(int argc, char** argv)
{
zoostCommon::SetOutputU8();
zoostCommon::SetStdLibrayU8();
std::string arg("default");
if (argc > 1) {
arg = std::string(argv[1]);
}
zoostPath zp;
std::string binPath;
if (!zp.GetBinaryPath(binPath)) {
std::cerr << "获取二进制目录失败。" << std::endl;
return 1;
}
auto from = fs::path(binPath).parent_path().append("template").append(arg);
if (!fs::exists(from)) {
std::cerr << "源目录不存在: " << from << std::endl;
return 1;
}
auto toPath = fs::current_path();
// toPath必须为空目录
if (!toPath.empty() && !fs::is_empty(toPath)) {
std::cerr << "目标目录不是空目录: " << toPath << std::endl;
return 1;
}
std::cout << "从: " << from << " 复制到: " << toPath << std::endl;
if (!CopyDirectory(from.string(), toPath.string())) {
std::cerr << "复制目录失败。" << std::endl;
return 1;
}
std::cout << "复制完成。" << std::endl;
// 进行替换操作。
auto cmakeFile = fs::path(toPath).append("CMakeLists.txt");
if (fs::exists(cmakeFile)) {
boost::nowide::ifstream inFile(cmakeFile);
if (!inFile.is_open()) {
std::cerr << "无法打开 CMakeLists.txt 文件进行读取。" << std::endl;
return 1;
}
std::string content((std::istreambuf_iterator<char>(inFile)), std::istreambuf_iterator<char>());
inFile.close();
boost::replace_all(content, "zedTemplate", fs::path(toPath).filename().string());
boost::nowide::ofstream outFile(cmakeFile);
if (!outFile.is_open()) {
std::cerr << "无法打开 CMakeLists.txt 文件进行写入。" << std::endl;
return 1;
}
outFile.write(content.c_str(), content.size());
outFile.close();
} else {
std::cerr << "CMakeLists.txt 文件不存在。" << std::endl;
return 1;
}
return 0;
}

3
template/default/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
.cache/
.qtcreator/
build*

View File

@@ -0,0 +1,8 @@
[
{
"context": "Editor",
"bindings": {
"alt-g": "editor::GoToDefinition",
},
},
]

View File

@@ -0,0 +1,26 @@
// Folder-specific settings
//
// For a full list of overridable settings, and general information on folder-specific settings,
// see the documentation: https://zed.dev/docs/configuring-zed#settings-files
{
"tab_size": 4,
"ensure_final_newline_on_save": true,
"lsp": {
"clangd": {
"binary": {
"arguments": [
"--header-insertion=never",
"--all-scopes-completion",
"--completion-style=detailed",
"--clang-tidy",
"-j=4",
"--pch-storage=memory",
"--compile-commands-dir=build",
"--background-index",
"--ranking-model=heuristics",
"--function-arg-placeholders=false",
],
},
},
},
}

View File

@@ -0,0 +1,54 @@
[
{
"label": "Debug-Config",
"command": "cmd",
"shell": {
"program": "C:\\Windows\\System32\\cmd.exe",
},
"env": {
"EXT_ARGS": "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_PREFIX_PATH=C:/local",
"CC": "clang",
"CXX": "clang++",
},
"args": [
"/c",
"cmake -Bbuild -S . -G Ninja %EXT_ARGS% -DCMAKE_BUILD_TYPE=Debug",
],
"cwd": "$ZED_WORKTREE_ROOT",
},
{
"label": "Debug-Build",
"command": "cmd",
"shell": {
"program": "C:\\Windows\\System32\\cmd.exe",
},
"args": ["/c", "cmake --build build --config Debug"],
"cwd": "$ZED_WORKTREE_ROOT",
},
{
"label": "Release-Config",
"command": "cmd",
"shell": {
"program": "C:\\Windows\\System32\\cmd.exe",
},
"env": {
"EXT_ARGS": "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_PREFIX_PATH=C:/local",
"CC": "clang",
"CXX": "clang++",
},
"args": [
"/c",
"cmake -Bbuild -S . -G Ninja %EXT_ARGS% -DCMAKE_BUILD_TYPE=Release",
],
"cwd": "$ZED_WORKTREE_ROOT",
},
{
"label": "Release-Build",
"command": "cmd",
"shell": {
"program": "C:\\Windows\\System32\\cmd.exe",
},
"args": ["/c", "cmake --build build --config Release"],
"cwd": "$ZED_WORKTREE_ROOT",
},
]

View File

@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.16)
project(zedTemplate LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib/${CMAKE_BUILD_TYPE})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE})
if (MSVC)
add_compile_options(/utf-8)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()
add_executable(zedTemplate main.cpp)

View File

@@ -0,0 +1,7 @@
#include <iostream>
int main()
{
std::cout << "Done." << std::endl;
return 0;
}