@@ -784,7 +784,11 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
784784 gen.conditional_includes (project.include_after );
785785 gen.conditional_cmake (project.cmake_after );
786786
787- if (!project.vcpkg .packages .empty ()) {
787+ if (project.vcpkg .enabled ()) {
788+ if (!is_root_project) {
789+ throw std::runtime_error (" [vcpkg] is only supported in the root project" );
790+ }
791+
788792 // Allow the user to specify a url or derive it from the version
789793 auto url = project.vcpkg .url ;
790794 auto version_name = url;
@@ -797,7 +801,8 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
797801 }
798802
799803 // Show a nicer error than vcpkg when specifying an invalid package name
800- for (const auto &package : project.vcpkg .packages ) {
804+ const auto &packages = project.vcpkg .packages ;
805+ for (const auto &package : packages) {
801806 if (!vcpkg_valid_identifier (package.name )) {
802807 throw std::runtime_error (" Invalid [vcpkg].packages name '" + package.name + " ' (needs to be lowercase alphanumeric)" );
803808 }
@@ -831,7 +836,6 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
831836 "dependencies": [
832837)" ;
833838
834- const auto &packages = project.vcpkg .packages ;
835839 for (size_t i = 0 ; i < packages.size (); i++) {
836840 const auto &package = packages[i];
837841 const auto &features = package.features ;
0 commit comments