diff options
Diffstat (limited to 'ctor.cc')
-rw-r--r-- | ctor.cc | 82 |
1 files changed, 73 insertions, 9 deletions
@@ -1,12 +1,53 @@ // -*- c++ -*- #include <libctor.h> +#include <filesystem> +#include <iostream> namespace { -BuildConfigurations myConfigs() +std::vector<Source> eval_mocs(const std::string& path, + const std::vector<std::pair<std::string, std::string>>& moc_list) { - return + std::vector<Source> 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<Source> 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<Source> 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}; } } |