summaryrefslogtreecommitdiff
path: root/libcppbuild.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libcppbuild.cc')
-rw-r--r--libcppbuild.cc37
1 files changed, 37 insertions, 0 deletions
diff --git a/libcppbuild.cc b/libcppbuild.cc
index 9fcc4d4..8d5231f 100644
--- a/libcppbuild.cc
+++ b/libcppbuild.cc
@@ -11,6 +11,7 @@
#include <list>
#include <array>
#include <deque>
+#include <fstream>
#include <getoptpp/getoptpp.hpp>
@@ -179,6 +180,9 @@ int main(int argc, char* argv[])
std::max(1u, std::thread::hardware_concurrency() * 2 - 1);
settings.verbose = 0;
+ bool write_compilation_database{false};
+ std::string compilation_database;
+
dg::Options opt;
opt.add("jobs", required_argument, 'j',
@@ -210,6 +214,14 @@ int main(int argc, char* argv[])
return 0;
});
+ opt.add("database", required_argument, 'd',
+ "Write compilation database json file.",
+ [&]() {
+ write_compilation_database = true;
+ compilation_database = optarg;
+ return 0;
+ });
+
opt.add("help", no_argument, 'h',
"Print this help text.",
[&]() {
@@ -246,6 +258,31 @@ int main(int argc, char* argv[])
}
}
+ if(write_compilation_database)
+ {
+ std::ofstream istr(compilation_database);
+ istr << "[";
+ bool first{true};
+ for(auto task : tasks)
+ {
+ auto s = task->toJSON();
+ if(!s.empty())
+ {
+ if(!first)
+ {
+ istr << ",\n";
+ }
+ else
+ {
+ istr << "\n";
+ }
+ first = false;
+ istr << s;
+ }
+ }
+ istr << "\n]\n";
+ }
+
for(auto task : tasks)
{
if(task->registerDepTasks(tasks))