summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--xmake.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/xmake.cpp b/xmake.cpp
index e5f85ac..e4cadfb 100644
--- a/xmake.cpp
+++ b/xmake.cpp
@@ -6,6 +6,7 @@
#include <sstream>
#include <stdexcept>
#include <string>
+#include <unordered_map>
#include <vector>
#include <boost/property_tree/ptree.hpp>
@@ -70,7 +71,7 @@ namespace {
void build(const pt::ptree& ptree) {
fs::path target{get_target(ptree)};
-
+ std::vector<fs::path> objects{get_objects(ptree)};
std::vector<fs::path> sources{get_sources(ptree)};
std::cout << "Target: " << target << std::endl;
@@ -80,6 +81,16 @@ namespace {
std::cout << " " << i << std::endl;
}
+ std::unordered_map<fs::path, std::vector<fs::path>> dependencies;
+ dependencies.emplace(target, objects);
+ for (const auto& p: sources) {
+ fs::path p_obj{p};
+ p_obj.replace_extension("o");
+ dependencies.emplace(p_obj, std::vector<fs::path>{p});
+ // TODO: add headers dependencies:
+ // g++ -MM -MF <depsfile> -c <cppfile>
+ }
+
std::vector<std::string> commands;
// compile
for (auto &p: sources) {
@@ -90,9 +101,8 @@ namespace {
}
}
// link
- std::vector<fs::path> objects{get_objects(ptree)};
- std::vector<fs::path> dependencies{sources};
- if (is_outdated(target, dependencies)) {
+ std::vector<fs::path> deps{sources};
+ if (is_outdated(target, deps)) {
std::string link_command{"g++"};
for (auto &i: objects) {
link_command += fmt::format(" {}", i.string());
@@ -174,7 +184,6 @@ int xmake(int argc, char* argv[])
exit(1);
}
-
} catch (const std::exception& ex) {
std::cerr << "xmake: " << ex.what() << std::endl;
return 1;