commit 9b00ecb5859dffbb7ef1e4248717dfb1d6c1fef2 Author: taynpg Date: Tue Mar 31 15:34:09 2026 +0800 初版可用 diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..8d63d3f --- /dev/null +++ b/.clang-format @@ -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 diff --git a/.clangd b/.clangd new file mode 100644 index 0000000..40557fb --- /dev/null +++ b/.clangd @@ -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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..531d993 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.cache/ +.qtcreator/ +build* diff --git a/.zed/keymap.json b/.zed/keymap.json new file mode 100644 index 0000000..bc550ff --- /dev/null +++ b/.zed/keymap.json @@ -0,0 +1,8 @@ +[ + { + "context": "Editor", + "bindings": { + "alt-g": "editor::GoToDefinition", + }, + }, +] diff --git a/.zed/settings.json b/.zed/settings.json new file mode 100644 index 0000000..df0a4b2 --- /dev/null +++ b/.zed/settings.json @@ -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", + ], + }, + }, + }, +} diff --git a/.zed/tasks.json b/.zed/tasks.json new file mode 100644 index 0000000..9deecc0 --- /dev/null +++ b/.zed/tasks.json @@ -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", + }, +] diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..6a629f5 --- /dev/null +++ b/CMakeLists.txt @@ -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) diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..a229ad3 --- /dev/null +++ b/main.cpp @@ -0,0 +1,111 @@ +#include +#include +#include +#include +#include +#include + +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(inFile)), std::istreambuf_iterator()); + 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; +} diff --git a/template/default/.gitignore b/template/default/.gitignore new file mode 100644 index 0000000..531d993 --- /dev/null +++ b/template/default/.gitignore @@ -0,0 +1,3 @@ +.cache/ +.qtcreator/ +build* diff --git a/template/default/.zed/keymap.json b/template/default/.zed/keymap.json new file mode 100644 index 0000000..bc550ff --- /dev/null +++ b/template/default/.zed/keymap.json @@ -0,0 +1,8 @@ +[ + { + "context": "Editor", + "bindings": { + "alt-g": "editor::GoToDefinition", + }, + }, +] diff --git a/template/default/.zed/settings.json b/template/default/.zed/settings.json new file mode 100644 index 0000000..df0a4b2 --- /dev/null +++ b/template/default/.zed/settings.json @@ -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", + ], + }, + }, + }, +} diff --git a/template/default/.zed/tasks.json b/template/default/.zed/tasks.json new file mode 100644 index 0000000..9deecc0 --- /dev/null +++ b/template/default/.zed/tasks.json @@ -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", + }, +] diff --git a/template/default/CMakeLists.txt b/template/default/CMakeLists.txt new file mode 100644 index 0000000..7817406 --- /dev/null +++ b/template/default/CMakeLists.txt @@ -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) diff --git a/template/default/main.cpp b/template/default/main.cpp new file mode 100644 index 0000000..8e14207 --- /dev/null +++ b/template/default/main.cpp @@ -0,0 +1,7 @@ +#include + +int main() +{ + std::cout << "Done." << std::endl; + return 0; +}