diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-06-20 09:35:40 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-06-20 09:35:40 +0200 |
| commit | a45e660211b0e262a53047ac09426fd736d6ef9c (patch) | |
| tree | 623bd89ea48d6e7d2e3da75fff0d69bf2c4fe027 /buildme/main.cpp | |
| parent | 7a76789c12e33e98eff1e5651cb08f50987d96b8 (diff) | |
buildme: initial commit.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'buildme/main.cpp')
| -rw-r--r-- | buildme/main.cpp | 60 |
1 files changed, 57 insertions, 3 deletions
diff --git a/buildme/main.cpp b/buildme/main.cpp index a328171..b91bd98 100644 --- a/buildme/main.cpp +++ b/buildme/main.cpp @@ -6,9 +6,63 @@ // #include <iostream> +#include <fstream> -int main(int argc, const char * argv[]) { - // insert code here... - std::cout << "Hello, World!\n"; +#include "json.hpp" + +using json = nlohmann::json; + +int main(int argc, const char * argv[]) +{ + std::cout << "buildme: "; + std::string path; + + if (argc == 1) + { + std::cout << "no files, defaulting to build.json\n"; + path = "./build.json"; + } + else + { + path = argv[1]; + } + + try + { + std::ifstream fJson(path); + json buildme = json::parse(fJson); + + std::string compiler = buildme["compiler_path"].get<std::string>(); + std::cout << "choose toolchain: " << compiler << std::endl; + + json headerSearchPath = buildme["headers_path"]; + std::cout << "search path: " << headerSearchPath.dump() << std::endl; + + json sourceFiles = buildme["sources_path"]; + std::cout << "source files: " << sourceFiles.dump() << std::endl; + + std::string cmdLine = compiler + " "; + + for (auto sources : sourceFiles) + { + cmdLine += sources.get<std::string>() + " "; + } + + for (auto sources : sourceFiles) + { + cmdLine += "-include=" + sources.get<std::string>() + " "; + } + + cmdLine += "-std=" + buildme["compiler_std"].get<std::string>() + " "; + + std::cout << "running: " << cmdLine << std::endl; + + std::system(cmdLine.c_str()); + } + catch (...) + { + return 1; + } + return 0; } |
