diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index 61353c538..b2fe24327 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -153,6 +153,7 @@ public: static bool IsMinGW() { return UsingMinGW; } + public: /// Default constructor. cmGlobalNinjaGenerator(); @@ -216,12 +217,12 @@ public: } virtual const char* GetCleanTargetName() const { return "clean"; } -public: - cmGeneratedFileStream* GetBuildFileStream() const - { return this->BuildFileStream; } - cmGeneratedFileStream* GetRulesFileStream() const - { return this->RulesFileStream; } + cmGeneratedFileStream* GetBuildFileStream() const { + return this->BuildFileStream; } + + cmGeneratedFileStream* GetRulesFileStream() const { + return this->RulesFileStream; } void AddCXXCompileCommand(const std::string &commandLine, const std::string &sourceFile); @@ -246,54 +247,10 @@ public: void AddCustomCommandRule(); void AddMacOSXContentRule(); -protected: - - /// Overloaded methods. - /// @see cmGlobalGenerator::CheckALLOW_DUPLICATE_CUSTOM_TARGETS() - virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS() { return true; } - -private: - - /// @see cmGlobalGenerator::ComputeTargetObjects - virtual void ComputeTargetObjects(cmGeneratorTarget* gt) const; - -private: - // In order to access the AddDependencyToAll() functions and co. - friend class cmLocalNinjaGenerator; - - // In order to access the SeenCustomCommand() function. - friend class cmNinjaTargetGenerator; - friend class cmNinjaNormalTargetGenerator; - friend class cmNinjaUtilityTargetGenerator; - -private: - void OpenBuildFileStream(); - void CloseBuildFileStream(); - - void CloseCompileCommandsStream(); - - void OpenRulesFileStream(); - void CloseRulesFileStream(); - - /// Write the common disclaimer text at the top of each build file. - void WriteDisclaimer(std::ostream& os); - - void AddDependencyToAll(cmTarget* target); - void AddDependencyToAll(const std::string& input); - - void WriteAssumedSourceDependencies(); - - void AppendTargetOutputs(cmTarget* target, cmNinjaDeps& outputs); - void AppendTargetDepends(cmTarget* target, cmNinjaDeps& outputs); - - void AddTargetAlias(const std::string& alias, cmTarget* target); - void WriteTargetAliases(std::ostream& os); - - void WriteBuiltinTargets(std::ostream& os); - void WriteTargetAll(std::ostream& os); - void WriteTargetRebuildManifest(std::ostream& os); - void WriteTargetClean(std::ostream& os); - void WriteTargetHelp(std::ostream& os); + bool HasCustomCommandOutput(const std::string &output) { + return this->CustomCommandOutputs.find(output) != + this->CustomCommandOutputs.end(); + } /// Called when we have seen the given custom command. Returns true /// if we has seen it before. @@ -309,11 +266,6 @@ private: this->AssumedSourceDependencies.erase(output); } - bool HasCustomCommandOutput(const std::string &output) { - return this->CustomCommandOutputs.find(output) != - this->CustomCommandOutputs.end(); - } - void AddAssumedSourceDependencies(const std::string &source, const cmNinjaDeps &deps) { std::set &ASD = this->AssumedSourceDependencies[source]; @@ -323,11 +275,59 @@ private: ASD.insert(deps.begin(), deps.end()); } - std::string ninjaCmd() const; + void AppendTargetOutputs(cmTarget* target, cmNinjaDeps& outputs); + void AppendTargetDepends(cmTarget* target, cmNinjaDeps& outputs); + void AddDependencyToAll(cmTarget* target); + void AddDependencyToAll(const std::string& input); + + const std::vector& GetLocalGenerators() const { + return LocalGenerators; } + + bool IsExcluded(cmLocalGenerator* root, cmTarget& target) { + return cmGlobalGenerator::IsExcluded(root, target); } + + int GetRuleCmdLength(const std::string& name) { + return RuleCmdLength[name]; } + + void AddTargetAlias(const std::string& alias, cmTarget* target); + + +protected: + + /// Overloaded methods. + /// @see cmGlobalGenerator::CheckALLOW_DUPLICATE_CUSTOM_TARGETS() + virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS() { return true; } - int GetRuleCmdLength(const std::string& name) { return RuleCmdLength[name]; } private: + + /// @see cmGlobalGenerator::ComputeTargetObjects + virtual void ComputeTargetObjects(cmGeneratorTarget* gt) const; + + void OpenBuildFileStream(); + void CloseBuildFileStream(); + + void CloseCompileCommandsStream(); + + void OpenRulesFileStream(); + void CloseRulesFileStream(); + + /// Write the common disclaimer text at the top of each build file. + void WriteDisclaimer(std::ostream& os); + + void WriteAssumedSourceDependencies(); + + void WriteTargetAliases(std::ostream& os); + + void WriteBuiltinTargets(std::ostream& os); + void WriteTargetAll(std::ostream& os); + void WriteTargetRebuildManifest(std::ostream& os); + void WriteTargetClean(std::ostream& os); + void WriteTargetHelp(std::ostream& os); + + std::string ninjaCmd() const; + + /// The file containing the build statement. (the relation ship of the /// compilation DAG). cmGeneratedFileStream* BuildFileStream; diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index ea9c406c0..d902f4ef7 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -61,7 +61,7 @@ void cmLocalNinjaGenerator::Generate() tg->Generate(); // Add the target to "all" if required. if (!this->GetGlobalNinjaGenerator()->IsExcluded( - this->GetGlobalNinjaGenerator()->LocalGenerators[0], + this->GetGlobalNinjaGenerator()->GetLocalGenerators()[0], t->second)) this->GetGlobalNinjaGenerator()->AddDependencyToAll(&t->second); delete tg; diff --git a/Source/cmLocalNinjaGenerator.h b/Source/cmLocalNinjaGenerator.h index ea44b2fe2..20b36e84e 100644 --- a/Source/cmLocalNinjaGenerator.h +++ b/Source/cmLocalNinjaGenerator.h @@ -45,7 +45,6 @@ public: /// Overloaded methods. @see cmLocalGenerator::GetTargetDirectory() virtual std::string GetTargetDirectory(cmTarget const& target) const; -public: const cmGlobalNinjaGenerator* GetGlobalNinjaGenerator() const; cmGlobalNinjaGenerator* GetGlobalNinjaGenerator(); @@ -67,17 +66,43 @@ public: std::string GetHomeRelativeOutputPath() const { return this->HomeRelativeOutputPath; } -protected: + std::string ConvertToNinjaPath(const char *path); + + struct map_to_ninja_path { + cmLocalNinjaGenerator *LocalGenerator; + map_to_ninja_path(cmLocalNinjaGenerator *LocalGen) + : LocalGenerator(LocalGen) {} + std::string operator()(const std::string &path) { + return LocalGenerator->ConvertToNinjaPath(path.c_str()); + } + }; + + map_to_ninja_path MapToNinjaPath() { + return map_to_ninja_path(this); + } + + void ExpandRuleVariables(std::string& string, + const RuleVariables& replaceValues) { + return cmLocalGenerator:: + ExpandRuleVariables(string, replaceValues); } + + std::string BuildCommandLine(const std::vector &cmdLines); + + void AppendTargetOutputs(cmTarget* target, cmNinjaDeps& outputs); + void AppendTargetDepends(cmTarget* target, cmNinjaDeps& outputs); + + void AddCustomCommandTarget(cmCustomCommand const* cc, cmTarget* target); + void AppendCustomCommandLines(const cmCustomCommand *cc, + std::vector &cmdLines); + void AppendCustomCommandDeps(const cmCustomCommand *cc, + cmNinjaDeps &ninjaDeps); + virtual std::string ConvertToLinkReference(std::string const& lib); + + +protected: virtual std::string ConvertToIncludeReference(std::string const& path); -private: - friend class cmGlobalNinjaGenerator; - - // In order to access to protected member of the local generator. - friend class cmNinjaTargetGenerator; - friend class cmNinjaNormalTargetGenerator; - friend class cmNinjaUtilityTargetGenerator; private: cmGeneratedFileStream& GetBuildFileStream() const; @@ -90,38 +115,13 @@ private: void SetConfigName(); - std::string ConvertToNinjaPath(const char *path); - - struct map_to_ninja_path; - friend struct map_to_ninja_path; - struct map_to_ninja_path { - cmLocalNinjaGenerator *LocalGenerator; - map_to_ninja_path(cmLocalNinjaGenerator *LocalGen) - : LocalGenerator(LocalGen) {} - std::string operator()(const std::string &path) { - return LocalGenerator->ConvertToNinjaPath(path.c_str()); - } - }; - map_to_ninja_path MapToNinjaPath() { - return map_to_ninja_path(this); - } - - void AppendTargetOutputs(cmTarget* target, cmNinjaDeps& outputs); - void AppendTargetDepends(cmTarget* target, cmNinjaDeps& outputs); - - void AppendCustomCommandDeps(const cmCustomCommand *cc, - cmNinjaDeps &ninjaDeps); - std::string BuildCommandLine(const std::vector &cmdLines); - void AppendCustomCommandLines(const cmCustomCommand *cc, - std::vector &cmdLines); void WriteCustomCommandRule(); void WriteCustomCommandBuildStatement(cmCustomCommand const *cc, const cmNinjaDeps& orderOnlyDeps); - void AddCustomCommandTarget(cmCustomCommand const* cc, cmTarget* target); void WriteCustomCommandBuildStatements(); -private: + std::string ConfigName; std::string HomeRelativeOutputPath; diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 36eb64d03..ac2b4688b 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -91,7 +91,7 @@ cmGlobalNinjaGenerator* cmNinjaTargetGenerator::GetGlobalGenerator() const const char* cmNinjaTargetGenerator::GetConfigName() const { - return this->LocalGenerator->ConfigName.c_str(); + return this->LocalGenerator->GetConfigName(); } // TODO: Picked up from cmMakefileTargetGenerator. Refactor it. diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h index 0a3329f8d..a2ca4bd8c 100644 --- a/Source/cmNinjaTargetGenerator.h +++ b/Source/cmNinjaTargetGenerator.h @@ -126,7 +126,7 @@ protected: private: cmNinjaTargetGenerator* Generator; }; - friend class MacOSXContentGeneratorType; + protected: MacOSXContentGeneratorType MacOSXContentGenerator; @@ -134,6 +134,7 @@ protected: cmOSXBundleGenerator* OSXBundleGenerator; std::set MacContentFolders; + private: cmTarget* Target; cmGeneratorTarget* GeneratorTarget;