Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion include/project_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ struct Package {
struct Vcpkg {
std::string version;
std::string url;
std::vector<std::string> packages;

struct Package {
std::string name;
std::vector<std::string> features;
};

std::vector<Package> packages;
};

enum TargetType {
Expand Down
31 changes: 26 additions & 5 deletions src/cmake_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,8 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {

// Show a nicer error than vcpkg when specifying an invalid package name
for (const auto &package : project.vcpkg.packages) {
if (!vcpkg_valid_identifier(package)) {
throw std::runtime_error("Invalid [vcpkg].packages name '" + package + "' (needs to be lowercase alphanumeric)");
if (!vcpkg_valid_identifier(package.name)) {
throw std::runtime_error("Invalid [vcpkg].packages name '" + package.name + "' (needs to be lowercase alphanumeric)");
}
}

Expand Down Expand Up @@ -611,10 +611,31 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
const auto &packages = project.vcpkg.packages;
for (size_t i = 0; i < packages.size(); i++) {
const auto &package = packages[i];
if (!vcpkg_valid_identifier(package)) {
throw std::runtime_error("Invalid vcpkg package name '" + package + "'");
const auto &features = package.features;
if (!vcpkg_valid_identifier(package.name)) {
throw std::runtime_error("Invalid vcpkg package name '" + package.name + "'");
}
for (const auto &feature : features) {
if (!vcpkg_valid_identifier(feature)) {
throw std::runtime_error("Invalid vcpkg package feature '" + feature + "'");
}
}
if (features.empty()) {
ofs << " \"" << package.name << '\"';
} else {
ofs << " {\n";
ofs << " \"name\": \"" << package.name << "\",\n";
ofs << " \"features\": [";
for (size_t j = 0; j < features.size(); j++) {
const auto &feature = features[j];
ofs << '\"' << feature << '\"';
if (j + 1 < features.size()) {
ofs << ',';
}
}
ofs << "]\n";
ofs << " }";
}
ofs << " \"" << package << '\"';
if (i + 1 < packages.size()) {
ofs << ',';
}
Expand Down
21 changes: 20 additions & 1 deletion src/project_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,26 @@ Project::Project(const Project *parent, const std::string &path, bool build) {
auto &v = checker.create(toml, "vcpkg");
v.optional("url", vcpkg.url);
v.optional("version", vcpkg.version);
v.required("packages", vcpkg.packages);
for (const auto &p : v.find("packages").as_array()) {
Vcpkg::Package package;
const auto &package_str = p.as_string().str;
const auto open_bracket = package_str.find('[');
const auto close_bracket = package_str.find(']', open_bracket);
if (open_bracket == std::string::npos && close_bracket == std::string::npos) {
package.name = package_str;
} else if (close_bracket != std::string::npos) {
package.name = package_str.substr(0, open_bracket);
const auto features = package_str.substr(open_bracket + 1, close_bracket - open_bracket - 1);
std::istringstream feature_stream{features};
std::string feature;
while (std::getline(feature_stream, feature, ',')) {
package.features.emplace_back(feature);
}
} else {
throw std::runtime_error("Invalid vcpkg package '" + package_str + "'");
}
vcpkg.packages.emplace_back(std::move(package));
}
}

checker.check(conditions);
Expand Down