From 5d0c57b85870326d54e799961a9f2a2b3e8fcc75 Mon Sep 17 00:00:00 2001 From: taynpg Date: Sat, 7 Mar 2026 23:01:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8F=AF=E7=94=A8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .clang-format | 20 ++ .clangd | 12 ++ .gitignore | 9 + .vscode/settings.json | 124 ++++++++++++ README.md | 3 + script/quick-xmake-install.bat | 116 +++++++++++ script/quick-xmake-uninstall.bat | 61 ++++++ src/main.cpp | 334 +++++++++++++++++++++++++++++++ xmake.lua | 100 +++++++++ 9 files changed, 779 insertions(+) create mode 100644 .clang-format create mode 100644 .clangd create mode 100644 .gitignore create mode 100644 .vscode/settings.json create mode 100644 README.md create mode 100644 script/quick-xmake-install.bat create mode 100644 script/quick-xmake-uninstall.bat create mode 100644 src/main.cpp create mode 100644 xmake.lua 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..e440f80 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store +compile_commands.json + +vv \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..eeb4506 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,124 @@ +{ + "files.autoSave": "onFocusChange", + "editor.fontSize": 14, + "editor.fontFamily": "'Source Code Pro', 'Source Code Pro', 'Source Code Pro'", + "editor.wordWrap": "on", + "terminal.integrated.fontFamily": "'Source Code Pro'", + "cmake.configureOnOpen": false, + "C_Cpp.intelliSenseEngine": "default", + "C_Cpp.default.compileCommands": "${workspaceRoot}/build/compile_commands.json", + "C_Cpp.default.cppStandard": "c++17", + "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools", + "editor.inlayHints.enabled": "off", + "editor.unicodeHighlight.allowedLocales": { + "ja": true, + "zh-hant": true, + "zh-hans": true + }, + "xmake.additionalConfigArguments": [ + + ], + "files.associations": { + "*.cfg": "json", + "xstring": "cpp", + "algorithm": "cpp", + "array": "cpp", + "atomic": "cpp", + "cctype": "cpp", + "charconv": "cpp", + "chrono": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "condition_variable": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "exception": "cpp", + "filesystem": "cpp", + "forward_list": "cpp", + "fstream": "cpp", + "functional": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "ios": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "iterator": "cpp", + "limits": "cpp", + "list": "cpp", + "locale": "cpp", + "map": "cpp", + "memory": "cpp", + "mutex": "cpp", + "new": "cpp", + "optional": "cpp", + "ostream": "cpp", + "ratio": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "string": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "thread": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "typeinfo": "cpp", + "unordered_map": "cpp", + "utility": "cpp", + "vector": "cpp", + "xfacet": "cpp", + "xhash": "cpp", + "xiosbase": "cpp", + "xlocale": "cpp", + "xlocbuf": "cpp", + "xlocinfo": "cpp", + "xlocmes": "cpp", + "xlocmon": "cpp", + "xlocnum": "cpp", + "xloctime": "cpp", + "xmemory": "cpp", + "xmemory0": "cpp", + "xstddef": "cpp", + "xtr1common": "cpp", + "xtree": "cpp", + "xutility": "cpp", + "bit": "cpp", + "compare": "cpp", + "concepts": "cpp", + "coroutine": "cpp", + "format": "cpp", + "stop_token": "cpp", + "bitset": "cpp", + "complex": "cpp", + "cstdarg": "cpp", + "set": "cpp", + "variant": "cpp", + "expected": "cpp", + "source_location": "cpp", + "regex": "cpp", + "*.in": "cpp", + "deque": "cpp", + "future": "cpp", + "queue": "cpp", + "resumable": "cpp", + "any": "cpp", + "codecvt": "cpp", + "csignal": "cpp", + "cwctype": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "random": "cpp", + "shared_mutex": "cpp", + "cinttypes": "cpp", + "cfenv": "cpp", + "unordered_set": "cpp", + "ranges": "cpp", + "typeindex": "cpp" + } +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..dc384bc --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# quick-xmake + +快速创建一个xmake控制台项目。 \ No newline at end of file diff --git a/script/quick-xmake-install.bat b/script/quick-xmake-install.bat new file mode 100644 index 0000000..0d4a078 --- /dev/null +++ b/script/quick-xmake-install.bat @@ -0,0 +1,116 @@ +@echo off +setlocal + +title Quick XMake Ҽ˵װ +echo ========================================= +echo Quick XMake - Ҽ˵װ +echo ========================================= +echo. + +REM ȡǰĿ¼ +for %%I in ("%~dp0.") do set "TOOLDIR=%%~fI" +set "DLLPATH=%TOOLDIR%\quick-xmake.dll" + +REM DLL ļǷ +if not exist "%DLLPATH%" ( + echo : quick-xmake.dll δҵ + echo 뽫ļ quick-xmake.dll ͬһĿ¼ + echo. + pause + exit /b 1 +) + +echo ڰװҼ˵... +echo. + +REM ɵע +echo ɵע... +reg delete "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake" /f 2>nul + +REM һ˵ +echo һ˵... +reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake" /ve /d "" /f +if %errorlevel% neq 0 ( + echo : һ˵ʧ + goto :error +) + +reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake" /v "MUIVerb" /d "quick-xmake" /f +reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake" /v "Icon" /d "%%SystemRoot%%\System32\shell32.dll,50" /f +reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake" /v "SubCommands" /d "" /f + +REM ˵ +echo ˵... + +REM ˵Create +reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake\shell\create" /ve /d "" /f +reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake\shell\create" /v "MUIVerb" /d "Create" /f +reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake\shell\create\command" /ve /d "rundll32.exe \"%DLLPATH%\",ContextMenuHandler \"%%V\" 0" /f + +REM ˵Build +reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake\shell\build" /ve /d "" /f +reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake\shell\build" /v "MUIVerb" /d "Build" /f +reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake\shell\build\command" /ve /d "rundll32.exe \"%DLLPATH%\",ContextMenuHandler \"%%V\" 1" /f + +REM ˵Set debug mode +reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake\shell\set-debug" /ve /d "" /f +reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake\shell\set-debug" /v "MUIVerb" /d "Set debug mode" /f +reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake\shell\set-debug\command" /ve /d "rundll32.exe \"%DLLPATH%\",ContextMenuHandler \"%%V\" 2" /f + +REM ˵Set release mode +reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake\shell\set-release" /ve /d "" /f +reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake\shell\set-release" /v "MUIVerb" /d "Set release mode" /f +reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake\shell\set-release\command" /ve /d "rundll32.exe \"%DLLPATH%\",ContextMenuHandler \"%%V\" 3" /f + +REM ˵Run +reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake\shell\run" /ve /d "" /f +reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake\shell\run" /v "MUIVerb" /d "Run" /f +reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake\shell\run\command" /ve /d "rundll32.exe \"%DLLPATH%\",ContextMenuHandler \"%%V\" 4" /f + +REM ˵Template +reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake\shell\template" /ve /d "" /f +reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake\shell\template" /v "MUIVerb" /d "Template" /f +reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake\shell\template\command" /ve /d "rundll32.exe \"%DLLPATH%\",ContextMenuHandler \"%%V\" 5" /f + +echo. +echo ========================================= +echo װɹ +echo ========================================= +echo. +echo ˵ṹ +echo ļпհ״Ҽ = quick-xmake = +echo Create +echo Build +echo Set debug mode +echo Set release mode +echo Run +echo. +echo ע +echo 1. űԶԹԱȨ +echo 2. ²˵Ҫ´Դʾ +echo 3. ҪԴ +echo. +choice /c YN /n /m "Դ (Y/N): " +if %errorlevel% equ 1 ( + echo Դ... + taskkill /f /im explorer.exe >nul 2>&1 + start explorer.exe + echo Դ +) else ( + echo ѡԺֶԴ + echo ´ļв鿴²˵ +) +echo. +pause +exit /b 0 + +:error +echo. +echo װгִ飺 +echo 1. ǷԹԱ +echo 2. עȨǷ +echo 3. ļ·Ƿַ +echo 4. DLLļǷռ +echo. +pause +exit /b 1 \ No newline at end of file diff --git a/script/quick-xmake-uninstall.bat b/script/quick-xmake-uninstall.bat new file mode 100644 index 0000000..e282917 --- /dev/null +++ b/script/quick-xmake-uninstall.bat @@ -0,0 +1,61 @@ +@echo off +setlocal + +title Quick XMake Ҽ˵ж +echo ========================================= +echo Quick XMake - Ҽ˵жع +echo ========================================= +echo. + +echo жҼ˵... +echo. + +REM ɾע㿪ʼ +echo ɾ˵... +reg delete "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake\shell\run\command" /f 2>nul +reg delete "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake\shell\template\command" /f 2>nul +reg delete "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake\shell\set-release\command" /f 2>nul +reg delete "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake\shell\set-debug\command" /f 2>nul +reg delete "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake\shell\build\command" /f 2>nul +reg delete "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake\shell\create\command" /f 2>nul + +echo ɾ˵... +reg delete "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake\shell\run" /f 2>nul +reg delete "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake\shell\template" /f 2>nul +reg delete "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake\shell\set-release" /f 2>nul +reg delete "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake\shell\set-debug" /f 2>nul +reg delete "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake\shell\build" /f 2>nul +reg delete "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake\shell\create" /f 2>nul + +echo ɾһ˵... +reg delete "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake\shell" /f 2>nul +reg delete "HKEY_CLASSES_ROOT\Directory\Background\shell\quick-xmake" /f 2>nul + +echo. +echo ========================================= +echo жسɹ +echo ========================================= +echo. +echo ɾ²˵ +echo Create +echo Build +echo Set debug mode +echo Set release mode +echo Run +echo. +echo ע +echo 1. ҪԴܿ˵Ƴ +echo 2. ǷԴ +echo. +choice /c YN /n /m "Դ (Y/N): " +if %errorlevel% equ 1 ( + echo Դ... + taskkill /f /im explorer.exe >nul 2>&1 + start explorer.exe + echo Դ +) else ( + echo ѡԺֶԴ +) +echo. +pause +exit /b 0 \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..ea07319 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,334 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace fs = std::filesystem; + +static std::shared_ptr logger; + +// 全局常量 +const char* MENU_NAME = "quick-xmake"; +const char* SUBMENU_NAMES[] = {"create", "build", "set-debug", "set-release"}; +const int SUBMENU_COUNT = 4; + +std::string WcharToChar(const wchar_t* wp, size_t m_encode = CP_ACP) +{ + std::string str; + int len = WideCharToMultiByte(m_encode, 0, wp, wcslen(wp), NULL, 0, NULL, NULL); + char* m_char = new char[len + 1]; + WideCharToMultiByte(m_encode, 0, wp, wcslen(wp), m_char, len, NULL, NULL); + m_char[len] = '\0'; + str = m_char; + delete m_char; + return str; +} + +std::string u8_to_ansi(const std::string& str) +{ + int wideCharLen = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, nullptr, 0); + if (wideCharLen <= 0) { + return ""; + } + std::wstring wideStr(wideCharLen, L'\0'); + MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, &wideStr[0], wideCharLen); + int gbkLen = WideCharToMultiByte(CP_ACP, 0, wideStr.c_str(), -1, nullptr, 0, nullptr, nullptr); + if (gbkLen <= 0) { + return ""; + } + std::string gbkStr(gbkLen, '\0'); + WideCharToMultiByte(CP_ACP, 0, wideStr.c_str(), -1, &gbkStr[0], gbkLen, nullptr, nullptr); + + gbkStr.resize(gbkLen - 1); + return gbkStr; +} +std::string ansi_to_u8(const std::string& str) +{ + int wideCharLen = MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, nullptr, 0); + if (wideCharLen <= 0) { + return ""; + } + std::wstring wideStr(wideCharLen, L'\0'); + MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, &wideStr[0], wideCharLen); + + int utf8Len = WideCharToMultiByte(CP_UTF8, 0, wideStr.c_str(), -1, nullptr, 0, nullptr, nullptr); + if (utf8Len <= 0) { + return ""; + } + std::string utf8Str(utf8Len, '\0'); + WideCharToMultiByte(CP_UTF8, 0, wideStr.c_str(), -1, &utf8Str[0], utf8Len, nullptr, nullptr); + + utf8Str.resize(utf8Len - 1); + return utf8Str; +} + +std::string GetQuickXmakeLogPath() +{ + try { + fs::path userDir; + char* userProfileEnv = std::getenv("USERPROFILE"); + if (userProfileEnv != nullptr) { + userDir = fs::path(userProfileEnv); + } else { + char* homeEnv = std::getenv("HOME"); + if (homeEnv != nullptr) { + userDir = fs::path(homeEnv); + } + } + if (userDir.empty() || !fs::exists(userDir)) { + userDir = fs::current_path(); + } + + fs::path logPath = userDir / ".config" / "quick-xmake" / "quick-xmake.log"; + + try { + fs::create_directories(logPath.parent_path()); + } catch (const std::exception& e) { + logger->error("Failed to create log directory: {}", ansi_to_u8(e.what())); + return "quick-xmake.log"; + } + + return logPath.string(); + + } catch (const std::exception& e) { + logger->error("Failed to get user directory: {}", ansi_to_u8(e.what())); + return "quick-xmake.log"; + } +} + +int ReplaceTemplate(const std::string& projectDir) +{ + fs::path p(projectDir); + p.append("xmake.lua"); + + if (!fs::exists(p)) { + logger->error("xmake.lua not found in {}", projectDir); + return 1; + } + + std::ifstream in(p.string()); + std::string content(std::istreambuf_iterator(in), {}); + in.close(); + + std::string newLuaContent = R"( +add_rules("mode.debug", "mode.release") +add_rules("plugin.compile_commands.autoupdate", {outputdir = "build"}) + +if is_plat("windows") then + add_cxxflags("/utf-8") + -- add_defines("WIN32_LEAN_AND_MEAN") +end + +set_languages("c++17") +)"; + + std::string lpre = R"(add_rules("mode.debug", "mode.release"))"; + boost::replace_all(content, lpre, newLuaContent); + std::ofstream out(p.string()); + out << content; + out.close(); + + fs::path pm(projectDir); + pm.append("src"); + pm.append("main.cpp"); + if (!fs::exists(pm)) { + logger->error("main.cpp not found in {}", projectDir); + return 1; + } + + std::ifstream inCpp(pm.string()); + std::string contentCpp(std::istreambuf_iterator(inCpp), {}); + inCpp.close(); + + std::string newCppContent = +R"(#ifdef _WIN32 +#include +#endif + +int main(int argc, char **argv) { + +#ifdef _WIN32 + SetConsoleOutputCP(CP_UTF8); +#endif +)"; + + std::string mpre = R"(int main(int argc, char **argv) {)"; + boost::replace_all(contentCpp, mpre, newCppContent); + std::ofstream outCpp(pm.string()); + outCpp << contentCpp; + outCpp.close(); + return 0; +} + +int ExecuteCmd(const std::string& exe, std::vector& args, const std::string& workDir) +{ + try { + // 构建 xmake 命令 + std::string xmakeCmd = "\"" + exe + "\""; + for (const auto& arg : args) { + xmakeCmd += " \"" + arg + "\""; + } + + // 完整的 cmd 命令:先 cd 到目录,然后执行 xmake,使用 /k 保持窗口打开 + std::string fullCmd = "cd /d \"" + workDir + "\" && " + xmakeCmd; + + logger->info("Command line: cmd /k {}", fullCmd); + + STARTUPINFOA si = {sizeof(STARTUPINFOA)}; + PROCESS_INFORMATION pi = {0}; + + // 设置控制台窗口 + si.dwFlags = STARTF_USESHOWWINDOW; + si.wShowWindow = SW_SHOW; + + // 构建包含 /k 的命令行 + std::string cmdLine = "cmd.exe /k \"" + fullCmd + "\""; + + BOOL success = CreateProcess(NULL, // 应用程序名称 + const_cast(cmdLine.c_str()), // 完整的命令行 + NULL, // 进程安全属性 + NULL, // 线程安全属性 + FALSE, // 不继承句柄 + CREATE_NEW_CONSOLE, // 创建新控制台 + NULL, // 环境块 + NULL, // 工作目录(已经在命令中指定) + &si, // STARTUPINFO + &pi // PROCESS_INFORMATION + ); + + if (!success) { + logger->error("CreateProcess failed: {}", GetLastError()); + return 1; + } + + // 立即返回,不等待进程结束 + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); + + logger->info("Process started successfully, console will remain open"); + return 0; // 立即返回成功 + + } catch (const std::exception& e) { + logger->error("Exception: {}", ansi_to_u8(e.what())); + return 1; + } +} + +extern "C" __declspec(dllexport) HRESULT CALLBACK ContextMenuHandler(HWND hwnd, HINSTANCE hinst, LPCSTR lpszCmdLine, int nCmdShow) +{ + std::shared_ptr quit(nullptr, [](void*) { + if (logger) { + logger->flush(); + } + spdlog::shutdown(); + }); + + auto file_sink = std::make_shared(GetQuickXmakeLogPath(), 1024 * 1024 * 50, 3); + file_sink->set_pattern("[%Y-%m-%d %H:%M:%S.%e][%l]: %v"); + std::vector sinks{file_sink}; + logger = std::make_shared("quick-xmake", sinks.begin(), sinks.end()); + logger->set_level(spdlog::level::debug); + spdlog::register_logger(logger); + + // 记录开始 + logger->info("=== ContextMenuHandler called ==="); + + std::string path = ansi_to_u8(lpszCmdLine); + logger->info("path:[{}], nCmdShow:[{}]", path, nCmdShow); + + std::vector vecArg; + boost::split(vecArg, path, boost::is_any_of(" ")); + if (vecArg.size() < 2) { + logger->error("invalid args: {}", path); + return S_OK; + } + + boost::trim_if(vecArg[0], boost::is_any_of("\"")); + // 0 是创建 + if (vecArg[1] == "0") { + std::vector args = {"create", "-l", "c++", "-P", "."}; + int ec = ExecuteCmd("xmake", args, vecArg[0]); + if (ec != 0) { + logger->error("xmake create failed, exit_code: {}", ec); + } else { + logger->info("xmake create success"); + } + } + // 1 是 build + else if (vecArg[1] == "1") { + std::vector args = {"build", "-P", "."}; + int ec = ExecuteCmd("xmake", args, vecArg[0]); + if (ec != 0) { + logger->error("xmake build failed, exit_code: {}", ec); + } else { + logger->info("xmake build success"); + } + } + // 2 是设置 debug + else if (vecArg[1] == "2") { + std::vector args = {"f", "-m", "debug", "-P", "."}; + int ec = ExecuteCmd("xmake", args, vecArg[0]); + if (ec != 0) { + logger->error("xmake config debug failed, exit_code: {}", ec); + } else { + logger->info("xmake config debug success"); + } + } + // 3 是设置 release + else if (vecArg[1] == "3") { + std::vector args = {"f", "-m", "release", "-P", "."}; + int ec = ExecuteCmd("xmake", args, vecArg[0]); + if (ec != 0) { + logger->error("xmake config release failed, exit_code: {}", ec); + } else { + logger->info("xmake config release success"); + } + } + // 4 是运行 + else if (vecArg[1] == "4") { + std::vector args = {"run", "-P", "."}; + int ec = ExecuteCmd("xmake", args, vecArg[0]); + if (ec != 0) { + logger->error("xmake run failed, exit_code: {}", ec); + } else { + logger->info("xmake run success"); + } + } + // 5 是替换 + else if (vecArg[1] == "5") { + auto r = ReplaceTemplate(vecArg[0]); + if (r) { + logger->info("replace template success"); + } else { + logger->error("replace template failed"); + } + } else { + logger->error("invalid vecArg[1]: {}", vecArg[1]); + return S_OK; + } + + logger->info("=== ContextMenuHandler end ==="); + return S_OK; +} + +// DLL入口点 +BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) +{ + return TRUE; +} + +// int main() +// { +// std::cout << "Hello World!\n"; +// ContextMenuHandler(NULL, NULL, "D:\\XmakeDemo\\simple_demo\\000 0", 0); +// return 0; +// } \ No newline at end of file diff --git a/xmake.lua b/xmake.lua new file mode 100644 index 0000000..c6c516b --- /dev/null +++ b/xmake.lua @@ -0,0 +1,100 @@ +add_rules("mode.debug", "mode.release") +add_rules("plugin.compile_commands.autoupdate", {outputdir = "build"}) + +if is_plat("windows") then + add_cxxflags("/utf-8") + add_defines("WIN32_LEAN_AND_MEAN") +end + +set_languages("c++17") + +add_requires("spdlog 1.17.0") +add_requires("fmt 12.1.0", { + configs = { + header_only = true + } +}) +add_requires("boost 1.90.0", { + configs = { + header_only = true + } +}) + +target("quick-xmake") + -- set_kind("binary") + set_kind("shared") + add_files("src/*.cpp") + add_syslinks("shell32", "user32", "ole32", "advapi32") + add_packages("spdlog") + add_packages("boost") + add_packages("fmt") + +-- +-- If you want to known more usage about xmake, please see https://xmake.io +-- +-- ## FAQ +-- +-- You can enter the project directory firstly before building project. +-- +-- $ cd projectdir +-- +-- 1. How to build project? +-- +-- $ xmake +-- +-- 2. How to configure project? +-- +-- $ xmake f -p [macosx|linux|iphoneos ..] -a [x86_64|i386|arm64 ..] -m [debug|release] +-- +-- 3. Where is the build output directory? +-- +-- The default output directory is `./build` and you can configure the output directory. +-- +-- $ xmake f -o outputdir +-- $ xmake +-- +-- 4. How to run and debug target after building project? +-- +-- $ xmake run [targetname] +-- $ xmake run -d [targetname] +-- +-- 5. How to install target to the system directory or other output directory? +-- +-- $ xmake install +-- $ xmake install -o installdir +-- +-- 6. Add some frequently-used compilation flags in xmake.lua +-- +-- @code +-- -- add debug and release modes +-- add_rules("mode.debug", "mode.release") +-- +-- -- add macro definition +-- add_defines("NDEBUG", "_GNU_SOURCE=1") +-- +-- -- set warning all as error +-- set_warnings("all", "error") +-- +-- -- set language: c99, c++11 +-- set_languages("c99", "c++11") +-- +-- -- set optimization: none, faster, fastest, smallest +-- set_optimize("fastest") +-- +-- -- add include search directories +-- add_includedirs("/usr/include", "/usr/local/include") +-- +-- -- add link libraries and search directories +-- add_links("tbox") +-- add_linkdirs("/usr/local/lib", "/usr/lib") +-- +-- -- add system link libraries +-- add_syslinks("z", "pthread") +-- +-- -- add compilation and link flags +-- add_cxflags("-stdnolib", "-fno-strict-aliasing") +-- add_ldflags("-L/usr/local/lib", "-lpthread", {force = true}) +-- +-- @endcode +-- +