Skip to content

Commit f8c34e5

Browse files
committed
Error when [vcpkg] is used from a non-root project
1 parent e6d783e commit f8c34e5

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

include/project_parser.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ struct Vcpkg {
4747
};
4848

4949
std::vector<Package> packages;
50+
51+
bool enabled() const {
52+
return !packages.empty();
53+
}
5054
};
5155

5256
enum TargetType {

src/cmake_generator.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)