cmake/Source/cmNinjaTargetGenerator.h

227 lines
8.1 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. */
2021-09-14 00:13:48 +02:00
#pragma once
2012-04-19 19:04:21 +03:00
2018-01-26 17:06:56 +01:00
#include "cmConfigure.h" // IWYU pragma: keep
2015-11-17 17:22:37 +01:00
2020-02-01 23:06:01 +01:00
#include <map>
#include <memory>
#include <set>
#include <string>
2020-08-30 11:54:41 +02:00
#include <utility>
2020-02-01 23:06:01 +01:00
#include <vector>
2020-08-30 11:54:41 +02:00
#include <cm3p/json/value.h>
2019-11-11 23:01:05 +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
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.
2019-11-11 23:01:05 +01:00
static std::unique_ptr<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.
2018-01-26 17:06:56 +01:00
~cmNinjaTargetGenerator() override;
2012-04-19 19:04:21 +03:00
2020-08-30 11:54:41 +02:00
virtual void Generate(const std::string& config) = 0;
2012-04-19 19:04:21 +03:00
std::string GetTargetName() const;
protected:
2020-08-30 11:54:41 +02:00
bool SetMsvcTargetPdbVariable(cmNinjaVars&, const std::string& config) const;
2013-03-16 19:13:01 +02:00
2020-08-30 11:54:41 +02:00
cmGeneratedFileStream& GetImplFileStream(const std::string& config) const;
cmGeneratedFileStream& GetCommonFileStream() const;
2012-04-19 19:04:21 +03:00
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
2020-08-30 11:54:41 +02:00
std::string LanguageCompilerRule(const std::string& lang,
const std::string& config) const;
2021-09-14 00:13:48 +02:00
std::string LanguagePreprocessAndScanRule(std::string const& lang,
const std::string& config) const;
std::string LanguageScanRule(std::string const& lang,
const std::string& config) const;
2020-08-30 11:54:41 +02:00
std::string LanguageDyndepRule(std::string const& lang,
const std::string& config) const;
2021-09-14 00:13:48 +02:00
bool NeedDyndep(std::string const& lang, std::string const& config) const;
bool NeedExplicitPreprocessing(std::string const& lang) const;
bool CompileWithDefines(std::string const& lang) const;
bool NeedCxxModuleSupport(std::string const& lang,
std::string const& config) const;
2012-04-19 19:04:21 +03:00
2020-08-30 11:54:41 +02:00
std::string OrderDependsTargetForTarget(const std::string& config);
2015-04-27 22:25:09 +02:00
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,
2020-08-30 11:54:41 +02:00
const std::string& language,
const std::string& config);
2012-04-19 19:04:21 +03:00
2020-08-30 11:54:41 +02:00
void AddIncludeFlags(std::string& flags, std::string const& lang,
const std::string& config) override;
2015-11-17 17:22:37 +01:00
2015-04-27 22:25:09 +02:00
std::string ComputeDefines(cmSourceFile const* source,
2020-08-30 11:54:41 +02:00
const std::string& language,
const std::string& config);
2012-04-19 19:04:21 +03:00
2018-04-23 21:13:27 +02:00
std::string ComputeIncludes(cmSourceFile const* source,
2020-08-30 11:54:41 +02:00
const std::string& language,
const std::string& config);
2018-04-23 21:13:27 +02:00
2021-09-14 00:13:48 +02:00
std::string const& ConvertToNinjaPath(const std::string& path) const
2016-07-09 11:21:54 +02:00
{
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
}
2021-09-14 00:13:48 +02:00
std::string ConvertToNinjaAbsPath(std::string path) const
{
return this->GetGlobalGenerator()->ConvertToNinjaAbsPath(std::move(path));
}
2012-04-19 19:04:21 +03:00
/// @return the list of link dependency for the given target @a target.
2020-08-30 11:54:41 +02:00
cmNinjaDeps ComputeLinkDeps(const std::string& linkLanguage,
2021-09-14 00:13:48 +02:00
const std::string& config,
bool ignoreType = false) const;
2012-04-19 19:04:21 +03:00
/// @return the source file path for the given @a source.
2021-09-14 00:13:48 +02:00
std::string GetCompiledSourceNinjaPath(cmSourceFile const* source) const;
2012-04-19 19:04:21 +03:00
/// @return the object file path for the given @a source.
2020-08-30 11:54:41 +02:00
std::string GetObjectFilePath(cmSourceFile const* source,
const std::string& config) 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.
2020-08-30 11:54:41 +02:00
std::string GetPreprocessedFilePath(cmSourceFile const* source,
const std::string& config) const;
2016-10-30 18:24:19 +01:00
/// @return the dyndep file path for this target.
2020-08-30 11:54:41 +02:00
std::string GetDyndepFilePath(std::string const& lang,
const std::string& config) const;
2016-10-30 18:24:19 +01:00
/// @return the target dependency scanner info file path
2020-08-30 11:54:41 +02:00
std::string GetTargetDependInfoPath(std::string const& lang,
const std::string& config) const;
2016-10-30 18:24:19 +01:00
2012-04-19 19:04:21 +03:00
/// @return the file path where the target named @a name is generated.
2020-08-30 11:54:41 +02:00
std::string GetTargetFilePath(const std::string& name,
const std::string& config) const;
2012-04-19 19:04:21 +03:00
/// @return the output path for the target.
2020-08-30 11:54:41 +02:00
virtual std::string GetTargetOutputDir(const std::string& config) const;
void WriteLanguageRules(const std::string& language,
const std::string& config);
void WriteCompileRule(const std::string& language,
const std::string& config);
void WriteObjectBuildStatements(const std::string& config,
const std::string& fileConfig,
bool firstForConfig);
void WriteObjectBuildStatement(cmSourceFile const* source,
const std::string& config,
const std::string& fileConfig,
bool firstForConfig);
void WriteTargetDependInfo(std::string const& lang,
const std::string& config);
void EmitSwiftDependencyInfo(cmSourceFile const* source,
const std::string& config);
2019-11-11 23:01:05 +01: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,
2021-09-14 00:13:48 +02:00
std::string const& defines, std::string const& includes,
std::string const& outputConfig);
2016-07-09 11:21:54 +02:00
2020-08-30 11:54:41 +02:00
void AdditionalCleanFiles(const std::string& config);
2019-11-11 23:01:05 +01:00
2020-08-30 11:54:41 +02:00
cmNinjaDeps GetObjects(const std::string& config) const;
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
2018-10-28 12:09:07 +01:00
// write rules for macOS Application Bundle content.
2016-07-09 11:21:54 +02:00
struct MacOSXContentGeneratorType
: cmOSXBundleGenerator::MacOSXContentGeneratorType
2012-08-04 10:26:08 +03:00
{
2020-08-30 11:54:41 +02:00
MacOSXContentGeneratorType(cmNinjaTargetGenerator* g,
std::string fileConfig)
2016-07-09 11:21:54 +02:00
: Generator(g)
2020-08-30 11:54:41 +02:00
, FileConfig(std::move(fileConfig))
2016-07-09 11:21:54 +02:00
{
}
2012-08-04 10:26:08 +03:00
2020-08-30 11:54:41 +02:00
void operator()(cmSourceFile const& source, const char* pkgloc,
const std::string& config) override;
2012-08-04 10:26:08 +03:00
private:
cmNinjaTargetGenerator* Generator;
2020-08-30 11:54:41 +02:00
std::string FileConfig;
2012-08-04 10:26:08 +03:00
};
friend struct MacOSXContentGeneratorType;
// Properly initialized by sub-classes.
2019-11-11 23:01:05 +01:00
std::unique_ptr<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;
2020-08-30 11:54:41 +02:00
struct ByConfig
{
/// List of object files for this target.
cmNinjaDeps Objects;
// Fortran Support
std::map<std::string, cmNinjaDeps> DDIFiles;
// Swift Support
Json::Value SwiftOutputMap;
std::vector<cmCustomCommand const*> CustomCommands;
cmNinjaDeps ExtraFiles;
std::unique_ptr<MacOSXContentGeneratorType> MacOSXContentGenerator;
};
std::map<std::string, ByConfig> Configs;
2012-04-19 19:04:21 +03:00
};