cmake/Source/cmMakefileTargetGenerator.h

257 lines
8.6 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
2018-01-26 17:06:56 +01:00
#include "cmConfigure.h" // IWYU pragma: keep
2015-11-17 17:22:37 +01:00
2016-10-30 18:24:19 +01:00
#include <iosfwd>
#include <map>
2020-02-01 23:06:01 +01:00
#include <memory>
2016-10-30 18:24:19 +01:00
#include <set>
#include <string>
#include <vector>
2017-04-14 19:02:05 +02:00
#include "cmCommonTargetGenerator.h"
2019-11-11 23:01:05 +01:00
#include "cmGeneratorTarget.h"
2017-04-14 19:02:05 +02:00
#include "cmLocalUnixMakefileGenerator3.h"
#include "cmOSXBundleGenerator.h"
2015-04-27 22:25:09 +02:00
class cmCustomCommandGenerator;
class cmGeneratedFileStream;
class cmGlobalUnixMakefileGenerator3;
2017-04-14 19:02:05 +02:00
class cmLinkLineComputer;
class cmOutputConverter;
class cmSourceFile;
2017-04-14 19:02:05 +02:00
class cmStateDirectory;
/** \class cmMakefileTargetGenerator
* \brief Support Routines for writing makefiles
*
*/
2016-07-09 11:21:54 +02:00
class cmMakefileTargetGenerator : public cmCommonTargetGenerator
{
public:
// constructor to set the ivars
2015-11-17 17:22:37 +01:00
cmMakefileTargetGenerator(cmGeneratorTarget* target);
2020-08-30 11:54:41 +02:00
cmMakefileTargetGenerator(const cmMakefileTargetGenerator&) = delete;
2018-01-26 17:06:56 +01:00
~cmMakefileTargetGenerator() override;
2020-08-30 11:54:41 +02:00
cmMakefileTargetGenerator& operator=(const cmMakefileTargetGenerator&) =
delete;
// construct using this factory call
2020-08-30 11:54:41 +02:00
static std::unique_ptr<cmMakefileTargetGenerator> New(
cmGeneratorTarget* tgt);
/* the main entry point for this class. Writes the Makefiles associated
with this target */
virtual void WriteRuleFiles() = 0;
/* return the number of actions that have progress reporting on them */
2016-07-09 11:21:54 +02:00
virtual unsigned long GetNumberOfProgressActions()
{
return this->NumberOfProgressActions;
}
std::string GetProgressFileNameFull() { return this->ProgressFileNameFull; }
2016-07-09 11:21:54 +02:00
cmGeneratorTarget* GetGeneratorTarget() { return this->GeneratorTarget; }
2012-08-04 10:26:08 +03:00
2020-08-30 11:54:41 +02:00
std::string GetConfigName();
protected:
2020-08-30 11:54:41 +02:00
void GetDeviceLinkFlags(std::string& linkFlags,
const std::string& linkLanguage);
2018-10-28 12:09:07 +01:00
void GetTargetLinkFlags(std::string& flags, const std::string& linkLanguage);
// create the file and directory etc
void CreateRuleFile();
// outputs the rules for object files and custom commands used by
// this target
void WriteTargetBuildRules();
// write some common code at the top of build.make
void WriteCommonCodeRules();
void WriteTargetLanguageFlags();
// write the clean rules for this target
void WriteTargetCleanRules();
// write the depend rules for this target
void WriteTargetDependRules();
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
{
2016-07-09 11:21:54 +02:00
MacOSXContentGeneratorType(cmMakefileTargetGenerator* gen)
: Generator(gen)
{
}
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:
cmMakefileTargetGenerator* Generator;
};
friend struct MacOSXContentGeneratorType;
// write the rules for an object
2015-04-27 22:25:09 +02:00
void WriteObjectRuleFiles(cmSourceFile const& source);
// write the depend.make file for an object
2015-04-27 22:25:09 +02:00
void WriteObjectDependRules(cmSourceFile const& source,
std::vector<std::string>& depends);
2021-09-14 00:13:48 +02:00
// CUDA device linking.
void WriteDeviceLinkRule(std::vector<std::string>& commands,
const std::string& output);
// write the build rule for a custom command
2015-04-27 22:25:09 +02:00
void GenerateCustomRuleFile(cmCustomCommandGenerator const& ccg);
// write a rule to drive building of more than one output from
// another rule
void GenerateExtraOutput(const char* out, const char* in,
bool symbolic = false);
2015-08-17 11:37:30 +02:00
void MakeEchoProgress(cmLocalUnixMakefileGenerator3::EchoProgress&) const;
2009-10-04 10:30:41 +03:00
// write out the variable that lists the objects for this target
void WriteObjectsVariable(std::string& variableName,
2015-04-27 22:25:09 +02:00
std::string& variableNameExternal,
bool useWatcomQuote);
void WriteObjectsStrings(std::vector<std::string>& objStrings,
std::string::size_type limit = std::string::npos);
// write the driver rule to build target outputs
2015-04-27 22:25:09 +02:00
void WriteTargetDriverRule(const std::string& main_output, bool relink);
void DriveCustomCommands(std::vector<std::string>& depends);
// append intertarget dependencies
2021-09-14 00:13:48 +02:00
void AppendTargetDepends(std::vector<std::string>& depends,
bool ignoreType = false);
2012-04-19 19:04:21 +03:00
// Append object file dependencies.
void AppendObjectDepends(std::vector<std::string>& depends);
2011-01-16 11:35:12 +01:00
// Append link rule dependencies (objects, etc.).
2018-10-28 12:09:07 +01:00
void AppendLinkDepends(std::vector<std::string>& depends,
const std::string& linkLanguage);
2011-01-16 11:35:12 +01:00
2012-02-18 12:40:36 +02:00
// Lookup the link rule for this target.
2015-04-27 22:25:09 +02:00
std::string GetLinkRule(const std::string& linkRuleVar);
/** Create a script to hold link rules and a command to invoke the
script at build time. */
void CreateLinkScript(const char* name,
std::vector<std::string> const& link_commands,
std::vector<std::string>& makefile_commands,
std::vector<std::string>& makefile_depends);
2020-08-30 11:54:41 +02:00
std::unique_ptr<cmLinkLineComputer> CreateLinkLineComputer(
2017-07-20 19:35:53 +02:00
cmOutputConverter* outputConverter, cmStateDirectory const& stateDir);
2017-04-14 19:02:05 +02:00
/** Create a response file with the given set of options. Returns
the relative path from the target build working directory to the
response file name. */
2016-07-09 11:21:54 +02:00
std::string CreateResponseFile(const char* name, std::string const& options,
std::vector<std::string>& makefile_depends);
2016-10-30 18:24:19 +01:00
bool CheckUseResponseFileForObjects(std::string const& l) const;
bool CheckUseResponseFileForLibraries(std::string const& l) const;
2015-04-27 22:25:09 +02:00
/** Create list of flags for link libraries. */
2017-04-14 19:02:05 +02:00
void CreateLinkLibs(cmLinkLineComputer* linkLineComputer,
std::string& linkLibs, bool useResponseFile,
std::vector<std::string>& makefile_depends);
2015-04-27 22:25:09 +02:00
/** Create lists of object files for linking and cleaning. */
void CreateObjectLists(bool useLinkScript, bool useArchiveRules,
bool useResponseFile, std::string& buildObjs,
2015-04-27 22:25:09 +02:00
std::vector<std::string>& makefile_depends,
bool useWatcomQuote);
2016-10-30 18:24:19 +01:00
/** Add commands for generate def files */
2017-07-20 19:35:53 +02:00
void GenDefFile(std::vector<std::string>& real_link_commands);
2016-10-30 18:24:19 +01:00
2020-08-30 11:54:41 +02:00
void AddIncludeFlags(std::string& flags, const std::string& lang,
const std::string& config) override;
2011-06-19 15:41:06 +03:00
virtual void CloseFileStreams();
2016-07-09 11:21:54 +02:00
cmLocalUnixMakefileGenerator3* LocalGenerator;
cmGlobalUnixMakefileGenerator3* GlobalGenerator;
2016-07-09 11:21:54 +02:00
enum CustomCommandDriveType
{
OnBuild,
OnDepends,
OnUtility
};
CustomCommandDriveType CustomCommandDriver;
// the full path to the build file
std::string BuildFileName;
std::string BuildFileNameFull;
// the full path to the progress file
std::string ProgressFileNameFull;
unsigned long NumberOfProgressActions;
2009-10-04 10:30:41 +03:00
bool NoRuleMessages;
2021-09-14 00:13:48 +02:00
bool CMP0113New = false;
// the path to the directory the build file is in
std::string TargetBuildDirectory;
std::string TargetBuildDirectoryFull;
// the stream for the build file
2020-08-30 11:54:41 +02:00
std::unique_ptr<cmGeneratedFileStream> BuildFileStream;
// the stream for the flag file
std::string FlagFileNameFull;
2020-08-30 11:54:41 +02:00
std::unique_ptr<cmGeneratedFileStream> FlagFileStream;
2016-07-09 11:21:54 +02:00
class StringList : public std::vector<std::string>
{
};
2015-04-27 22:25:09 +02:00
std::map<std::string, StringList> FlagFileDepends;
// the stream for the info file
std::string InfoFileNameFull;
2020-08-30 11:54:41 +02:00
std::unique_ptr<cmGeneratedFileStream> InfoFileStream;
// files to clean
2019-11-11 23:01:05 +01:00
std::set<std::string> CleanFiles;
// objects used by this target
std::vector<std::string> Objects;
std::vector<std::string> ExternalObjects;
// Set of object file names that will be built in this directory.
2015-04-27 22:25:09 +02:00
std::set<std::string> ObjectFiles;
// Set of extra output files to be driven by the build.
2015-04-27 22:25:09 +02:00
std::set<std::string> ExtraFiles;
2021-09-14 00:13:48 +02:00
// Set of custom command output files to be driven by the build.
std::set<std::string> CustomCommandOutputs;
2020-02-01 23:06:01 +01:00
using MultipleOutputPairsType = std::map<std::string, std::string>;
MultipleOutputPairsType MultipleOutputPairs;
2016-07-09 11:21:54 +02:00
bool WriteMakeRule(std::ostream& os, const char* comment,
2015-04-27 22:25:09 +02:00
const std::vector<std::string>& outputs,
const std::vector<std::string>& depends,
const std::vector<std::string>& commands,
bool in_help = false);
// Target name info.
2019-11-11 23:01:05 +01:00
cmGeneratorTarget::Names TargetNames;
2018-10-28 12:09:07 +01:00
// macOS content info.
2015-04-27 22:25:09 +02:00
std::set<std::string> MacContentFolders;
2019-11-11 23:01:05 +01:00
std::unique_ptr<cmOSXBundleGenerator> OSXBundleGenerator;
2020-08-30 11:54:41 +02:00
std::unique_ptr<MacOSXContentGeneratorType> MacOSXContentGenerator;
};