summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2024-05-01 15:51:40 +0200
committerRoland Reichwein <mail@reichwein.it>2024-05-01 15:51:40 +0200
commit8c344cf8fabded65cee42c69f63d2e47b9bef8d3 (patch)
treec15f1323df43782d8c410939d234be4f5a449285
parent16cf84958d059b7500f43dd1ba53e1ed680529a2 (diff)
First build possible
-rw-r--r--Makefile2
-rw-r--r--xmake.cpp49
2 files changed, 50 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 2a8759d..fec3007 100644
--- a/Makefile
+++ b/Makefile
@@ -6,6 +6,8 @@ OBJ=$(SRC:.cpp=.o)
all: $(PROJECTNAME)
+LDLIBS += -lfmt
+
$(PROJECTNAME): $(OBJ)
$(CXX) $(LDFLAGS) $^ $(LDLIBS) $(LIBS) -o $@
diff --git a/xmake.cpp b/xmake.cpp
index 9d953cc..c1095f4 100644
--- a/xmake.cpp
+++ b/xmake.cpp
@@ -1,14 +1,19 @@
#include "xmake.h"
+#include <cstdlib>
#include <filesystem>
#include <iostream>
#include <sstream>
+#include <stdexcept>
#include <string>
+#include <vector>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/process.hpp>
+#include <fmt/format.h>
+
namespace fs = std::filesystem;
namespace bp = boost::process;
namespace pt = boost::property_tree;
@@ -54,9 +59,51 @@ int xmake(int argc, char* argv[])
// TODO: clearlist
// TODO: dependencies
// TODO: buildlist
+ std::string target{ptree.get<std::string>("xmake.build.name")};
+
+ std::vector<std::string> sources;
+ for (pt::ptree::value_type &v: ptree.get_child("xmake.build")) {
+ if (v.first == "source")
+ sources.push_back(v.second.data());
+ }
+
+ std::cout << "Target: " << target << std::endl;
+
+ std::cout << "Sources: " << std::endl;
+ for (auto &i: sources) {
+ std::cout << " " << i << std::endl;
+ }
+
+ std::vector<std::string> commands;
+ // compile
+ for (auto &i: sources) {
+ fs::path p{i};
+ commands.push_back(fmt::format("g++ -std=c++17 -c {} -o {}", p.string(), p.replace_extension("o").string()));
+ }
+ // link
+ std::string link_command{"g++"};
+ for (auto &i: sources) {
+ link_command += fmt::format(" {}", fs::path{i}.replace_extension("o").string());
+ }
+ link_command += fmt::format(" -o {}", target);
+ commands.push_back(link_command);
+
+ std::cout << "Commands: " << std::endl;
+ for (auto &i: commands) {
+ std::cout << " " << i << std::endl;
+ }
+
+ std::cout << "Running commands: " << std::endl;
+ for (auto &i: commands) {
+ std::cout << i << std::endl;
+ int result{system(i.c_str())};
+ if (result != 0) {
+ throw std::runtime_error(fmt::format("Error {}", result));
+ }
+ }
} catch (const std::exception& ex) {
- std::cerr << "Error: " << ex.what() << std::endl;
+ std::cerr << "xmake: " << ex.what() << std::endl;
return 1;
}