// -*- c++ -*- #include #include #include #include #include int execute(const std::string& command, const std::vector& args, bool verbose = true); 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() { // // Qookie-cast client // BuildConfiguration qookie = { .target = "qookie", // output filename .sources = { "src/qookie.cc", "src/database.cc", "src/database_gourmet.cc", "src/database_krecipes.cc", "src/mainwindow.cc", "src/viewer.cc", "src/client.cc", }, .flags = { .cxxflags = { "-fPIC", "-Wall", "-Werror", "-Wextra",// "-Wconversion", "-Wno-deprecated-copy", "-g", }, }, .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); } // // Qookie-cast client // BuildConfiguration qookie_cast_client = { .target = "qookie-cast-client", // output filename .sources = { "src/qookie-cast-client.cc", }, .flags = { .cxxflags = { "-fPIC", "-Wall", "-Werror", "-Wextra",// "-Wconversion", "-Wno-deprecated-copy", "-g", }, }, .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}; } ExternalConfigurations ctorExtConfigs() { return { { .name = "qt", .external = ExternalManual{ .flags = { .cxxflags = { "-I/usr/include/qt5", }, .ldflags = { "-lQt5Core", "-lQt5Network", "-lQt5Gui", "-lQt5Widgets", }, }, }, }, { .name = "sqlite", .external = ExternalManual{ .flags = { .ldflags = { "-lsqlite3", }, }, }, }, }; } } // Register callbacks REG(myConfigs); REG(ctorExtConfigs);