Commit fc8b90af authored by Saleem Abdulrasool's avatar Saleem Abdulrasool

Create and use `cmGeneratorTarget::Names`

Rather than taking a number of out parameters for the various names,
create a structure that is reused for both `GetLibraryNames` and
`GetExecutableNames`.  Replace uses according to the new interface.
parent 8a1d25af
......@@ -1617,13 +1617,7 @@ std::string cmGeneratorTarget::GetSOName(const std::string& config) const
return "";
}
// Compute the soname that will be built.
std::string name;
std::string soName;
std::string realName;
std::string impName;
std::string pdbName;
this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
return soName;
return this->GetLibraryNames(config).SharedObject;
}
static bool shouldAddFullLevel(cmGeneratorTarget::BundleDirectoryLevel level)
......@@ -3394,17 +3388,13 @@ void cmGeneratorTarget::ComputeTargetManifest(const std::string& config) const
cmGlobalGenerator* gg = this->LocalGenerator->GetGlobalGenerator();
// Get the names.
std::string name;
std::string soName;
std::string realName;
std::string impName;
std::string pdbName;
cmGeneratorTarget::Names targetNames;
if (this->GetType() == cmStateEnums::EXECUTABLE) {
this->GetExecutableNames(name, realName, impName, pdbName, config);
targetNames = this->GetExecutableNames(config);
} else if (this->GetType() == cmStateEnums::STATIC_LIBRARY ||
this->GetType() == cmStateEnums::SHARED_LIBRARY ||
this->GetType() == cmStateEnums::MODULE_LIBRARY) {
this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
targetNames = this->GetLibraryNames(config);
} else {
return;
}
......@@ -3415,34 +3405,34 @@ void cmGeneratorTarget::ComputeTargetManifest(const std::string& config) const
// Add each name.
std::string f;
if (!name.empty()) {
if (!targetNames.Output.empty()) {
f = dir;
f += "/";
f += name;
f += targetNames.Output;
gg->AddToManifest(f);
}
if (!soName.empty()) {
if (!targetNames.SharedObject.empty()) {
f = dir;
f += "/";
f += soName;
f += targetNames.SharedObject;
gg->AddToManifest(f);
}
if (!realName.empty()) {
if (!targetNames.Real.empty()) {
f = dir;
f += "/";
f += realName;
f += targetNames.Real;
gg->AddToManifest(f);
}
if (!pdbName.empty()) {
if (!targetNames.PDB.empty()) {
f = dir;
f += "/";
f += pdbName;
f += targetNames.PDB;
gg->AddToManifest(f);
}
if (!impName.empty()) {
if (!targetNames.ImportLibrary.empty()) {
f = this->GetDirectory(config, cmStateEnums::ImportLibraryArtifact);
f += "/";
f += impName;
f += targetNames.ImportLibrary;
gg->AddToManifest(f);
}
}
......@@ -3520,29 +3510,17 @@ std::string cmGeneratorTarget::NormalGetRealName(
if (this->GetType() == cmStateEnums::EXECUTABLE) {
// Compute the real name that will be built.
std::string name;
std::string realName;
std::string impName;
std::string pdbName;
this->GetExecutableNames(name, realName, impName, pdbName, config);
return realName;
return this->GetExecutableNames(config).Real;
}
// Compute the real name that will be built.
std::string name;
std::string soName;
std::string realName;
std::string impName;
std::string pdbName;
this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
return realName;
}
void cmGeneratorTarget::GetLibraryNames(std::string& name, std::string& soName,
std::string& realName,
std::string& impName,
std::string& pdbName,
const std::string& config) const
return this->GetLibraryNames(config).Real;
}
cmGeneratorTarget::Names cmGeneratorTarget::GetLibraryNames(
const std::string& config) const
{
cmGeneratorTarget::Names targetNames;
// This should not be called for imported targets.
// TODO: Split cmTarget into a class hierarchy to get compile-time
// enforcement of the limited imported target API.
......@@ -3550,7 +3528,6 @@ void cmGeneratorTarget::GetLibraryNames(std::string& name, std::string& soName,
std::string msg = "GetLibraryNames called on imported target: ";
msg += this->GetName();
this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg);
return;
}
// Check for library version properties.
......@@ -3576,50 +3553,51 @@ void cmGeneratorTarget::GetLibraryNames(std::string& name, std::string& soName,
// Get the components of the library name.
std::string prefix;
std::string base;
std::string suffix;
this->GetFullNameInternal(config, cmStateEnums::RuntimeBinaryArtifact,
prefix, base, suffix);
prefix, targetNames.Base, suffix);
// The library name.
name = prefix + base + suffix;
targetNames.Output = prefix + targetNames.Base + suffix;
if (this->IsFrameworkOnApple()) {
realName = prefix;
targetNames.Real = prefix;
if (!this->Makefile->PlatformIsAppleEmbedded()) {
realName += "Versions/";
realName += this->GetFrameworkVersion();
realName += "/";
targetNames.Real += "Versions/";
targetNames.Real += this->GetFrameworkVersion();
targetNames.Real += "/";
}
realName += base;
soName = realName;
targetNames.Real += targetNames.Base;
targetNames.SharedObject = targetNames.Real;
} else {
// The library's soname.
this->ComputeVersionedName(soName, prefix, base, suffix, name, soversion);
this->ComputeVersionedName(targetNames.SharedObject, prefix,
targetNames.Base, suffix, targetNames.Output,
soversion);
// The library's real name on disk.
this->ComputeVersionedName(realName, prefix, base, suffix, name, version);
this->ComputeVersionedName(targetNames.Real, prefix, targetNames.Base,
suffix, targetNames.Output, version);
}
// The import library name.
if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
this->GetType() == cmStateEnums::MODULE_LIBRARY) {
impName =
targetNames.ImportLibrary =
this->GetFullNameInternal(config, cmStateEnums::ImportLibraryArtifact);
} else {
impName.clear();
}
// The program database file name.
pdbName = this->GetPDBName(config);
targetNames.PDB = this->GetPDBName(config);
return targetNames;
}
void cmGeneratorTarget::GetExecutableNames(std::string& name,
std::string& realName,
std::string& impName,
std::string& pdbName,
const std::string& config) const
cmGeneratorTarget::Names cmGeneratorTarget::GetExecutableNames(
const std::string& config) const
{
cmGeneratorTarget::Names targetNames;
// This should not be called for imported targets.
// TODO: Split cmTarget into a class hierarchy to get compile-time
// enforcement of the limited imported target API.
......@@ -3644,34 +3622,35 @@ void cmGeneratorTarget::GetExecutableNames(std::string& name,
// Get the components of the executable name.
std::string prefix;
std::string base;
std::string suffix;
this->GetFullNameInternal(config, cmStateEnums::RuntimeBinaryArtifact,
prefix, base, suffix);
prefix, targetNames.Base, suffix);
// The executable name.
name = prefix + base + suffix;
targetNames.Output = prefix + targetNames.Base + suffix;
// The executable's real name on disk.
#if defined(__CYGWIN__)
realName = prefix + base;
targetNames.Real = prefix + targetNames.Base;
#else
realName = name;
targetNames.Real = targetNames.Output;
#endif
if (version) {
realName += "-";
realName += version;
targetNames.Real += "-";
targetNames.Real += version;
}
#if defined(__CYGWIN__)
realName += suffix;
targetNames.Real += suffix;
#endif
// The import library name.
impName =
targetNames.ImportLibrary =
this->GetFullNameInternal(config, cmStateEnums::ImportLibraryArtifact);
// The program database file name.
pdbName = this->GetPDBName(config);
targetNames.PDB = this->GetPDBName(config);
return targetNames;
}
std::string cmGeneratorTarget::GetFullNameInternal(
......
......@@ -568,19 +568,25 @@ public:
void GetAutoUicOptions(std::vector<std::string>& result,
const std::string& config) const;
struct Names
{
std::string Base;
std::string Output;
std::string Real;
std::string ImportLibrary;
std::string PDB;
std::string SharedObject;
};
/** 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 std::string& config) const;
Names GetExecutableNames(const std::string& config) 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 std::string& config) const;
Names GetLibraryNames(const std::string& config) const;
/**
* Compute whether this target must be relinked before installing.
......
......@@ -40,12 +40,8 @@ void cmGhsMultiTargetGenerator::Generate()
switch (this->GeneratorTarget->GetType()) {
case cmStateEnums::EXECUTABLE: {
// Get the name of the executable to generate.
std::string targetName;
std::string targetNameImport;
std::string targetNamePDB;
this->GeneratorTarget->GetExecutableNames(
targetName, this->TargetNameReal, targetNameImport, targetNamePDB,
this->ConfigName);
this->TargetNameReal =
this->GeneratorTarget->GetExecutableNames(this->ConfigName).Real;
if (cmGhsMultiTargetGenerator::DetermineIfIntegrityApp()) {
this->TagType = GhsMultiGpj::INTERGRITY_APPLICATION;
} else {
......@@ -54,13 +50,8 @@ void cmGhsMultiTargetGenerator::Generate()
break;
}
case cmStateEnums::STATIC_LIBRARY: {
std::string targetName;
std::string targetNameSO;
std::string targetNameImport;
std::string targetNamePDB;
this->GeneratorTarget->GetLibraryNames(
targetName, targetNameSO, this->TargetNameReal, targetNameImport,
targetNamePDB, this->ConfigName);
this->TargetNameReal =
this->GeneratorTarget->GetLibraryNames(this->ConfigName).Real;
this->TagType = GhsMultiGpj::LIBRARY;
break;
}
......@@ -71,13 +62,8 @@ void cmGhsMultiTargetGenerator::Generate()
return;
}
case cmStateEnums::OBJECT_LIBRARY: {
std::string targetName;
std::string targetNameSO;
std::string targetNameImport;
std::string targetNamePDB;
this->GeneratorTarget->GetLibraryNames(
targetName, targetNameSO, this->TargetNameReal, targetNameImport,
targetNamePDB, this->ConfigName);
this->TargetNameReal =
this->GeneratorTarget->GetLibraryNames(this->ConfigName).Real;
this->TagType = GhsMultiGpj::SUBPROJECT;
break;
}
......
......@@ -123,19 +123,15 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(
// There is a bug in cmInstallCommand if this fails.
assert(this->NamelinkMode == NamelinkModeNone);
std::string targetName;
std::string targetNameReal;
std::string targetNameImport;
std::string targetNamePDB;
this->Target->GetExecutableNames(targetName, targetNameReal,
targetNameImport, targetNamePDB, config);
cmGeneratorTarget::Names targetNames =
this->Target->GetExecutableNames(config);
if (this->ImportLibrary) {
std::string from1 = fromDirConfig + targetNameImport;
std::string to1 = toDir + targetNameImport;
std::string from1 = fromDirConfig + targetNames.ImportLibrary;
std::string to1 = toDir + targetNames.ImportLibrary;
filesFrom.push_back(std::move(from1));
filesTo.push_back(std::move(to1));
std::string targetNameImportLib;
if (this->Target->GetImplibGNUtoMS(config, targetNameImport,
if (this->Target->GetImplibGNUtoMS(config, targetNames.ImportLibrary,
targetNameImportLib)) {
filesFrom.push_back(fromDirConfig + targetNameImportLib);
filesTo.push_back(toDir + targetNameImportLib);
......@@ -144,8 +140,8 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(
// An import library looks like a static library.
type = cmInstallType_STATIC_LIBRARY;
} else {
std::string from1 = fromDirConfig + targetName;
std::string to1 = toDir + targetName;
std::string from1 = fromDirConfig + targetNames.Output;
std::string to1 = toDir + targetNames.Output;
// Handle OSX Bundles.
if (this->Target->IsAppBundleOnApple()) {
......@@ -170,12 +166,12 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(
if (!mf->PlatformIsAppleEmbedded()) {
to1 += "Contents/MacOS/";
}
to1 += targetName;
to1 += targetNames.Output;
} else {
// Tweaks apply to the real file, so list it first.
if (targetNameReal != targetName) {
std::string from2 = fromDirConfig + targetNameReal;
std::string to2 = toDir += targetNameReal;
if (targetNames.Real != targetNames.Output) {
std::string from2 = fromDirConfig + targetNames.Real;
std::string to2 = toDir += targetNames.Real;
filesFrom.push_back(std::move(from2));
filesTo.push_back(std::move(to2));
}
......@@ -185,23 +181,18 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(
filesTo.push_back(std::move(to1));
}
} else {
std::string targetName;
std::string targetNameSO;
std::string targetNameReal;
std::string targetNameImport;
std::string targetNamePDB;
this->Target->GetLibraryNames(targetName, targetNameSO, targetNameReal,
targetNameImport, targetNamePDB, config);
cmGeneratorTarget::Names targetNames =
this->Target->GetLibraryNames(config);
if (this->ImportLibrary) {
// There is a bug in cmInstallCommand if this fails.
assert(this->NamelinkMode == NamelinkModeNone);
std::string from1 = fromDirConfig + targetNameImport;
std::string to1 = toDir + targetNameImport;
std::string from1 = fromDirConfig + targetNames.ImportLibrary;
std::string to1 = toDir + targetNames.ImportLibrary;
filesFrom.push_back(std::move(from1));
filesTo.push_back(std::move(to1));
std::string targetNameImportLib;
if (this->Target->GetImplibGNUtoMS(config, targetNameImport,
if (this->Target->GetImplibGNUtoMS(config, targetNames.ImportLibrary,
targetNameImportLib)) {
filesFrom.push_back(fromDirConfig + targetNameImportLib);
filesTo.push_back(toDir + targetNameImportLib);
......@@ -243,11 +234,11 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(
type = cmInstallType_DIRECTORY;
literal_args += " USE_SOURCE_PERMISSIONS";
std::string from1 = fromDirConfig + targetName;
std::string from1 = fromDirConfig + targetNames.Output;
from1 = cmSystemTools::GetFilenamePath(from1);
// Tweaks apply to the binary inside the bundle.
std::string to1 = toDir + targetNameReal;
std::string to1 = toDir + targetNames.Real;
filesFrom.push_back(std::move(from1));
filesTo.push_back(std::move(to1));
......@@ -256,10 +247,11 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(
type = cmInstallType_DIRECTORY;
literal_args += " USE_SOURCE_PERMISSIONS";
std::string targetNameBase = targetName.substr(0, targetName.find('/'));
std::string targetNameBase =
targetNames.Output.substr(0, targetNames.Output.find('/'));
std::string from1 = fromDirConfig + targetNameBase;
std::string to1 = toDir + targetName;
std::string to1 = toDir + targetNames.Output;
filesFrom.push_back(std::move(from1));
filesTo.push_back(std::move(to1));
......@@ -267,25 +259,26 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(
bool haveNamelink = false;
// Library link name.
std::string fromName = fromDirConfig + targetName;
std::string toName = toDir + targetName;
std::string fromName = fromDirConfig + targetNames.Output;
std::string toName = toDir + targetNames.Output;
// Library interface name.
std::string fromSOName;
std::string toSOName;
if (targetNameSO != targetName) {
if (targetNames.SharedObject != targetNames.Output) {
haveNamelink = true;
fromSOName = fromDirConfig + targetNameSO;
toSOName = toDir + targetNameSO;
fromSOName = fromDirConfig + targetNames.SharedObject;
toSOName = toDir + targetNames.SharedObject;
}
// Library implementation name.
std::string fromRealName;
std::string toRealName;
if (targetNameReal != targetName && targetNameReal != targetNameSO) {
if (targetNames.Real != targetNames.Output &&
targetNames.Real != targetNames.SharedObject) {
haveNamelink = true;
fromRealName = fromDirConfig + targetNameReal;
toRealName = toDir + targetNameReal;
fromRealName = fromDirConfig + targetNames.Real;
toRealName = toDir + targetNames.Real;
}
// Add the names based on the current namelink mode.
......@@ -416,48 +409,37 @@ std::string cmInstallTargetGenerator::GetInstallFilename(
std::string fname;
// Compute the name of the library.
if (target->GetType() == cmStateEnums::EXECUTABLE) {
std::string targetName;
std::string targetNameReal;
std::string targetNameImport;
std::string targetNamePDB;
target->GetExecutableNames(targetName, targetNameReal, targetNameImport,
targetNamePDB, config);
cmGeneratorTarget::Names targetNames = target->GetExecutableNames(config);
if (nameType == NameImplib) {
// Use the import library name.
if (!target->GetImplibGNUtoMS(config, targetNameImport, fname,
if (!target->GetImplibGNUtoMS(config, targetNames.ImportLibrary, fname,
"${CMAKE_IMPORT_LIBRARY_SUFFIX}")) {
fname = targetNameImport;
fname = targetNames.ImportLibrary;
}
} else if (nameType == NameReal) {
// Use the canonical name.
fname = targetNameReal;
fname = targetNames.Real;
} else {
// Use the canonical name.
fname = targetName;
fname = targetNames.Output;
}
} else {
std::string targetName;
std::string targetNameSO;
std::string targetNameReal;
std::string targetNameImport;
std::string targetNamePDB;
target->GetLibraryNames(targetName, targetNameSO, targetNameReal,
targetNameImport, targetNamePDB, config);
cmGeneratorTarget::Names targetNames = target->GetLibraryNames(config);
if (nameType == NameImplib) {
// Use the import library name.
if (!target->GetImplibGNUtoMS(config, targetNameImport, fname,
if (!target->GetImplibGNUtoMS(config, targetNames.ImportLibrary, fname,
"${CMAKE_IMPORT_LIBRARY_SUFFIX}")) {
fname = targetNameImport;
fname = targetNames.ImportLibrary;
}
} else if (nameType == NameSO) {
// Use the soname.
fname = targetNameSO;
fname = targetNames.SharedObject;
} else if (nameType == NameReal) {
// Use the real name.
fname = targetNameReal;
fname = targetNames.Real;
} else {
// Use the canonical name.
fname = targetName;
fname = targetNames.Output;
}
}
......
......@@ -1043,13 +1043,8 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(
}
case cmStateEnums::SHARED_LIBRARY:
case cmStateEnums::MODULE_LIBRARY: {
std::string targetName;
std::string targetNameSO;
std::string targetNameFull;
std::string targetNameImport;
std::string targetNamePDB;
target->GetLibraryNames(targetName, targetNameSO, targetNameFull,
targetNameImport, targetNamePDB, configName);
cmGeneratorTarget::Names targetNames =
target->GetLibraryNames(configName);
// Compute the link library and directory information.
cmComputeLinkInformation* pcli = target->GetLinkInformation(configName);
......@@ -1085,7 +1080,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(
fout << "\"\n";
temp = target->GetDirectory(configName);
temp += "/";
temp += targetNameFull;
temp += targetNames.Output;
fout << "\t\t\t\tOutputFile=\""
<< this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
this->WriteTargetVersionAttribute(fout, target);
......@@ -1095,7 +1090,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(
fout << "\"\n";
temp = target->GetPDBDirectory(configName);
temp += "/";
temp += targetNamePDB;
temp += targetNames.PDB;
fout << "\t\t\t\tProgramDatabaseFile=\""
<< this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
if (targetOptions.IsDebug()) {
......@@ -1118,7 +1113,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(
temp =
target->GetDirectory(configName, cmStateEnums::ImportLibraryArtifact);
temp += "/";
temp += targetNameImport;
temp += targetNames.ImportLibrary;
fout << "\t\t\t\tImportLibrary=\""
<< this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"";
if (this->FortranProject) {
......@@ -1127,12 +1122,8 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(
fout << "/>\n";
} break;
case cmStateEnums::EXECUTABLE: {
std::string targetName;
std::string targetNameFull;
std::string targetNameImport;
std::string targetNamePDB;
target->GetExecutableNames(targetName, targetNameFull, targetNameImport,
targetNamePDB, configName);
cmGeneratorTarget::Names targetNames =
target->GetExecutableNames(configName);
// Compute the link library and directory information.
cmComputeLinkInformation* pcli = target->GetLinkInformation(configName);
......@@ -1170,7 +1161,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(
fout << "\"\n";
temp = target->GetDirectory(configName);
temp += "/";
temp += targetNameFull;
temp += targetNames.Output;
fout << "\t\t\t\tOutputFile=\""
<< this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
this->WriteTargetVersionAttribute(fout, target);
......@@ -1180,8 +1171,8 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(
fout << "\"\n";
std::string path = this->ConvertToXMLOutputPathSingle(
target->GetPDBDirectory(configName).c_str());
fout << "\t\t\t\tProgramDatabaseFile=\"" << path << "/" << targetNamePDB
<< "\"\n";
fout << "\t\t\t\tProgramDatabaseFile=\"" << path << "/"
<< targetNames.PDB << "\"\n";
if (targetOptions.IsDebug()) {
fout << "\t\t\t\tGenerateDebugInformation=\"true\"\n";
}
......@@ -1216,7 +1207,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(
temp =
target->GetDirectory(configName, cmStateEnums::ImportLibraryArtifact);
temp += "/";
temp += targetNameImport;
temp += targetNames.ImportLibrary;
fout << "\t\t\t\tImportLibrary=\""
<< this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
break;
......
......@@ -31,9 +31,8 @@ cmMakefileExecutableTargetGenerator::cmMakefileExecutableTargetGenerator(
: cmMakefileTargetGenerator(target)
{
this->CustomCommandDriver = OnDepends;
this->GeneratorTarget->GetExecutableNames(
this->TargetNameOut, this->TargetNameReal, this->TargetNameImport,
this->TargetNamePDB, this->ConfigName);
this->TargetNames =
this->GeneratorTarget->GetExecutableNames(this->