Merge topic 'constify'

15eeace cmTarget: Trivially make more API const.
be9dfb6 cmTarget: Make GetExportMacro const.
0794c13 cmTarget: Make NameResolvesToFramework const.
1c27521 cmGlobalGenerator: Make NameResolvesToFramework const.
37554ac cmMakefile: Make FindTarget const.
8841d73 cmMakefile: Make IsAlias const.
36e31cd cmTarget: Make GetInterfaceLinkLibraries const.
04d398d cmTarget: Make GetTargetSourceFileFlags const.
50d1520 cmTarget: Make custom command accessors API const.
0f87643 cmGeneratorTarget: Make GetIncludeDirectories const.
This commit is contained in:
Brad King 2013-11-20 09:08:47 -05:00 committed by CMake Topic Stage
commit a61025135b
12 changed files with 83 additions and 74 deletions

View File

@ -611,8 +611,8 @@ const char* cmGeneratorTarget::GetCreateRuleVariable() const
}
//----------------------------------------------------------------------------
std::vector<std::string> cmGeneratorTarget::GetIncludeDirectories(
const char *config)
std::vector<std::string>
cmGeneratorTarget::GetIncludeDirectories(const char *config) const
{
return this->Target->GetIncludeDirectories(config);
}

View File

@ -70,7 +70,7 @@ public:
const char* GetCreateRuleVariable() const;
/** Get the include directories for this target. */
std::vector<std::string> GetIncludeDirectories(const char *config);
std::vector<std::string> GetIncludeDirectories(const char *config) const;
bool IsSystemIncludeDirectory(const char *dir, const char *config) const;

View File

