Skip to content

Commit

Permalink
Add cmake-config command to mob.
Browse files Browse the repository at this point in the history
  • Loading branch information
Holt59 committed Oct 19, 2024
1 parent 2cc3c3a commit c6ac23e
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 10 deletions.
43 changes: 43 additions & 0 deletions src/cmd/cmake_config.cpp
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions src/cmd/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ namespace mob {
std::make_unique<release_command>(),
std::make_unique<git_command>(),
std::make_unique<inis_command>(),
std::make_unique<tx_command>()};
std::make_unique<tx_command>(),
std::make_unique<cmake_config_command>()};

// commands are shown in the help
help->set_commands(commands);
Expand Down
16 changes: 7 additions & 9 deletions src/tasks/modorganizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/tasks/tasks.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit c6ac23e

Please sign in to comment.