From 4226837dbc5aaec6cbbd145c8036c85b64d8d2f2 Mon Sep 17 00:00:00 2001 From: Jie Date: Mon, 25 Nov 2024 14:40:38 +0800 Subject: [PATCH] init --- .gitignore | 8 +++++ .vscode/settings.json | 69 +++++++++++++++++++++++++++++++++++++++ src/main.cpp | 49 ++++++++++++++++++++++++++++ xmake.lua | 76 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 202 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/settings.json create mode 100644 src/main.cpp create mode 100644 xmake.lua diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1521057 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..05b6b31 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,69 @@ +{ + "files.associations": { + "*.cpp": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "charconv": "cpp", + "chrono": "cpp", + "codecvt": "cpp", + "compare": "cpp", + "concepts": "cpp", + "condition_variable": "cpp", + "cstdint": "cpp", + "deque": "cpp", + "list": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "mutex": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "semaphore": "cpp", + "span": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "thread": "cpp", + "cinttypes": "cpp", + "typeinfo": "cpp", + "variant": "cpp", + "format": "cpp" + } +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..cceacd1 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,49 @@ +#include +#include +#include +#include +#include +#include +namespace fs = std::filesystem; + +std::string get_projectname(){ + auto workdir = fs::canonical(fs::current_path()); + while(true){ + for(auto& entry : fs::directory_iterator(workdir)){ + if(entry.path().filename() == "xmake.lua"){ + auto file = std::ifstream(entry.path(), std::ios::in); + std::string line; + while(getline(file, line)){ + if(line.find("target") != std::string::npos){ + return line.substr(line.find("\"") + 1, line.find_last_of("\"") - line.find_first_of("\"") -1); + } + } + } + } + if(workdir == fs::path("/home")){ + return ""; + } + workdir = workdir.parent_path(); + } +} + +int main(int argc, char** const argv){ + auto res = std::system("xmake build"); + if(argc < 2){ + if(res != 0) return -1; + return std::system("xmake run"); + } + auto project_name = get_projectname(); + if(project_name == ""){ + std::cout << "[Error] Not Find Xmake Project File" << std::endl; + return -1; + } + std::string opt; + for(int i = 1; i