From 15cd73d6c24a2ad888d5c324a64fc7ea4b760d91 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 1 Mar 2024 08:03:37 -0500 Subject: cmGlobalGenerator: compute target features before synthetic targets For `import std;` support, CMake needs to know the standard library involved in order to ensure that the right target is linked. Afterwards, the created synthetic targets need their target compile features computed. --- Source/cmGeneratorTarget.cxx | 12 ++++++++++++ Source/cmGlobalGenerator.cxx | 26 ++++++++++++++++---------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 2ec1a29..f0acb9c 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -8414,6 +8414,8 @@ void ComputeLinkImplTransitive(cmGeneratorTarget const* self, bool cmGeneratorTarget::DiscoverSyntheticTargets(cmSyntheticTargetCache& cache, std::string const& config) { + std::vector allConfigs = + this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig); cmOptionalLinkImplementation impl; this->ComputeLinkImplementationLibraries(config, impl, this, LinkInterfaceFor::Link); @@ -8488,9 +8490,19 @@ bool cmGeneratorTarget::DiscoverSyntheticTargets(cmSyntheticTargetCache& cache, // Create the generator target and attach it to the local generator. auto gtp = cm::make_unique(tgt, lg); + synthDep = gtp.get(); cache.CxxModuleTargets[targetName] = synthDep; + + // See `localGen->ComputeTargetCompileFeatures()` call in + // `cmGlobalGenerator::Compute` for where non-synthetic targets resolve + // this. + for (auto const& innerConfig : allConfigs) { + gtp->ComputeCompileFeatures(innerConfig); + } + gtp->DiscoverSyntheticTargets(cache, config); + lg->AddGeneratorTarget(std::move(gtp)); } else { synthDep = cached->second; diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 213142a..c0af34b 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1581,6 +1581,19 @@ bool cmGlobalGenerator::Compute() } #endif + // Perform up-front computation in order to handle errors (such as unknown + // features) at this point. While processing the compile features we also + // calculate and cache the language standard required by the compile + // features. + // + // Synthetic targets performed this inside of + // `cmLocalGenerator::DiscoverSyntheticTargets` + for (const auto& localGen : this->LocalGenerators) { + if (!localGen->ComputeTargetCompileFeatures()) { + return false; + } + } + // Iterate through all targets and set up C++20 module targets. // Create target templates for each imported target with C++20 modules. // INTERFACE library with BMI-generating rules and a collation step? @@ -1588,6 +1601,9 @@ bool cmGlobalGenerator::Compute() // Make `add_dependencies(imported_target // $<$:synth1> // $<$:synth2>)` + // + // Note that synthetic target creation performs the above marked + // steps on the created targets. if (!this->DiscoverSyntheticTargets()) { return false; } @@ -1597,16 +1613,6 @@ bool cmGlobalGenerator::Compute() localGen->AddHelperCommands(); } - // Perform up-front computation in order to handle errors (such as unknown - // features) at this point. While processing the compile features we also - // calculate and cache the language standard required by the compile - // features. - for (const auto& localGen : this->LocalGenerators) { - if (!localGen->ComputeTargetCompileFeatures()) { - return false; - } - } - // Add automatically generated sources (e.g. unity build). // Add unity sources after computing compile features. Unity sources do // not change the set of languages or features, but we need to know them -- cgit v0.12