mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-09-25 04:09:36 +03:00
Add the ALIAS target concept for libraries and executables.
* The ALIAS name must match a validity regex. * Executables and libraries may be aliased. * An ALIAS acts immutable. It can not be used as the lhs of target_link_libraries or other commands. * An ALIAS can be used with add_custom_command, add_custom_target, and add_test in the same way regular targets can. * The target of an ALIAS can be retrieved with the ALIASED_TARGET target property. * An ALIAS does not appear in the generated buildsystem. It is kept separate from cmMakefile::Targets for that reason. * A target may have multiple aliases. * An ALIAS target may not itself have an alias. * An IMPORTED target may not have an alias. * An ALIAS may not be exported or imported.
This commit is contained in:
@@ -30,6 +30,7 @@ bool cmAddExecutableCommand
|
||||
bool excludeFromAll = false;
|
||||
bool importTarget = false;
|
||||
bool importGlobal = false;
|
||||
bool isAlias = false;
|
||||
while ( s != args.end() )
|
||||
{
|
||||
if (*s == "WIN32")
|
||||
@@ -57,6 +58,11 @@ bool cmAddExecutableCommand
|
||||
++s;
|
||||
importGlobal = true;
|
||||
}
|
||||
else if(*s == "ALIAS")
|
||||
{
|
||||
++s;
|
||||
isAlias = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
@@ -83,6 +89,72 @@ bool cmAddExecutableCommand
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (isAlias)
|
||||
{
|
||||
if(!cmGeneratorExpression::IsValidTargetName(exename.c_str()))
|
||||
{
|
||||
this->SetError(("Invalid name for ALIAS: " + exename).c_str());
|
||||
return false;
|
||||
}
|
||||
if(excludeFromAll)
|
||||
{
|
||||
this->SetError("EXCLUDE_FROM_ALL with ALIAS makes no sense.");
|
||||
return false;
|
||||
}
|
||||
if(importTarget || importGlobal)
|
||||
{
|
||||
this->SetError("IMPORTED with ALIAS is not allowed.");
|
||||
return false;
|
||||
}
|
||||
if(args.size() != 3)
|
||||
{
|
||||
cmOStringStream e;
|
||||
e << "ALIAS requires exactly one target argument.";
|
||||
this->SetError(e.str().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
const char *aliasedName = s->c_str();
|
||||
if(this->Makefile->IsAlias(aliasedName))
|
||||
{
|
||||
cmOStringStream e;
|
||||
e << "cannot create ALIAS target \"" << exename
|
||||
<< "\" because target \"" << aliasedName << "\" is itself an ALIAS.";
|
||||
this->SetError(e.str().c_str());
|
||||
return false;
|
||||
}
|
||||
cmTarget *aliasedTarget =
|
||||
this->Makefile->FindTargetToUse(aliasedName, true);
|
||||
if(!aliasedTarget)
|
||||
{
|
||||
cmOStringStream e;
|
||||
e << "cannot create ALIAS target \"" << exename
|
||||
<< "\" because target \"" << aliasedName << "\" does not already "
|
||||
"exist.";
|
||||
this->SetError(e.str().c_str());
|
||||
return false;
|
||||
}
|
||||
cmTarget::TargetType type = aliasedTarget->GetType();
|
||||
if(type != cmTarget::EXECUTABLE)
|
||||
{
|
||||
cmOStringStream e;
|
||||
e << "cannot create ALIAS target \"" << exename
|
||||
<< "\" because target \"" << aliasedName << "\" is not an "
|
||||
"executable.";
|
||||
this->SetError(e.str().c_str());
|
||||
return false;
|
||||
}
|
||||
if(aliasedTarget->IsImported())
|
||||
{
|
||||
cmOStringStream e;
|
||||
e << "cannot create ALIAS target \"" << exename
|
||||
<< "\" because target \"" << aliasedName << "\" is IMPORTED.";
|
||||
this->SetError(e.str().c_str());
|
||||
return false;
|
||||
}
|
||||
this->Makefile->AddAlias(exename.c_str(), aliasedTarget);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Handle imported target creation.
|
||||
if(importTarget)
|
||||
|
||||
Reference in New Issue
Block a user