Merge topic 'minor-cleanups'

820986ed cmLocalGenerator: Constify GetIncludeDirectories method.
b3e2e332 QtAutogen: Get the global generator from the Makefile.
61c0113c cmLocalUnixMakefileGenerator3: Remove unused method.
080489b8 cmMakefile: Use member directly instead of through method.
8bfaadfa cmMakefile: Move IsRoot API from cmLocalGenerator.
217c243d cmake: Update the current snapshot when Resetting.
eb05dcd6 cmLocalGenerator: Add IssueMessage method.
cfae7fa4 cmMakefile: Use cmOutputConverter instead of cmLocalGenerator.
ccf7760f cmOutputConverter: Constify API.
This commit is contained in:
Brad King 2015-06-22 13:00:32 -04:00 committed by CMake Topic Stage
commit ec6d6be57d
15 changed files with 81 additions and 58 deletions

View File

@ -705,7 +705,8 @@ cmTargetTraceDependencies
e << "Evaluation output file\n \"" << sf->GetFullPath()
<< "\"\ndepends on the sources of a target it is used in. This "
"is a dependency loop and is not allowed.";
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
this->GeneratorTarget
->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str());
return;
}
if(emitted.insert(sf).second && this->SourcesQueued.insert(sf).second)

View File

@ -529,7 +529,7 @@ cmGlobalUnixMakefileGenerator3
cmLocalUnixMakefileGenerator3* lg)
{
// Only subdirectories need these rules.
if(lg->IsRootMakefile())
if(lg->GetMakefile()->IsRootMakefile())
{
return;
}
@ -1034,7 +1034,7 @@ void cmGlobalUnixMakefileGenerator3::WriteHelpRule
static_cast<cmLocalUnixMakefileGenerator3 *>(this->LocalGenerators[i]);
// for the passed in makefile or if this is the top Makefile wripte out
// the targets
if (lg2 == lg || lg->IsRootMakefile())
if (lg2 == lg || lg->GetMakefile()->IsRootMakefile())
{
// for each target Generate the rule files for each target.
cmTargets& targets = lg2->GetMakefile()->GetTargets();

View File

@ -68,9 +68,20 @@ cmLocalGenerator::~cmLocalGenerator()
delete this->Makefile;
}
bool cmLocalGenerator::IsRootMakefile() const
void cmLocalGenerator::IssueMessage(cmake::MessageType t,
std::string const& text) const
{
return !this->StateSnapshot.GetBuildsystemDirectoryParent().IsValid();
cmListFileContext lfc;
lfc.FilePath = this->StateSnapshot.GetCurrentSourceDirectory();
lfc.FilePath += "/CMakeLists.txt";
if(!this->GlobalGenerator->GetCMakeInstance()->GetIsInTryCompile())
{
cmOutputConverter converter(this->StateSnapshot);
lfc.FilePath = converter.Convert(lfc.FilePath, cmLocalGenerator::HOME);
}
lfc.Line = 0;
this->GlobalGenerator->GetCMakeInstance()->IssueMessage(t, text, lfc);
}
//----------------------------------------------------------------------------
@ -98,7 +109,7 @@ void cmLocalGenerator::ComputeObjectMaxPath()
w << "CMAKE_OBJECT_PATH_MAX is set to " << pmax
<< ", which is less than the minimum of 128. "
<< "The value will be ignored.";
this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
this->IssueMessage(cmake::AUTHOR_WARNING, w.str());
}
}
else
@ -107,7 +118,7 @@ void cmLocalGenerator::ComputeObjectMaxPath()
w << "CMAKE_OBJECT_PATH_MAX is set to \"" << plen
<< "\", which fails to parse as a positive integer. "
<< "The value will be ignored.";
this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
this->IssueMessage(cmake::AUTHOR_WARNING, w.str());
}
}
this->ObjectMaxPathViolations.clear();
@ -1317,7 +1328,7 @@ void cmLocalGenerator::AddCompileOptions(
"higher \"" << it->first << "_STANDARD\" \"" << standard << "\". "
"This is not permitted. The COMPILE_FEATURES may not both depend on "
"and be depended on by the link implementation." << std::endl;
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
this->IssueMessage(cmake::FATAL_ERROR, e.str());
return;
}
}
@ -1330,7 +1341,7 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs,
const std::string& lang,
const std::string& config,
bool stripImplicitInclDirs
)
) const
{
// Need to decide whether to automatically include the source and
// binary directories at the beginning of the include path.
@ -2041,7 +2052,7 @@ AddCompilerRequirementFlag(std::string &flags, cmTarget const* target,
"dialect \"" << lang << standardProp << "\" "
<< (ext ? "(with compiler extensions)" : "") << ", but CMake "
"does not know the compile flags to use to enable it.";
this->GetMakefile()->IssueMessage(cmake::FATAL_ERROR, e.str());
this->IssueMessage(cmake::FATAL_ERROR, e.str());
}
else
{
@ -2085,7 +2096,7 @@ AddCompilerRequirementFlag(std::string &flags, cmTarget const* target,
std::string e =
"CMAKE_" + lang + "_STANDARD_DEFAULT is set to invalid value '" +
std::string(defaultStd) + "'";
this->Makefile->IssueMessage(cmake::INTERNAL_ERROR, e);
this->IssueMessage(cmake::INTERNAL_ERROR, e);
return;
}
@ -2301,7 +2312,7 @@ bool cmLocalGenerator::GetShouldUseOldFlags(bool shared,
<< flagsVar << " was removed.\n"
<< cmPolicies::GetPolicyWarning(cmPolicies::CMP0018);
this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, e.str());
this->IssueMessage(cmake::AUTHOR_WARNING, e.str());
// fall through to OLD behaviour
}
case cmPolicies::OLD:
@ -2813,7 +2824,7 @@ cmLocalGenerator
<< " " << ssin << "\n"
<< "cannot be safely placed under this directory. "
<< "The build may not work correctly.";
this->Makefile->IssueMessage(cmake::WARNING, m.str());
this->IssueMessage(cmake::WARNING, m.str());
}
}
#else

