cmake/Source/cmLocalUnixMakefileGenerator3.h

301 lines
10 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 cmLocalUnixMakefileGenerator3_h
#define cmLocalUnixMakefileGenerator3_h
2018-01-26 17:06:56 +01:00
#include "cmConfigure.h" // IWYU pragma: keep
2016-10-30 18:24:19 +01:00
#include <iosfwd>
#include <map>
#include <set>
#include <string>
2019-11-11 23:01:05 +01:00
#include <utility>
2016-10-30 18:24:19 +01:00
#include <vector>
2009-10-04 10:30:41 +03:00
2020-02-01 23:06:01 +01:00
#include "cmDepends.h"
#include "cmLocalCommonGenerator.h"
class cmCustomCommand;
2015-04-27 22:25:09 +02:00
class cmCustomCommandGenerator;
2016-10-30 18:24:19 +01:00
class cmGeneratorTarget;
class cmGlobalGenerator;
class cmMakefile;
/** \class cmLocalUnixMakefileGenerator3
* \brief Write a LocalUnix makefiles.
*
* cmLocalUnixMakefileGenerator3 produces a LocalUnix makefile from its
* member Makefile.
*/
2015-11-17 17:22:37 +01:00
class cmLocalUnixMakefileGenerator3 : public cmLocalCommonGenerator
{
public:
2015-11-17 17:22:37 +01:00
cmLocalUnixMakefileGenerator3(cmGlobalGenerator* gg, cmMakefile* mf);
2018-01-26 17:06:56 +01:00
~cmLocalUnixMakefileGenerator3() override;
2020-08-30 11:54:41 +02:00
std::string GetConfigName() const;
2018-01-26 17:06:56 +01:00
void ComputeHomeRelativeOutputPath() override;
/**
2012-02-18 12:40:36 +02:00
* Generate the makefile for this directory.
*/
2018-01-26 17:06:56 +01:00
void Generate() override;
// this returns the relative path between the HomeOutputDirectory and this
// local generators StartOutputDirectory
2016-07-09 11:21:54 +02:00
const std::string& GetHomeRelativeOutputPath();
2020-08-30 11:54:41 +02:00
/**
* Convert a file path to a Makefile target or dependency with
* escaping and quoting suitable for the generator's make tool.
*/
std::string ConvertToMakefilePath(std::string const& path) const;
2012-02-18 12:40:36 +02:00
// Write out a make rule
2016-07-09 11:21:54 +02:00
void WriteMakeRule(std::ostream& os, const char* comment,
2015-04-27 22:25:09 +02:00
const std::string& target,
const std::vector<std::string>& depends,
2016-07-09 11:21:54 +02:00
const std::vector<std::string>& commands, bool symbolic,
bool in_help = false);
2012-02-18 12:40:36 +02:00
// write the main variables used by the makefiles
void WriteMakeVariables(std::ostream& makefileStream);
/**
* Set max makefile variable size, default is 0 which means unlimited.
*/
void SetMakefileVariableSize(int s) { this->MakefileVariableSize = s; }
/**
* Set whether passing a make target on a command line requires an
* extra level of escapes.
*/
void SetMakeCommandEscapeTargetTwice(bool b)
2016-07-09 11:21:54 +02:00
{
this->MakeCommandEscapeTargetTwice = b;
}
/**
* Set whether the Borland curly brace command line hack should be
* applied.
*/
2016-07-09 11:21:54 +02:00
void SetBorlandMakeCurlyHack(bool b) { this->BorlandMakeCurlyHack = b; }
// used in writing out Cmake files such as WriteDirectoryInformation
2020-08-30 11:54:41 +02:00
static void WriteCMakeArgument(std::ostream& os, const std::string& s);
2012-02-18 12:40:36 +02:00
/** creates the common disclaimer text at the top of each makefile */
void WriteDisclaimer(std::ostream& os);
// write a comment line #====... in the stream
void WriteDivider(std::ostream& os);
/** used to create a recursive make call */
2019-11-11 23:01:05 +01:00
std::string GetRecursiveMakeCall(const std::string& makefile,
2015-04-27 22:25:09 +02:00
const std::string& tgt);
2012-02-18 12:40:36 +02:00
// append flags to a string
2018-04-23 21:13:27 +02:00
void AppendFlags(std::string& flags,
const std::string& newFlags) const override;
2020-02-01 23:06:01 +01:00
using cmLocalCommonGenerator::AppendFlags;
// append an echo command
2016-07-09 11:21:54 +02:00
enum EchoColor
{
EchoNormal,
EchoDepend,
EchoBuild,
EchoLink,
EchoGenerate,
EchoGlobal
};
struct EchoProgress
{
std::string Dir;
std::string Arg;
};
2015-08-17 11:37:30 +02:00
void AppendEcho(std::vector<std::string>& commands, std::string const& text,
2018-01-26 17:06:56 +01:00
EchoColor color = EchoNormal, EchoProgress const* = nullptr);
/** Get whether the makefile is to have color. */
bool GetColorMakefile() const { return this->ColorMakefile; }
2018-01-26 17:06:56 +01:00
std::string GetTargetDirectory(
cmGeneratorTarget const* target) const override;
2016-07-09 11:21:54 +02:00
// create a command that cds to the start dir then runs the commands
2012-02-18 12:40:36 +02:00
void CreateCDCommand(std::vector<std::string>& commands,
2018-04-23 21:13:27 +02:00
std::string const& targetDir,
std::string const& relDir);
2019-11-11 23:01:05 +01:00
static std::string ConvertToQuotedOutputPath(const std::string& p,
2015-04-27 22:25:09 +02:00
bool useWatcomQuote);
2015-04-27 22:25:09 +02:00
std::string CreateMakeVariable(const std::string& sin,
const std::string& s2in);
/** Called from command-line hook to bring dependencies up to date
for a target. */
2019-11-11 23:01:05 +01:00
bool UpdateDependencies(const std::string& tgtInfo, bool verbose,
2018-01-26 17:06:56 +01:00
bool color) override;
/** Called from command-line hook to clear dependencies. */
2018-01-26 17:06:56 +01:00
void ClearDependencies(cmMakefile* mf, bool verbose) override;
2012-02-18 12:40:36 +02:00
/** write some extra rules such as make test etc */
void WriteSpecialTargetsTop(std::ostream& makefileStream);
void WriteSpecialTargetsBottom(std::ostream& makefileStream);
2020-02-01 23:06:01 +01:00
std::string GetRelativeTargetDirectory(
cmGeneratorTarget const* target) const;
// File pairs for implicit dependency scanning. The key of the map
// is the depender and the value is the explicit dependee.
2019-11-11 23:01:05 +01:00
struct ImplicitDependFileMap : public cmDepends::DependencyMap
2016-07-09 11:21:54 +02:00
{
};
struct ImplicitDependLanguageMap
: public std::map<std::string, ImplicitDependFileMap>
{
};
struct ImplicitDependTargetMap
: public std::map<std::string, ImplicitDependLanguageMap>
{
};
ImplicitDependLanguageMap const& GetImplicitDepends(
cmGeneratorTarget const* tgt);
2016-03-13 13:35:51 +01:00
void AddImplicitDepends(cmGeneratorTarget const* tgt,
2019-11-11 23:01:05 +01:00
const std::string& lang, const std::string& obj,
const std::string& src);
// write the target rules for the local Makefile into the stream
void WriteLocalAllRules(std::ostream& ruleFileStream);
2012-02-18 12:40:36 +02:00
2015-04-27 22:25:09 +02:00
std::vector<std::string> const& GetLocalHelp() { return this->LocalHelp; }
/** Get whether to create rules to generate preprocessed and
assembly sources. This could be converted to a variable lookup
later. */
bool GetCreatePreprocessedSourceRules()
2016-07-09 11:21:54 +02:00
{
return !this->SkipPreprocessedSourceRules;
2016-07-09 11:21:54 +02:00
}
bool GetCreateAssemblySourceRules()
2016-07-09 11:21:54 +02:00
{
return !this->SkipAssemblySourceRules;
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
2012-02-18 12:40:36 +02:00
// Fill the vector with the target names for the object files,
// preprocessed files and assembly files. Currently only used by the
2009-10-04 10:30:41 +03:00
// Eclipse generator.
void GetIndividualFileTargets(std::vector<std::string>& targets);
2012-02-18 12:40:36 +02:00
protected:
void WriteLocalMakefile();
2012-02-18 12:40:36 +02:00
// write the target rules for the local Makefile into the stream
void WriteLocalMakefileTargets(std::ostream& ruleFileStream,
2016-07-09 11:21:54 +02:00
std::set<std::string>& emitted);
2009-05-01 17:43:35 +03:00
// this method Writes the Directory information files
void WriteDirectoryInformationFile();
2012-02-18 12:40:36 +02:00
// write the depend info
2016-03-13 13:35:51 +01:00
void WriteDependLanguageInfo(std::ostream& cmakefileStream,
2016-07-09 11:21:54 +02:00
cmGeneratorTarget* tgt);
2012-02-18 12:40:36 +02:00
// this converts a file name that is relative to the StartOuputDirectory
// into a full path
std::string ConvertToFullPath(const std::string& localPath);
void WriteConvenienceRule(std::ostream& ruleFileStream,
2015-04-27 22:25:09 +02:00
const std::string& realTarget,
const std::string& helpTarget);
void AppendRuleDepend(std::vector<std::string>& depends,
const char* ruleFileName);
2011-06-19 15:41:06 +03:00
void AppendRuleDepends(std::vector<std::string>& depends,
std::vector<std::string> const& ruleFiles);
void AppendCustomDepends(std::vector<std::string>& depends,
const std::vector<cmCustomCommand>& ccs);
void AppendCustomDepend(std::vector<std::string>& depends,
2015-04-27 22:25:09 +02:00
cmCustomCommandGenerator const& cc);
2016-10-30 18:24:19 +01:00
void AppendCustomCommands(std::vector<std::string>& commands,
const std::vector<cmCustomCommand>& ccs,
cmGeneratorTarget* target,
std::string const& relative);
void AppendCustomCommand(std::vector<std::string>& commands,
cmCustomCommandGenerator const& ccg,
cmGeneratorTarget* target,
std::string const& relative,
bool echo_comment = false,
2018-01-26 17:06:56 +01:00
std::ostream* content = nullptr);
void AppendCleanCommand(std::vector<std::string>& commands,
2019-11-11 23:01:05 +01:00
const std::set<std::string>& files,
2016-10-30 18:24:19 +01:00
cmGeneratorTarget* target,
2018-01-26 17:06:56 +01:00
const char* filename = nullptr);
2019-11-11 23:01:05 +01:00
void AppendDirectoryCleanCommand(std::vector<std::string>& commands);
2018-08-09 18:06:22 +02:00
// Helper methods for dependency updates.
2019-11-11 23:01:05 +01:00
bool ScanDependencies(std::string const& targetDir,
std::string const& dependFile,
std::string const& internalDependFile,
cmDepends::DependencyMap& validDeps);
void CheckMultipleOutputs(bool verbose);
private:
2016-10-30 18:24:19 +01:00
std::string MaybeConvertWatcomShellCommand(std::string const& cmd);
2015-04-27 22:25:09 +02:00
friend class cmMakefileTargetGenerator;
friend class cmMakefileExecutableTargetGenerator;
friend class cmMakefileLibraryTargetGenerator;
friend class cmMakefileUtilityTargetGenerator;
friend class cmGlobalUnixMakefileGenerator3;
ImplicitDependTargetMap ImplicitDepends;
std::string HomeRelativeOutputPath;
2012-04-19 19:04:21 +03:00
struct LocalObjectEntry
{
2019-11-11 23:01:05 +01:00
cmGeneratorTarget* Target = nullptr;
2012-04-19 19:04:21 +03:00
std::string Language;
2019-11-11 23:01:05 +01:00
LocalObjectEntry() = default;
LocalObjectEntry(cmGeneratorTarget* t, std::string lang)
2016-07-09 11:21:54 +02:00
: Target(t)
2019-11-11 23:01:05 +01:00
, Language(std::move(lang))
2016-07-09 11:21:54 +02:00
{
}
2012-04-19 19:04:21 +03:00
};
2016-07-09 11:21:54 +02:00
struct LocalObjectInfo : public std::vector<LocalObjectEntry>
2012-04-19 19:04:21 +03:00
{
2019-11-11 23:01:05 +01:00
bool HasSourceExtension = false;
bool HasPreprocessRule = false;
bool HasAssembleRule = false;
2012-04-19 19:04:21 +03:00
};
2015-04-27 22:25:09 +02:00
void GetLocalObjectFiles(
2016-07-09 11:21:54 +02:00
std::map<std::string, LocalObjectInfo>& localObjectFiles);
2015-04-27 22:25:09 +02:00
2012-04-19 19:04:21 +03:00
void WriteObjectConvenienceRule(std::ostream& ruleFileStream,
2019-11-11 23:01:05 +01:00
const char* comment,
const std::string& output,
2012-04-19 19:04:21 +03:00
LocalObjectInfo const& info);
2015-04-27 22:25:09 +02:00
std::vector<std::string> LocalHelp;
/* does the work for each target */
2015-04-27 22:25:09 +02:00
std::map<std::string, std::string> MakeVariableMap;
std::map<std::string, std::string> ShortMakeVariableMap;
2015-11-17 17:22:37 +01:00
int MakefileVariableSize;
bool MakeCommandEscapeTargetTwice;
bool BorlandMakeCurlyHack;
bool ColorMakefile;
bool SkipPreprocessedSourceRules;
bool SkipAssemblySourceRules;
};
#endif