@ -1986,7 +1986,7 @@ void cmGlobalGenerator::AddAlias(const char *name, cmTarget *tgt)
}
//----------------------------------------------------------------------------
bool cmGlobalGenerator::IsAlias(const char *name)
bool cmGlobalGenerator::IsAlias(const char *name) const
{
return this->AliasTargets.find(name) != this->AliasTargets.end();
}
@ -1994,15 +1994,16 @@ bool cmGlobalGenerator::IsAlias(const char *name)
//----------------------------------------------------------------------------
cmTarget*
cmGlobalGenerator::FindTarget(const char* project, const char* name,
bool excludeAliases)
bool excludeAliases) const
{
// if project specific
if(project)
{
std::vector<cmLocalGenerator*>* gens = &this->ProjectMap[project];
for(unsigned int i = 0; i < gens->size(); ++i)
std::map<cmStdString, std::vector<cmLocalGenerator*> >::const_iterator
gens = this->ProjectMap.find(project);
for(unsigned int i = 0; i < gens->second.size(); ++i)
{
cmTarget* ret = (*gens)[i]->GetMakefile()->FindTarget(name,
cmTarget* ret = (gens->second)[i]->GetMakefile()->FindTarget(name,
excludeAliases);
if(ret)
{
@ -2015,14 +2016,14 @@ cmGlobalGenerator::FindTarget(const char* project, const char* name,
{
if (!excludeAliases)
{
std::map<cmStdString, cmTarget*>::iterator ai
std::map<cmStdString, cmTarget*>::const_iterator ai
= this->AliasTargets.find(name);
if (ai != this->AliasTargets.end())
{
return ai->second;
}
}
std::map<cmStdString,cmTarget *>::iterator i =
std::map<cmStdString,cmTarget *>::const_iterator i =
this->TotalTargets.find ( name );
if ( i != this->TotalTargets.end() )
{
@ -2038,7 +2039,8 @@ cmGlobalGenerator::FindTarget(const char* project, const char* name,
}
//----------------------------------------------------------------------------
bool cmGlobalGenerator::NameResolvesToFramework(const std::string& libname)
bool
cmGlobalGenerator::NameResolvesToFramework(const std::string& libname) const
{
if(cmSystemTools::IsPathToFramework(libname.c_str()))
{
@ -2412,7 +2414,7 @@ cmTarget cmGlobalGenerator::CreateGlobalTarget(
// Store the custom command in the target.
cmCustomCommand cc(0, no_outputs, no_depends, *commandLines, 0,
workingDirectory);
target.GetPostBuildCommands().push_back(cc);
target.AddPostBuildCommand(cc);
target.SetProperty("EchoString", message);
std::vector<std::string>::iterator dit;
for ( dit = depends.begin(); dit != depends.end(); ++ dit )

View File

@ -207,14 +207,14 @@ public:
///! Find a target by name by searching the local generators.
cmTarget* FindTarget(const char* project, const char* name,
bool excludeAliases = false);
bool excludeAliases = false) const;
void AddAlias(const char *name, cmTarget *tgt);
bool IsAlias(const char *name);
bool IsAlias(const char *name) const;
/** Determine if a name resolves to a framework on disk or a built target
that is a framework. */
bool NameResolvesToFramework(const std::string& libname);
bool NameResolvesToFramework(const std::string& libname) const;
/** If check to see if the target is linked to by any other
target in the project */

View File

@ -903,13 +903,13 @@ cmMakefile::AddCustomCommandToTarget(const char* target,
switch(type)
{
case cmTarget::PRE_BUILD:
ti->second.GetPreBuildCommands().push_back(cc);
ti->second.AddPreBuildCommand(cc);
break;
case cmTarget::PRE_LINK:
ti->second.GetPreLinkCommands().push_back(cc);
ti->second.AddPreLinkCommand(cc);
break;
case cmTarget::POST_BUILD:
ti->second.GetPostBuildCommands().push_back(cc);
ti->second.AddPostBuildCommand(cc);
break;
}
}
@ -3822,21 +3822,19 @@ const char* cmMakefile::GetFeature(const char* feature, const char* config)
return 0;
}
cmTarget* cmMakefile::FindTarget(const char* name, bool excludeAliases)
cmTarget* cmMakefile::FindTarget(const char* name, bool excludeAliases) const
{
if (!excludeAliases)
{
std::map<std::string, cmTarget*>::iterator i
std::map<std::string, cmTarget*>::const_iterator i
= this->AliasTargets.find(name);
if (i != this->AliasTargets.end())
{
return i->second;
}
}
cmTargets& tgts = this->GetTargets();
cmTargets::iterator i = tgts.find ( name );
if ( i != tgts.end() )
cmTargets::iterator i = this->Targets.find( name );
if ( i != this->Targets.end() )
{
return &i->second;
}

View File

@ -533,7 +533,7 @@ public:
this->GeneratorTargets = targets;
}
cmTarget* FindTarget(const char* name, bool excludeAliases = false);
cmTarget* FindTarget(const char* name, bool excludeAliases = false) const;
/** Find a target to use in place of the given name. The target
returned may be imported or built within the project. */
@ -902,7 +902,7 @@ protected:
std::string ProjectName; // project name
// libraries, classes, and executables
cmTargets Targets;
mutable cmTargets Targets;
std::map<std::string, cmTarget*> AliasTargets;
cmGeneratorTargetsType GeneratorTargets;
std::vector<cmSourceFile*> SourceFiles;

View File

@ -534,7 +534,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
std::replace(linkLibraries.begin(), linkLibraries.end(), '\\', '/');
}
std::vector<cmCustomCommand> *cmdLists[3] = {
const std::vector<cmCustomCommand> *cmdLists[3] = {
&this->GetTarget()->GetPreBuildCommands(),
&this->GetTarget()->GetPreLinkCommands(),
&this->GetTarget()->GetPostBuildCommands()

View File

@ -257,7 +257,7 @@ bool cmQtAutoGenerators::InitializeAutogenTarget(cmTarget* target)
workingDirectory.c_str());
cc.SetEscapeOldStyle(false);
cc.SetEscapeAllowMakeVars(true);
target->GetPreBuildCommands().push_back(cc);
target->AddPreBuildCommand(cc);
}
else
#endif

View File

@ -91,8 +91,8 @@ public:
}
~cmTargetInternals();
typedef cmTarget::SourceFileFlags SourceFileFlags;
std::map<cmSourceFile const*, SourceFileFlags> SourceFlagsMap;
bool SourceFileFlagsConstructed;
mutable std::map<cmSourceFile const*, SourceFileFlags> SourceFlagsMap;
mutable bool SourceFileFlagsConstructed;
// The backtrace when the target was created.
cmListFileBacktrace Backtrace;
@ -438,7 +438,7 @@ bool cmTarget::IsExecutableWithExports() const
}
//----------------------------------------------------------------------------
bool cmTarget::IsLinkable()
bool cmTarget::IsLinkable() const
{
return (this->GetType() == cmTarget::STATIC_LIBRARY ||
this->GetType() == cmTarget::SHARED_LIBRARY ||
@ -577,7 +577,7 @@ void cmTarget::ProcessSourceExpression(std::string const& expr)
//----------------------------------------------------------------------------
struct cmTarget::SourceFileFlags
cmTarget::GetTargetSourceFileFlags(const cmSourceFile* sf)
cmTarget::GetTargetSourceFileFlags(const cmSourceFile* sf) const
{
struct SourceFileFlags flags;
this->ConstructSourceFileFlags();
@ -591,7 +591,7 @@ cmTarget::GetTargetSourceFileFlags(const cmSourceFile* sf)
}
//----------------------------------------------------------------------------
void cmTarget::ConstructSourceFileFlags()
void cmTarget::ConstructSourceFileFlags() const
{
if(this->Internal->SourceFileFlagsConstructed)
{
@ -769,9 +769,9 @@ void cmTarget::ClearDependencyInformation( cmMakefile& mf,
}
//----------------------------------------------------------------------------
bool cmTarget::NameResolvesToFramework(const std::string& libname)
bool cmTarget::NameResolvesToFramework(const std::string& libname) const
{
return this->GetMakefile()->GetLocalGenerator()->GetGlobalGenerator()->
return this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
NameResolvesToFramework(libname);
}
@ -811,7 +811,7 @@ void cmTarget::GetDirectLinkLibraries(const char *config,
//----------------------------------------------------------------------------
void cmTarget::GetInterfaceLinkLibraries(const char *config,
std::vector<std::string> &libs, cmTarget *head)
std::vector<std::string> &libs, cmTarget *head) const
{
const char *prop = this->GetProperty("INTERFACE_LINK_LIBRARIES");
if (prop)
@ -834,7 +834,7 @@ void cmTarget::GetInterfaceLinkLibraries(const char *config,
//----------------------------------------------------------------------------
std::string cmTarget::GetDebugGeneratorExpressions(const std::string &value,
cmTarget::LinkLibraryType llt)
cmTarget::LinkLibraryType llt) const
{
if (llt == GENERAL)
{
@ -2276,7 +2276,7 @@ static void cmTargetCheckINTERFACE_LINK_LIBRARIES(const char* value,
}
//----------------------------------------------------------------------------
void cmTarget::CheckProperty(const char* prop, cmMakefile* context)
void cmTarget::CheckProperty(const char* prop, cmMakefile* context) const
{
// Certain properties need checking.
if(strncmp(prop, "LINK_INTERFACE_LIBRARIES", 24) == 0)
@ -2382,7 +2382,7 @@ std::string cmTarget::GetDirectory(const char* config, bool implib) const
}
//----------------------------------------------------------------------------
std::string cmTarget::GetPDBDirectory(const char* config)
std::string cmTarget::GetPDBDirectory(const char* config) const
{
if(OutputInfo const* info = this->GetOutputInfo(config))
{
@ -2453,7 +2453,7 @@ const char* cmTarget::NormalGetLocation(const char* config) const
}
//----------------------------------------------------------------------------
void cmTarget::GetTargetVersion(int& major, int& minor)
void cmTarget::GetTargetVersion(int& major, int& minor) const
{
int patch;
this->GetTargetVersion(false, major, minor, patch);
@ -2461,7 +2461,7 @@ void cmTarget::GetTargetVersion(int& major, int& minor)
//----------------------------------------------------------------------------
void cmTarget::GetTargetVersion(bool soversion,
int& major, int& minor, int& patch)
int& major, int& minor, int& patch) const
{
// Set the default values.
major = 0;
@ -2489,7 +2489,7 @@ void cmTarget::GetTargetVersion(bool soversion,
}
//----------------------------------------------------------------------------
const char* cmTarget::GetFeature(const char* feature, const char* config)
const char* cmTarget::GetFeature(const char* feature, const char* config) const
{
if(config && *config)
{
@ -3145,7 +3145,7 @@ bool cmTarget::HasMacOSXRpath(const char* config) const
}
//----------------------------------------------------------------------------
bool cmTarget::IsImportedSharedLibWithoutSOName(const char* config)
bool cmTarget::IsImportedSharedLibWithoutSOName(const char* config) const
{
if(this->IsImported() && this->GetType() == cmTarget::SHARED_LIBRARY)
{
@ -3597,14 +3597,14 @@ void cmTarget::GetExecutableNames(std::string& name,
}
//----------------------------------------------------------------------------
bool cmTarget::HasImplibGNUtoMS()
bool cmTarget::HasImplibGNUtoMS() const
{
return this->HasImportLibrary() && this->GetPropertyAsBool("GNUtoMS");
}
//----------------------------------------------------------------------------
bool cmTarget::GetImplibGNUtoMS(std::string const& gnuName,
std::string& out, const char* newExt)
std::string& out, const char* newExt) const
{
if(this->HasImplibGNUtoMS() &&
gnuName.size() > 6 && gnuName.substr(gnuName.size()-6) == ".dll.a")
@ -3976,7 +3976,7 @@ bool cmTarget::ComputePDBOutputDir(const char* config, std::string& out) const
}
//----------------------------------------------------------------------------
bool cmTarget::UsesDefaultOutputDir(const char* config, bool implib)
bool cmTarget::UsesDefaultOutputDir(const char* config, bool implib) const
{
std::string dir;
return this->ComputeOutputDir(config, implib, dir);
@ -4037,7 +4037,7 @@ std::string cmTarget::GetFrameworkVersion() const
}
//----------------------------------------------------------------------------
const char* cmTarget::GetExportMacro()
const char* cmTarget::GetExportMacro() const
{
// Define the symbol for targets that export symbols.
if(this->GetType() == cmTarget::SHARED_LIBRARY ||

View File

@ -114,12 +114,18 @@ public:
/**
* Get the list of the custom commands for this target
*/
std::vector<cmCustomCommand> &GetPreBuildCommands()
std::vector<cmCustomCommand> const &GetPreBuildCommands() const
{return this->PreBuildCommands;}
std::vector<cmCustomCommand> &GetPreLinkCommands()
std::vector<cmCustomCommand> const &GetPreLinkCommands() const
{return this->PreLinkCommands;}
std::vector<cmCustomCommand> &GetPostBuildCommands()
std::vector<cmCustomCommand> const &GetPostBuildCommands() const
{return this->PostBuildCommands;}
void AddPreBuildCommand(cmCustomCommand const &cmd)
{this->PreBuildCommands.push_back(cmd);}
void AddPreLinkCommand(cmCustomCommand const &cmd)
{this->PreLinkCommands.push_back(cmd);}
void AddPostBuildCommand(cmCustomCommand const &cmd)
{this->PostBuildCommands.push_back(cmd);}
/**
* Get the list of the source files used by this target
@ -156,7 +162,8 @@ public:
/**
* Get the flags for a given source file as used in this target
*/
struct SourceFileFlags GetTargetSourceFileFlags(const cmSourceFile* sf);
struct SourceFileFlags
GetTargetSourceFileFlags(const cmSourceFile* sf) const;
/**
* Add sources to the target.
@ -179,7 +186,7 @@ public:
cmTarget const* head) const;
void GetInterfaceLinkLibraries(const char *config,
std::vector<std::string> &,
cmTarget *head);
cmTarget *head) const;
/** Compute the link type to use for the given configuration. */
LinkLibraryType ComputeLinkType(const char* config) const;
@ -190,7 +197,7 @@ public:
void ClearDependencyInformation(cmMakefile& mf, const char* target);
// Check to see if a library is a framework and treat it different on Mac
bool NameResolvesToFramework(const std::string& libname);
bool NameResolvesToFramework(const std::string& libname) const;
void AddLinkLibrary(cmMakefile& mf,
const char *target, const char* lib,
LinkLibraryType llt);
@ -212,14 +219,14 @@ public:
* Set the path where this target should be installed. This is relative to
* INSTALL_PREFIX
*/
std::string GetInstallPath() {return this->InstallPath;}
std::string GetInstallPath() const {return this->InstallPath;}
void SetInstallPath(const char *name) {this->InstallPath = name;}
/**
* Set the path where this target (if it has a runtime part) should be
* installed. This is relative to INSTALL_PREFIX
*/
std::string GetRuntimeInstallPath() {return this->RuntimeInstallPath;}
std::string GetRuntimeInstallPath() const {return this->RuntimeInstallPath;}
void SetRuntimeInstallPath(const char *name) {
this->RuntimeInstallPath = name; }
@ -246,9 +253,9 @@ public:
const char *GetProperty(const char *prop) const;
const char *GetProperty(const char *prop, cmProperty::ScopeType scope) const;
bool GetPropertyAsBool(const char *prop) const;
void CheckProperty(const char* prop, cmMakefile* context);
void CheckProperty(const char* prop, cmMakefile* context) const;
const char* GetFeature(const char* feature, const char* config);
const char* GetFeature(const char* feature, const char* config) const;
bool IsImported() const {return this->IsImportedTarget;}
@ -330,7 +337,7 @@ public:
If the configuration name is given then the generator will add its
subdirectory for that configuration. Otherwise just the canonical
pdb output directory is given. */
std::string GetPDBDirectory(const char* config = 0);
std::string GetPDBDirectory(const char* config = 0) const;
/** Get the location of the target in the build tree for the given
configuration. This location is suitable for use as the LOCATION
@ -340,12 +347,13 @@ public:
/** Get the target major and minor version numbers interpreted from
the VERSION property. Version 0 is returned if the property is
not set or cannot be parsed. */
void GetTargetVersion(int& major, int& minor);
void GetTargetVersion(int& major, int& minor) const;
/** Get the target major, minor, and patch version numbers
interpreted from the VERSION or SOVERSION property. Version 0
is returned if the property is not set or cannot be parsed. */
void GetTargetVersion(bool soversion, int& major, int& minor, int& patch);
void
GetTargetVersion(bool soversion, int& major, int& minor, int& patch) const;
/**
* Make sure the full path to all source files is known.
@ -377,7 +385,7 @@ public:
/** Test for special case of a third-party shared library that has
no soname at all. */
bool IsImportedSharedLibWithoutSOName(const char* config);
bool IsImportedSharedLibWithoutSOName(const char* config) const;
/** Get the full path to the target according to the settings in its
makefile and the configuration type. */
@ -399,12 +407,12 @@ public:
std::string& pdbName, const char* config) const;
/** Does this target have a GNU implib to convert to MS format? */
bool HasImplibGNUtoMS();
bool HasImplibGNUtoMS() const;
/** Convert the given GNU import library name (.dll.a) to a name with a new
extension (.lib or ${CMAKE_IMPORT_LIBRARY_SUFFIX}). */
bool GetImplibGNUtoMS(std::string const& gnuName, std::string& out,
const char* newExt = 0);
const char* newExt = 0) const;
/**
* Compute whether this target must be relinked before installing.
@ -442,7 +450,7 @@ public:
/** Get the macro to define when building sources in this target.
If no macro should be defined null is returned. */
const char* GetExportMacro();
const char* GetExportMacro() const;
void GetCompileDefinitions(std::vector<std::string> &result,
const char *config) const;
@ -459,10 +467,10 @@ public:
bool IsExecutableWithExports() const;
/** Return whether this target may be used to link another target. */
bool IsLinkable();
bool IsLinkable() const;
/** Return whether or not the target is for a DLL platform. */
bool IsDLLPlatform() { return this->DLLPlatform; }
bool IsDLLPlatform() const { return this->DLLPlatform; }
/** Return whether or not the target has a DLL import library. */
bool HasImportLibrary() const;
@ -493,7 +501,7 @@ public:
/** Return whether this target uses the default value for its output
directory. */
bool UsesDefaultOutputDir(const char* config, bool implib);
bool UsesDefaultOutputDir(const char* config, bool implib) const;
/** @return the mac content directory for this target. */
std::string GetMacContentDirectory(const char* config,
@ -546,7 +554,7 @@ public:
const char *config) const;
std::string GetDebugGeneratorExpressions(const std::string &value,
cmTarget::LinkLibraryType llt);
cmTarget::LinkLibraryType llt) const;
void AddSystemIncludeDirectories(const std::set<cmStdString> &incs);
void AddSystemIncludeDirectories(const std::vector<std::string> &incs);
@ -671,7 +679,7 @@ private:
bool HaveInstallRule;
std::string InstallPath;
std::string RuntimeInstallPath;
std::string ExportMacro;
mutable std::string ExportMacro;
std::set<cmStdString> Utilities;
bool RecordDependencies;
mutable cmPropertyMap Properties;
@ -736,7 +744,7 @@ private:
friend class cmTargetTraceDependencies;
cmTargetInternalPointer Internal;
void ConstructSourceFileFlags();
void ConstructSourceFileFlags() const;
void ComputeVersionedName(std::string& vName,
std::string const& prefix,
std::string const& base,

View File

@ -1794,7 +1794,7 @@ cmVisualStudio10TargetGenerator::WriteEvents(std::string const& configName)
void cmVisualStudio10TargetGenerator::WriteEvent(
const char* name,
std::vector<cmCustomCommand> & commands,
std::vector<cmCustomCommand> const& commands,
std::string const& configName)
{
if(commands.size() == 0)
@ -1807,10 +1807,10 @@ void cmVisualStudio10TargetGenerator::WriteEvent(
std::string script;
const char* pre = "";
std::string comment;
for(std::vector<cmCustomCommand>::iterator i = commands.begin();
for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
i != commands.end(); ++i)
{
cmCustomCommand& command = *i;
const cmCustomCommand& command = *i;
comment += pre;
comment += lg->ConstructComment(command);
script += pre;

View File

@ -87,7 +87,8 @@ private:
void AddLibraries(cmComputeLinkInformation& cli, std::string& libstring);
void WriteLibOptions(std::string const& config);
void WriteEvents(std::string const& configName);
void WriteEvent(const char* name, std::vector<cmCustomCommand> & commands,
void WriteEvent(const char* name,
std::vector<cmCustomCommand> const& commands,
std::string const& configName);
void WriteGroupSources(const char* name, ToolSources const& sources,
std::vector<cmSourceGroup>& );