diff --git a/include/project_parser.hpp b/include/project_parser.hpp index 1887029..33e4d7a 100644 --- a/include/project_parser.hpp +++ b/include/project_parser.hpp @@ -199,6 +199,7 @@ struct Project { Project(const Project *parent, const std::string &path, bool build); const Project *root() const; + bool cmake_minimum_version(int major, int minor) const; }; bool is_root_path(const std::string &path); diff --git a/src/project_parser.cpp b/src/project_parser.cpp index 206de11..5c4220a 100644 --- a/src/project_parser.cpp +++ b/src/project_parser.cpp @@ -741,6 +741,26 @@ const Project *Project::root() const { return root; } +bool Project::cmake_minimum_version(int major, int minor) const { + // NOTE: this code is like pulling teeth, sorry + auto root_version = root()->cmake_version; + puts(root_version.c_str()); + auto range_index = root_version.find("..."); + if (range_index != std::string::npos) { + root_version.resize(range_index); + } + + auto period_index = root_version.find('.'); + auto root_major = atoi(root_version.substr(0, period_index).c_str()); + int root_minor = 0; + if (period_index != std::string::npos) { + auto end_index = root_version.find('.', period_index + 1); + root_minor = atoi(root_version.substr(period_index + 1, end_index).c_str()); + } + + return std::tie(root_major, root_minor) >= std::tie(major, minor); +} + bool is_root_path(const std::string &path) { const auto toml_path = fs::path(path) / "cmake.toml"; if (!fs::exists(toml_path)) {