diff --git a/src/cmd/cmake_config.cpp b/src/cmd/cmake_config.cpp new file mode 100644 index 0000000..b9d9421 --- /dev/null +++ b/src/cmd/cmake_config.cpp @@ -0,0 +1,43 @@ +#include "pch.h" + +#include "../core/conf.h" +#include "../tasks/tasks.h" + +#include "commands.h" + +namespace mob { + + cmake_config_command::cmake_config_command() : command(requires_options) {} + + command::meta_t cmake_config_command::meta() const + { + return {"cmake-config", "print CMake configuration variables"}; + } + + clipp::group cmake_config_command::do_group() + { + return clipp::group( + clipp::command("cmake-config").set(picked_), + (clipp::option("-h", "--help") >> help_) % ("shows this message"), + clipp::command("prefix-path").set(var_, variable::prefix_path) | + clipp::command("install-prefix").set(var_, variable::install_prefix)); + } + + std::string cmake_config_command::do_doc() + { + return "Print CMake variables to be used when configuring projects.\n"; + } + + int cmake_config_command::do_run() + { + switch (var_) { + case variable::prefix_path: + u8cerr << tasks::modorganizer::cmake_prefix_path(); + break; + case variable::install_prefix: + u8cout << conf().path().install().string(); + break; + } + return 0; + } +} // namespace mob diff --git a/src/cmd/commands.h b/src/cmd/commands.h index beb177c..a771e54 100644 --- a/src/cmd/commands.h +++ b/src/cmd/commands.h @@ -406,4 +406,20 @@ namespace mob { void do_build(); }; + // print CMake configuration variables + // + class cmake_config_command : public command { + public: + cmake_config_command(); + meta_t meta() const override; + + protected: + clipp::group do_group() override; + int do_run() override; + std::string do_doc() override; + + enum class variable { prefix_path, install_prefix }; + variable var_; + }; + } // namespace mob diff --git a/src/main.cpp b/src/main.cpp index 74f8b9b..a7d1c8d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -129,7 +129,8 @@ namespace mob { std::make_unique(), std::make_unique(), std::make_unique(), - std::make_unique()}; + std::make_unique(), + std::make_unique()}; // commands are shown in the help help->set_commands(commands); diff --git a/src/tasks/modorganizer.cpp b/src/tasks/modorganizer.cpp index 9a053d1..07ff92a 100644 --- a/src/tasks/modorganizer.cpp +++ b/src/tasks/modorganizer.cpp @@ -3,15 +3,6 @@ namespace mob::tasks { - // build CMAKE_PREFIX_PATH for MO2 tasks - // - std::string cmake_prefix_path() - { - return conf().path().qt_install().string() + ";" + - (modorganizer::super_path() / "cmake_common").string() + ";" + - (conf().path().install() / "lib" / "cmake").string(); - } - // given a vector of names (some projects have more than one, see add_tasks() in // main.cpp), this prepends the simplified name to the vector and returns it // @@ -89,6 +80,13 @@ namespace mob::tasks { } } + std::string modorganizer::cmake_prefix_path() + { + return conf().path().qt_install().string() + ";" + + (modorganizer::super_path() / "cmake_common").string() + ";" + + (conf().path().install() / "lib" / "cmake").string(); + } + fs::path modorganizer::source_path() const { // something like build/modorganizer_super/uibase diff --git a/src/tasks/tasks.h b/src/tasks/tasks.h index 390258c..40ffb11 100644 --- a/src/tasks/tasks.h +++ b/src/tasks/tasks.h @@ -205,6 +205,10 @@ namespace mob::tasks { // class modorganizer : public task { public: + // build CMAKE_PREFIX_PATH for MO2 tasks + // + static std::string cmake_prefix_path(); + // path of the root modorganizer_super directory // static fs::path super_path();