From 69528ba012ac2238f63464fb84e7623f3088603a Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 19 Jun 2021 18:00:48 +0200 Subject: Add compilation database generation. --- libcppbuild.cc | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'libcppbuild.cc') diff --git a/libcppbuild.cc b/libcppbuild.cc index 9fcc4d4..8d5231f 100644 --- a/libcppbuild.cc +++ b/libcppbuild.cc @@ -11,6 +11,7 @@ #include #include #include +#include #include @@ -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)) -- cgit v1.2.3