STYLE: preparations for the INSTALL(EXPORT ...) generator

-move std::string Destination to cmInstallGenerator, since all (except
the script one) have it and add a const accessor so it can be queried
-use temporary variables in cmInstallCommand for the generators so they can be reused easier
-some more const

Alex
This commit is contained in:
Alexander Neundorf 2007-06-19 11:11:06 -04:00
parent f786f3ae32
commit 617602e9e9
9 changed files with 71 additions and 49 deletions

View File

@ -410,6 +410,10 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
{ {
// Handle each target type. // Handle each target type.
cmTarget& target = *(*ti); cmTarget& target = *(*ti);
cmInstallTargetGenerator* archiveGenerator = 0;
cmInstallTargetGenerator* runtimeGenerator = 0;
cmInstallTargetGenerator* libraryGenerator = 0;
switch(target.GetType()) switch(target.GetType())
{ {
case cmTarget::SHARED_LIBRARY: case cmTarget::SHARED_LIBRARY:
@ -424,23 +428,24 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
if(archive_destination) if(archive_destination)
{ {
// The import library uses the ARCHIVE properties. // The import library uses the ARCHIVE properties.
this->Makefile->AddInstallGenerator( archiveGenerator = new cmInstallTargetGenerator(target,
new cmInstallTargetGenerator(target, archive_dest.c_str(), true, archive_dest.c_str(),
true,
archive_permissions.c_str(), archive_permissions.c_str(),
archive_configurations, archive_configurations,
archive_component.c_str(), archive_component.c_str(),
archive_optional)); archive_optional);
} }
if(runtime_destination) if(runtime_destination)
{ {
// The DLL uses the RUNTIME properties. // The DLL uses the RUNTIME properties.
this->Makefile->AddInstallGenerator( runtimeGenerator = new cmInstallTargetGenerator(target,
new cmInstallTargetGenerator(target, runtime_dest.c_str(), runtime_dest.c_str(),
false, false,
runtime_permissions.c_str(), runtime_permissions.c_str(),
runtime_configurations, runtime_configurations,
runtime_component.c_str(), runtime_component.c_str(),
runtime_optional)); runtime_optional);
} }
} }
else else
@ -449,13 +454,13 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
if(library_destination) if(library_destination)
{ {
// The shared library uses the LIBRARY properties. // The shared library uses the LIBRARY properties.
this->Makefile->AddInstallGenerator( libraryGenerator = new cmInstallTargetGenerator(target,
new cmInstallTargetGenerator(target, library_dest.c_str(), library_dest.c_str(),
false, false,
library_permissions.c_str(), library_permissions.c_str(),
library_configurations, library_configurations,
library_component.c_str(), library_component.c_str(),
library_optional)); library_optional);
} }
else else
{ {
@ -473,12 +478,13 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
// Static libraries use ARCHIVE properties. // Static libraries use ARCHIVE properties.
if(archive_destination) if(archive_destination)
{ {
this->Makefile->AddInstallGenerator( archiveGenerator = new cmInstallTargetGenerator(target,
new cmInstallTargetGenerator(target, archive_dest.c_str(), false, archive_dest.c_str(),
false,
archive_permissions.c_str(), archive_permissions.c_str(),
archive_configurations, archive_configurations,
archive_component.c_str(), archive_component.c_str(),
archive_optional)); archive_optional);
} }
else else
{ {
@ -495,12 +501,13 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
// Modules use LIBRARY properties. // Modules use LIBRARY properties.
if(library_destination) if(library_destination)
{ {
this->Makefile->AddInstallGenerator( libraryGenerator = new cmInstallTargetGenerator(target,
new cmInstallTargetGenerator(target, library_dest.c_str(), false, library_dest.c_str(),
false,
library_permissions.c_str(), library_permissions.c_str(),
library_configurations, library_configurations,
library_component.c_str(), library_component.c_str(),
library_optional)); library_optional);
} }
else else
{ {
@ -517,12 +524,13 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
// Executables use the RUNTIME properties. // Executables use the RUNTIME properties.
if(runtime_destination) if(runtime_destination)
{ {
this->Makefile->AddInstallGenerator( runtimeGenerator = new cmInstallTargetGenerator(target,
new cmInstallTargetGenerator(target, runtime_dest.c_str(), false, runtime_dest.c_str(),
false,
runtime_permissions.c_str(), runtime_permissions.c_str(),
runtime_configurations, runtime_configurations,
runtime_component.c_str(), runtime_component.c_str(),
runtime_optional)); runtime_optional);
} }
else else
{ {
@ -539,12 +547,13 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
if(dll_platform && archive_destination) if(dll_platform && archive_destination)
{ {
// The import library uses the ARCHIVE properties. // The import library uses the ARCHIVE properties.
this->Makefile->AddInstallGenerator( archiveGenerator = new cmInstallTargetGenerator(target,
new cmInstallTargetGenerator(target, archive_dest.c_str(), true, archive_dest.c_str(),
true,
archive_permissions.c_str(), archive_permissions.c_str(),
archive_configurations, archive_configurations,
archive_component.c_str(), archive_component.c_str(),
true)); true);
} }
} }
break; break;
@ -553,6 +562,10 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
// Ignore the case. // Ignore the case.
break; break;
} }
this->Makefile->AddInstallGenerator(archiveGenerator);
this->Makefile->AddInstallGenerator(runtimeGenerator);
this->Makefile->AddInstallGenerator(libraryGenerator);
} }
// Tell the global generator about any installation component names // Tell the global generator about any installation component names
@ -1114,7 +1127,7 @@ cmInstallCommand::HandleDirectoryMode(std::vector<std::string> const& args)
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmInstallCommand::ComputeDestination(const char* destination, void cmInstallCommand::ComputeDestination(const char* destination,
std::string& dest) std::string& dest) const
{ {
if(destination) if(destination)
{ {
@ -1142,7 +1155,7 @@ void cmInstallCommand::ComputeDestination(const char* destination,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool cmInstallCommand::CheckPermissions(std::string const& arg, bool cmInstallCommand::CheckPermissions(std::string const& arg,
std::string& permissions) std::string& permissions) const
{ {
// Table of valid permissions. // Table of valid permissions.
const char* table[] = const char* table[] =

View File

@ -248,8 +248,8 @@ private:
bool HandleTargetsMode(std::vector<std::string> const& args); bool HandleTargetsMode(std::vector<std::string> const& args);
bool HandleFilesMode(std::vector<std::string> const& args); bool HandleFilesMode(std::vector<std::string> const& args);
bool HandleDirectoryMode(std::vector<std::string> const& args); bool HandleDirectoryMode(std::vector<std::string> const& args);
void ComputeDestination(const char* destination, std::string& dest); void ComputeDestination(const char* destination, std::string& dest) const;
bool CheckPermissions(std::string const& arg, std::string& permissions); bool CheckPermissions(std::string const& arg, std::string& permissions)const;
}; };

View File

@ -27,7 +27,7 @@ cmInstallDirectoryGenerator
std::vector<std::string> const& configurations, std::vector<std::string> const& configurations,
const char* component, const char* component,
const char* literal_args): const char* literal_args):
Directories(dirs), Destination(dest), cmInstallGenerator(dest), Directories(dirs),
FilePermissions(file_permissions), DirPermissions(dir_permissions), FilePermissions(file_permissions), DirPermissions(dir_permissions),
Configurations(configurations), Component(component), Configurations(configurations), Component(component),
LiteralArguments(literal_args) LiteralArguments(literal_args)

View File

@ -37,7 +37,6 @@ public:
protected: protected:
virtual void GenerateScript(std::ostream& os); virtual void GenerateScript(std::ostream& os);
std::vector<std::string> Directories; std::vector<std::string> Directories;
std::string Destination;
std::string FilePermissions; std::string FilePermissions;
std::string DirPermissions; std::string DirPermissions;
std::vector<std::string> Configurations; std::vector<std::string> Configurations;

View File

@ -27,7 +27,7 @@ cmInstallFilesGenerator
const char* component, const char* component,
const char* rename, const char* rename,
bool optional): bool optional):
Files(files), Destination(dest), Programs(programs), cmInstallGenerator(dest), Files(files), Programs(programs),
FilePermissions(file_permissions), Configurations(configurations), FilePermissions(file_permissions), Configurations(configurations),
Component(component), Rename(rename), Optional(optional) Component(component), Rename(rename), Optional(optional)
{ {

View File

@ -37,7 +37,6 @@ public:
protected: protected:
virtual void GenerateScript(std::ostream& os); virtual void GenerateScript(std::ostream& os);
std::vector<std::string> Files; std::vector<std::string> Files;
std::string Destination;
bool Programs; bool Programs;
std::string FilePermissions; std::string FilePermissions;
std::vector<std::string> Configurations; std::vector<std::string> Configurations;

View File

@ -29,6 +29,7 @@ class cmInstallGenerator
{ {
public: public:
cmInstallGenerator(); cmInstallGenerator();
cmInstallGenerator(const char* dest):Destination(dest?dest:"") {}
virtual ~cmInstallGenerator(); virtual ~cmInstallGenerator();
void Generate(std::ostream& os, const char* config, void Generate(std::ostream& os, const char* config,
@ -47,11 +48,13 @@ public:
const char* literal_args = 0 const char* literal_args = 0
); );
const char* GetDestination() const {return this->Destination.c_str();}
protected: protected:
virtual void GenerateScript(std::ostream& os)=0; virtual void GenerateScript(std::ostream& os)=0;
const char* ConfigurationName; const char* ConfigurationName;
std::vector<std::string> const* ConfigurationTypes; std::vector<std::string> const* ConfigurationTypes;
std::string Destination;
}; };
#endif #endif

View File

@ -27,7 +27,7 @@ cmInstallTargetGenerator
const char* file_permissions, const char* file_permissions,
std::vector<std::string> const& configurations, std::vector<std::string> const& configurations,
const char* component, bool optional): const char* component, bool optional):
Target(&t), Destination(dest), ImportLibrary(implib), cmInstallGenerator(dest), Target(&t), ImportLibrary(implib),
FilePermissions(file_permissions), Configurations(configurations), FilePermissions(file_permissions), Configurations(configurations),
Component(component), Optional(optional) Component(component), Optional(optional)
{ {
@ -58,11 +58,11 @@ void cmInstallTargetGenerator::GenerateScript(std::ostream& os)
} }
// Write variable settings to do per-configuration references. // Write variable settings to do per-configuration references.
this->PrepareScriptReference(os, this->Target, "BUILD", true, false); this->PrepareScriptReference(os, this->Target, "BUILD", true, this->ImportLibrary, false);
// Create the per-configuration reference. // Create the per-configuration reference.
std::string fromName = this->GetScriptReference(this->Target, "BUILD", std::string fromName = this->GetScriptReference(this->Target, "BUILD",
false); this->ImportLibrary, false);
std::string fromFile = fromDir; std::string fromFile = fromDir;
fromFile += fromName; fromFile += fromName;
@ -137,7 +137,7 @@ void cmInstallTargetGenerator::GenerateScript(std::ostream& os)
// Compute the source locations of the bundle executable and // Compute the source locations of the bundle executable and
// Info.plist file. // Info.plist file.
this->PrepareScriptReference(os, this->Target, "INSTALL", this->PrepareScriptReference(os, this->Target, "INSTALL",
false, false); false, this->ImportLibrary, false);
fromFile += ".app"; fromFile += ".app";
type = cmTarget::INSTALL_DIRECTORY; type = cmTarget::INSTALL_DIRECTORY;
literal_args += " USE_SOURCE_PERMISSIONS"; literal_args += " USE_SOURCE_PERMISSIONS";
@ -188,6 +188,12 @@ void cmInstallTargetGenerator::GenerateScript(std::ostream& os)
this->AddStripRule(os, type, quotedFullDestinationFilename, optional); this->AddStripRule(os, type, quotedFullDestinationFilename, optional);
} }
std::string cmInstallTargetGenerator::GetInstallFilename(const char* config) const
{
return cmInstallTargetGenerator::GetInstallFilename(this->Target, config, this->ImportLibrary, false);
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
std::string cmInstallTargetGenerator::GetInstallFilename(cmTarget* target, std::string cmInstallTargetGenerator::GetInstallFilename(cmTarget* target,
const char* config, const char* config,
@ -250,7 +256,7 @@ void
cmInstallTargetGenerator cmInstallTargetGenerator
::PrepareScriptReference(std::ostream& os, cmTarget* target, ::PrepareScriptReference(std::ostream& os, cmTarget* target,
const char* place, bool useConfigDir, const char* place, bool useConfigDir,
bool useSOName) bool implib, bool useSOName)
{ {
// If the target name may vary with the configuration type then // If the target name may vary with the configuration type then
// store all possible names ahead of time in variables. // store all possible names ahead of time in variables.
@ -270,11 +276,11 @@ cmInstallTargetGenerator
} }
fname += this->GetInstallFilename(target, i->c_str(), fname += this->GetInstallFilename(target, i->c_str(),
this->ImportLibrary, useSOName); implib, useSOName);
// Set a variable with the target name for this configuration. // Set a variable with the target name for this configuration.
os << "SET(" << target->GetName() << "_" << place os << "SET(" << target->GetName() << "_" << place
<< (this->ImportLibrary? "_IMPNAME_" : "_NAME_") << *i << (implib? "_IMPNAME_" : "_NAME_") << *i
<< " \"" << fname << "\")\n"; << " \"" << fname << "\")\n";
} }
} }
@ -282,20 +288,20 @@ cmInstallTargetGenerator
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
std::string cmInstallTargetGenerator::GetScriptReference(cmTarget* target, std::string cmInstallTargetGenerator::GetScriptReference(cmTarget* target,
const char* place, const char* place,
bool useSOName) bool implib, bool useSOName)
{ {
if(this->ConfigurationTypes->empty()) if(this->ConfigurationTypes->empty())
{ {
// Reference the target by its one configuration name. // Reference the target by its one configuration name.
return this->GetInstallFilename(target, this->ConfigurationName, return this->GetInstallFilename(target, this->ConfigurationName,
this->ImportLibrary, useSOName); implib, useSOName);
} }
else else
{ {
// Reference the target using the per-configuration variable. // Reference the target using the per-configuration variable.
std::string ref = "${"; std::string ref = "${";
ref += target->GetName(); ref += target->GetName();
if(this->ImportLibrary) if(implib)
{ {
ref += "_"; ref += "_";
ref += place; ref += place;
@ -361,13 +367,13 @@ void cmInstallTargetGenerator
{ {
// Map from the build-tree install_name. // Map from the build-tree install_name.
this->PrepareScriptReference(os, tgt, "REMAP_FROM", this->PrepareScriptReference(os, tgt, "REMAP_FROM",
!for_build.empty(), true); !for_build.empty(), false, true);
for_build += this->GetScriptReference(tgt, "REMAP_FROM", true); for_build += this->GetScriptReference(tgt, "REMAP_FROM", false, true);
// Map to the install-tree install_name. // Map to the install-tree install_name.
this->PrepareScriptReference(os, tgt, "REMAP_TO", this->PrepareScriptReference(os, tgt, "REMAP_TO",
false, true); false, false, true);
for_install += this->GetScriptReference(tgt, "REMAP_TO", true); for_install += this->GetScriptReference(tgt, "REMAP_TO", false, true);
// Store the mapping entry. // Store the mapping entry.
install_name_remap[for_build] = for_install; install_name_remap[for_build] = for_install;
@ -378,7 +384,7 @@ void cmInstallTargetGenerator
} }
// Edit the install_name of the target itself if necessary. // Edit the install_name of the target itself if necessary.
this->PrepareScriptReference(os, this->Target, "REMAPPED", false, true); this->PrepareScriptReference(os, this->Target, "REMAPPED", false, this->ImportLibrary, true);
std::string new_id; std::string new_id;
if(this->Target->GetType() == cmTarget::SHARED_LIBRARY) if(this->Target->GetType() == cmTarget::SHARED_LIBRARY)
{ {
@ -390,7 +396,7 @@ void cmInstallTargetGenerator
{ {
// Prepare to refer to the install-tree install_name. // Prepare to refer to the install-tree install_name.
new_id = for_install; new_id = for_install;
new_id += this->GetScriptReference(this->Target, "REMAPPED", true); new_id += this->GetScriptReference(this->Target, "REMAPPED", this->ImportLibrary, true);
} }
} }
@ -416,7 +422,7 @@ void cmInstallTargetGenerator
os << "\n -change \"" << i->first << "\" \"" << i->second << "\""; os << "\n -change \"" << i->first << "\" \"" << i->second << "\"";
} }
os << "\n \"$ENV{DESTDIR}" << destination << "/" os << "\n \"$ENV{DESTDIR}" << destination << "/"
<< this->GetScriptReference(this->Target, "REMAPPED", true) << "\")\n"; << this->GetScriptReference(this->Target, "REMAPPED", this->ImportLibrary, true) << "\")\n";
os << "ENDIF(" << component_test << ")\n"; os << "ENDIF(" << component_test << ")\n";
} }
} }

View File

@ -36,16 +36,19 @@ public:
); );
virtual ~cmInstallTargetGenerator(); virtual ~cmInstallTargetGenerator();
std::string GetInstallFilename(const char* config) const;
static std::string GetInstallFilename(cmTarget*target, const char* config, static std::string GetInstallFilename(cmTarget*target, const char* config,
bool implib, bool useSOName); bool implib, bool useSOName);
const std::vector<std::string>& GetConfigurations() const {return this->Configurations;}
protected: protected:
virtual void GenerateScript(std::ostream& os); virtual void GenerateScript(std::ostream& os);
void PrepareScriptReference(std::ostream& os, cmTarget* target, void PrepareScriptReference(std::ostream& os, cmTarget* target,
const char* place, bool useConfigDir, const char* place, bool useConfigDir,
bool useSOName); bool implib, bool useSOName);
std::string GetScriptReference(cmTarget* target, const char* place, std::string GetScriptReference(cmTarget* target, const char* place,
bool useSOName); bool implib, bool useSOName);
void AddInstallNamePatchRule(std::ostream& os, const char* destination); void AddInstallNamePatchRule(std::ostream& os, const char* destination);
void AddStripRule(std::ostream& os, void AddStripRule(std::ostream& os,
cmTarget::TargetType type, cmTarget::TargetType type,
@ -56,7 +59,6 @@ protected:
const std::string& quotedFullDestinationFilename); const std::string& quotedFullDestinationFilename);
cmTarget* Target; cmTarget* Target;
std::string Destination;
bool ImportLibrary; bool ImportLibrary;
std::string FilePermissions; std::string FilePermissions;
std::vector<std::string> Configurations; std::vector<std::string> Configurations;