diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2023-10-01 14:23:00 (GMT) |
---|---|---|
committer | Ben Boeckel <ben.boeckel@kitware.com> | 2024-08-27 16:37:34 (GMT) |
commit | 48faa19c194364ab33a2a95ddc6a9f003e9d2e06 (patch) | |
tree | 093546446275577f2ffd2023d02fff51411d8169 /Source/cmBuildDatabase.cxx | |
parent | cedfaa010fc7c084c676be079c9845c84ac302ce (diff) | |
download | CMake-48faa19c194364ab33a2a95ddc6a9f003e9d2e06.zip CMake-48faa19c194364ab33a2a95ddc6a9f003e9d2e06.tar.gz CMake-48faa19c194364ab33a2a95ddc6a9f003e9d2e06.tar.bz2 |
cmBuildDatabase: support writing template files
Diffstat (limited to 'Source/cmBuildDatabase.cxx')
-rw-r--r-- | Source/cmBuildDatabase.cxx | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/Source/cmBuildDatabase.cxx b/Source/cmBuildDatabase.cxx index b2d714f..fafcee1 100644 --- a/Source/cmBuildDatabase.cxx +++ b/Source/cmBuildDatabase.cxx @@ -3,6 +3,7 @@ #include "cmBuildDatabase.h" #include <cstdlib> +#include <set> #include <utility> #include <cm/memory> @@ -15,10 +16,23 @@ #include "cmsys/FStream.hxx" +#include "cmComputeLinkInformation.h" +#include "cmFileSet.h" #include "cmGeneratedFileStream.h" +#include "cmGeneratorTarget.h" +#include "cmGlobalGenerator.h" +#include "cmListFileCache.h" +#include "cmLocalGenerator.h" +#include "cmSourceFile.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" +namespace { + +std::string PlaceholderName = "<__CMAKE_UNKNOWN>"; + +} + cmBuildDatabase::cmBuildDatabase() = default; cmBuildDatabase::cmBuildDatabase(cmBuildDatabase const&) = default; cmBuildDatabase::~cmBuildDatabase() = default; @@ -374,6 +388,78 @@ cmBuildDatabase cmBuildDatabase::Merge( return db; } +cmBuildDatabase cmBuildDatabase::ForTarget(cmGeneratorTarget* gt, + std::string const& config) +{ + cmBuildDatabase db; + + Set set; + set.Name = cmStrCat(gt->GetName(), '@', config); + set.FamilyName = gt->GetFamilyName(); + if (auto* cli = gt->GetLinkInformation(config)) { + std::set<cmGeneratorTarget const*> emitted; + std::vector<cmGeneratorTarget const*> targets; + for (auto const& item : cli->GetItems()) { + auto const* linkee = item.Target; + if (linkee && linkee->HaveCxx20ModuleSources() && + !linkee->IsImported() && emitted.insert(linkee).second) { + set.VisibleSets.push_back(cmStrCat(linkee->GetName(), '@', config)); + } + } + } + + for (auto const& sfbt : gt->GetSourceFiles(config)) { + auto const* sf = sfbt.Value; + + bool isCXXModule = false; + bool isPrivate = true; + if (sf->GetLanguage() != "CXX"_s) { + auto const* fs = gt->GetFileSetForSource(config, sf); + if (fs && fs->GetType() == "CXX_MODULES"_s) { + isCXXModule = true; + isPrivate = !cmFileSetVisibilityIsForInterface(fs->GetVisibility()); + } + } + + TranslationUnit tu; + + // FIXME: Makefiles will want this to be the current working directory. + tu.WorkDirectory = gt->GetLocalGenerator()->GetBinaryDirectory(); + tu.Source = sf->GetFullPath(); + if (!gt->IsSynthetic()) { + auto* gg = gt->GetGlobalGenerator(); + std::string const objectDir = gg->ConvertToOutputPath( + cmStrCat(gt->GetSupportDirectory(), gg->GetConfigDirectory(config))); + std::string const objectFileName = gt->GetObjectName(sf); + tu.Object = cmStrCat(objectDir, '/', objectFileName); + } + if (isCXXModule) { + tu.Provides[PlaceholderName] = PlaceholderName; + } + + cmGeneratorTarget::ClassifiedFlags classifiedFlags = + gt->GetClassifiedFlagsForSource(sf, config); + for (auto const& classifiedFlag : classifiedFlags) { + if (classifiedFlag.Classification == + cmGeneratorTarget::FlagClassification::BaselineFlag) { + tu.BaselineArguments.push_back(classifiedFlag.Flag); + tu.LocalArguments.push_back(classifiedFlag.Flag); + } else if (classifiedFlag.Classification == + cmGeneratorTarget::FlagClassification::PrivateFlag) { + tu.LocalArguments.push_back(classifiedFlag.Flag); + } + tu.Arguments.push_back(classifiedFlag.Flag); + } + tu.Private = isPrivate; + + set.TranslationUnits.emplace_back(std::move(tu)); + } + + db.Sets.emplace_back(std::move(set)); + + return db; +} + int cmcmd_cmake_module_compile_db( std::vector<std::string>::const_iterator argBeg, std::vector<std::string>::const_iterator argEnd) |