From 1a8d7736a99c974462310e4efea2f47713255a8b Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Mon, 2 May 2022 19:50:11 +0200 Subject: Moc generation through ctor. --- ctor.cc | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 73 insertions(+), 9 deletions(-) diff --git a/ctor.cc b/ctor.cc index 2354499..7abd01b 100644 --- a/ctor.cc +++ b/ctor.cc @@ -1,12 +1,53 @@ // -*- c++ -*- #include +#include +#include namespace { -BuildConfigurations myConfigs() +std::vector eval_mocs(const std::string& path, + const std::vector>& moc_list) { - return + std::vector sources; + for(const auto& moc : moc_list) { + std::filesystem::path input(moc.first); + std::filesystem::path output(moc.second); + + std::filesystem::path fspath(path); + + if(!std::filesystem::exists(fspath / input)) + { + std::cerr << "Missing moc input file: " << input.string() << '\n'; + exit(1); + } + + if(!std::filesystem::exists(path / output) || + std::filesystem::last_write_time(path / input) > + std::filesystem::last_write_time(path / output)) + { + std::string cmd = "cd \"" + path + "\"; moc "; + cmd += "-o \"" + output.string() + "\" \"" + input.string() + "\""; + std::cerr << cmd << "\n"; + auto ret = system(cmd.data()); + if(ret != 0) + { + std::cerr << "moc generation failed: " << cmd << '\n'; + exit(ret); + } + } + sources.push_back((path / output).string()); + } + + return sources; +} + +BuildConfigurations myConfigs() +{ + // + // Qookie-cast client + // + BuildConfiguration qookie = { .target = "qookie", // output filename .sources = { @@ -15,11 +56,8 @@ BuildConfigurations myConfigs() "src/database_gourmet.cc", "src/database_krecipes.cc", "src/mainwindow.cc", - "src/moc_mainwindow.cc", "src/viewer.cc", - "src/moc_viewer.cc", "src/client.cc", - "src/moc_client.cc", }, .flags = { .cxxflags = { @@ -40,12 +78,27 @@ BuildConfigurations myConfigs() "-lsqlite3", } }, - }, + }; + std::vector qookie_mocs = + eval_mocs("src", + { + { "mainwindow.h", "moc_mainwindow.cc"}, + { "viewer.h", "moc_viewer.cc"}, + { "client.h", "moc_client.cc"}, + }); + for(const auto& moc : qookie_mocs) + { + qookie.sources.push_back(moc); + } + + // + // Qookie-cast client + // + BuildConfiguration qookie_cast_client = { .target = "qookie-cast-client", // output filename .sources = { "src/qookie-cast-client.cc", - "src/moc_qookie-cast-client.cc", }, .flags = { .cxxflags = { @@ -67,8 +120,19 @@ BuildConfigurations myConfigs() // "-lQt5WebKit", } }, - } - }; + }; + + std::vector qookie_cast_client_mocs = + eval_mocs("src", + { + { "qookie-cast-client.h", "moc_qookie-cast-client.cc"}, + }); + for(const auto& moc : qookie_cast_client_mocs) + { + qookie_cast_client.sources.push_back(moc); + } + + return {qookie, qookie_cast_client}; } } -- cgit v1.2.3