From be0ef6d6153eaa0887f31fa798dae6c759ac17ae Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Thu, 28 Mar 2024 11:36:15 +0100 Subject: [PATCH] Generate find-package before fetch-content --- src/cmake_generator.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/cmake_generator.cpp b/src/cmake_generator.cpp index 7539217..314afb5 100644 --- a/src/cmake_generator.cpp +++ b/src/cmake_generator.cpp @@ -900,6 +900,20 @@ void generate_cmake(const char *path, const parser::Project *parent_project) { ofs << "}\n"; } + if (!project.packages.empty()) { + comment("Packages"); + for (const auto &dep : project.packages) { + auto version = dep.version; + if (version == "*") + version.clear(); + auto required = dep.required ? "REQUIRED" : ""; + auto config = dep.config ? "CONFIG" : ""; + auto components = std::make_pair("COMPONENTS", dep.components); + ConditionScope cs(gen, dep.condition); + cmd("find_package")(dep.name, version, required, config, components).endl(); + } + } + if (!project.contents.empty()) { cmd("include")("FetchContent").endl(); if (!project.root()->vcpkg.enabled()) { @@ -935,20 +949,6 @@ void generate_cmake(const char *path, const parser::Project *parent_project) { } } - if (!project.packages.empty()) { - comment("Packages"); - for (const auto &dep : project.packages) { - auto version = dep.version; - if (version == "*") - version.clear(); - auto required = dep.required ? "REQUIRED" : ""; - auto config = dep.config ? "CONFIG" : ""; - auto components = std::make_pair("COMPONENTS", dep.components); - ConditionScope cs(gen, dep.condition); - cmd("find_package")(dep.name, version, required, config, components).endl(); - } - } - auto add_subdir = [&](const std::string &dir) { // clang-format off comment("Subdirectory: " + dir);