cmake/Source/cmNinjaTargetGenerator.h

173 lines
5.5 KiB
C
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2012-04-19 19:04:21 +03:00
#ifndef cmNinjaTargetGenerator_h
#define cmNinjaTargetGenerator_h
2017-07-20 19:35:53 +02:00
#include "cmConfigure.h"
2015-11-17 17:22:37 +01:00
2016-10-30 18:24:19 +01:00
#include "cmCommonTargetGenerator.h"
2015-11-17 17:22:37 +01:00
#include "cmGlobalNinjaGenerator.h"
2016-07-09 11:21:54 +02:00
#include "cmNinjaTypes.h"
2012-08-04 10:26:08 +03:00
#include "cmOSXBundleGenerator.h"
2012-04-19 19:04:21 +03:00
2016-10-30 18:24:19 +01:00
#include <set>
#include <string>
#include <vector>
class cmCustomCommand;
2012-04-19 19:04:21 +03:00
class cmGeneratedFileStream;
class cmGeneratorTarget;
2016-10-30 18:24:19 +01:00
class cmLocalNinjaGenerator;
2012-04-19 19:04:21 +03:00
class cmMakefile;
class cmSourceFile;
2016-07-09 11:21:54 +02:00
class cmNinjaTargetGenerator : public cmCommonTargetGenerator
2012-04-19 19:04:21 +03:00
{
public:
/// Create a cmNinjaTargetGenerator according to the @a target's type.
2014-08-03 19:52:23 +02:00
static cmNinjaTargetGenerator* New(cmGeneratorTarget* target);
2012-04-19 19:04:21 +03:00
/// Build a NinjaTargetGenerator.
2015-11-17 17:22:37 +01:00
cmNinjaTargetGenerator(cmGeneratorTarget* target);
2012-04-19 19:04:21 +03:00
/// Destructor.
2016-10-30 18:24:19 +01:00
~cmNinjaTargetGenerator() CM_OVERRIDE;
2012-04-19 19:04:21 +03:00
virtual void Generate() = 0;
std::string GetTargetName() const;
2015-04-27 22:25:09 +02:00
bool NeedDepTypeMSVC(const std::string& lang) const;
2014-08-03 19:52:23 +02:00
2012-04-19 19:04:21 +03:00
protected:
2013-03-16 19:13:01 +02:00
bool SetMsvcTargetPdbVariable(cmNinjaVars&) const;
2012-04-19 19:04:21 +03:00
cmGeneratedFileStream& GetBuildFileStream() const;
cmGeneratedFileStream& GetRulesFileStream() const;
2013-03-16 19:13:01 +02:00
cmGeneratorTarget* GetGeneratorTarget() const
2016-07-09 11:21:54 +02:00
{
return this->GeneratorTarget;
}
2013-03-16 19:13:01 +02:00
2012-04-19 19:04:21 +03:00
cmLocalNinjaGenerator* GetLocalGenerator() const
2016-07-09 11:21:54 +02:00
{
return this->LocalGenerator;
}
2012-04-19 19:04:21 +03:00
cmGlobalNinjaGenerator* GetGlobalGenerator() const;
2016-07-09 11:21:54 +02:00
cmMakefile* GetMakefile() const { return this->Makefile; }
2012-04-19 19:04:21 +03:00
2015-08-17 11:37:30 +02:00
std::string LanguageCompilerRule(const std::string& lang) const;
2016-10-30 18:24:19 +01:00
std::string LanguagePreprocessRule(std::string const& lang) const;
bool NeedExplicitPreprocessing(std::string const& lang) const;
std::string LanguageDyndepRule(std::string const& lang) const;
bool NeedDyndep(std::string const& lang) const;
2012-04-19 19:04:21 +03:00
2015-04-27 22:25:09 +02:00
std::string OrderDependsTargetForTarget();
std::string ComputeOrderDependsForTarget();
2012-04-19 19:04:21 +03:00
/**
* Compute the flags for compilation of object files for a given @a language.
* @note Generally it is the value of the variable whose name is computed
* by LanguageFlagsVarName().
*/
2015-04-27 22:25:09 +02:00
std::string ComputeFlagsForObject(cmSourceFile const* source,
2012-04-19 19:04:21 +03:00
const std::string& language);
2016-10-30 18:24:19 +01:00
void AddIncludeFlags(std::string& flags,
std::string const& lang) CM_OVERRIDE;
2015-11-17 17:22:37 +01:00
2015-04-27 22:25:09 +02:00
std::string ComputeDefines(cmSourceFile const* source,
2012-04-19 19:04:21 +03:00
const std::string& language);
2016-07-09 11:21:54 +02:00
std::string ConvertToNinjaPath(const std::string& path) const
{
2015-11-17 17:22:37 +01:00
return this->GetGlobalGenerator()->ConvertToNinjaPath(path);
2012-04-19 19:04:21 +03:00
}
2016-07-09 11:21:54 +02:00
cmGlobalNinjaGenerator::MapToNinjaPathImpl MapToNinjaPath() const
{
2015-11-17 17:22:37 +01:00
return this->GetGlobalGenerator()->MapToNinjaPath();
2012-04-19 19:04:21 +03:00
}
/// @return the list of link dependency for the given target @a target.
cmNinjaDeps ComputeLinkDeps() const;
/// @return the source file path for the given @a source.
2015-04-27 22:25:09 +02:00
std::string GetSourceFilePath(cmSourceFile const* source) const;
2012-04-19 19:04:21 +03:00
/// @return the object file path for the given @a source.
2015-04-27 22:25:09 +02:00
std::string GetObjectFilePath(cmSourceFile const* source) const;
2012-04-19 19:04:21 +03:00
2016-10-30 18:24:19 +01:00
/// @return the preprocessed source file path for the given @a source.
std::string GetPreprocessedFilePath(cmSourceFile const* source) const;
/// @return the dyndep file path for this target.
std::string GetDyndepFilePath(std::string const& lang) const;
/// @return the target dependency scanner info file path
std::string GetTargetDependInfoPath(std::string const& lang) const;
2012-04-19 19:04:21 +03:00
/// @return the file path where the target named @a name is generated.
std::string GetTargetFilePath(const std::string& name) const;
/// @return the output path for the target.
virtual std::string GetTargetOutputDir() const;
void WriteLanguageRules(const std::string& language);
void WriteCompileRule(const std::string& language);
void WriteObjectBuildStatements();
2017-07-20 19:35:53 +02:00
void WriteObjectBuildStatement(cmSourceFile const* source);
2016-10-30 18:24:19 +01:00
void WriteTargetDependInfo(std::string const& lang);
2012-04-19 19:04:21 +03:00
2015-11-17 17:22:37 +01:00
void ExportObjectCompileCommand(
2016-07-09 11:21:54 +02:00
std::string const& language, std::string const& sourceFileName,
std::string const& objectDir, std::string const& objectFileName,
std::string const& objectFileDir, std::string const& flags,
std::string const& defines, std::string const& includes);
cmNinjaDeps GetObjects() const { return this->Objects; }
2012-04-19 19:04:21 +03:00
2013-03-16 19:13:01 +02:00
void EnsureDirectoryExists(const std::string& dir) const;
void EnsureParentDirectoryExists(const std::string& path) const;
2012-06-27 20:52:58 +03:00
2012-08-04 10:26:08 +03:00
// write rules for Mac OS X Application Bundle content.
2016-07-09 11:21:54 +02:00
struct MacOSXContentGeneratorType
: cmOSXBundleGenerator::MacOSXContentGeneratorType
2012-08-04 10:26:08 +03:00
{
2016-07-09 11:21:54 +02:00
MacOSXContentGeneratorType(cmNinjaTargetGenerator* g)
: Generator(g)
{
}
2012-08-04 10:26:08 +03:00
2016-10-30 18:24:19 +01:00
void operator()(cmSourceFile const& source,
const char* pkgloc) CM_OVERRIDE;
2012-08-04 10:26:08 +03:00
private:
cmNinjaTargetGenerator* Generator;
};
friend struct MacOSXContentGeneratorType;
MacOSXContentGeneratorType* MacOSXContentGenerator;
// Properly initialized by sub-classes.
cmOSXBundleGenerator* OSXBundleGenerator;
2015-04-27 22:25:09 +02:00
std::set<std::string> MacContentFolders;
2012-08-04 10:26:08 +03:00
2015-04-27 22:25:09 +02:00
void addPoolNinjaVariable(const std::string& pool_property,
2016-07-09 11:21:54 +02:00
cmGeneratorTarget* target, cmNinjaVars& vars);
bool ForceResponseFile();
2012-08-04 10:26:08 +03:00
2012-04-19 19:04:21 +03:00
private:
cmLocalNinjaGenerator* LocalGenerator;
/// List of object files for this target.
cmNinjaDeps Objects;
2016-10-30 18:24:19 +01:00
cmNinjaDeps DDIFiles; // TODO: Make per-language.
2015-04-27 22:25:09 +02:00
std::vector<cmCustomCommand const*> CustomCommands;
2016-10-30 18:24:19 +01:00
cmNinjaDeps ExtraFiles;
2012-04-19 19:04:21 +03:00
};
#endif // ! cmNinjaTargetGenerator_h