@@ -579,8 +579,8 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
579579
580580 // Show a nicer error than vcpkg when specifying an invalid package name
581581 for (const auto &package : project.vcpkg .packages ) {
582- if (!vcpkg_valid_identifier (package)) {
583- throw std::runtime_error (" Invalid [vcpkg].packages name '" + package + " ' (needs to be lowercase alphanumeric)" );
582+ if (!vcpkg_valid_identifier (package. name )) {
583+ throw std::runtime_error (" Invalid [vcpkg].packages name '" + package. name + " ' (needs to be lowercase alphanumeric)" );
584584 }
585585 }
586586
@@ -611,10 +611,31 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
611611 const auto &packages = project.vcpkg .packages ;
612612 for (size_t i = 0 ; i < packages.size (); i++) {
613613 const auto &package = packages[i];
614- if (!vcpkg_valid_identifier (package)) {
615- throw std::runtime_error (" Invalid vcpkg package name '" + package + " '" );
614+ const auto &features = package.features ;
615+ if (!vcpkg_valid_identifier (package.name )) {
616+ throw std::runtime_error (" Invalid vcpkg package name '" + package.name + " '" );
617+ }
618+ for (const auto &feature : features) {
619+ if (!vcpkg_valid_identifier (feature)) {
620+ throw std::runtime_error (" Invalid vcpkg package feature '" + feature + " '" );
621+ }
622+ }
623+ if (features.empty ()) {
624+ ofs << " \" " << package.name << ' \" ' ;
625+ } else {
626+ ofs << " {\n " ;
627+ ofs << " \" name\" : \" " << package.name << " \" ,\n " ;
628+ ofs << " \" features\" : [" ;
629+ for (size_t j = 0 ; j < features.size (); j++) {
630+ const auto &feature = features[j];
631+ ofs << ' \" ' << feature << ' \" ' ;
632+ if (j + 1 < features.size ()) {
633+ ofs << ' ,' ;
634+ }
635+ }
636+ ofs << " ]\n " ;
637+ ofs << " }" ;
616638 }
617- ofs << " \" " << package << ' \" ' ;
618639 if (i + 1 < packages.size ()) {
619640 ofs << ' ,' ;
620641 }
0 commit comments