View File

@ -14,6 +14,7 @@
#include "cmStandardIncludes.h"
#include "cmState.h"
#include "cmake.h"
#include "cmOutputConverter.h"
class cmMakefile;
@ -39,9 +40,6 @@ public:
cmState::Snapshot snapshot);
virtual ~cmLocalGenerator();
/// @return whether we are processing the top CMakeLists.txt file.
bool IsRootMakefile() const;
/**
* Generate the makefile for this directory.
*/
@ -185,7 +183,7 @@ public:
cmGeneratorTarget* target,
const std::string& lang = "C",
const std::string& config = "",
bool stripImplicitInclDirs = true);
bool stripImplicitInclDirs = true) const;
void AddCompileOptions(std::string& flags, cmTarget* target,
const std::string& lang, const std::string& config);
void AddCompileDefinitions(std::set<std::string>& defines,
@ -304,6 +302,9 @@ public:
bool IsMinGWMake() const;
bool IsNMake() const;
void IssueMessage(cmake::MessageType t, std::string const& text) const;
void ComputeObjectMaxPath();
protected:
///! put all the libraries for a target on into the given stream

View File

@ -58,7 +58,7 @@ void cmLocalNinjaGenerator::Generate()
#endif
// We do that only once for the top CMakeLists.txt file.
if(this->IsRootMakefile())
if(this->Makefile->IsRootMakefile())
{
this->WriteBuildFileTop();
@ -298,7 +298,7 @@ void cmLocalNinjaGenerator::WriteProcessedMakefile(std::ostream& os)
<< "# Write statements declared in CMakeLists.txt:" << std::endl
<< "# "
<< this->Makefile->GetDefinition("CMAKE_CURRENT_LIST_FILE") << std::endl;
if(this->IsRootMakefile())
if(this->Makefile->IsRootMakefile())
os << "# Which is the root file." << std::endl;
cmGlobalNinjaGenerator::WriteDivider(os);
os << std::endl;

View File

@ -149,9 +149,6 @@ public:
void AddImplicitDepends(cmTarget const& tgt, const std::string& lang,
const char* obj, const char* src);
void AppendGlobalTargetDepends(std::vector<std::string>& depends,
cmTarget& target);
// write the target rules for the local Makefile into the stream
void WriteLocalAllRules(std::ostream& ruleFileStream);

View File

@ -105,7 +105,7 @@ public:
++it;
if(it == this->VarStack.rend())
{
cmLocalGenerator* plg = mf->GetLocalGenerator()->GetParent();
cmLocalGenerator* plg = mf->LocalGenerator->GetParent();
if(!plg)
{
return false;
@ -264,8 +264,8 @@ void cmMakefile::IssueMessage(cmake::MessageType t,
if(!this->GetCMakeInstance()->GetIsInTryCompile())
{
lfc.FilePath = this->LocalGenerator->Convert(lfc.FilePath,
cmLocalGenerator::HOME);
cmOutputConverter converter(this->StateSnapshot);
lfc.FilePath = converter.Convert(lfc.FilePath, cmOutputConverter::HOME);
}
lfc.Line = 0;
this->GetCMakeInstance()->IssueMessage(t, text, lfc);
@ -1620,6 +1620,11 @@ void cmMakefile::PopMacroScope(bool reportError)
this->PopFunctionBlockerBarrier(reportError);
}
bool cmMakefile::IsRootMakefile() const
{
return !this->StateSnapshot.GetBuildsystemDirectoryParent().IsValid();
}
//----------------------------------------------------------------------------
class cmMakefileCurrent
{
@ -1975,8 +1980,8 @@ void cmMakefile::LogUnused(const char* reason,
lfc.FilePath = path;
lfc.Line = 0;
}
lfc.FilePath = this->LocalGenerator->Convert(lfc.FilePath,
cmLocalGenerator::HOME);
cmOutputConverter converter(this->StateSnapshot);
lfc.FilePath = converter.Convert(lfc.FilePath, cmOutputConverter::HOME);
if (this->CheckSystemVars ||
cmSystemTools::IsSubDirectory(path,
@ -2873,8 +2878,9 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew(
{
std::ostringstream msg;
cmListFileContext lfc;
lfc.FilePath = this->LocalGenerator
->Convert(filename, cmLocalGenerator::HOME);
cmOutputConverter converter(this->StateSnapshot);
lfc.FilePath =
converter.Convert(filename, cmOutputConverter::HOME);
lfc.Line = line;
msg << "uninitialized variable \'" << lookup << "\'";
this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING,

View File

@ -90,6 +90,9 @@ public:
*/
void AddFunctionBlocker(cmFunctionBlocker* fb);
/// @return whether we are processing the top CMakeLists.txt file.
bool IsRootMakefile() const;
/**
* Remove the function blocker whose scope ends with the given command.
* This returns ownership of the function blocker object.

View File

@ -27,7 +27,7 @@ cmOutputConverter::cmOutputConverter(cmState::Snapshot snapshot)
std::string
cmOutputConverter::ConvertToOutputForExistingCommon(const std::string& remote,
std::string const& result,
OutputFormat format)
OutputFormat format) const
{
// If this is a windows shell, the result has a space, and the path
// already exists, we can use a short-path to reference it without a
@ -50,7 +50,7 @@ cmOutputConverter::ConvertToOutputForExistingCommon(const std::string& remote,
std::string
cmOutputConverter::ConvertToOutputForExisting(const std::string& remote,
RelativeRoot local,
OutputFormat format)
OutputFormat format) const
{
static_cast<void>(local);
@ -65,7 +65,7 @@ cmOutputConverter::ConvertToOutputForExisting(const std::string& remote,
std::string
cmOutputConverter::ConvertToOutputForExisting(RelativeRoot remote,
const std::string& local,
OutputFormat format)
OutputFormat format) const
{
// Perform standard conversion.
std::string result = this->Convert(remote, local, format, true);
@ -76,7 +76,7 @@ cmOutputConverter::ConvertToOutputForExisting(RelativeRoot remote,
}
//----------------------------------------------------------------------------
const char* cmOutputConverter::GetRelativeRootPath(RelativeRoot relroot)
const char* cmOutputConverter::GetRelativeRootPath(RelativeRoot relroot) const
{
switch (relroot)
{
@ -91,7 +91,7 @@ const char* cmOutputConverter::GetRelativeRootPath(RelativeRoot relroot)
std::string cmOutputConverter::Convert(const std::string& source,
RelativeRoot relative,
OutputFormat output)
OutputFormat output) const
{
// Convert the path to a relative path.
std::string result = source;
@ -125,7 +125,7 @@ std::string cmOutputConverter::Convert(const std::string& source,
//----------------------------------------------------------------------------
std::string cmOutputConverter::ConvertToOutputFormat(const std::string& source,
OutputFormat output)
OutputFormat output) const
{
std::string result = source;
// Convert it to an output path.
@ -163,7 +163,7 @@ std::string cmOutputConverter::ConvertToOutputFormat(const std::string& source,
std::string cmOutputConverter::Convert(RelativeRoot remote,
const std::string& local,
OutputFormat output,
bool optional)
bool optional) const
{
const char* remotePath = this->GetRelativeRootPath(remote);
@ -192,7 +192,7 @@ static bool cmOutputConverterNotAbove(const char* a, const char* b)
std::string
cmOutputConverter::ConvertToRelativePath(const std::vector<std::string>& local,
const std::string& in_remote,
bool force)
bool force) const
{
// The path should never be quoted.
assert(in_remote[0] != '\"');
@ -318,7 +318,7 @@ static bool cmOutputConverterIsShellOperator(const std::string& str)
std::string cmOutputConverter::EscapeForShell(const std::string& str,
bool makeVars,
bool forEcho,
bool useWatcomQuote)
bool useWatcomQuote) const
{
// Do not escape shell operators.
if(cmOutputConverterIsShellOperator(str))

View File

@ -39,35 +39,35 @@ public:
enum RelativeRoot { NONE, FULL, HOME, START, HOME_OUTPUT, START_OUTPUT };
enum OutputFormat { UNCHANGED, MAKERULE, SHELL, WATCOMQUOTE, RESPONSE };
std::string ConvertToOutputFormat(const std::string& source,
OutputFormat output);
OutputFormat output) const;
std::string Convert(const std::string& remote, RelativeRoot local,
OutputFormat output = UNCHANGED);
OutputFormat output = UNCHANGED) const;
std::string Convert(RelativeRoot remote, const std::string& local,
OutputFormat output = UNCHANGED,
bool optional = false);
bool optional = false) const;
/**
* Get path for the specified relative root.
*/
const char* GetRelativeRootPath(RelativeRoot relroot);
const char* GetRelativeRootPath(RelativeRoot relroot) const;
///! for existing files convert to output path and short path if spaces
std::string ConvertToOutputForExisting(const std::string& remote,
RelativeRoot local = START_OUTPUT,
OutputFormat format = SHELL);
OutputFormat format = SHELL) const;
/** For existing path identified by RelativeRoot convert to output
path and short path if spaces. */
std::string ConvertToOutputForExisting(RelativeRoot remote,
const std::string& local = "",
OutputFormat format = SHELL);
OutputFormat format = SHELL) const;
void SetLinkScriptShell(bool linkScriptShell);
std::string EscapeForShell(const std::string& str,
bool makeVars = false,
bool forEcho = false,
bool useWatcomQuote = false);
bool useWatcomQuote = false) const;
static std::string EscapeForCMake(const std::string& str);
@ -88,14 +88,14 @@ public:
*/
std::string ConvertToRelativePath(const std::vector<std::string>& local,
const std::string& in_remote,
bool force = false);
bool force = false) const;
private:
cmState* GetState() const;
std::string ConvertToOutputForExistingCommon(const std::string& remote,
std::string const& result,
OutputFormat format);
OutputFormat format) const;
private:
cmState::Snapshot StateSnapshot;

View File

@ -53,7 +53,7 @@ bool cmProjectCommand
// CMAKE_PROJECT_NAME will match PROJECT_NAME, and cmake --build
// will work.
if(!this->Makefile->GetDefinition("CMAKE_PROJECT_NAME")
|| (this->Makefile->GetLocalGenerator()->IsRootMakefile()))
|| (this->Makefile->IsRootMakefile()))
{
this->Makefile->AddDefinition("CMAKE_PROJECT_NAME", args[0].c_str());
this->Makefile->AddCacheDefinition

View File

@ -368,8 +368,7 @@ bool cmQtAutoGenerators::InitializeAutogenTarget(cmTarget* target)
#if defined(_WIN32) && !defined(__CYGWIN__)
bool usePRE_BUILD = false;
cmLocalGenerator* localGen = makefile->GetLocalGenerator();
cmGlobalGenerator* gg = localGen->GetGlobalGenerator();
cmGlobalGenerator* gg = makefile->GetGlobalGenerator();
if(gg->GetName().find("Visual Studio") != std::string::npos)
{
cmGlobalVisualStudioGenerator* vsgg =

View File

@ -219,13 +219,13 @@ void cmState::RemoveCacheEntryProperty(std::string const& key,
->GetCacheIterator(key.c_str()).SetProperty(propertyName, (void*)0);
}
void cmState::Reset()
cmState::Snapshot cmState::Reset()
{
this->GlobalProperties.clear();
this->PropertyDefinitions.clear();
this->BuildsystemDirectory.Truncate();
this->SnapshotData.Truncate();
PositionType pos = this->SnapshotData.Truncate();
this->DefineProperty
("RULE_LAUNCH_COMPILE", cmProperty::DIRECTORY,
@ -246,6 +246,8 @@ void cmState::Reset()
this->DefineProperty
("RULE_LAUNCH_CUSTOM", cmProperty::TARGET,
"", "", true);
return Snapshot(this, pos);
}
void cmState::DefineProperty(const std::string& name,
@ -741,14 +743,14 @@ void cmState::Snapshot::SetCurrentBinaryDirectory(std::string const& dir)
}
std::vector<std::string> const&
cmState::Snapshot::GetCurrentSourceDirectoryComponents()
cmState::Snapshot::GetCurrentSourceDirectoryComponents() const
{
return this->Position->BuildSystemDirectory
->CurrentSourceDirectoryComponents;
}
std::vector<std::string> const&
cmState::Snapshot::GetCurrentBinaryDirectoryComponents()
cmState::Snapshot::GetCurrentBinaryDirectoryComponents() const
{
return this->Position->BuildSystemDirectory
->CurrentBinaryDirectoryComponents;

View File

@ -43,8 +43,10 @@ public:
const char* GetCurrentBinaryDirectory() const;
void SetCurrentBinaryDirectory(std::string const& dir);
std::vector<std::string> const& GetCurrentSourceDirectoryComponents();
std::vector<std::string> const& GetCurrentBinaryDirectoryComponents();
std::vector<std::string> const&
GetCurrentSourceDirectoryComponents() const;
std::vector<std::string> const&
GetCurrentBinaryDirectoryComponents() const;
const char* GetRelativePathTopSource() const;
const char* GetRelativePathTopBinary() const;
@ -103,7 +105,7 @@ public:
void RemoveCacheEntryProperty(std::string const& key,
std::string const& propertyName);
void Reset();
Snapshot Reset();
// Define a property
void DefineProperty(const std::string& name, cmProperty::ScopeType scope,
const char *ShortDescription,

View File

@ -186,7 +186,7 @@ cmake::~cmake()
void cmake::CleanupCommandsAndMacros()
{
this->State->Reset();
this->CurrentSnapshot = this->State->Reset();
this->State->RemoveUserDefinedCommands();
}
@ -370,6 +370,7 @@ void cmake::ReadListFile(const std::vector<std::string>& args,
// read in the list file to fill the cache
if(path)
{
this->CurrentSnapshot = this->State->Reset();
std::string homeDir = this->GetHomeDirectory();
std::string homeOutputDir = this->GetHomeOutputDirectory();
this->SetHomeDirectory(cmSystemTools::GetCurrentWorkingDirectory());