cmake/Source/cmMakefileTargetGenerator.h

249 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. */
#ifndef cmMakefileTargetGenerator_h
#define cmMakefileTargetGenerator_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 <iosfwd>
#include <map>
#include <set>
#include <string>
#include <vector>
2017-04-14 19:02:05 +02:00
#include "cmCommonTargetGenerator.h"
#include "cmLocalUnixMakefileGenerator3.h"
#include "cmOSXBundleGenerator.h"
2015-04-27 22:25:09 +02:00
class cmCustomCommandGenerator;
class cmGeneratedFileStream;
2016-10-30 18:24:19 +01:00
class cmGeneratorTarget;
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);
2016-10-30 18:24:19 +01:00
~cmMakefileTargetGenerator() CM_OVERRIDE;
// construct using this factory call
2016-07-09 11:21:54 +02:00
static 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
protected:
// 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 provide require rules for this target
void WriteTargetRequiresRules();
// write the clean rules for this target
void WriteTargetCleanRules();
// write the depend rules for this target
void WriteTargetDependRules();
// 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(cmMakefileTargetGenerator* gen)
: Generator(gen)
{
}
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:
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 build rule for an object
2016-07-09 11:21:54 +02:00
void WriteObjectBuildFile(std::string& obj, const std::string& lang,
2015-04-27 22:25:09 +02:00
cmSourceFile const& source,
std::vector<std::string>& depends);
// 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);
// 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
void AppendTargetDepends(std::vector<std::string>& depends);
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.).
void AppendLinkDepends(std::vector<std::string>& depends);
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);
2017-04-14 19:02:05 +02:00
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
void AddIncludeFlags(std::string& flags,
const std::string& lang) CM_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;
// the path to the directory the build file is in
std::string TargetBuildDirectory;
std::string TargetBuildDirectoryFull;
// the stream for the build file
2016-07-09 11:21:54 +02:00
cmGeneratedFileStream* BuildFileStream;
// the stream for the flag file
std::string FlagFileNameFull;
2016-07-09 11:21:54 +02:00
cmGeneratedFileStream* FlagFileStream;
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;
2016-07-09 11:21:54 +02:00
cmGeneratedFileStream* InfoFileStream;
// files to clean
std::vector<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;
2015-04-27 22:25:09 +02:00
typedef std::map<std::string, std::string> MultipleOutputPairsType;
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.
std::string TargetNameOut;
std::string TargetNameSO;
std::string TargetNameReal;
std::string TargetNameImport;
std::string TargetNamePDB;
// Mac OS X content info.
2015-04-27 22:25:09 +02:00
std::set<std::string> MacContentFolders;
2012-08-04 10:26:08 +03:00
cmOSXBundleGenerator* OSXBundleGenerator;
MacOSXContentGeneratorType* MacOSXContentGenerator;
};
#endif