diff --git a/src/cmd/cmake.cpp b/src/cmd/cmake.cpp deleted file mode 100644 index f6ef356..0000000 --- a/src/cmd/cmake.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include "pch.h" -#include "../tasks/tasks.h" -#include "commands.h" - -namespace mob { - - cmake_command::cmake_command() : command(requires_options) {} - - command::meta_t cmake_command::meta() const - { - return {"cmake", "runs cmake in a directory"}; - } - - clipp::group cmake_command::do_group() - { - return clipp::group( - clipp::command("cmake").set(picked_), - - (clipp::option("-h", "--help") >> help_) % "shows this message", - - (clipp::option("-G", "--generator") & clipp::value("GEN") >> gen_) % - ("sets the -G option for cmake [default: VS]"), - - (clipp::option("-c", "--cmd") & clipp::value("CMD") >> cmd_) % - "overrides the cmake command line [default: \"..\"]", - - (clipp::option("--x64").set(x64_, true) | - clipp::option("--x86").set(x64_, false)) % - "whether to use the x64 or x86 vcvars; if -G is not set, " - "whether to pass \"-A Win32\" or \"-A x64\" for the default " - "VS generator [default: x64]", - - (clipp::option("--install-prefix") & clipp::value("PATH") >> prefix_) % - "sets CMAKE_INSTALL_PREFIX [default: empty]", - - (clipp::option("-d", "--debug").set(debug_, true)) % - "whether to configure for debug mode [default: false]", - - (clipp::value("PATH") >> path_) % "path from which to run `cmake`"); - } - - int cmake_command::do_run() - { - auto t = tasks::modorganizer::create_cmake_tool( - fs::path(utf8_to_utf16(path_)), mob::cmake::generate, - debug_ ? config::debug : config::relwithdebinfo); - - t.generator(gen_); - t.cmd(cmd_); - t.prefix(prefix_); - t.output(path_); - - if (!x64_) - t.architecture(arch::x86); - - // copy the global context, the tool will modify it - context cxcopy(gcx()); - - t.run(cxcopy); - - return 0; - } - - std::string cmake_command::do_doc() - { - return "Runs `cmake ..` in the given directory with the same command line\n" - "as the one used for modorganizer projects."; - } - -} // namespace mob diff --git a/src/cmd/commands.h b/src/cmd/commands.h index 267a133..beb177c 100644 --- a/src/cmd/commands.h +++ b/src/cmd/commands.h @@ -367,27 +367,6 @@ namespace mob { std::vector get_repos() const; }; - // runs cmake in a directory with the same parameters as `build` would - // - class cmake_command : public command { - public: - cmake_command(); - meta_t meta() const override; - - protected: - clipp::group do_group() override; - int do_run() override; - std::string do_doc() override; - - private: - std::string gen_; - std::string cmd_; - bool x64_ = true; - bool debug_ = false; - std::string prefix_; - std::string path_; - }; - // lists the inis found by mob // class inis_command : public command { diff --git a/src/main.cpp b/src/main.cpp index e7b476e..49d8316 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -126,7 +126,6 @@ namespace mob { std::make_unique(), std::make_unique(), std::make_unique(), - std::make_unique(), std::make_unique(), std::make_unique()}; diff --git a/src/tasks/modorganizer.cpp b/src/tasks/modorganizer.cpp index f6e9345..9ef84d1 100644 --- a/src/tasks/modorganizer.cpp +++ b/src/tasks/modorganizer.cpp @@ -3,6 +3,14 @@ namespace mob::tasks { + // build CMAKE_PREFIX_PATH for MO2 tasks + // + std::string cmake_prefix_path() + { + return conf().path().qt_install().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 // @@ -86,15 +94,6 @@ namespace mob::tasks { return super_path() / name(); } - fs::path modorganizer::project_file_path() const - { - // ask cmake for the build path it would use - const auto build_path = create_cmake_tool(source_path()).build_path(); - - // use the INSTALL project - return build_path / (project_ + ".sln"); - } - fs::path modorganizer::super_path() { return conf().path().build(); @@ -127,7 +126,7 @@ namespace mob::tasks { // cmake clean if (is_set(c, clean::reconfigure)) - run_tool(create_cmake_tool(cmake::clean)); + run_tool(cmake(cmake::clean).root(source_path())); } void modorganizer::do_fetch() @@ -163,48 +162,38 @@ namespace mob::tasks { // not all modorganizer projects need to actually be built, such as // cmake_common, so don't try if there's no cmake file - if (!fs::exists(source_path() / "CMakeLists.txt")) { + if (!exists(source_path() / "CMakeLists.txt")) { cx().trace(context::generic, "{} has no CMakeLists.txt, not building", repo_); return; } + // if there is a CMakeLists.txt, there must be a CMakePresets.json otherwise + // we cannot build + if (!exists(source_path() / "CMakePresets.json")) { + gcx().bail_out(context::generic, + "{} has no CMakePresets.txt, aborting build", repo_); + } + // run cmake - run_tool(create_cmake_tool()); + run_tool(cmake(cmake::generate) + .generator(cmake::vs) + .def("CMAKE_INSTALL_PREFIX:PATH", conf().path().install()) + .def("CMAKE_PREFIX_PATH", cmake_prefix_path()) + .preset("vs2022-windows") + .root(source_path())); // run cmake --build with default target // TODO: handle rebuild by adding `--clean-first` - run_tool(cmake(cmake::build).configuration(mob::config::relwithdebinfo)); + run_tool(cmake(cmake::build) + .root(source_path()) + .configuration(mob::config::relwithdebinfo)); // run cmake --install - run_tool(cmake(cmake::install).configuration(mob::config::relwithdebinfo)); - } - - cmake modorganizer::create_cmake_tool(cmake::ops o) - { - return create_cmake_tool(source_path(), o, task_conf().configuration()); - } - - cmake modorganizer::create_cmake_tool(const fs::path& root, cmake::ops o, config c) - { - - if (!exists(root / "CMakePresets.json")) { - gcx().bail_out(context::generic, "missing CMakePresets.json in {}", - root.string()); - } - - cmake g(o); - - g.generator(cmake::vs) - .def("CMAKE_INSTALL_PREFIX:PATH", conf().path().install()) - .def("CMAKE_PREFIX_PATH", - conf().path().qt_install().string() + ";" + - (conf().path().install() / "lib" / "cmake").string()) - .preset("vs2022-windows") - .root(root); - - return std::move(g); + run_tool(cmake(cmake::install) + .root(source_path()) + .configuration(mob::config::relwithdebinfo)); } } // namespace mob::tasks diff --git a/src/tasks/task.cpp b/src/tasks/task.cpp index 451366b..5f411ee 100644 --- a/src/tasks/task.cpp +++ b/src/tasks/task.cpp @@ -413,6 +413,7 @@ namespace mob { cx().info(context::generic, "build and install"); do_build_and_install(); + cx().info(context::generic, "done"); } void task::check_bailed() diff --git a/src/tasks/tasks.h b/src/tasks/tasks.h index 5aae2ea..390258c 100644 --- a/src/tasks/tasks.h +++ b/src/tasks/tasks.h @@ -250,26 +250,6 @@ namespace mob::tasks { private: std::string repo_; std::string project_; - - // creates the cmake tool for this MO project - // - cmake create_cmake_tool(cmake::ops o = cmake::generate); - - // creates the msbuild tool for this MO project - // - msbuild create_msbuild_tool(msbuild::ops o = msbuild::build); - - // this is the file targeted by the msbuild tool - // - // it's not actually the .sln file because the cmake files have historically - // been inconsistent in what the main project in the solution is and whether - // the INSTALL project was enabled or not, so just building the .sln itself - // might not actually build everything - // - // by targeting the INSTALL project directly, everything will always be - // built correctly, regardless of how the solution file is generated - // - fs::path project_file_path() const; }; class ncc : public basic_task {