Commit c4373b33 authored by Stephen Kelly's avatar Stephen Kelly
Browse files

cmTarget: Make GetProperty() const.

This has follow-on effects for other methods and classes. Further
work on making the use of const cmTarget pointers common can be
done, particularly with a view to generate-time methods.
parent cfb66613
......@@ -172,7 +172,8 @@ satisfy dependencies.
//----------------------------------------------------------------------------
cmComputeLinkDepends
::cmComputeLinkDepends(cmTarget* target, const char* config, cmTarget* head)
::cmComputeLinkDepends(cmTarget const* target, const char* config,
cmTarget const* head)
{
// Store context information.
this->Target = target;
......
......@@ -32,7 +32,8 @@ class cmake;
class cmComputeLinkDepends
{
public:
cmComputeLinkDepends(cmTarget* target, const char* config, cmTarget *head);
cmComputeLinkDepends(cmTarget const* target, const char* config,
cmTarget const* head);
~cmComputeLinkDepends();
// Basic information about each link item.
......@@ -58,8 +59,8 @@ public:
private:
// Context information.
cmTarget* Target;
cmTarget* HeadTarget;
cmTarget const* Target;
cmTarget const* HeadTarget;
cmMakefile* Makefile;
cmLocalGenerator* LocalGenerator;
cmGlobalGenerator* GlobalGenerator;
......
......@@ -239,8 +239,8 @@ because this need be done only for shared libraries without soname-s.
//----------------------------------------------------------------------------
cmComputeLinkInformation
::cmComputeLinkInformation(cmTarget* target, const char* config,
cmTarget *headTarget)
::cmComputeLinkInformation(cmTarget const* target, const char* config,
cmTarget const* headTarget)
{
// Store context information.
this->Target = target;
......
......@@ -29,8 +29,8 @@ class cmOrderDirectories;
class cmComputeLinkInformation
{
public:
cmComputeLinkInformation(cmTarget* target, const char* config,
cmTarget* headTarget);
cmComputeLinkInformation(cmTarget const* target, const char* config,
cmTarget const* headTarget);
~cmComputeLinkInformation();
bool Compute();
......@@ -74,8 +74,8 @@ private:
std::set<cmTarget*> SharedLibrariesLinked;
// Context information.
cmTarget* Target;
cmTarget* HeadTarget;
cmTarget const* Target;
cmTarget const* HeadTarget;
cmMakefile* Makefile;
cmLocalGenerator* LocalGenerator;
cmGlobalGenerator* GlobalGenerator;
......
......@@ -34,7 +34,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
std::string outputVariable;
std::string copyFile;
std::string copyFileError;
std::vector<cmTarget*> targets;
std::vector<cmTarget const*> targets;
std::string libsToLink = " ";
bool useOldLinkLibs = true;
char targetNameBuf[64];
......
......@@ -463,7 +463,7 @@ void cmExportFileGenerator::PopulateCompatibleInterfaceProperties(
}
//----------------------------------------------------------------------------
void cmExportFileGenerator::GenerateInterfaceProperties(cmTarget *target,
void cmExportFileGenerator::GenerateInterfaceProperties(cmTarget const* target,
std::ostream& os,
const ImportPropertyMap &properties)
{
......@@ -885,7 +885,7 @@ void cmExportFileGenerator::GenerateExpectedTargetsCode(std::ostream& os,
//----------------------------------------------------------------------------
void
cmExportFileGenerator
::GenerateImportTargetCode(std::ostream& os, cmTarget* target)
::GenerateImportTargetCode(std::ostream& os, cmTarget const* target)
{
// Construct the imported target name.
std::string targetName = this->Namespace;
......@@ -951,7 +951,7 @@ cmExportFileGenerator
void
cmExportFileGenerator
::GenerateImportPropertyCode(std::ostream& os, const char* config,
cmTarget* target,
cmTarget const* target,
ImportPropertyMap const& properties)
{
// Construct the imported target name.
......
......@@ -60,9 +60,9 @@ protected:
void GenerateImportHeaderCode(std::ostream& os, const char* config = 0);
void GenerateImportFooterCode(std::ostream& os);
void GenerateImportVersionCode(std::ostream& os);
void GenerateImportTargetCode(std::ostream& os, cmTarget* target);
void GenerateImportTargetCode(std::ostream& os, cmTarget const* target);
void GenerateImportPropertyCode(std::ostream& os, const char* config,
cmTarget* target,
cmTarget const* target,
ImportPropertyMap const& properties);
void GenerateImportedFileChecksCode(std::ostream& os, cmTarget* target,
ImportPropertyMap const& properties,
......@@ -115,7 +115,7 @@ protected:
ImportPropertyMap &properties);
void PopulateCompatibleInterfaceProperties(cmTarget *target,
ImportPropertyMap &properties);
void GenerateInterfaceProperties(cmTarget *target, std::ostream& os,
void GenerateInterfaceProperties(cmTarget const* target, std::ostream& os,
const ImportPropertyMap &properties);
void PopulateIncludeDirectoriesInterface(
cmTargetExport *target,
......
......@@ -18,11 +18,11 @@
//----------------------------------------------------------------------------
bool cmExportTryCompileFileGenerator::GenerateMainFile(std::ostream& os)
{
std::set<cmTarget*> emitted;
std::set<cmTarget*> emittedDeps;
std::set<cmTarget const*> emitted;
std::set<cmTarget const*> emittedDeps;
while(!this->Exports.empty())
{
cmTarget* te = this->Exports.back();
cmTarget const* te = this->Exports.back();
this->Exports.pop_back();
if (emitted.insert(te).second)
{
......@@ -45,8 +45,8 @@ bool cmExportTryCompileFileGenerator::GenerateMainFile(std::ostream& os)
}
std::string cmExportTryCompileFileGenerator::FindTargets(const char *propName,
cmTarget *tgt,
std::set<cmTarget*> &emitted)
cmTarget const* tgt,
std::set<cmTarget const*> &emitted)
{
const char *prop = tgt->GetProperty(propName);
if(!prop)
......@@ -70,8 +70,8 @@ std::string cmExportTryCompileFileGenerator::FindTargets(const char *propName,
std::string result = cge->Evaluate(tgt->GetMakefile(), this->Config,
false, &dummyHead, tgt, &dagChecker);
const std::set<cmTarget*> &allTargets = cge->GetAllTargetsSeen();
for(std::set<cmTarget*>::const_iterator li = allTargets.begin();
const std::set<cmTarget const*> &allTargets = cge->GetAllTargetsSeen();
for(std::set<cmTarget const*>::const_iterator li = allTargets.begin();
li != allTargets.end(); ++li)
{
if(emitted.insert(*li).second)
......@@ -84,9 +84,9 @@ std::string cmExportTryCompileFileGenerator::FindTargets(const char *propName,
//----------------------------------------------------------------------------
void
cmExportTryCompileFileGenerator::PopulateProperties(cmTarget* target,
cmExportTryCompileFileGenerator::PopulateProperties(cmTarget const* target,
ImportPropertyMap& properties,
std::set<cmTarget*> &emitted)
std::set<cmTarget const*> &emitted)
{
cmPropertyMap props = target->GetProperties();
for(cmPropertyMap::const_iterator i = props.begin(); i != props.end(); ++i)
......
......@@ -21,7 +21,7 @@ class cmExportTryCompileFileGenerator: public cmExportFileGenerator
{
public:
/** Set the list of targets to export. */
void SetExports(const std::vector<cmTarget*> &exports)
void SetExports(const std::vector<cmTarget const*> &exports)
{ this->Exports = exports; }
void SetConfig(const char *config) { this->Config = config; }
protected:
......@@ -39,18 +39,18 @@ protected:
cmTarget*,
cmTarget*) {}
void PopulateProperties(cmTarget* target,
void PopulateProperties(cmTarget const* target,
ImportPropertyMap& properties,
std::set<cmTarget*> &emitted);
std::set<cmTarget const*> &emitted);
std::string InstallNameDir(cmTarget* target,
const std::string& config);
private:
std::string FindTargets(const char *prop, cmTarget *tgt,
std::set<cmTarget*> &emitted);
std::string FindTargets(const char *prop, cmTarget const* tgt,
std::set<cmTarget const*> &emitted);
std::vector<cmTarget*> Exports;
std::vector<cmTarget const*> Exports;
const char *Config;
};
......
......@@ -140,14 +140,25 @@ void cmFindCommon::RerootPaths(std::vector<std::string>& paths)
}
const char* rootPath =
this->Makefile->GetDefinition("CMAKE_FIND_ROOT_PATH");
if((rootPath == 0) || (strlen(rootPath) == 0))
const char* osxRootPath =
this->Makefile->GetDefinition("_CMAKE_OSX_SYSROOT_PATH");
const bool noRootPath = !rootPath || !*rootPath;
const bool noOSXRootPath = !osxRootPath || !*osxRootPath;
if(noRootPath && noOSXRootPath)
{
return;
}
// Construct the list of path roots with no trailing slashes.
std::vector<std::string> roots;
cmSystemTools::ExpandListArgument(rootPath, roots);
if(rootPath)
{
cmSystemTools::ExpandListArgument(rootPath, roots);
}
if(osxRootPath)
{
roots.push_back(osxRootPath);
}
for(std::vector<std::string>::iterator ri = roots.begin();
ri != roots.end(); ++ri)
{
......
......@@ -53,7 +53,7 @@ cmGeneratorExpression::~cmGeneratorExpression()
//----------------------------------------------------------------------------
const char *cmCompiledGeneratorExpression::Evaluate(
cmMakefile* mf, const char* config, bool quiet,
cmTarget *headTarget,
cmTarget const* headTarget,
cmGeneratorExpressionDAGChecker *dagChecker) const
{
return this->Evaluate(mf,
......@@ -67,8 +67,8 @@ const char *cmCompiledGeneratorExpression::Evaluate(
//----------------------------------------------------------------------------
const char *cmCompiledGeneratorExpression::Evaluate(
cmMakefile* mf, const char* config, bool quiet,
cmTarget *headTarget,
cmTarget *currentTarget,
cmTarget const* headTarget,
cmTarget const* currentTarget,
cmGeneratorExpressionDAGChecker *dagChecker) const
{
if (!this->NeedsEvaluation)
......
......@@ -80,12 +80,12 @@ class cmCompiledGeneratorExpression
public:
const char* Evaluate(cmMakefile* mf, const char* config,
bool quiet = false,
cmTarget *headTarget = 0,
cmTarget *currentTarget = 0,
cmTarget const* headTarget = 0,
cmTarget const* currentTarget = 0,
cmGeneratorExpressionDAGChecker *dagChecker = 0) const;
const char* Evaluate(cmMakefile* mf, const char* config,
bool quiet,
cmTarget *headTarget,
cmTarget const* headTarget,
cmGeneratorExpressionDAGChecker *dagChecker) const;
/** Get set of targets found during evaluations. */
......@@ -95,7 +95,7 @@ public:
std::set<cmStdString> const& GetSeenTargetProperties() const
{ return this->SeenTargetProperties; }
std::set<cmTarget*> const& GetAllTargetsSeen() const
std::set<cmTarget const*> const& GetAllTargetsSeen() const
{ return this->AllTargetsSeen; }
~cmCompiledGeneratorExpression();
......@@ -129,7 +129,7 @@ private:
bool NeedsEvaluation;
mutable std::set<cmTarget*> DependTargets;
mutable std::set<cmTarget*> AllTargetsSeen;
mutable std::set<cmTarget const*> AllTargetsSeen;
mutable std::set<cmStdString> SeenTargetProperties;
mutable std::string Output;
mutable bool HadContextSensitiveCondition;
......
......@@ -661,8 +661,8 @@ static const char* targetPropertyTransitiveWhitelist[] = {
};
std::string getLinkedTargetsContent(const std::vector<std::string> &libraries,
cmTarget *target,
cmTarget *headTarget,
cmTarget const* target,
cmTarget const* headTarget,
cmGeneratorExpressionContext *context,
cmGeneratorExpressionDAGChecker *dagChecker,
const std::string &interfacePropertyName)
......@@ -726,7 +726,7 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
cmsys::RegularExpression propertyNameValidator;
propertyNameValidator.compile("^[A-Za-z0-9_]+$");
cmTarget* target = context->HeadTarget;
cmTarget const* target = context->HeadTarget;
std::string propertyName = *parameters.begin();
if (!target && parameters.size() == 1)
......@@ -914,7 +914,8 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
interfacePropertyName = "INTERFACE_COMPILE_OPTIONS";
}
cmTarget *headTarget = context->HeadTarget ? context->HeadTarget : target;
cmTarget const* headTarget = context->HeadTarget
? context->HeadTarget : target;
const char * const *transBegin =
cmArrayBegin(targetPropertyTransitiveWhitelist) + 1;
......@@ -1091,7 +1092,8 @@ static const char* targetPolicyWhitelist[] = {
#undef TARGET_POLICY_STRING
};
cmPolicies::PolicyStatus statusForTarget(cmTarget *tgt, const char *policy)
cmPolicies::PolicyStatus statusForTarget(cmTarget const* tgt,
const char *policy)
{
#define RETURN_POLICY(POLICY) \
if (strcmp(policy, #POLICY) == 0) \
......
......@@ -24,13 +24,13 @@ struct cmGeneratorExpressionContext
{
cmListFileBacktrace Backtrace;
std::set<cmTarget*> DependTargets;
std::set<cmTarget*> AllTargets;
std::set<cmTarget const*> AllTargets;
std::set<cmStdString> SeenTargetProperties;
cmMakefile *Makefile;
const char *Config;
cmTarget *HeadTarget; // The target whose property is being evaluated.
cmTarget *CurrentTarget; // The dependent of HeadTarget which appears
// directly or indirectly in the property.
cmTarget const* HeadTarget; // The target whose property is being evaluated.
cmTarget const* CurrentTarget; // The dependent of HeadTarget which appears
// directly or indirectly in the property.
bool Quiet;
bool HadError;
bool HadContextSensitiveCondition;
......
......@@ -273,7 +273,7 @@ bool cmOrderDirectoriesConstraintLibrary::FindConflict(std::string const& dir)
//----------------------------------------------------------------------------
cmOrderDirectories::cmOrderDirectories(cmGlobalGenerator* gg,
cmTarget* target,
cmTarget const* target,
const char* purpose)
{
this->GlobalGenerator = gg;
......
......@@ -27,7 +27,7 @@ class cmTarget;
class cmOrderDirectories
{
public:
cmOrderDirectories(cmGlobalGenerator* gg, cmTarget* target,
cmOrderDirectories(cmGlobalGenerator* gg, cmTarget const* target,
const char* purpose);
~cmOrderDirectories();
void AddRuntimeLibrary(std::string const& fullPath, const char* soname = 0);
......@@ -41,7 +41,7 @@ public:
std::vector<std::string> const& GetOrderedDirectories();
private:
cmGlobalGenerator* GlobalGenerator;
cmTarget* Target;
cmTarget const* Target;
std::string Purpose;
bool Computed;
......
This diff is collapsed.
......@@ -36,9 +36,10 @@ class cmListFileBacktrace;
class cmTarget;
struct cmTargetLinkInformationMap:
public std::map<std::pair<cmTarget*, std::string>, cmComputeLinkInformation*>
public std::map<std::pair<cmTarget const* , std::string>,
cmComputeLinkInformation*>
{
typedef std::map<std::pair<cmTarget*, std::string>,
typedef std::map<std::pair<cmTarget const* , std::string>,
cmComputeLinkInformation*> derived;
cmTargetLinkInformationMap() {}
cmTargetLinkInformationMap(cmTargetLinkInformationMap const& r);
......@@ -94,7 +95,7 @@ public:
///! Set/Get the name of the target
const char* GetName() const {return this->Name.c_str();}
const char* GetExportName();
const char* GetExportName() const;
///! Set the cmMakefile that owns this target
void SetMakefile(cmMakefile *mf);
......@@ -176,13 +177,13 @@ public:
{return this->OriginalLinkLibraries;}
void GetDirectLinkLibraries(const char *config,
std::vector<std::string> &,
cmTarget *head);
cmTarget const* head) const;
void GetInterfaceLinkLibraries(const char *config,
std::vector<std::string> &,
cmTarget *head);
/** Compute the link type to use for the given configuration. */
LinkLibraryType ComputeLinkType(const char* config);
LinkLibraryType ComputeLinkType(const char* config) const;
/**
* Clear the dependency information recorded for this target, if any.
......@@ -204,7 +205,7 @@ public:
void MergeLinkLibraries( cmMakefile& mf, const char* selfname,
const LinkLibraryVectorType& libs );
const std::vector<std::string>& GetLinkDirectories();
const std::vector<std::string>& GetLinkDirectories() const;
void AddLinkDirectory(const char* d);
......@@ -226,7 +227,7 @@ public:
/**
* Get/Set whether there is an install rule for this target.
*/
bool GetHaveInstallRule() { return this->HaveInstallRule; }
bool GetHaveInstallRule() const { return this->HaveInstallRule; }
void SetHaveInstallRule(bool h) { this->HaveInstallRule = h; }
/** Add a utility on which this project depends. A utility is an executable
......@@ -243,9 +244,9 @@ public:
///! Set/Get a property of this target file
void SetProperty(const char *prop, const char *value);
void AppendProperty(const char* prop, const char* value,bool asString=false);
const char *GetProperty(const char *prop);
const char *GetProperty(const char *prop, cmProperty::ScopeType scope);
bool GetPropertyAsBool(const char *prop);
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);
const char* GetFeature(const char* feature, const char* config);
......@@ -281,10 +282,10 @@ public:
/** Get the link interface for the given configuration. Returns 0
if the target cannot be linked. */
LinkInterface const* GetLinkInterface(const char* config,
cmTarget *headTarget);
cmTarget const* headTarget) const;
void GetTransitivePropertyLinkLibraries(const char* config,
cmTarget *headTarget,
std::vector<std::string> &libs);
cmTarget const* headTarget,
std::vector<std::string> &libs) const;
/** The link implementation specifies the direct library
dependencies needed by the object files of the target. */
......@@ -301,7 +302,7 @@ public:
std::vector<std::string> WrongConfigLibraries;
};
LinkImplementation const* GetLinkImplementation(const char* config,
cmTarget *head);
cmTarget const* head) const;
/** Link information from the transitive closure of the link
implementation and the interfaces of its dependencies. */
......@@ -313,17 +314,18 @@ public:
// Languages whose runtime libraries must be linked.
std::vector<std::string> Languages;
};
LinkClosure const* GetLinkClosure(const char* config, cmTarget *head);
LinkClosure const* GetLinkClosure(const char* config,
cmTarget const* head) const;
/** Strip off leading and trailing whitespace from an item named in
the link dependencies of this target. */
std::string CheckCMP0004(std::string const& item);
std::string CheckCMP0004(std::string const& item) const;
/** Get the directory in which this target will be built. If the
configuration name is given then the generator will add its
subdirectory for that configuration. Otherwise just the canonical
output directory is given. */
std::string GetDirectory(const char* config = 0, bool implib = false);
std::string GetDirectory(const char* config = 0, bool implib = false) const;
/** Get the directory in which this targets .pdb files will be placed.
If the configuration name is given then the generator will add its
......@@ -334,7 +336,7 @@ public:
/** Get the location of the target in the build tree for the given
configuration. This location is suitable for use as the LOCATION
target property. */
const char* GetLocation(const char* config);
const char* GetLocation(const char* config) const;
/** Get the target major and minor version numbers interpreted from
the VERSION property. Version 0 is returned if the property is
......@@ -358,23 +360,24 @@ public:
bool FindSourceFiles();
///! Return the preferred linker language for this target
const char* GetLinkerLanguage(const char* config = 0, cmTarget *head = 0);
const char* GetLinkerLanguage(const char* config = 0,
cmTarget const* head = 0) const;
/** Get the full name of the target according to the settings in its
makefile. */
std::string GetFullName(const char* config=0, bool implib = false);
std::string GetFullName(const char* config=0, bool implib = false) const;
void GetFullNameComponents(std::string& prefix,
std::string& base, std::string& suffix,
const char* config=0, bool implib = false);
/** Get the name of the pdb file for the target. */
std::string GetPDBName(const char* config=0);
std::string GetPDBName(const char* config=0) const;
/** Whether this library has soname enabled and platform supports it. */
bool HasSOName(const char* config);
bool HasSOName(const char* config) const;
/** Get the soname of the target. Allowed only for a shared library. */
std::string GetSOName(const char* config);
std::string GetSOName(const char* config) const;
/** Whether this library has \@rpath and platform supports it. */
bool HasMacOSXRpath(const char* config);
......@@ -386,21 +389,21 @@ public:
/** Get the full path to the target according to the settings in its
makefile and the configuration type. */
std::string GetFullPath(const char* config=0, bool implib = false,
bool realname = false);
bool realname = false) const;
/** Get the names of the library needed to generate a build rule
that takes into account shared library version numbers. This
should be called only on a library target. */
void GetLibraryNames(std::string& name, std::string& soName,
std::string& realName, std::string& impName,
std::string& pdbName, const char* config);
std::string& pdbName, const char* config) const;
/** Get the names of the executable needed to generate a build rule
that takes into account executable version numbers. This should
be called only on an executable target. */
void GetExecutableNames(std::string& name, std::string& realName,
std::string& impName,
std::string& pdbName, const char* config);
std::string& pdbName, const char* config) const;
/** Does this target have a GNU implib to convert to MS format? */
bool HasImplibGNUtoMS();
......@@ -415,11 +418,11 @@ public:
*/
bool NeedRelinkBeforeInstall(const char* config);
bool HaveBuildTreeRPATH(const char *config);
bool HaveInstallTreeRPATH();
bool HaveBuildTreeRPATH(const char *config) const;
bool HaveInstallTreeRPATH() const;
/** Return true if builtin chrpath will work for this target */
bool IsChrpathUsed(const char* config);
bool IsChrpathUsed(const char* config) const;
/** Return the install name directory for the target in the
* build tree. For example: "\@rpath/", "\@loader_path/",
......@@ -431,15 +434,15 @@ public:
std::string GetInstallNameDirForInstallTree();
cmComputeLinkInformation* GetLinkInformation(const char* config,
cmTarget *head = 0);
cmTarget const* head = 0) const;
// Get the properties
cmPropertyMap &GetProperties() { return this->Properties; };
cmPropertyMap &GetProperties() const { return this->Properties; };
bool GetMappedConfig(std::string const& desired_config,
const char** loc,
const char** imp,
std::string& suffix);
std::string& suffix) const;
// Define the properties
static void DefineProperties(cmake *cm);
......@@ -460,7 +463,7 @@ public:
/** Return whether this target is an executable with symbol exports
enabled. */
bool IsExecutableWithExports();
bool IsExecutableWithExports() const;
/** Return whether this target may be used to link another target. */
bool IsLinkable();
......@@ -469,25 +472,25 @@ public:
bool IsDLLPlatform() { return this->DLLPlatform; }
/** Return whether or not the target has a DLL import library. */
bool HasImportLibrary();
bool HasImportLibrary() const;
/** Return whether this target is a shared library Framework on
Apple. */
bool IsFrameworkOnApple();
bool IsFrameworkOnApple() const;
/** Return whether this target is a CFBundle (plugin) on Apple. */
bool IsCFBundleOnApple();
bool IsCFBundleOnApple() const;
/** Return whether this target is an executable Bundle on Apple. */