diff options
author | Brad King <brad.king@kitware.com> | 2024-01-10 15:14:58 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2024-01-10 15:15:46 (GMT) |
commit | 446abdf324621fe7c0df14301b418cd5ceddf0f5 (patch) | |
tree | 7fd077dfcb2f071d4a96fe99cdcfb2b324098bed /Source | |
parent | 8c4f0bf6a3c45d7442b851dd3e9ee28ced2e730f (diff) | |
parent | 63bbb3768d3cf87459b6b66effa8726f38cc745a (diff) | |
download | CMake-446abdf324621fe7c0df14301b418cd5ceddf0f5.zip CMake-446abdf324621fe7c0df14301b418cd5ceddf0f5.tar.gz CMake-446abdf324621fe7c0df14301b418cd5ceddf0f5.tar.bz2 |
Merge topic 'cxxmodules-no-unity'
63bbb3768d cmLocalGenerator: ignore scanned sources for unity builds
76b5383123 cmGlobalGenerator: add unity sources after computing target compile features
7fc2a83fe6 Tests/CXXModules: add a test with unity build support
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !9118
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmGlobalGenerator.cxx | 30 | ||||
-rw-r--r-- | Source/cmGlobalGenerator.h | 1 | ||||
-rw-r--r-- | Source/cmLocalGenerator.cxx | 9 |
3 files changed, 39 insertions, 1 deletions
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index e74a8b0..8a07073 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1612,6 +1612,13 @@ bool cmGlobalGenerator::Compute() } } + // Add unity sources after computing compile features. Unity sources do + // not change the set of languages or features, but we need to know them + // to filter out sources that are scanned for C++ module dependencies. + if (!this->AddUnitySources()) { + return false; + } + for (const auto& localGen : this->LocalGenerators) { cmMakefile* mf = localGen->GetMakefile(); for (const auto& g : mf->GetInstallGenerators()) { @@ -1888,7 +1895,6 @@ bool cmGlobalGenerator::AddAutomaticSources() if (!gt->CanCompileSources()) { continue; } - lg->AddUnityBuild(gt.get()); lg->AddISPCDependencies(gt.get()); // Targets that reuse a PCH are handled below. if (!gt->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM")) { @@ -1920,6 +1926,28 @@ bool cmGlobalGenerator::AddAutomaticSources() return true; } +bool cmGlobalGenerator::AddUnitySources() +{ + for (const auto& lg : this->LocalGenerators) { + for (const auto& gt : lg->GetGeneratorTargets()) { + if (!gt->CanCompileSources()) { + continue; + } + lg->AddUnityBuild(gt.get()); + } + } + // The above transformation may have changed the classification of sources. + // Clear the source list and classification cache (KindedSources) of all + // targets so that it will be recomputed correctly by the generators later + // now that the above transformations are done for all targets. + for (const auto& lg : this->LocalGenerators) { + for (const auto& gt : lg->GetGeneratorTargets()) { + gt->ClearSourcesCache(); + } + } + return true; +} + std::unique_ptr<cmLinkLineComputer> cmGlobalGenerator::CreateLinkLineComputer( cmOutputConverter* outputConverter, cmStateDirectory const& stateDir) const { diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index d83b669..b1ce323 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -679,6 +679,7 @@ protected: bool AddHeaderSetVerification(); bool AddAutomaticSources(); + bool AddUnitySources(); std::string SelectMakeProgram(const std::string& makeProgram, const std::string& makeDefault = "") const; diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 38c49ed..ab1de4f 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -3210,6 +3210,15 @@ void cmLocalGenerator::AddUnityBuild(cmGeneratorTarget* target) std::vector<cmSourceFile*> sources; target->GetSourceFiles(sources, configs[ci]); for (cmSourceFile* sf : sources) { + // Files which need C++ scanning cannot participate in unity builds as + // there is a single place in TUs that may perform module-dependency bits + // and a unity source cannot `#include` them in-order and represent a + // valid TU. + if (sf->GetLanguage() == "CXX"_s && + target->NeedDyndepForSource("CXX", configs[ci], sf)) { + continue; + } + auto mi = index.find(sf); if (mi == index.end()) { unitySources.emplace_back(sf); |