cmGeneratorTarget: add a method to build classified command lines

This is essentially an extraction of the `Ninja` generator's command
line building logic. Porting generators to reuse this construction is a
task for the future.
This commit is contained in:
Ben Boeckel
2024-05-06 18:06:11 -04:00
parent c96ea5684d
commit cedfaa010f
2 changed files with 479 additions and 0 deletions
+59
View File
@@ -517,6 +517,64 @@ public:
std::vector<std::string> GetAppleArchs(std::string const& config,
cm::optional<std::string> lang) const;
// The classification of the flag.
enum class FlagClassification
{
// The flag is for the execution of the tool (e.g., the compiler itself,
// any launchers, etc.).
ExecutionFlag,
// The flag is "baseline" and should be apply to TUs which may interact
// with this compilation (e.g., imported modules).
BaselineFlag,
// The flag is "private" and doesn't need to apply to interacting TUs.
PrivateFlag,
// Flags for the TU itself (e.g., output paths, dependency scanning, etc.).
LocationFlag,
};
enum class FlagKind
{
// Not a flag (executable or other entries).
NotAFlag,
// Flags for support of the build system.
BuildSystem,
// A compilation flag.
Compile,
// An include flag.
Include,
// A compile definition.
Definition,
};
struct ClassifiedFlag
{
ClassifiedFlag(FlagClassification cls, FlagKind kind, std::string flag)
: Classification(cls)
, Kind(kind)
, Flag(std::move(flag))
{
}
FlagClassification Classification;
FlagKind Kind;
std::string Flag;
};
using ClassifiedFlags = std::vector<ClassifiedFlag>;
ClassifiedFlags GetClassifiedFlagsForSource(cmSourceFile const* sf,
std::string const& config);
struct SourceVariables
{
std::string TargetPDB;
std::string TargetCompilePDB;
std::string ObjectDir;
std::string ObjectFileDir;
std::string DependencyFile;
std::string DependencyTarget;
// Dependency flags (if used)
std::string DependencyFlags;
};
SourceVariables GetSourceVariables(cmSourceFile const* sf,
std::string const& config);
void AddExplicitLanguageFlags(std::string& flags,
cmSourceFile const& sf) const;
@@ -1452,6 +1510,7 @@ private:
std::map<std::string, cmFileSet const*> FileSetCache;
std::map<cmGeneratorTarget const*, std::vector<cmGeneratorTarget const*>>
SyntheticDeps;
std::map<cmSourceFile const*, ClassifiedFlags> SourceFlags;
};
mutable std::map<std::string, InfoByConfig> Configs;
};