CMake/Source/cmGlobalNinjaGenerator.h

661 lines
21 KiB
C
Raw Normal View History

Simplify CMake per-source license notices Per-source copyright/license notice headers that spell out copyright holder names and years are hard to maintain and often out-of-date or plain wrong. Precise contributor information is already maintained automatically by the version control tool. Ultimately it is the receiver of a file who is responsible for determining its licensing status, and per-source notices are merely a convenience. Therefore it is simpler and more accurate for each source to have a generic notice of the license name and references to more detailed information on copyright holders and full license terms. Our `Copyright.txt` file now contains a list of Contributors whose names appeared source-level copyright notices. It also references version control history for more precise information. Therefore we no longer need to spell out the list of Contributors in each source file notice. Replace CMake per-source copyright/license notice headers with a short description of the license and links to `Copyright.txt` and online information available from "https://cmake.org/licensing". The online URL also handles cases of modules being copied out of our source into other projects, so we can drop our notices about replacing links with full license text. Run the `Utilities/Scripts/filter-notices.bash` script to perform the majority of the replacements mechanically. Manually fix up shebang lines and trailing newlines in a few files. Manually update the notices in a few files that the script does not handle.
2016-09-27 15:01:08 -04:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2011-11-11 05:00:49 +00:00
#ifndef cmGlobalNinjaGenerator_h
#define cmGlobalNinjaGenerator_h
2011-11-11 05:00:49 +00:00
#include "cmConfigure.h" // IWYU pragma: keep
#include <iosfwd>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cm/optional>
#include "cm_codecvt.hxx"
#include "cmGeneratedFileStream.h"
#include "cmGlobalCommonGenerator.h"
#include "cmGlobalGeneratorFactory.h"
#include "cmNinjaTypes.h"
#include "cmPolicies.h"
#include "cmStringAlgorithms.h"
class cmCustomCommand;
class cmGeneratorTarget;
class cmLinkLineComputer;
class cmLocalGenerator;
class cmMakefile;
class cmOutputConverter;
class cmState;
class cmStateDirectory;
class cmake;
struct cmDocumentationEntry;
2011-11-11 05:00:49 +00:00
/**
* \class cmGlobalNinjaGenerator
* \brief Write a build.ninja file.
*
* The main differences between this generator and the UnixMakefile
* generator family are:
* - We don't care about VERBOSE variable or RULE_MESSAGES property since
* it is handle by Ninja's -v option.
* - We don't care about computing any progress status since Ninja manages
* it itself.
* - We generate one build.ninja and one rules.ninja per project.
* - We try to minimize the number of generated rules: one per target and
* language.
* - We use Ninja special variable $in and $out to produce nice output.
* - We extensively use Ninja variable overloading system to minimize the
* number of generated rules.
*/
class cmGlobalNinjaGenerator : public cmGlobalCommonGenerator
2011-11-11 05:00:49 +00:00
{
public:
/// The default name of Ninja's build file. Typically: build.ninja.
static const char* NINJA_BUILD_FILE;
/// The default name of Ninja's rules file. Typically: rules.ninja.
/// It is included in the main build.ninja file.
static const char* NINJA_RULES_FILE;
/// The indentation string used when generating Ninja's build file.
static const char* INDENT;
/// The shell command used for a no-op.
static std::string const SHELL_NOOP;
2011-11-11 05:00:49 +00:00
/// Write @a count times INDENT level to output stream @a os.
static void Indent(std::ostream& os, int count);
/// Write a divider in the given output stream @a os.
static void WriteDivider(std::ostream& os);
static std::string EncodeRuleName(std::string const& name);
std::string EncodeLiteral(const std::string& lit);
std::string EncodePath(const std::string& path);
2011-11-11 05:00:49 +00:00
std::unique_ptr<cmLinkLineComputer> CreateLinkLineComputer(
cmOutputConverter* outputConverter,
cmStateDirectory const& stateDir) const override;
2011-11-11 05:00:49 +00:00
/**
* Write the given @a comment to the output stream @a os. It
* handles new line character properly.
*/
static void WriteComment(std::ostream& os, const std::string& comment);
/**
* Utilized by the generator factory to determine if this generator
* supports toolsets.
*/
static bool SupportsToolset() { return false; }
/**
* Utilized by the generator factory to determine if this generator
* supports platforms.
*/
static bool SupportsPlatform() { return false; }
bool IsIPOSupported() const override { return true; }
/**
* Write a build statement @a build to @a os.
* @warning no escaping of any kind is done here.
*/
void WriteBuild(std::ostream& os, cmNinjaBuild const& build,
int cmdLineLimit = 0, bool* usedResponseFile = nullptr);
void WriteCustomCommandBuild(
const std::string& command, const std::string& description,
const std::string& comment, const std::string& depfile,
const std::string& pool, bool uses_terminal, bool restat,
const cmNinjaDeps& outputs, const std::string& config,
const cmNinjaDeps& explicitDeps = cmNinjaDeps(),
const cmNinjaDeps& orderOnlyDeps = cmNinjaDeps());
void WriteMacOSXContentBuild(std::string input, std::string output,
const std::string& config);
2011-11-11 05:00:49 +00:00
/**
* Write a rule statement to @a os.
2011-11-11 05:00:49 +00:00
* @warning no escaping of any kind is done here.
*/
static void WriteRule(std::ostream& os, cmNinjaRule const& rule);
2011-11-11 05:00:49 +00:00
/**
* Write a variable named @a name to @a os with value @a value and an
* optional @a comment. An @a indent level can be specified.
* @warning no escaping of any kind is done here.
*/
static void WriteVariable(std::ostream& os, const std::string& name,
2011-11-11 05:00:49 +00:00
const std::string& value,
const std::string& comment = "", int indent = 0);
2011-11-11 05:00:49 +00:00
/**
* Write an include statement including @a filename with an optional
* @a comment to the @a os stream.
*/
static void WriteInclude(std::ostream& os, const std::string& filename,
2011-11-11 05:00:49 +00:00
const std::string& comment = "");
/**
* Write a default target statement specifying @a targets as
* the default targets.
*/
static void WriteDefault(std::ostream& os, const cmNinjaDeps& targets,
2011-11-11 05:00:49 +00:00
const std::string& comment = "");
bool IsGCCOnWindows() const { return UsingGCCOnWindows; }
2012-07-18 11:27:49 +02:00
2011-11-11 05:00:49 +00:00
public:
cmGlobalNinjaGenerator(cmake* cm);
2011-11-11 05:00:49 +00:00
static std::unique_ptr<cmGlobalGeneratorFactory> NewFactory()
{
return std::unique_ptr<cmGlobalGeneratorFactory>(
new cmGlobalGeneratorSimpleFactory<cmGlobalNinjaGenerator>());
}
2011-11-11 05:00:49 +00:00
std::unique_ptr<cmLocalGenerator> CreateLocalGenerator(
cmMakefile* mf) override;
2011-11-11 05:00:49 +00:00
std::string GetName() const override
{
return cmGlobalNinjaGenerator::GetActualName();
}
2011-11-11 05:00:49 +00:00
static std::string GetActualName() { return "Ninja"; }
2011-11-11 05:00:49 +00:00
/** Get encoding used by generator for ninja files */
codecvt::Encoding GetMakefileEncoding() const override;
static void GetDocumentation(cmDocumentationEntry& entry);
2011-11-11 05:00:49 +00:00
2016-06-27 21:25:27 +02:00
void EnableLanguage(std::vector<std::string> const& languages,
cmMakefile* mf, bool optional) override;
2011-11-11 05:00:49 +00:00
std::vector<GeneratedMakeCommand> GenerateBuildCommand(
const std::string& makeProgram, const std::string& projectName,
const std::string& projectDir, std::vector<std::string> const& targetNames,
const std::string& config, bool fast, int jobs, bool verbose,
std::vector<std::string> const& makeOptions =
std::vector<std::string>()) override;
2011-11-11 05:00:49 +00:00
// Setup target names
const char* GetAllTargetName() const override { return "all"; }
const char* GetInstallTargetName() const override { return "install"; }
const char* GetInstallLocalTargetName() const override
{
2011-11-11 05:00:49 +00:00
return "install/local";
}
const char* GetInstallStripTargetName() const override
{
2011-11-11 05:00:49 +00:00
return "install/strip";
}
const char* GetTestTargetName() const override { return "test"; }
const char* GetPackageTargetName() const override { return "package"; }
const char* GetPackageSourceTargetName() const override
{
2011-11-11 05:00:49 +00:00
return "package_source";
}
const char* GetEditCacheTargetName() const override { return "edit_cache"; }
const char* GetRebuildCacheTargetName() const override
{
2011-11-11 05:00:49 +00:00
return "rebuild_cache";
}
const char* GetCleanTargetName() const override { return "clean"; }
2011-11-11 05:00:49 +00:00
bool SupportsCustomCommandDepfile() const override { return true; }
virtual cmGeneratedFileStream* GetImplFileStream(
const std::string& /*config*/) const
{
return this->BuildFileStream.get();
}
virtual cmGeneratedFileStream* GetConfigFileStream(
const std::string& /*config*/) const
{
return this->BuildFileStream.get();
}
virtual cmGeneratedFileStream* GetDefaultFileStream() const
{
return this->BuildFileStream.get();
}
virtual cmGeneratedFileStream* GetCommonFileStream() const
{
return this->BuildFileStream.get();
}
2012-07-18 11:27:49 +02:00
cmGeneratedFileStream* GetRulesFileStream() const
{
return this->RulesFileStream.get();
}
2011-11-11 05:00:49 +00:00
std::string const& ConvertToNinjaPath(const std::string& path) const;
struct MapToNinjaPathImpl
{
cmGlobalNinjaGenerator* GG;
MapToNinjaPathImpl(cmGlobalNinjaGenerator* gg)
: GG(gg)
{
}
std::string operator()(std::string const& path)
{
return this->GG->ConvertToNinjaPath(path);
}
};
MapToNinjaPathImpl MapToNinjaPath() { return { this }; }
// -- Additional clean files
void AddAdditionalCleanFile(std::string fileName, const std::string& config);
const char* GetAdditionalCleanTargetName() const
{
return "CMakeFiles/clean.additional";
}
static const char* GetByproductsForCleanTargetName()
{
return "CMakeFiles/cmake_byproducts_for_clean_target";
}
void AddCXXCompileCommand(const std::string& commandLine,
const std::string& sourceFile);
2011-11-11 05:00:49 +00:00
/**
* Add a rule to the generated build system.
* Call WriteRule() behind the scene but perform some check before like:
* - Do not add twice the same rule.
*/
void AddRule(cmNinjaRule const& rule);
2011-11-11 05:00:49 +00:00
bool HasRule(const std::string& name);
void AddCustomCommandRule();
void AddMacOSXContentRule();
2011-11-11 05:00:49 +00:00
bool HasCustomCommandOutput(const std::string& output)
{
2012-07-18 11:27:49 +02:00
return this->CustomCommandOutputs.find(output) !=
this->CustomCommandOutputs.end();
2012-07-18 11:27:49 +02:00
}
/// Called when we have seen the given custom command. Returns true
/// if we has seen it before.
bool SeenCustomCommand(cmCustomCommand const* cc, const std::string& config)
{
return !this->Configs[config].CustomCommands.insert(cc).second;
2012-07-18 11:27:49 +02:00
}
/// Called when we have seen the given custom command output.
void SeenCustomCommandOutput(const std::string& output)
{
2012-07-18 11:27:49 +02:00
this->CustomCommandOutputs.insert(output);
// We don't need the assumed dependencies anymore, because we have
// an output.
this->AssumedSourceDependencies.erase(output);
}
void AddAssumedSourceDependencies(const std::string& source,
const cmNinjaDeps& deps)
{
std::set<std::string>& ASD = this->AssumedSourceDependencies[source];
2012-07-18 11:27:49 +02:00
// Because we may see the same source file multiple times (same source
// specified in multiple targets), compute the union of any assumed
// dependencies.
ASD.insert(deps.begin(), deps.end());
}
static std::string OrderDependsTargetForTarget(
cmGeneratorTarget const* target, const std::string& config);
void AppendTargetOutputs(
cmGeneratorTarget const* target, cmNinjaDeps& outputs,
const std::string& config,
cmNinjaTargetDepends depends = DependOnTargetArtifact);
void AppendTargetDepends(
cmGeneratorTarget const* target, cmNinjaDeps& outputs,
const std::string& config, const std::string& fileConfig,
cmNinjaTargetDepends depends = DependOnTargetArtifact);
Ninja: Fix inter-target order-only dependencies of custom commands Custom command dependencies are followed for each target's source files and add their transitive closure to the corresponding target. This means that when a custom command in one target has a dependency on a custom command in another target, both will appear in the dependent target's sources. For the Makefile, VS IDE, and Xcode generators this is not a problem because each target gets its own independent build system that is evaluated in target dependency order. By the time the dependent target is built the custom command that belongs to one of its dependencies will already have been brought up to date. For the Ninja generator we need to generate a monolithic build system covering all targets so we can have only one copy of a custom command. This means that we need to reconcile the target-level ordering dependencies from its appearance in multiple targets to include only the least-dependent common set. This is done by computing the set intersection of the dependencies of all the targets containing a custom command. However, we previously included only the direct dependencies so any target-level dependency not directly added to all targets into which a custom command propagates was discarded. Fix this by computing the transitive closure of dependencies for each target and then intersecting those sets. That will get the common set of dependencies. Also add a test to cover a case in which the incorrectly dropped target ordering dependencies would fail.
2016-07-20 09:32:32 -04:00
void AppendTargetDependsClosure(cmGeneratorTarget const* target,
cmNinjaDeps& outputs,
const std::string& config);
Ninja: Improve performance with deeply-dependent custom targets The commit v3.7.0-rc1~339^2 (Ninja: Fix inter-target order-only dependencies of custom command, 2016-07-20) might cause performance degradations for larger projects. Especially when using custom commands as an input for each compilation rule (e.g. generated headers). For reference in the following I am referring to Source/cmGlobalNinjaGenerator.cxx: -> cmGlobalNinjaGenerator::AppendTargetDependsClosure -> cmGlobalNinjaGenerator::ComputeTargetDependsClosure It turned out that the mentioned commit is doing (indirectly) some redundant work that might impact performance when generating large projects. Imagine the dependency tree of custom targets: A \ C - D - E / B For each target the transitive closure is calculated recursively, but as the TargetDependsClosures are only cached on the top most level, everything downstream has to be recalculated. I.e. A->C->D->E B->C->D->E This ultimately leads to a lot of redundant calls to AppendTargetOutputs. The recursive nature of the algorithm itself is not significant to the problem, but reducing the work to actually to be done work, eliminates the performance problem. This patch changes the way, intermediate results are cached. Rather than caching the closure of targets, we cache the closure of outputs. Such that in the example above at B->C the cache already would kick in. Caching the outputs has one disadvantage that the patch takes care of. In case of such a structure A E \ / \ C - D G / \ / B F the calling order for A would be A->C->D->E->G (at which time G is seen to the recursion) then the recursion returns until it reaches A->C->D->F (at which the seen G would prevent to recurse down to G) But this would poison the cache for F with a wrong value (without G). Hence we use a local result set to ensure the cache is still consistently populated. For a large C++ project with around 25k targets this reduced the CMake configure / generate time from ~40s to ~29s. Signed-off-by: Matthias Maennich <matthias@maennich.net>
2017-08-31 23:48:02 +02:00
void AppendTargetDependsClosure(cmGeneratorTarget const* target,
cmNinjaOuts& outputs,
const std::string& config, bool omit_self);
2012-07-18 11:27:49 +02:00
void AppendDirectoryForConfig(const std::string& prefix,
const std::string& config,
const std::string& suffix,
std::string& dir) override;
virtual void AppendNinjaFileArgument(GeneratedMakeCommand& /*command*/,
const std::string& /*config*/) const
{
}
virtual void AddRebuildManifestOutputs(cmNinjaDeps& outputs) const
{
outputs.push_back(this->NinjaOutputPath(NINJA_BUILD_FILE));
}
int GetRuleCmdLength(const std::string& name) { return RuleCmdLength[name]; }
2012-07-18 11:27:49 +02:00
void AddTargetAlias(const std::string& alias, cmGeneratorTarget* target,
const std::string& config);
2012-07-18 11:27:49 +02:00
void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const override;
// Ninja generator uses 'deps' and 'msvc_deps_prefix' introduced in 1.3
static std::string RequiredNinjaVersion() { return "1.3"; }
static std::string RequiredNinjaVersionForConsolePool() { return "1.5"; }
static std::string RequiredNinjaVersionForImplicitOuts() { return "1.7"; }
static std::string RequiredNinjaVersionForManifestRestat() { return "1.8"; }
static std::string RequiredNinjaVersionForMultilineDepfile()
{
return "1.9";
}
static std::string RequiredNinjaVersionForDyndeps() { return "1.10"; }
static std::string RequiredNinjaVersionForRestatTool() { return "1.10"; }
static std::string RequiredNinjaVersionForUnconditionalRecompactTool()
{
return "1.10";
}
static std::string RequiredNinjaVersionForCleanDeadTool() { return "1.10"; }
bool SupportsConsolePool() const;
bool SupportsImplicitOuts() const;
bool SupportsManifestRestat() const;
bool SupportsMultilineDepfile() const;
2016-10-08 12:21:35 +02:00
std::string NinjaOutputPath(std::string const& path) const;
bool HasOutputPathPrefix() const { return !this->OutputPathPrefix.empty(); }
void StripNinjaOutputPathPrefixAsSuffix(std::string& path);
bool WriteDyndepFile(std::string const& dir_top_src,
std::string const& dir_top_bld,
std::string const& dir_cur_src,
std::string const& dir_cur_bld,
std::string const& arg_dd,
std::vector<std::string> const& arg_ddis,
std::string const& module_dir,
std::vector<std::string> const& linked_target_dirs,
std::string const& arg_lang);
virtual std::string BuildAlias(const std::string& alias,
const std::string& /*config*/) const
{
return alias;
}
virtual std::string ConfigDirectory(const std::string& /*config*/) const
{
return "";
}
cmNinjaDeps& GetByproductsForCleanTarget()
{
return this->ByproductsForCleanTarget;
}
cmNinjaDeps& GetByproductsForCleanTarget(const std::string& config)
{
return this->Configs[config].ByproductsForCleanTarget;
}
bool EnableCrossConfigBuild() const;
std::set<std::string> GetCrossConfigs(const std::string& config) const;
2011-11-11 05:00:49 +00:00
protected:
void Generate() override;
bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS() const override { return true; }
2011-11-11 05:00:49 +00:00
virtual bool OpenBuildFileStreams();
virtual void CloseBuildFileStreams();
bool OpenFileStream(std::unique_ptr<cmGeneratedFileStream>& stream,
const std::string& name);
static cm::optional<std::set<std::string>> ListSubsetWithAll(
const std::set<std::string>& all, const std::set<std::string>& defaults,
const std::vector<std::string>& items);
virtual bool InspectConfigTypeVariables() { return true; }
std::set<std::string> CrossConfigs;
std::set<std::string> DefaultConfigs;
std::string DefaultFileConfig;
private:
std::string GetEditCacheCommand() const override;
bool FindMakeProgram(cmMakefile* mf) override;
void CheckNinjaFeatures();
bool CheckLanguages(std::vector<std::string> const& languages,
cmMakefile* mf) const override;
bool CheckFortran(cmMakefile* mf) const;
void CloseCompileCommandsStream();
bool OpenRulesFileStream();
2011-11-11 05:00:49 +00:00
void CloseRulesFileStream();
void CleanMetaData();
2011-11-11 05:00:49 +00:00
/// Write the common disclaimer text at the top of each build file.
void WriteDisclaimer(std::ostream& os);
2012-02-05 01:48:08 +00:00
void WriteAssumedSourceDependencies();
2011-11-11 05:00:49 +00:00
void WriteTargetAliases(std::ostream& os);
void WriteFolderTargets(std::ostream& os);
void WriteUnknownExplicitDependencies(std::ostream& os);
2011-11-11 05:00:49 +00:00
void WriteBuiltinTargets(std::ostream& os);
void WriteTargetDefault(std::ostream& os);
2011-11-11 05:00:49 +00:00
void WriteTargetRebuildManifest(std::ostream& os);
bool WriteTargetCleanAdditional(std::ostream& os);
void WriteTargetClean(std::ostream& os);
2012-04-19 17:07:35 +02:00
void WriteTargetHelp(std::ostream& os);
2011-11-11 05:00:49 +00:00
Ninja: Fix inter-target order-only dependencies of custom commands Custom command dependencies are followed for each target's source files and add their transitive closure to the corresponding target. This means that when a custom command in one target has a dependency on a custom command in another target, both will appear in the dependent target's sources. For the Makefile, VS IDE, and Xcode generators this is not a problem because each target gets its own independent build system that is evaluated in target dependency order. By the time the dependent target is built the custom command that belongs to one of its dependencies will already have been brought up to date. For the Ninja generator we need to generate a monolithic build system covering all targets so we can have only one copy of a custom command. This means that we need to reconcile the target-level ordering dependencies from its appearance in multiple targets to include only the least-dependent common set. This is done by computing the set intersection of the dependencies of all the targets containing a custom command. However, we previously included only the direct dependencies so any target-level dependency not directly added to all targets into which a custom command propagates was discarded. Fix this by computing the transitive closure of dependencies for each target and then intersecting those sets. That will get the common set of dependencies. Also add a test to cover a case in which the incorrectly dropped target ordering dependencies would fail.
2016-07-20 09:32:32 -04:00
void ComputeTargetDependsClosure(
cmGeneratorTarget const* target,
std::set<cmGeneratorTarget const*>& depends);
std::string CMakeCmd() const;
std::string NinjaCmd() const;
2014-10-09 17:22:45 -06:00
/// The file containing the build statement. (the relationship of the
2011-11-11 05:00:49 +00:00
/// compilation DAG).
std::unique_ptr<cmGeneratedFileStream> BuildFileStream;
2011-11-11 05:00:49 +00:00
/// The file containing the rule statements. (The action attached to each
/// edge of the compilation DAG).
std::unique_ptr<cmGeneratedFileStream> RulesFileStream;
std::unique_ptr<cmGeneratedFileStream> CompileCommandsStream;
2011-11-11 05:00:49 +00:00
/// The set of rules added to the generated build system.
std::unordered_set<std::string> Rules;
2011-11-11 05:00:49 +00:00
/// Length of rule command, used by rsp file evaluation
std::unordered_map<std::string, int> RuleCmdLength;
bool UsingGCCOnWindows = false;
2011-11-11 05:00:49 +00:00
/// The set of custom command outputs we have seen.
std::set<std::string> CustomCommandOutputs;
/// Whether we are collecting known build outputs and needed
/// dependencies to determine unknown dependencies.
bool ComputingUnknownDependencies = false;
cmPolicies::PolicyStatus PolicyCMP0058 = cmPolicies::WARN;
/// The combined explicit dependencies of custom build commands
std::set<std::string> CombinedCustomCommandExplicitDependencies;
/// When combined with CombinedCustomCommandExplicitDependencies it allows
/// us to detect the set of explicit dependencies that have
std::set<std::string> CombinedBuildOutputs;
2011-11-11 05:00:49 +00:00
/// The mapping from source file to assumed dependencies.
2017-08-25 23:25:09 +02:00
std::map<std::string, std::set<std::string>> AssumedSourceDependencies;
2011-11-11 05:00:49 +00:00
struct TargetAlias
{
cmGeneratorTarget* GeneratorTarget;
std::string Config;
};
using TargetAliasMap = std::map<std::string, TargetAlias>;
2011-11-11 05:00:49 +00:00
TargetAliasMap TargetAliases;
TargetAliasMap DefaultTargetAliases;
/// the local cache for calls to ConvertToNinjaPath
mutable std::unordered_map<std::string, std::string> ConvertToNinjaPathCache;
std::string NinjaCommand;
std::string NinjaVersion;
bool NinjaSupportsConsolePool = false;
bool NinjaSupportsImplicitOuts = false;
bool NinjaSupportsManifestRestat = false;
bool NinjaSupportsMultilineDepfile = false;
bool NinjaSupportsDyndeps = false;
bool NinjaSupportsRestatTool = false;
bool NinjaSupportsUnconditionalRecompactTool = false;
bool NinjaSupportsCleanDeadTool = false;
private:
void InitOutputPathPrefix();
std::string OutputPathPrefix;
std::string TargetAll;
std::string CMakeCacheFile;
struct ByConfig
{
std::set<std::string> AdditionalCleanFiles;
/// The set of custom commands we have seen.
std::set<cmCustomCommand const*> CustomCommands;
std::map<cmGeneratorTarget const*, cmNinjaOuts> TargetDependsClosures;
TargetAliasMap TargetAliases;
cmNinjaDeps ByproductsForCleanTarget;
};
std::map<std::string, ByConfig> Configs;
cmNinjaDeps ByproductsForCleanTarget;
};
class cmGlobalNinjaMultiGenerator : public cmGlobalNinjaGenerator
{
public:
/// The default name of Ninja's common file. Typically: common.ninja.
static const char* NINJA_COMMON_FILE;
/// The default file extension to use for per-config Ninja files.
static const char* NINJA_FILE_EXTENSION;
cmGlobalNinjaMultiGenerator(cmake* cm);
bool IsMultiConfig() const override { return true; }
static std::unique_ptr<cmGlobalGeneratorFactory> NewFactory()
{
return std::unique_ptr<cmGlobalGeneratorFactory>(
new cmGlobalGeneratorSimpleFactory<cmGlobalNinjaMultiGenerator>());
}
static void GetDocumentation(cmDocumentationEntry& entry);
std::string GetName() const override
{
return cmGlobalNinjaMultiGenerator::GetActualName();
}
static std::string GetActualName() { return "Ninja Multi-Config"; }
std::string BuildAlias(const std::string& alias,
const std::string& config) const override
{
if (config.empty()) {
return alias;
}
return cmStrCat(alias, ":", config);
}
std::string ConfigDirectory(const std::string& config) const override
{
if (!config.empty()) {
return cmStrCat('/', config);
}
return "";
}
const char* GetCMakeCFGIntDir() const override { return "${CONFIGURATION}"; }
std::string ExpandCFGIntDir(const std::string& str,
const std::string& config) const override;
cmGeneratedFileStream* GetImplFileStream(
const std::string& config) const override
{
return this->ImplFileStreams.at(config).get();
}
cmGeneratedFileStream* GetConfigFileStream(
const std::string& config) const override
{
return this->ConfigFileStreams.at(config).get();
}
cmGeneratedFileStream* GetDefaultFileStream() const override
{
return this->DefaultFileStream.get();
}
cmGeneratedFileStream* GetCommonFileStream() const override
{
return this->CommonFileStream.get();
}
void AppendNinjaFileArgument(GeneratedMakeCommand& command,
const std::string& config) const override;
static std::string GetNinjaImplFilename(const std::string& config);
static std::string GetNinjaConfigFilename(const std::string& config);
void AddRebuildManifestOutputs(cmNinjaDeps& outputs) const override;
void GetQtAutoGenConfigs(std::vector<std::string>& configs) const override;
bool InspectConfigTypeVariables() override;
std::string GetDefaultBuildConfig() const override;
bool ReadCacheEntriesForBuild(const cmState& state) override;
bool SupportsDefaultBuildType() const override { return true; }
bool SupportsCrossConfigs() const override { return true; }
bool SupportsDefaultConfigs() const override { return true; }
protected:
bool OpenBuildFileStreams() override;
void CloseBuildFileStreams() override;
private:
std::map<std::string, std::unique_ptr<cmGeneratedFileStream>>
ImplFileStreams;
std::map<std::string, std::unique_ptr<cmGeneratedFileStream>>
ConfigFileStreams;
std::unique_ptr<cmGeneratedFileStream> CommonFileStream;
std::unique_ptr<cmGeneratedFileStream> DefaultFileStream;
2011-11-11 05:00:49 +00:00
};
#endif // ! cmGlobalNinjaGenerator_h