From 9cdbb0cf222050b061d1cfdf21968cd775bd1eee Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Wed, 8 Jun 2022 18:10:04 +0200 Subject: Update libctor for function generation support which makes it possible to add better moc generation. --- ctor.cc | 108 ++++++++++++++++++---------------------------------------------- 1 file changed, 30 insertions(+), 78 deletions(-) (limited to 'ctor.cc') diff --git a/ctor.cc b/ctor.cc index d4d4e28..3c6d6ee 100644 --- a/ctor.cc +++ b/ctor.cc @@ -12,63 +12,10 @@ int execute(const std::string& command, namespace { -class PathRAII -{ -public: - PathRAII(const std::filesystem::path& path) - { - pwd = std::filesystem::current_path(); - std::filesystem::current_path(path); - } - - ~PathRAII() - { - std::filesystem::current_path(pwd); - } - -private: - std::filesystem::path pwd; -}; - -std::vector eval_mocs(const std::string& path, - const std::vector>& moc_list) -{ - 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)) - { - PathRAII p(path); - auto ret = execute("/usr/bin/moc", {"-o", output.string(), input.string()}); - if(ret != 0) - { - std::cerr << "moc generation failed\n"; - exit(ret); - } - } - sources.push_back((path / output).string()); - } - - return sources; -} - -BuildConfigurations myConfigs() +BuildConfigurations myConfigs(const Settings& settings) { // - // Qookie-cast client + // Qookie main application // BuildConfiguration qookie = { @@ -78,9 +25,13 @@ BuildConfigurations myConfigs() "src/database.cc", "src/database_gourmet.cc", "src/database_krecipes.cc", + "src/database_qookie.cc", "src/mainwindow.cc", "src/viewer.cc", "src/client.cc", + settings.builddir + "/moc_mainwindow.cc", + settings.builddir + "/moc_viewer.cc", + settings.builddir + "/moc_client.cc", }, .flags = { .cxxflags = { @@ -92,17 +43,27 @@ BuildConfigurations myConfigs() }, .externals = { "qt", "sqlite" }, }; - 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); - } + + // + // Moc generation for all configurations + // + BuildConfiguration mocs = + { + .sources = { + { "src/mainwindow.h", "moc_mainwindow.cc"}, + { "src/viewer.h", "moc_viewer.cc"}, + { "src/client.h", "moc_client.cc"}, + { "src/qookie-cast-client.h", "moc_qookie-cast-client.cc"}, + }, + .function = [](const std::string& input, + const std::string& output, + const BuildConfiguration& config, + const Settings& settings) + { + return execute("/usr/bin/moc", {"-I../src", "-o", output, input}, + settings.verbose > 0); + } + }; // // Qookie-cast client @@ -112,6 +73,7 @@ BuildConfigurations myConfigs() .target = "qookie-cast-client", // output filename .sources = { "src/qookie-cast-client.cc", + settings.builddir + "/moc_qookie-cast-client.cc", }, .flags = { .cxxflags = { @@ -124,20 +86,10 @@ BuildConfigurations myConfigs() .externals = {"qt"}, }; - 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}; + return { qookie, mocs, qookie_cast_client }; } -ExternalConfigurations ctorExtConfigs() +ExternalConfigurations ctorExtConfigs(const Settings& settings) { return { -- cgit v1.2.3