diff options
-rw-r--r-- | ctor.cc | 126 | ||||
m--------- | libctor | 0 |
2 files changed, 40 insertions, 86 deletions
@@ -1,76 +1,25 @@ // -*- c++ -*- -#include <libctor.h> +#include <ctor.h> #include <filesystem> #include <iostream> #include <string> #include <vector> -int execute(const std::string& command, - const std::vector<std::string>& args, - bool verbose = true); +int execute(const ctor::settings& settings, + const std::string& command, + const std::vector<std::string>& args = {}, + const std::map<std::string, std::string>& env = {}, + bool terminate = false); 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<Source> eval_mocs(const std::string& path, - const std::vector<std::pair<std::string, std::string>>& moc_list) -{ - 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)) - { - 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() +ctor::build_configurations myConfigs(const ctor::settings& settings) { // - // Qookie-cast client + // Qookie main application // - BuildConfiguration qookie = + ctor::build_configuration qookie = { .target = "qookie", // output filename .sources = { @@ -78,9 +27,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,26 +45,37 @@ BuildConfigurations myConfigs() }, .externals = { "qt", "sqlite" }, }; - 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); - } + + // + // Moc generation for all configurations + // + ctor::build_configuration 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 ctor::build_configuration& config, + const ctor::settings& settings) + { + return execute(settings, "/usr/bin/moc", + {"-I../src", "-o", output, input}); + } + }; // // Qookie-cast client // - BuildConfiguration qookie_cast_client = + ctor::build_configuration qookie_cast_client = { .target = "qookie-cast-client", // output filename .sources = { "src/qookie-cast-client.cc", + {settings.builddir + "/moc_qookie-cast-client.cc"}, }, .flags = { .cxxflags = { @@ -124,26 +88,16 @@ BuildConfigurations myConfigs() .externals = {"qt"}, }; - 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}; + return { qookie, mocs, qookie_cast_client }; } -ExternalConfigurations ctorExtConfigs() +ctor::external_configurations ctorExtConfigs(const ctor::settings& settings) { return { { .name = "qt", - .external = ExternalManual{ + .external = ctor::external_manual{ .flags = { .cxxflags = { "-I/usr/include/qt5", @@ -159,7 +113,7 @@ ExternalConfigurations ctorExtConfigs() }, { .name = "sqlite", - .external = ExternalManual{ + .external = ctor::external_manual{ .flags = { .ldflags = { "-lsqlite3", diff --git a/libctor b/libctor -Subproject fb88dc797f1f5f420416521d4b3088bf6b8450a +Subproject f4b6372c1fe8d48aceb853272e0b822b967a56d |