ENH: add the IMPORT keyword to ADD_EXECUTABLE(), which generates an

"imported" executable target. This can then be used e.g. with
ADD_CUSTOM_COMMAND() to generate stuff. It adds a second container for
"imported" targets, and FindTarget() now takes an additional argument bool
useImportedTargets to specify whether you also want to search in the
imported targets or only in the "normal" targets.

Alex
This commit is contained in:
Alexander Neundorf 2007-05-22 10:24:59 -04:00
parent 6be930f0cf
commit 4878c00905
24 changed files with 485 additions and 320 deletions

View File

@ -32,7 +32,7 @@ bool cmAddDependenciesCommand::InitialPass(
cmTarget* target = cmTarget* target =
this->GetMakefile()->GetLocalGenerator()-> this->GetMakefile()->GetLocalGenerator()->
GetGlobalGenerator()->FindTarget(0, target_name.c_str()); GetGlobalGenerator()->FindTarget(0, target_name.c_str(), false);
if(target) if(target)
{ {
std::vector<std::string>::const_iterator s = args.begin(); std::vector<std::string>::const_iterator s = args.begin();

View File

@ -32,6 +32,7 @@ bool cmAddExecutableCommand::InitialPass(std::vector<std::string> const& args)
bool use_win32 = false; bool use_win32 = false;
bool use_macbundle = false; bool use_macbundle = false;
bool excludeFromAll = false; bool excludeFromAll = false;
bool importTarget = false;
while ( s != args.end() ) while ( s != args.end() )
{ {
if (*s == "WIN32") if (*s == "WIN32")
@ -49,11 +50,22 @@ bool cmAddExecutableCommand::InitialPass(std::vector<std::string> const& args)
++s; ++s;
excludeFromAll = true; excludeFromAll = true;
} }
else if(*s == "IMPORT")
{
++s;
importTarget = true;
}
else else
{ {
break; break;
} }
} }
if (importTarget)
{
cmTarget* target = this->Makefile->AddNewTarget(cmTarget::EXECUTABLE, exename.c_str(), true);
return true;
}
if (s == args.end()) if (s == args.end())
{ {

View File

@ -29,7 +29,7 @@ bool cmGetTargetPropertyCommand::InitialPass(
const char* targetName = args[1].c_str(); const char* targetName = args[1].c_str();
cmTarget *tgt = this->Makefile->GetLocalGenerator()->GetGlobalGenerator() cmTarget *tgt = this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
->FindTarget(0,targetName); ->FindTarget(0, targetName, true);
if (tgt) if (tgt)
{ {
cmTarget& target = *tgt; cmTarget& target = *tgt;

View File

@ -625,6 +625,7 @@ void cmGlobalGenerator::Configure()
this->LocalGenerators.clear(); this->LocalGenerators.clear();
this->TargetDependencies.clear(); this->TargetDependencies.clear();
this->TotalTargets.clear(); this->TotalTargets.clear();
this->ImportedTotalTargets.clear();
this->ProjectToTargetMap.clear(); this->ProjectToTargetMap.clear();
this->ProjectMap.clear(); this->ProjectMap.clear();
@ -1179,7 +1180,8 @@ cmLocalGenerator* cmGlobalGenerator::FindLocalGenerator(const char* start_dir)
cmTarget* cmGlobalGenerator::FindTarget(const char* project, cmTarget* cmGlobalGenerator::FindTarget(const char* project,
const char* name) const char* name,
bool useImportedTargets)
{ {
// if project specific // if project specific
if(project) if(project)
@ -1187,7 +1189,8 @@ cmTarget* cmGlobalGenerator::FindTarget(const char* project,
std::vector<cmLocalGenerator*>* gens = &this->ProjectMap[project]; std::vector<cmLocalGenerator*>* gens = &this->ProjectMap[project];
for(unsigned int i = 0; i < gens->size(); ++i) for(unsigned int i = 0; i < gens->size(); ++i)
{ {
cmTarget* ret = (*gens)[i]->GetMakefile()->FindTarget(name); cmTarget* ret = (*gens)[i]->GetMakefile()->FindTarget(name,
useImportedTargets);
if(ret) if(ret)
{ {
return ret; return ret;
@ -1197,13 +1200,22 @@ cmTarget* cmGlobalGenerator::FindTarget(const char* project,
// if all projects/directories // if all projects/directories
else else
{ {
std::map<cmStdString,cmTarget *>::iterator i = std::map<cmStdString,cmTarget *>::iterator i =
this->TotalTargets.find(name); this->TotalTargets.find ( name );
if (i == this->TotalTargets.end()) if ( i != this->TotalTargets.end() )
{ {
return 0; return i->second;
}
if ( useImportedTargets )
{
std::map<cmStdString,cmTarget *>::iterator importedTarget =
this->ImportedTotalTargets.find ( name );
if ( importedTarget != this->ImportedTotalTargets.end() )
{
return importedTarget->second;
}
} }
return i->second;
} }
return 0; return 0;
} }
@ -1549,12 +1561,12 @@ std::vector<cmTarget *>& cmGlobalGenerator
if(emitted.insert(lib->first).second) if(emitted.insert(lib->first).second)
{ {
cmTarget *target2 = cmTarget *target2 =
target.GetMakefile()->FindTarget(lib->first.c_str()); target.GetMakefile()->FindTarget(lib->first.c_str(), false);
// search each local generator until a match is found // search each local generator until a match is found
if (!target2) if (!target2)
{ {
target2 = this->FindTarget(0,lib->first.c_str()); target2 = this->FindTarget(0,lib->first.c_str(), false);
} }
// if a match was found then ... // if a match was found then ...
@ -1575,12 +1587,12 @@ std::vector<cmTarget *>& cmGlobalGenerator
// Don't emit the same utility twice for this target. // Don't emit the same utility twice for this target.
if(emitted.insert(*util).second) if(emitted.insert(*util).second)
{ {
cmTarget *target2 = target.GetMakefile()->FindTarget(util->c_str()); cmTarget *target2 = target.GetMakefile()->FindTarget(util->c_str(), false);
// search each local generator until a match is found // search each local generator until a match is found
if (!target2) if (!target2)
{ {
target2 = this->FindTarget(0,util->c_str()); target2 = this->FindTarget(0,util->c_str(), false);
} }
// if a match was found then ... // if a match was found then ...
@ -1594,3 +1606,14 @@ std::vector<cmTarget *>& cmGlobalGenerator
return result; return result;
} }
void cmGlobalGenerator::AddTarget(cmTargets::value_type &v)
{
if (v.second.IsImported())
{
this->ImportedTotalTargets[v.first] = &v.second;
}
else
{
this->TotalTargets[v.first] = &v.second;
}
}

View File

@ -157,7 +157,7 @@ public:
void FindMakeProgram(cmMakefile*); void FindMakeProgram(cmMakefile*);
///! Find a target by name by searching the local generators. ///! Find a target by name by searching the local generators.
cmTarget* FindTarget(const char* project, const char* name); cmTarget* FindTarget(const char* project, const char* name, bool useImportedTargets);
/** If check to see if the target is linked to by any other /** If check to see if the target is linked to by any other
target in the project */ target in the project */
@ -177,9 +177,8 @@ public:
configuration. This is valid during generation only. */ configuration. This is valid during generation only. */
cmTargetManifest const& GetTargetManifest() { return this->TargetManifest; } cmTargetManifest const& GetTargetManifest() { return this->TargetManifest; }
void AddTarget(cmTargets::value_type &v) { void AddTarget(cmTargets::value_type &v);
this->TotalTargets[v.first] = &v.second;};
/** Support for multiple custom command outputs. */ /** Support for multiple custom command outputs. */
virtual void CheckMultipleOutputs(cmMakefile* mf, bool verbose); virtual void CheckMultipleOutputs(cmMakefile* mf, bool verbose);
@ -240,6 +239,7 @@ private:
// this is used to improve performance // this is used to improve performance
std::map<cmStdString,cmTarget *> TotalTargets; std::map<cmStdString,cmTarget *> TotalTargets;
std::map<cmStdString,cmTarget *> ImportedTotalTargets;
std::map<cmStdString, std::vector<cmTarget *> > TargetDependencies; std::map<cmStdString, std::vector<cmTarget *> > TargetDependencies;
}; };

View File

@ -641,51 +641,49 @@ cmGlobalUnixMakefileGenerator3
// simple name) // simple name)
if(t->second.GetName() && if(t->second.GetName() &&
strlen(t->second.GetName()) && strlen(t->second.GetName()) &&
emitted.insert(t->second.GetName()).second) emitted.insert(t->second.GetName()).second &&
// Handle user targets here. Global targets are handled in
// the local generator on a per-directory basis.
((t->second.GetType() == cmTarget::EXECUTABLE) ||
(t->second.GetType() == cmTarget::STATIC_LIBRARY) ||
(t->second.GetType() == cmTarget::SHARED_LIBRARY) ||
(t->second.GetType() == cmTarget::MODULE_LIBRARY) ||
(t->second.GetType() == cmTarget::UTILITY)))
{ {
// Handle user targets here. Global targets are handled in // Add a rule to build the target by name.
// the local generator on a per-directory basis. lg->WriteDivider(ruleFileStream);
if((t->second.GetType() == cmTarget::EXECUTABLE) || ruleFileStream
(t->second.GetType() == cmTarget::STATIC_LIBRARY) || << "# Target rules for targets named "
(t->second.GetType() == cmTarget::SHARED_LIBRARY) || << t->second.GetName() << "\n\n";
(t->second.GetType() == cmTarget::MODULE_LIBRARY) ||
(t->second.GetType() == cmTarget::UTILITY)) // Write the rule.
{ commands.clear();
// Add a rule to build the target by name. std::string tmp = cmake::GetCMakeFilesDirectoryPostSlash();
lg->WriteDivider(ruleFileStream); tmp += "Makefile2";
ruleFileStream commands.push_back(lg->GetRecursiveMakeCall
<< "# Target rules for targets named " (tmp.c_str(),t->second.GetName()));
<< t->second.GetName() << "\n\n"; depends.clear();
depends.push_back("cmake_check_build_system");
// Write the rule. lg->WriteMakeRule(ruleFileStream,
commands.clear(); "Build rule for target.",
std::string tmp = cmake::GetCMakeFilesDirectoryPostSlash(); t->second.GetName(), depends, commands,
tmp += "Makefile2"; true);
commands.push_back(lg->GetRecursiveMakeCall
(tmp.c_str(),t->second.GetName())); // Add a fast rule to build the target
depends.clear(); std::string localName = lg->GetRelativeTargetDirectory(t->second);
depends.push_back("cmake_check_build_system"); std::string makefileName;
lg->WriteMakeRule(ruleFileStream, makefileName = localName;
"Build rule for target.", makefileName += "/build.make";
t->second.GetName(), depends, commands, depends.clear();
true); commands.clear();
std::string makeTargetName = localName;
// Add a fast rule to build the target makeTargetName += "/build";
std::string localName = lg->GetRelativeTargetDirectory(t->second); localName = t->second.GetName();
std::string makefileName; localName += "/fast";
makefileName = localName; commands.push_back(lg->GetRecursiveMakeCall
makefileName += "/build.make"; (makefileName.c_str(), makeTargetName.c_str()));
depends.clear(); lg->WriteMakeRule(ruleFileStream, "fast build rule for target.",
commands.clear(); localName.c_str(), depends, commands, true);
std::string makeTargetName = localName;
makeTargetName += "/build";
localName = t->second.GetName();
localName += "/fast";
commands.push_back(lg->GetRecursiveMakeCall
(makefileName.c_str(), makeTargetName.c_str()));
lg->WriteMakeRule(ruleFileStream, "fast build rule for target.",
localName.c_str(), depends, commands, true);
}
} }
} }
} }
@ -714,7 +712,13 @@ cmGlobalUnixMakefileGenerator3
cmTargets& targets = lg->GetMakefile()->GetTargets(); cmTargets& targets = lg->GetMakefile()->GetTargets();
for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t) for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
{ {
if (t->second.GetName() && strlen(t->second.GetName())) if (t->second.GetName()
&& strlen(t->second.GetName())
&& ((t->second.GetType() == cmTarget::EXECUTABLE)
|| (t->second.GetType() == cmTarget::STATIC_LIBRARY)
|| (t->second.GetType() == cmTarget::SHARED_LIBRARY)
|| (t->second.GetType() == cmTarget::MODULE_LIBRARY)
|| (t->second.GetType() == cmTarget::UTILITY)))
{ {
std::string makefileName; std::string makefileName;
// Add a rule to build the target by name. // Add a rule to build the target by name.
@ -722,165 +726,158 @@ cmGlobalUnixMakefileGenerator3
makefileName = localName; makefileName = localName;
makefileName += "/build.make"; makefileName += "/build.make";
if (((t->second.GetType() == cmTarget::EXECUTABLE) || bool needRequiresStep =
(t->second.GetType() == cmTarget::STATIC_LIBRARY) || this->NeedRequiresStep(lg,t->second.GetName());
(t->second.GetType() == cmTarget::SHARED_LIBRARY) ||
(t->second.GetType() == cmTarget::MODULE_LIBRARY) ||
(t->second.GetType() == cmTarget::UTILITY)))
{
bool needRequiresStep =
this->NeedRequiresStep(lg,t->second.GetName());
lg->WriteDivider(ruleFileStream);
ruleFileStream
<< "# Target rules for target "
<< localName << "\n\n";
commands.clear(); lg->WriteDivider(ruleFileStream);
if (t->second.GetType() != cmTarget::UTILITY) ruleFileStream
<< "# Target rules for target "
<< localName << "\n\n";
commands.clear();
if (t->second.GetType() != cmTarget::UTILITY)
{
makeTargetName = localName;
makeTargetName += "/depend";
commands.push_back(lg->GetRecursiveMakeCall
(makefileName.c_str(),makeTargetName.c_str()));
// add requires if we need it for this generator
if (needRequiresStep)
{ {
makeTargetName = localName; makeTargetName = localName;
makeTargetName += "/depend"; makeTargetName += "/requires";
commands.push_back(lg->GetRecursiveMakeCall commands.push_back(lg->GetRecursiveMakeCall
(makefileName.c_str(),makeTargetName.c_str())); (makefileName.c_str(),makeTargetName.c_str()));
// add requires if we need it for this generator
if (needRequiresStep)
{
makeTargetName = localName;
makeTargetName += "/requires";
commands.push_back(lg->GetRecursiveMakeCall
(makefileName.c_str(),makeTargetName.c_str()));
}
} }
makeTargetName = localName; }
makeTargetName += "/build"; makeTargetName = localName;
commands.push_back(lg->GetRecursiveMakeCall makeTargetName += "/build";
(makefileName.c_str(),makeTargetName.c_str())); commands.push_back(lg->GetRecursiveMakeCall
(makefileName.c_str(),makeTargetName.c_str()));
// Write the rule.
localName += "/all"; // Write the rule.
depends.clear(); localName += "/all";
depends.clear();
std::string progressDir = std::string progressDir =
lg->GetMakefile()->GetHomeOutputDirectory(); lg->GetMakefile()->GetHomeOutputDirectory();
progressDir += cmake::GetCMakeFilesDirectory(); progressDir += cmake::GetCMakeFilesDirectory();
{
cmOStringStream progCmd;
progCmd << "$(CMAKE_COMMAND) -E cmake_progress_report ";
// all target counts
progCmd << lg->Convert(progressDir.c_str(),
cmLocalGenerator::FULL,
cmLocalGenerator::SHELL);
progCmd << " ";
std::vector<int> &progFiles = lg->ProgressFiles[t->first];
for (std::vector<int>::iterator i = progFiles.begin();
i != progFiles.end(); ++i)
{
progCmd << " " << *i;
}
commands.push_back(progCmd.str());
}
progressDir = "Built target ";
progressDir += t->first;
lg->AppendEcho(commands,progressDir.c_str());
this->AppendGlobalTargetDepends(depends,t->second);
lg->WriteMakeRule(ruleFileStream, "All Build rule for target.",
localName.c_str(), depends, commands, true);
// add the all/all dependency
if (!exclude && !t->second.GetPropertyAsBool("EXCLUDE_FROM_ALL"))
{
depends.clear();
depends.push_back(localName);
commands.clear();
lg->WriteMakeRule(ruleFileStream, "Include target in all.",
"all", depends, commands, true);
}
// Write the rule.
commands.clear();
progressDir = lg->GetMakefile()->GetHomeOutputDirectory();
progressDir += cmake::GetCMakeFilesDirectory();
{
// TODO: Convert the total progress count to a make variable.
cmOStringStream progCmd;
progCmd << "$(CMAKE_COMMAND) -E cmake_progress_start ";
// # in target
progCmd << lg->Convert(progressDir.c_str(),
cmLocalGenerator::FULL,
cmLocalGenerator::SHELL);
//
std::set<cmStdString> emitted;
progCmd << " "
<< this->GetTargetTotalNumberOfActions(t->second,
emitted);
commands.push_back(progCmd.str());
}
std::string tmp = cmake::GetCMakeFilesDirectoryPostSlash();
tmp += "Makefile2";
commands.push_back(lg->GetRecursiveMakeCall
(tmp.c_str(),localName.c_str()));
{ {
cmOStringStream progCmd; cmOStringStream progCmd;
progCmd << "$(CMAKE_COMMAND) -E cmake_progress_start "; // # 0 progCmd << "$(CMAKE_COMMAND) -E cmake_progress_report ";
// all target counts
progCmd << lg->Convert(progressDir.c_str(), progCmd << lg->Convert(progressDir.c_str(),
cmLocalGenerator::FULL, cmLocalGenerator::FULL,
cmLocalGenerator::SHELL); cmLocalGenerator::SHELL);
progCmd << " 0"; progCmd << " ";
std::vector<int> &progFiles = lg->ProgressFiles[t->first];
for (std::vector<int>::iterator i = progFiles.begin();
i != progFiles.end(); ++i)
{
progCmd << " " << *i;
}
commands.push_back(progCmd.str()); commands.push_back(progCmd.str());
} }
depends.clear(); progressDir = "Built target ";
depends.push_back("cmake_check_build_system"); progressDir += t->first;
localName = lg->GetRelativeTargetDirectory(t->second); lg->AppendEcho(commands,progressDir.c_str());
localName += "/rule";
lg->WriteMakeRule(ruleFileStream, this->AppendGlobalTargetDepends(depends,t->second);
"Build rule for subdir invocation for target.", lg->WriteMakeRule(ruleFileStream, "All Build rule for target.",
localName.c_str(), depends, commands, true); localName.c_str(), depends, commands, true);
// Add a target with the canonical name (no prefix, suffix or path). // add the all/all dependency
commands.clear(); if (!exclude && !t->second.GetPropertyAsBool("EXCLUDE_FROM_ALL"))
{
depends.clear(); depends.clear();
depends.push_back(localName); depends.push_back(localName);
lg->WriteMakeRule(ruleFileStream, "Convenience name for target.", commands.clear();
t->second.GetName(), depends, commands, true); lg->WriteMakeRule(ruleFileStream, "Include target in all.",
"all", depends, commands, true);
// Add rules to prepare the target for installation. }
if(t->second.NeedRelinkBeforeInstall())
{ // Write the rule.
localName = lg->GetRelativeTargetDirectory(t->second); commands.clear();
localName += "/preinstall"; progressDir = lg->GetMakefile()->GetHomeOutputDirectory();
depends.clear(); progressDir += cmake::GetCMakeFilesDirectory();
commands.clear();
commands.push_back(lg->GetRecursiveMakeCall {
(makefileName.c_str(), localName.c_str())); // TODO: Convert the total progress count to a make variable.
lg->WriteMakeRule(ruleFileStream, cmOStringStream progCmd;
"Pre-install relink rule for target.", progCmd << "$(CMAKE_COMMAND) -E cmake_progress_start ";
localName.c_str(), depends, commands, true); // # in target
depends.clear(); progCmd << lg->Convert(progressDir.c_str(),
depends.push_back(localName); cmLocalGenerator::FULL,
commands.clear(); cmLocalGenerator::SHELL);
lg->WriteMakeRule(ruleFileStream, "Prepare target for install.", //
"preinstall", depends, commands, true); std::set<cmStdString> emitted;
} progCmd << " "
<< this->GetTargetTotalNumberOfActions(t->second,
// add the clean rule emitted);
commands.push_back(progCmd.str());
}
std::string tmp = cmake::GetCMakeFilesDirectoryPostSlash();
tmp += "Makefile2";
commands.push_back(lg->GetRecursiveMakeCall
(tmp.c_str(),localName.c_str()));
{
cmOStringStream progCmd;
progCmd << "$(CMAKE_COMMAND) -E cmake_progress_start "; // # 0
progCmd << lg->Convert(progressDir.c_str(),
cmLocalGenerator::FULL,
cmLocalGenerator::SHELL);
progCmd << " 0";
commands.push_back(progCmd.str());
}
depends.clear();
depends.push_back("cmake_check_build_system");
localName = lg->GetRelativeTargetDirectory(t->second);
localName += "/rule";
lg->WriteMakeRule(ruleFileStream,
"Build rule for subdir invocation for target.",
localName.c_str(), depends, commands, true);
// Add a target with the canonical name (no prefix, suffix or path).
commands.clear();
depends.clear();
depends.push_back(localName);
lg->WriteMakeRule(ruleFileStream, "Convenience name for target.",
t->second.GetName(), depends, commands, true);
// Add rules to prepare the target for installation.
if(t->second.NeedRelinkBeforeInstall())
{
localName = lg->GetRelativeTargetDirectory(t->second); localName = lg->GetRelativeTargetDirectory(t->second);
makeTargetName = localName; localName += "/preinstall";
makeTargetName += "/clean";
depends.clear(); depends.clear();
commands.clear(); commands.clear();
commands.push_back(lg->GetRecursiveMakeCall commands.push_back(lg->GetRecursiveMakeCall
(makefileName.c_str(), makeTargetName.c_str())); (makefileName.c_str(), localName.c_str()));
lg->WriteMakeRule(ruleFileStream, "clean rule for target.", lg->WriteMakeRule(ruleFileStream,
makeTargetName.c_str(), depends, commands, true); "Pre-install relink rule for target.",
localName.c_str(), depends, commands, true);
depends.clear();
depends.push_back(localName);
commands.clear(); commands.clear();
depends.push_back(makeTargetName); lg->WriteMakeRule(ruleFileStream, "Prepare target for install.",
lg->WriteMakeRule(ruleFileStream, "clean rule for target.", "preinstall", depends, commands, true);
"clean", depends, commands, true);
} }
// add the clean rule
localName = lg->GetRelativeTargetDirectory(t->second);
makeTargetName = localName;
makeTargetName += "/clean";
depends.clear();
commands.clear();
commands.push_back(lg->GetRecursiveMakeCall
(makefileName.c_str(), makeTargetName.c_str()));
lg->WriteMakeRule(ruleFileStream, "clean rule for target.",
makeTargetName.c_str(), depends, commands, true);
commands.clear();
depends.push_back(makeTargetName);
lg->WriteMakeRule(ruleFileStream, "clean rule for target.",
"clean", depends, commands, true);
} }
} }
} }
@ -1060,12 +1057,12 @@ cmGlobalUnixMakefileGenerator3
// first check the same dir as the current target // first check the same dir as the current target
lg3 = static_cast<cmLocalUnixMakefileGenerator3 *> lg3 = static_cast<cmLocalUnixMakefileGenerator3 *>
(target.GetMakefile()->GetLocalGenerator()); (target.GetMakefile()->GetLocalGenerator());
result = target.GetMakefile()->FindTarget(name); result = target.GetMakefile()->FindTarget(name, false);
// search each local generator until a match is found // search each local generator until a match is found
if (!result) if (!result)
{ {
result = this->FindTarget(0,name); result = this->FindTarget(0, name, false);
if (result) if (result)
{ {
lg3 = static_cast<cmLocalUnixMakefileGenerator3 *> lg3 = static_cast<cmLocalUnixMakefileGenerator3 *>

View File

@ -401,7 +401,7 @@ void cmGlobalVisualStudio6Generator::WriteProject(std::ostream& fout,
if(j->first != dspname) if(j->first != dspname)
{ {
// is the library part of this DSW ? If so add dependency // is the library part of this DSW ? If so add dependency
if(this->FindTarget(0, j->first.c_str())) if(this->FindTarget(0, j->first.c_str()), false)
{ {
fout << "Begin Project Dependency\n"; fout << "Begin Project Dependency\n";
fout << "Project_Dep_Name " << j->first.c_str() << "\n"; fout << "Project_Dep_Name " << j->first.c_str() << "\n";

View File

@ -333,7 +333,9 @@ cmGlobalVisualStudio71Generator
if(j->first != dspname) if(j->first != dspname)
{ {
// is the library part of this SLN ? If so add dependency // is the library part of this SLN ? If so add dependency
if(this->FindTarget(this->CurrentProject.c_str(), j->first.c_str())) if(this->FindTarget(this->CurrentProject.c_str(),
j->first.c_str()),
false)
{ {
fout << "\t\t{" << this->GetGUID(j->first.c_str()) << "} = {" fout << "\t\t{" << this->GetGUID(j->first.c_str()) << "} = {"
<< this->GetGUID(j->first.c_str()) << "}\n"; << this->GetGUID(j->first.c_str()) << "}\n";

View File

@ -588,7 +588,9 @@ cmGlobalVisualStudio7Generator
if(j->first != dspname) if(j->first != dspname)
{ {
// is the library part of this SLN ? If so add dependency // is the library part of this SLN ? If so add dependency
if(this->FindTarget(this->CurrentProject.c_str(), j->first.c_str())) if(this->FindTarget(this->CurrentProject.c_str(),
j->first.c_str()),
false)
{ {
std::string guid = this->GetGUID(j->first.c_str()); std::string guid = this->GetGUID(j->first.c_str());
if(guid.size() == 0) if(guid.size() == 0)

View File

@ -94,7 +94,7 @@ void cmGlobalVisualStudio8Generator::Generate()
mf->AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET, false, mf->AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET, false,
no_working_directory, no_depends, no_working_directory, no_depends,
noCommandLines); noCommandLines);
cmTarget* tgt = mf->FindTarget(CMAKE_CHECK_BUILD_SYSTEM_TARGET); cmTarget* tgt = mf->FindTarget(CMAKE_CHECK_BUILD_SYSTEM_TARGET, false);
if(!tgt) if(!tgt)
{ {
cmSystemTools::Error("Error adding target " cmSystemTools::Error("Error adding target "

View File

@ -104,7 +104,7 @@ cmGlobalVisualStudioGenerator::FixUtilityDependsForTarget(cmTarget& target)
target.GetUtilities().begin(); target.GetUtilities().begin();
ui != target.GetUtilities().end(); ++ui) ui != target.GetUtilities().end(); ++ui)
{ {
if(cmTarget* depTarget = this->FindTarget(0, ui->c_str())) if(cmTarget* depTarget = this->FindTarget(0, ui->c_str(), false))
{ {
if(depTarget->GetType() == cmTarget::STATIC_LIBRARY || if(depTarget->GetType() == cmTarget::STATIC_LIBRARY ||
depTarget->GetType() == cmTarget::SHARED_LIBRARY || depTarget->GetType() == cmTarget::SHARED_LIBRARY ||
@ -149,7 +149,7 @@ cmGlobalVisualStudioGenerator::CreateUtilityDependTarget(cmTarget& target)
this->CreateGUID(altNameStr.c_str()); this->CreateGUID(altNameStr.c_str());
// The intermediate target should depend on the original target. // The intermediate target should depend on the original target.
if(cmTarget* alt = this->FindTarget(0, altNameStr.c_str())) if(cmTarget* alt = this->FindTarget(0, altNameStr.c_str(), false))
{ {
alt->AddUtility(target.GetName()); alt->AddUtility(target.GetName());
} }
@ -205,7 +205,7 @@ cmGlobalVisualStudioGenerator::GetUtilityForTarget(cmTarget& target,
{ {
// The depender is a target that links. Lookup the dependee to // The depender is a target that links. Lookup the dependee to
// see if it provides an alternative dependency name. // see if it provides an alternative dependency name.
if(cmTarget* depTarget = this->FindTarget(0, name)) if(cmTarget* depTarget = this->FindTarget(0, name, false))
{ {
// Check for an alternative name created by FixUtilityDepends. // Check for an alternative name created by FixUtilityDepends.
if(const char* altName = if(const char* altName =

View File

@ -272,7 +272,7 @@ cmGlobalXCodeGenerator::AddExtraTargets(cmLocalGenerator* root,
mf->AddUtilityCommand("ALL_BUILD", true, no_depends, mf->AddUtilityCommand("ALL_BUILD", true, no_depends,
no_working_directory, no_working_directory,
"echo", "Build all projects"); "echo", "Build all projects");
cmTarget* allbuild = mf->FindTarget("ALL_BUILD"); cmTarget* allbuild = mf->FindTarget("ALL_BUILD", false);
// Add XCODE depend helper // Add XCODE depend helper
std::string dir = mf->GetCurrentOutputDirectory(); std::string dir = mf->GetCurrentOutputDirectory();
@ -1035,8 +1035,7 @@ void cmGlobalXCodeGenerator
cc.GetDepends().begin(); cc.GetDepends().begin();
d != cc.GetDepends().end(); ++d) d != cc.GetDepends().end(); ++d)
{ {
if(!this->FindTarget(this->CurrentProject.c_str(), if(!this->FindTarget(this->CurrentProject.c_str(), d->c_str(), false))
d->c_str()))
{ {
// if the depend is not a target but // if the depend is not a target but
// is a full path then use it, if not then // is a full path then use it, if not then
@ -1860,7 +1859,7 @@ void cmGlobalXCodeGenerator
{ {
// Add this dependency. // Add this dependency.
cmTarget* t = this->FindTarget(this->CurrentProject.c_str(), cmTarget* t = this->FindTarget(this->CurrentProject.c_str(),
lib->first.c_str()); lib->first.c_str(), false);
cmXCodeObject* dptarget = this->FindXCodeTarget(t); cmXCodeObject* dptarget = this->FindXCodeTarget(t);
if(dptarget) if(dptarget)
{ {
@ -1876,7 +1875,7 @@ void cmGlobalXCodeGenerator
i != cmtarget->GetUtilities().end(); ++i) i != cmtarget->GetUtilities().end(); ++i)
{ {
cmTarget* t = this->FindTarget(this->CurrentProject.c_str(), cmTarget* t = this->FindTarget(this->CurrentProject.c_str(),
i->c_str()); i->c_str(), false);
// if the target is in this project then make target depend // if the target is in this project then make target depend
// on it. It may not be in this project if this is a sub // on it. It may not be in this project if this is a sub
// project from the top. // project from the top.

View File

@ -50,10 +50,8 @@ bool cmIncludeExternalMSProjectCommand
cmSystemTools::ConvertToUnixSlashes(path); cmSystemTools::ConvertToUnixSlashes(path);
// Create a target instance for this utility. // Create a target instance for this utility.
cmTarget target; cmTarget* target=this->Makefile->AddNewTarget(cmTarget::UTILITY, utility_name.c_str());
target.SetType(cmTarget::UTILITY, utility_name.c_str()); target->SetProperty("EXCLUDE_FROM_ALL","FALSE");
target.SetProperty("EXCLUDE_FROM_ALL","FALSE");
target.SetMakefile(this->Makefile);
std::vector<std::string> no_outputs; std::vector<std::string> no_outputs;
cmCustomCommandLines commandLines; cmCustomCommandLines commandLines;
cmCustomCommandLine commandLine; cmCustomCommandLine commandLine;
@ -61,13 +59,7 @@ bool cmIncludeExternalMSProjectCommand
commandLine.push_back(path); commandLine.push_back(path);
commandLines.push_back(commandLine); commandLines.push_back(commandLine);
cmCustomCommand cc(no_outputs, depends, commandLines, 0, 0); cmCustomCommand cc(no_outputs, depends, commandLines, 0, 0);
target.GetPostBuildCommands().push_back(cc); target->GetPostBuildCommands().push_back(cc);
// Add the target to the set of targets.
cmTargets::iterator it =
this->Makefile->GetTargets()
.insert(cmTargets::value_type(utility_name.c_str(),target)).first;
this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->AddTarget(*it);
} }
#endif #endif
return true; return true;

View File

@ -252,7 +252,7 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
else if(doing_targets) else if(doing_targets)
{ {
// Lookup this target in the current directory. // Lookup this target in the current directory.
if(cmTarget* target = this->Makefile->FindTarget(args[i].c_str())) if(cmTarget* target = this->Makefile->FindTarget(args[i].c_str(), false))
{ {
// Found the target. Check its type. // Found the target. Check its type.
if(target->GetType() != cmTarget::EXECUTABLE && if(target->GetType() != cmTarget::EXECUTABLE &&

View File

@ -376,7 +376,7 @@ void cmInstallTargetGenerator
{ {
if(cmTarget* tgt = this->Target->GetMakefile()-> if(cmTarget* tgt = this->Target->GetMakefile()->
GetLocalGenerator()->GetGlobalGenerator()-> GetLocalGenerator()->GetGlobalGenerator()->
FindTarget(0, lib.c_str())) FindTarget(0, lib.c_str(), false))
{ {
if(tgt->GetType() == cmTarget::SHARED_LIBRARY) if(tgt->GetType() == cmTarget::SHARED_LIBRARY)
{ {

View File

@ -148,8 +148,7 @@ void cmLocalGenerator::TraceDependencies()
if ((t->second.GetType() != cmTarget::INSTALL_FILES) if ((t->second.GetType() != cmTarget::INSTALL_FILES)
&& (t->second.GetType() != cmTarget::INSTALL_PROGRAMS) && (t->second.GetType() != cmTarget::INSTALL_PROGRAMS)
&& (t->second.GetType() != cmTarget::INSTALL_DIRECTORY) && (t->second.GetType() != cmTarget::INSTALL_DIRECTORY)
&& (strncmp(t->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) != 0) && (strncmp(t->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) != 0))
&& (t->second.GetPropertyAsBool("IMPORTED") == false))
{ {
std::string projectFilename; std::string projectFilename;
if (this->IsMakefileGenerator == false) // only use of this variable if (this->IsMakefileGenerator == false) // only use of this variable
@ -1733,7 +1732,7 @@ void cmLocalGenerator
(j->second == cmTarget::GENERAL || j->second == linkType)) (j->second == cmTarget::GENERAL || j->second == linkType))
{ {
// Compute the proper name to use to link this library. // Compute the proper name to use to link this library.
cmTarget* tgt = this->GlobalGenerator->FindTarget(0, lib.c_str()); cmTarget* tgt = this->GlobalGenerator->FindTarget(0, lib.c_str(), false);
bool impexe = (tgt && bool impexe = (tgt &&
tgt->GetType() == cmTarget::EXECUTABLE && tgt->GetType() == cmTarget::EXECUTABLE &&
tgt->GetPropertyAsBool("ENABLE_EXPORTS")); tgt->GetPropertyAsBool("ENABLE_EXPORTS"));
@ -1963,7 +1962,7 @@ std::string cmLocalGenerator::GetRealDependency(const char* inName,
} }
// Look for a CMake target with the given name. // Look for a CMake target with the given name.
if(cmTarget* target = this->GlobalGenerator->FindTarget(0, name.c_str())) if(cmTarget* target = this->GlobalGenerator->FindTarget(0,name.c_str(),false))
{ {
// make sure it is not just a coincidence that the target name // make sure it is not just a coincidence that the target name
// found is part of the inName // found is part of the inName
@ -2029,8 +2028,8 @@ std::string cmLocalGenerator::GetRealLocation(const char* inName,
{ {
std::string outName=inName; std::string outName=inName;
// Look for a CMake target with the given name. // Look for a CMake target with the given name.
cmTarget* target = this->GlobalGenerator->FindTarget(0, inName); cmTarget* target = this->GlobalGenerator->FindTarget(0, inName, true);
if ((target!=0) && (target->GetType()==cmTarget::EXECUTABLE)) if ((target != 0) && (target->GetType() == cmTarget::EXECUTABLE))
{ {
outName = target->GetLocation( config ); outName = target->GetLocation( config );
} }

View File

@ -114,7 +114,6 @@ void cmLocalUnixMakefileGenerator3::Generate()
if (tg) if (tg)
{ {
this->TargetGenerators.push_back(tg); this->TargetGenerators.push_back(tg);
// t->second.TraceVSDependencies(empty, this->Makefile);
tg->WriteRuleFiles(); tg->WriteRuleFiles();
} }
} }

View File

@ -1051,7 +1051,8 @@ void cmLocalVisualStudio6Generator
// Compute the proper name to use to link this library. // Compute the proper name to use to link this library.
std::string lib; std::string lib;
std::string libDebug; std::string libDebug;
cmTarget* tgt = this->GlobalGenerator->FindTarget(0, j->first.c_str()); cmTarget* tgt = this->GlobalGenerator->FindTarget(0, j->first.c_str(),
false);
if(tgt) if(tgt)
{ {
lib = cmSystemTools::GetFilenameWithoutExtension lib = cmSystemTools::GetFilenameWithoutExtension

View File

@ -825,12 +825,10 @@ void cmMakefile::AddUtilityCommand(const char* utilityName,
bool escapeOldStyle, const char* comment) bool escapeOldStyle, const char* comment)
{ {
// Create a target instance for this utility. // Create a target instance for this utility.
cmTarget target; cmTarget* target = this->AddNewTarget(cmTarget::UTILITY, utilityName, false);
target.SetMakefile(this);
target.SetType(cmTarget::UTILITY, utilityName);
if (excludeFromAll) if (excludeFromAll)
{ {
target.SetProperty("EXCLUDE_FROM_ALL", "TRUE"); target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
} }
if(!comment) if(!comment)
{ {
@ -850,7 +848,7 @@ void cmMakefile::AddUtilityCommand(const char* utilityName,
commandLines, comment, commandLines, comment,
workingDirectory, no_replace, workingDirectory, no_replace,
escapeOldStyle); escapeOldStyle);
target.GetSourceLists().push_back(force); target->GetSourceLists().push_back(force);
// The output is not actually created so mark it symbolic. // The output is not actually created so mark it symbolic.
if(cmSourceFile* sf = this->GetSource(force.c_str())) if(cmSourceFile* sf = this->GetSource(force.c_str()))
@ -862,11 +860,6 @@ void cmMakefile::AddUtilityCommand(const char* utilityName,
cmSystemTools::Error("Could not get source file entry for ", cmSystemTools::Error("Could not get source file entry for ",
force.c_str()); force.c_str());
} }
// Add the target to the set of targets.
cmTargets::iterator it =
this->Targets.insert(cmTargets::value_type(utilityName,target)).first;
this->LocalGenerator->GetGlobalGenerator()->AddTarget(*it);
} }
void cmMakefile::AddDefineFlag(const char* flag) void cmMakefile::AddDefineFlag(const char* flag)
@ -940,7 +933,7 @@ void cmMakefile::AddLinkLibraryForTarget(const char *target,
if ( i != this->Targets.end()) if ( i != this->Targets.end())
{ {
cmTarget* tgt = cmTarget* tgt =
this->GetCMakeInstance()->GetGlobalGenerator()->FindTarget(0, lib); this->GetCMakeInstance()->GetGlobalGenerator()->FindTarget(0, lib, false);
if(tgt) if(tgt)
{ {
bool allowModules = true; bool allowModules = true;
@ -1343,53 +1336,64 @@ void cmMakefile::AddLibrary(const char* lname, int shared,
const std::vector<std::string> &srcs, const std::vector<std::string> &srcs,
bool excludeFromAll) bool excludeFromAll)
{ {
cmTarget target; cmTarget* target=0;
switch (shared) switch (shared)
{ {
case 0: case 0:
target.SetType(cmTarget::STATIC_LIBRARY, lname); target=this->AddNewTarget(cmTarget::STATIC_LIBRARY, lname, false);
break; break;
case 1: case 1:
target.SetType(cmTarget::SHARED_LIBRARY, lname); target=this->AddNewTarget(cmTarget::SHARED_LIBRARY, lname, false);
break; break;
case 2: case 2:
target.SetType(cmTarget::MODULE_LIBRARY, lname); target=this->AddNewTarget(cmTarget::MODULE_LIBRARY, lname, false);
break; break;
default: default:
target.SetType(cmTarget::STATIC_LIBRARY, lname); target=this->AddNewTarget(cmTarget::STATIC_LIBRARY, lname, false);
} }
target.SetMakefile(this);
// Clear its dependencies. Otherwise, dependencies might persist // Clear its dependencies. Otherwise, dependencies might persist
// over changes in CMakeLists.txt, making the information stale and // over changes in CMakeLists.txt, making the information stale and
// hence useless. // hence useless.
target.ClearDependencyInformation( *this, lname ); target->ClearDependencyInformation( *this, lname );
if(excludeFromAll) if(excludeFromAll)
{ {
target.SetProperty("EXCLUDE_FROM_ALL", "TRUE"); target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
} }
target.GetSourceLists() = srcs; target->GetSourceLists() = srcs;
this->AddGlobalLinkInformation(lname, target); this->AddGlobalLinkInformation(lname, *target);
cmTargets::iterator it =
this->Targets.insert(cmTargets::value_type(lname,target)).first;
this->LocalGenerator->GetGlobalGenerator()->AddTarget(*it);
} }
cmTarget* cmMakefile::AddExecutable(const char *exeName, cmTarget* cmMakefile::AddExecutable(const char *exeName,
const std::vector<std::string> &srcs, const std::vector<std::string> &srcs,
bool excludeFromAll) bool excludeFromAll)
{ {
cmTarget target; cmTarget* target = this->AddNewTarget(cmTarget::EXECUTABLE, exeName, false);
target.SetType(cmTarget::EXECUTABLE, exeName);
target.SetMakefile(this);
if(excludeFromAll) if(excludeFromAll)
{ {
target.SetProperty("EXCLUDE_FROM_ALL", "TRUE"); target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
} }
target.GetSourceLists() = srcs; target->GetSourceLists() = srcs;
this->AddGlobalLinkInformation(exeName, target); this->AddGlobalLinkInformation(exeName, *target);
cmTargets::iterator it = return target;
this->Targets.insert(cmTargets::value_type(exeName,target)).first; }
cmTarget* cmMakefile::AddNewTarget(cmTarget::TargetType type, const char* name, bool isImported)
{
cmTargets::iterator it;
cmTarget target;
target.SetType(type, name);
target.SetMakefile(this);
if (isImported)
{
target.MarkAsImported();
it=this->ImportedTargets.insert(cmTargets::value_type(target.GetName(), target)).first;
}
else
{
it=this->Targets.insert(cmTargets::value_type(target.GetName(), target)).first;
}
this->LocalGenerator->GetGlobalGenerator()->AddTarget(*it); this->LocalGenerator->GetGlobalGenerator()->AddTarget(*it);
return &it->second; return &it->second;
} }
@ -2709,7 +2713,7 @@ const char *cmMakefile::GetProperty(const char* prop,
return this->GetCMakeInstance()->GetProperty(prop,scope); return this->GetCMakeInstance()->GetProperty(prop,scope);
} }
return retVal; return retVal;
} }
bool cmMakefile::GetPropertyAsBool(const char* prop) bool cmMakefile::GetPropertyAsBool(const char* prop)
@ -2718,16 +2722,26 @@ bool cmMakefile::GetPropertyAsBool(const char* prop)
} }
cmTarget* cmMakefile::FindTarget(const char* name) cmTarget* cmMakefile::FindTarget(const char* name, bool useImportedTargets)
{ {
cmTargets& tgts = this->GetTargets(); cmTargets& tgts = this->GetTargets();
cmTargets::iterator i = tgts.find(name); cmTargets::iterator i = tgts.find ( name );
if (i == tgts.end()) if ( i != tgts.end() )
{ {
return 0; return &i->second;
} }
return &i->second;
if (useImportedTargets)
{
cmTargets::iterator impTarget = this->ImportedTargets.find(name);
if (impTarget != this->ImportedTargets.end())
{
return &impTarget->second;
}
}
return 0;
} }
cmTest* cmMakefile::CreateTest(const char* testName) cmTest* cmMakefile::CreateTest(const char* testName)

View File

@ -167,6 +167,8 @@ public:
void AddDefineFlag(const char* definition); void AddDefineFlag(const char* definition);
void RemoveDefineFlag(const char* definition); void RemoveDefineFlag(const char* definition);
cmTarget* AddNewTarget(cmTarget::TargetType type, const char* name, bool isImported);
/** /**
* Add an executable to the build. * Add an executable to the build.
*/ */
@ -416,8 +418,9 @@ public:
* Get the list of targets * Get the list of targets
*/ */
cmTargets &GetTargets() { return this->Targets; } cmTargets &GetTargets() { return this->Targets; }
const cmTargets &GetImportedTargets() const { return this->ImportedTargets; }
cmTarget* FindTarget(const char* name); cmTarget* FindTarget(const char* name, bool useImportedTargets);
/** /**
@ -741,6 +744,7 @@ protected:
// libraries, classes, and executables // libraries, classes, and executables
cmTargets Targets; cmTargets Targets;
cmTargets ImportedTargets;
std::vector<cmSourceFile*> SourceFiles; std::vector<cmSourceFile*> SourceFiles;
// Tests // Tests

View File

@ -1194,7 +1194,7 @@ void cmMakefileTargetGenerator
{ {
// Depend on other CMake targets. // Depend on other CMake targets.
if(cmTarget* tgt = if(cmTarget* tgt =
this->GlobalGenerator->FindTarget(0, lib->first.c_str())) this->GlobalGenerator->FindTarget(0, lib->first.c_str(), false))
{ {
if(const char* location = if(const char* location =
tgt->GetLocation(this->LocalGenerator->ConfigurationName.c_str())) tgt->GetLocation(this->LocalGenerator->ConfigurationName.c_str()))

View File

@ -96,7 +96,7 @@ bool cmSetTargetPropertiesCommand
cmMakefile *mf) cmMakefile *mf)
{ {
cmTarget* target = cmTarget* target =
mf->GetLocalGenerator()->GetGlobalGenerator()->FindTarget(0, tname); mf->GetLocalGenerator()->GetGlobalGenerator()->FindTarget(0, tname, true);
if ( target) if ( target)
{ {
// now loop through all the props and set them // now loop through all the props and set them

View File

@ -38,7 +38,7 @@ cmTarget::cmTarget()
this->LinkDirectoriesComputed = false; this->LinkDirectoriesComputed = false;
this->HaveInstallRule = false; this->HaveInstallRule = false;
this->DLLPlatform = false; this->DLLPlatform = false;
this->IsImportedTarget = false;
} }
// define properties // define properties
@ -90,7 +90,7 @@ void cmTarget::DefineProperties(cmake *cm)
cm->DefineProperty cm->DefineProperty
("EchoString", cmProperty::TARGET, ("EchoString", cmProperty::TARGET,
"A message to be displayed when the target it built.", "A message to be displayed when the target is built.",
"A message to display on some generaters (such as makefiles) when " "A message to display on some generaters (such as makefiles) when "
"the target is built."); "the target is built.");
@ -424,8 +424,8 @@ cmTarget
{ {
std::string command = *cit->begin(); std::string command = *cit->begin();
// see if we can find a target with this name // see if we can find a target with this name
cmTarget* t = this->Makefile->GetLocalGenerator()-> cmTarget* t = this->Makefile->GetLocalGenerator()->
GetGlobalGenerator()->FindTarget ( 0, command.c_str() ); GetGlobalGenerator()->FindTarget(0, command.c_str(), false);
if ( ( t ) && ( t->GetType() ==cmTarget::EXECUTABLE ) ) if ( ( t ) && ( t->GetType() ==cmTarget::EXECUTABLE ) )
{ {
this->AddUtility ( command.c_str() ); this->AddUtility ( command.c_str() );
@ -577,7 +577,7 @@ void cmTarget::TraceVSDependencies(std::string projFile,
const std::string& currentCommand = (*it)[0]; const std::string& currentCommand = (*it)[0];
// see if we can find a target with this name // see if we can find a target with this name
cmTarget* t = this->Makefile->GetLocalGenerator()-> cmTarget* t = this->Makefile->GetLocalGenerator()->
GetGlobalGenerator()->FindTarget(0, currentCommand.c_str()); GetGlobalGenerator()->FindTarget(0, currentCommand.c_str(), false);
if (( t) && (t->GetType()==cmTarget::EXECUTABLE)) if (( t) && (t->GetType()==cmTarget::EXECUTABLE))
{ {
automaticTargetDepends.push_back(currentCommand); automaticTargetDepends.push_back(currentCommand);
@ -600,7 +600,7 @@ void cmTarget::TraceVSDependencies(std::string projFile,
bool isUtility = false; bool isUtility = false;
// see if we can find a target with this name // see if we can find a target with this name
cmTarget* t = this->Makefile->GetLocalGenerator()-> cmTarget* t = this->Makefile->GetLocalGenerator()->
GetGlobalGenerator()->FindTarget(0, dep.c_str()); GetGlobalGenerator()->FindTarget(0, dep.c_str(), false);
if(t) if(t)
{ {
// if we find the target and the dep was given as a full // if we find the target and the dep was given as a full
@ -783,7 +783,7 @@ const std::vector<std::string>& cmTarget::GetLinkDirectories()
this->Makefile->GetLocalGenerator()->GetGlobalGenerator()) this->Makefile->GetLocalGenerator()->GetGlobalGenerator())
{ {
tgt = (this->Makefile->GetLocalGenerator()->GetGlobalGenerator() tgt = (this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
->FindTarget(0, lib.c_str())); ->FindTarget(0, lib.c_str(), false));
} }
if(tgt) if(tgt)
{ {
@ -1220,7 +1220,31 @@ void cmTarget::SetProperty(const char* prop, const char* value)
this->Properties.SetProperty(prop, value, cmProperty::TARGET); this->Properties.SetProperty(prop, value, cmProperty::TARGET);
} }
void cmTarget::MarkAsImported()
{
this->IsImportedTarget = true;
}
const char* cmTarget::GetDirectory(const char* config, bool implib) const char* cmTarget::GetDirectory(const char* config, bool implib)
{
if (this->IsImported())
{
return this->ImportedGetDirectory(config, implib);
}
else
{
return this->NormalGetDirectory(config, implib);
}
}
const char* cmTarget::ImportedGetDirectory(const char* config, bool implib)
{
const char* location=this->GetLocation(config);
std::string directory=cmSystemTools::GetFilenamePath(location);
return directory.c_str();
}
const char* cmTarget::NormalGetDirectory(const char* config, bool implib)
{ {
if(config && *config) if(config && *config)
{ {
@ -1237,6 +1261,34 @@ const char* cmTarget::GetDirectory(const char* config, bool implib)
} }
const char* cmTarget::GetLocation(const char* config) const char* cmTarget::GetLocation(const char* config)
{
if (this->IsImported())
{
return this->ImportedGetLocation(config);
}
else
{
return this->NormalGetLocation(config);
}
}
const char* cmTarget::ImportedGetLocation(const char* config)
{
if ((config) && (strlen(config)))
{
std::string propertyName=config;
propertyName+="_LOCATION";
const char* configLocation=this->GetProperty(propertyName.c_str());
if ((configLocation) && (strlen(configLocation)))
{
return configLocation;
}
}
return this->GetProperty("LOCATION");
}
const char* cmTarget::NormalGetLocation(const char* config)
{ {
this->Location = this->GetDirectory(); this->Location = this->GetDirectory();
if(!this->Location.empty()) if(!this->Location.empty())
@ -1283,6 +1335,11 @@ const char *cmTarget::GetProperty(const char* prop)
void cmTarget::ComputeObjectFiles() void cmTarget::ComputeObjectFiles()
{ {
if (this->IsImported())
{
return;
}
// Force the SourceFiles vector to be populated // Force the SourceFiles vector to be populated
this->GenerateSourceFilesFromSourceLists(*this->Makefile); this->GenerateSourceFilesFromSourceLists(*this->Makefile);
std::vector<std::string> dirs; std::vector<std::string> dirs;
@ -1336,33 +1393,43 @@ const char *cmTarget::GetProperty(const char* prop,
return 0; return 0;
} }
// watch for special "computed" properties that are dependent on other // don't use GetLocation() for imported targets, because there this
// properties or variables, always recompute them // calls GetProperty() to get the location...
if (!strcmp(prop,"LOCATION")) if (!this->IsImported())
{
// watch for special "computed" properties that are dependent on other
// properties or variables, always recompute them
if (!strcmp(prop,"LOCATION"))
{
// Set the LOCATION property of the target. Note that this cannot take
// into account the per-configuration name of the target because the
// configuration type may not be known at CMake time. We should
// deprecate this feature and instead support transforming an executable
// target name given as the command part of custom commands into the
// proper path at build time. Alternatively we could put environment
// variable settings in all custom commands that hold the name of the
// target for each configuration and then give a reference to the
// variable in the location.
this->SetProperty("LOCATION", this->GetLocation(0));
}
// Per-configuration location can be computed.
int len = static_cast<int>(strlen(prop));
if(len > 9 && strcmp(prop+len-9, "_LOCATION") == 0)
{
std::string configName(prop, len-9);
this->SetProperty(prop, this->GetLocation(configName.c_str()));
}
if(strcmp(prop, "OBJECT_FILES") == 0)
{
this->ComputeObjectFiles();
}
}
if (strcmp(prop,"IMPORTED") == 0)
{ {
// Set the LOCATION property of the target. Note that this cannot take return this->IsImported()?"TRUE":"FALSE";
// into account the per-configuration name of the target because the
// configuration type may not be known at CMake time. We should
// deprecate this feature and instead support transforming an executable
// target name given as the command part of custom commands into the
// proper path at build time. Alternatively we could put environment
// variable settings in all custom commands that hold the name of the
// target for each configuration and then give a reference to the
// variable in the location.
this->SetProperty("LOCATION", this->GetLocation(0));
}
// Per-configuration location can be computed.
int len = static_cast<int>(strlen(prop));
if(len > 9 && strcmp(prop+len-9, "_LOCATION") == 0)
{
std::string configName(prop, len-9);
this->SetProperty(prop, this->GetLocation(configName.c_str()));
}
if(strcmp(prop, "OBJECT_FILES") == 0)
{
this->ComputeObjectFiles();
} }
// the type property returns what type the target is // the type property returns what type the target is
@ -1607,13 +1674,48 @@ std::string cmTarget::GetFullNameInternal(TargetType type, const char* config,
return prefix+base+suffix; return prefix+base+suffix;
} }
//----------------------------------------------------------------------------
void cmTarget::GetFullNameInternal(TargetType type, void cmTarget::GetFullNameInternal(TargetType type,
const char* config, const char* config,
bool implib, bool implib,
std::string& outPrefix, std::string& outPrefix,
std::string& outBase, std::string& outBase,
std::string& outSuffix) std::string& outSuffix)
{
if (this->IsImported())
{
this->ImportedGetFullNameInternal(type, config, implib,
outPrefix, outBase, outSuffix);
}
else
{
this->NormalGetFullNameInternal(type, config, implib,
outPrefix, outBase, outSuffix);
}
}
void cmTarget::ImportedGetFullNameInternal(TargetType type,
const char* config,
bool implib,
std::string& outPrefix,
std::string& outBase,
std::string& outSuffix)
{
// find the basename, suffix and prefix from getLocation()
// implib ?
std::string location=this->GetLocation(config);
outBase=cmSystemTools::GetFilenameWithoutExtension(location);
outSuffix = cmSystemTools::GetFilenameExtension(location);
outPrefix.clear();
}
//----------------------------------------------------------------------------
void cmTarget::NormalGetFullNameInternal(TargetType type,
const char* config,
bool implib,
std::string& outPrefix,
std::string& outBase,
std::string& outSuffix)
{ {
// Use just the target name for non-main target types. // Use just the target name for non-main target types.
if(type != cmTarget::STATIC_LIBRARY && if(type != cmTarget::STATIC_LIBRARY &&

View File

@ -44,7 +44,7 @@ public:
/** /**
* Return the type of target. * Return the type of target.
*/ */
TargetType GetType() TargetType GetType() const
{ {
return this->TargetTypeValue; return this->TargetTypeValue;
} }
@ -54,6 +54,8 @@ public:
*/ */
void SetType(TargetType f, const char* name); void SetType(TargetType f, const char* name);
void MarkAsImported();
///! Set/Get the name of the target ///! Set/Get the name of the target
const char* GetName() const {return this->Name.c_str();} const char* GetName() const {return this->Name.c_str();}
@ -161,6 +163,8 @@ public:
const char *GetProperty(const char *prop); const char *GetProperty(const char *prop);
const char *GetProperty(const char *prop, cmProperty::ScopeType scope); const char *GetProperty(const char *prop, cmProperty::ScopeType scope);
bool GetPropertyAsBool(const char *prop); bool GetPropertyAsBool(const char *prop);
bool IsImported() const {return this->IsImportedTarget;}
/** Get the directory in which this target will be built. If the /** Get the directory in which this target will be built. If the
configuration name is given then the generator will add its configuration name is given then the generator will add its
@ -327,6 +331,7 @@ private:
void GetFullNameInternal(TargetType type, const char* config, bool implib, void GetFullNameInternal(TargetType type, const char* config, bool implib,
std::string& outPrefix, std::string& outBase, std::string& outPrefix, std::string& outBase,
std::string& outSuffix); std::string& outSuffix);
void GetLibraryNamesInternal(std::string& name, void GetLibraryNamesInternal(std::string& name,
std::string& soName, std::string& soName,
std::string& realName, std::string& realName,
@ -348,6 +353,19 @@ private:
// Get the full path to the target output directory. // Get the full path to the target output directory.
const char* GetOutputDir(bool implib); const char* GetOutputDir(bool implib);
const char* ImportedGetLocation(const char* config);
const char* NormalGetLocation(const char* config);
void NormalGetFullNameInternal(TargetType type, const char* config, bool implib,
std::string& outPrefix, std::string& outBase,
std::string& outSuffix);
void ImportedGetFullNameInternal(TargetType type, const char* config, bool implib,
std::string& outPrefix, std::string& outBase,
std::string& outSuffix);
const char* ImportedGetDirectory(const char* config, bool implib);
const char* NormalGetDirectory(const char* config, bool implib);
private: private:
std::string Name; std::string Name;
std::vector<cmCustomCommand> PreBuildCommands; std::vector<cmCustomCommand> PreBuildCommands;
@ -376,6 +394,7 @@ private:
cmPropertyMap Properties; cmPropertyMap Properties;
LinkLibraryVectorType OriginalLinkLibraries; LinkLibraryVectorType OriginalLinkLibraries;
bool DLLPlatform; bool DLLPlatform;
bool IsImportedTarget;
// The cmMakefile instance that owns this target. This should // The cmMakefile instance that owns this target. This should
// always be set. // always be set.