diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2021-06-19 18:00:48 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2021-06-19 18:19:44 +0200 |
commit | 69528ba012ac2238f63464fb84e7623f3088603a (patch) | |
tree | c587fb15494d448a572e28ad6156aa9bb196ac17 /libcppbuild.cc | |
parent | f1fda74cb76600b746cc3239f3ebf2f69ce2bf53 (diff) |
Add compilation database generation.
Diffstat (limited to 'libcppbuild.cc')
-rw-r--r-- | libcppbuild.cc | 37 |
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)) |