Skip to content

Commit 8dcc11e

Browse files
committed
Add helper function Project::cmake_minimum_version for version-dependent features
1 parent 51dc49e commit 8dcc11e

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

include/project_parser.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ struct Project {
199199

200200
Project(const Project *parent, const std::string &path, bool build);
201201
const Project *root() const;
202+
bool cmake_minimum_version(int major, int minor) const;
202203
};
203204

204205
bool is_root_path(const std::string &path);

src/project_parser.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,26 @@ const Project *Project::root() const {
741741
return root;
742742
}
743743

744+
bool Project::cmake_minimum_version(int major, int minor) const {
745+
// NOTE: this code is like pulling teeth, sorry
746+
auto root_version = root()->cmake_version;
747+
puts(root_version.c_str());
748+
auto range_index = root_version.find("...");
749+
if (range_index != std::string::npos) {
750+
root_version.resize(range_index);
751+
}
752+
753+
auto period_index = root_version.find('.');
754+
auto root_major = atoi(root_version.substr(0, period_index).c_str());
755+
int root_minor = 0;
756+
if (period_index != std::string::npos) {
757+
auto end_index = root_version.find('.', period_index + 1);
758+
root_minor = atoi(root_version.substr(period_index + 1, end_index).c_str());
759+
}
760+
761+
return std::tie(root_major, root_minor) >= std::tie(major, minor);
762+
}
763+
744764
bool is_root_path(const std::string &path) {
745765
const auto toml_path = fs::path(path) / "cmake.toml";
746766
if (!fs::exists(toml_path)) {

0 commit comments

Comments
 (0)