cmTarget: Construct with basic information up front

Avoid having partially constructed cmTarget instances around,
except for the special case of GLOBAL_TARGET construction.
This commit is contained in:
Brad King 2016-09-14 14:28:07 -04:00
parent 9d11bd5066
commit 00e78c1990
5 changed files with 36 additions and 32 deletions

View File

@ -77,9 +77,8 @@ std::string cmExportTryCompileFileGenerator::FindTargets(
CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(prop); CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(prop);
cmTarget dummyHead; cmTarget dummyHead("try_compile_dummy_exe", cmState::EXECUTABLE,
dummyHead.SetType(cmState::EXECUTABLE, "try_compile_dummy_exe"); cmTarget::VisibilityNormal, tgt->Target->GetMakefile());
dummyHead.SetMakefile(tgt->Target->GetMakefile());
cmGeneratorTarget gDummyHead(&dummyHead, tgt->GetLocalGenerator()); cmGeneratorTarget gDummyHead(&dummyHead, tgt->GetLocalGenerator());

View File

@ -2352,8 +2352,8 @@ cmTarget cmGlobalGenerator::CreateGlobalTarget(
const char* workingDirectory, bool uses_terminal) const char* workingDirectory, bool uses_terminal)
{ {
// Package // Package
cmTarget target; cmTarget target(name, cmState::GLOBAL_TARGET, cmTarget::VisibilityNormal,
target.SetType(cmState::GLOBAL_TARGET, name); CM_NULLPTR);
target.SetProperty("EXCLUDE_FROM_ALL", "TRUE"); target.SetProperty("EXCLUDE_FROM_ALL", "TRUE");
std::vector<std::string> no_outputs; std::vector<std::string> no_outputs;

View File

@ -1925,10 +1925,10 @@ cmTarget* cmMakefile::AddNewTarget(cmState::TargetType type,
const std::string& name) const std::string& name)
{ {
cmTargets::iterator it = cmTargets::iterator it =
this->Targets.insert(cmTargets::value_type(name, cmTarget())).first; this->Targets
cmTarget& target = it->second; .insert(cmTargets::value_type(
target.SetType(type, name); name, cmTarget(name, type, cmTarget::VisibilityNormal, this)))
target.SetMakefile(this); .first;
this->GetGlobalGenerator()->IndexTarget(&it->second); this->GetGlobalGenerator()->IndexTarget(&it->second);
return &it->second; return &it->second;
} }
@ -3710,10 +3710,10 @@ cmTarget* cmMakefile::AddImportedTarget(const std::string& name,
cmState::TargetType type, bool global) cmState::TargetType type, bool global)
{ {
// Create the target. // Create the target.
CM_AUTO_PTR<cmTarget> target(new cmTarget); CM_AUTO_PTR<cmTarget> target(
target->SetType(type, name); new cmTarget(name, type, global ? cmTarget::VisibilityImportedGlobally
target->MarkAsImported(global); : cmTarget::VisibilityImported,
target->SetMakefile(this); this));
// Add to the set of available imported targets. // Add to the set of available imported targets.
this->ImportedTargets[name] = target.get(); this->ImportedTargets[name] = target.get();

View File

@ -59,15 +59,22 @@ public:
std::vector<cmListFileBacktrace> LinkImplementationPropertyBacktraces; std::vector<cmListFileBacktrace> LinkImplementationPropertyBacktraces;
}; };
cmTarget::cmTarget() cmTarget::cmTarget(std::string const& name, cmState::TargetType type,
Visibility vis, cmMakefile* mf)
{ {
assert(mf || type == cmState::GLOBAL_TARGET);
this->Makefile = CM_NULLPTR; this->Makefile = CM_NULLPTR;
this->HaveInstallRule = false; this->HaveInstallRule = false;
this->DLLPlatform = false; this->DLLPlatform = false;
this->IsAndroid = false; this->IsAndroid = false;
this->IsImportedTarget = false; this->IsImportedTarget =
this->ImportedGloballyVisible = false; (vis == VisibilityImported || vis == VisibilityImportedGlobally);
this->ImportedGloballyVisible = vis == VisibilityImportedGlobally;
this->BuildInterfaceIncludesAppended = false; this->BuildInterfaceIncludesAppended = false;
this->SetType(type, name);
if (mf) {
this->SetMakefile(mf);
}
} }
void cmTarget::SetType(cmState::TargetType type, const std::string& name) void cmTarget::SetType(cmState::TargetType type, const std::string& name)
@ -1071,12 +1078,6 @@ void cmTarget::CheckProperty(const std::string& prop,
} }
} }
void cmTarget::MarkAsImported(bool global)
{
this->IsImportedTarget = true;
this->ImportedGloballyVisible = global;
}
bool cmTarget::HandleLocationPropertyPolicy(cmMakefile* context) const bool cmTarget::HandleLocationPropertyPolicy(cmMakefile* context) const
{ {
if (this->IsImported()) { if (this->IsImported()) {

View File

@ -63,7 +63,16 @@ private:
class cmTarget class cmTarget
{ {
public: public:
cmTarget(); enum Visibility
{
VisibilityNormal,
VisibilityImported,
VisibilityImportedGlobally
};
cmTarget(std::string const& name, cmState::TargetType type, Visibility vis,
cmMakefile* mf);
enum CustomCommandType enum CustomCommandType
{ {
PRE_BUILD, PRE_BUILD,
@ -76,21 +85,13 @@ public:
*/ */
cmState::TargetType GetType() const { return this->TargetTypeValue; } cmState::TargetType GetType() const { return this->TargetTypeValue; }
/**
* Set the target type
*/
void SetType(cmState::TargetType f, const std::string& name);
void MarkAsImported(bool global = false);
///! Set/Get the name of the target ///! Set/Get the name of the target
const std::string& GetName() const { return this->Name; } const std::string& GetName() const { return this->Name; }
/** Get a copy of this target adapted for the given directory. */ /** Get a copy of this target adapted for the given directory. */
cmTarget CopyForDirectory(cmMakefile* mf) const; cmTarget CopyForDirectory(cmMakefile* mf) const;
///! Set the cmMakefile that owns this target /** Get the cmMakefile that owns this target. */
void SetMakefile(cmMakefile* mf);
cmMakefile* GetMakefile() const { return this->Makefile; } cmMakefile* GetMakefile() const { return this->Makefile; }
#define DECLARE_TARGET_POLICY(POLICY) \ #define DECLARE_TARGET_POLICY(POLICY) \
@ -282,6 +283,9 @@ public:
}; };
private: private:
void SetType(cmState::TargetType f, const std::string& name);
void SetMakefile(cmMakefile* mf);
bool HandleLocationPropertyPolicy(cmMakefile* context) const; bool HandleLocationPropertyPolicy(cmMakefile* context) const;
const char* GetSuffixVariableInternal(bool implib) const; const char* GetSuffixVariableInternal(bool implib) const;