ENH: Improved indentation of generated cmake_install.cmake code.
This commit is contained in:
parent
c8b263c674
commit
c83ae4673d
@ -60,7 +60,8 @@ void cmInstallGenerator
|
|||||||
std::vector<std::string> const& configurations,
|
std::vector<std::string> const& configurations,
|
||||||
const char* component /* = 0 */,
|
const char* component /* = 0 */,
|
||||||
const char* rename /* = 0 */,
|
const char* rename /* = 0 */,
|
||||||
const char* literal_args /* = 0 */
|
const char* literal_args /* = 0 */,
|
||||||
|
cmInstallGeneratorIndent const& indent
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// Use the FILE command to install the file.
|
// Use the FILE command to install the file.
|
||||||
@ -76,6 +77,7 @@ void cmInstallGenerator
|
|||||||
case cmTarget::INSTALL_FILES:
|
case cmTarget::INSTALL_FILES:
|
||||||
default: stype = "FILE"; break;
|
default: stype = "FILE"; break;
|
||||||
}
|
}
|
||||||
|
os << indent;
|
||||||
os << "FILE(INSTALL DESTINATION \"" << dest << "\" TYPE " << stype.c_str();
|
os << "FILE(INSTALL DESTINATION \"" << dest << "\" TYPE " << stype.c_str();
|
||||||
if(optional)
|
if(optional)
|
||||||
{
|
{
|
||||||
@ -120,9 +122,9 @@ void cmInstallGenerator
|
|||||||
for(std::vector<std::string>::const_iterator fi = files.begin();
|
for(std::vector<std::string>::const_iterator fi = files.begin();
|
||||||
fi != files.end(); ++fi)
|
fi != files.end(); ++fi)
|
||||||
{
|
{
|
||||||
os << "\n \"" << *fi << "\"";
|
os << "\n" << indent << " \"" << *fi << "\"";
|
||||||
}
|
}
|
||||||
os << "\n ";
|
os << "\n" << indent << " ";
|
||||||
if(!(literal_args && *literal_args))
|
if(!(literal_args && *literal_args))
|
||||||
{
|
{
|
||||||
os << " ";
|
os << " ";
|
||||||
|
@ -21,6 +21,32 @@
|
|||||||
|
|
||||||
class cmLocalGenerator;
|
class cmLocalGenerator;
|
||||||
|
|
||||||
|
class cmInstallGeneratorIndent
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
cmInstallGeneratorIndent(): Level(0) {}
|
||||||
|
cmInstallGeneratorIndent(int level): Level(level) {}
|
||||||
|
void Write(std::ostream& os) const
|
||||||
|
{
|
||||||
|
for(int i=0; i < this->Level; ++i)
|
||||||
|
{
|
||||||
|
os << " ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cmInstallGeneratorIndent Next(int step = 2) const
|
||||||
|
{
|
||||||
|
return cmInstallGeneratorIndent(this->Level + step);
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
int Level;
|
||||||
|
};
|
||||||
|
inline std::ostream& operator<<(std::ostream& os,
|
||||||
|
cmInstallGeneratorIndent const& indent)
|
||||||
|
{
|
||||||
|
indent.Write(os);
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
/** \class cmInstallGenerator
|
/** \class cmInstallGenerator
|
||||||
* \brief Support class for generating install scripts.
|
* \brief Support class for generating install scripts.
|
||||||
*
|
*
|
||||||
@ -46,7 +72,8 @@ public:
|
|||||||
= std::vector<std::string>(),
|
= std::vector<std::string>(),
|
||||||
const char* component = 0,
|
const char* component = 0,
|
||||||
const char* rename = 0,
|
const char* rename = 0,
|
||||||
const char* literal_args = 0
|
const char* literal_args = 0,
|
||||||
|
cmInstallGeneratorIndent const& indent = cmInstallGeneratorIndent()
|
||||||
);
|
);
|
||||||
|
|
||||||
const char* GetDestination() const {return this->Destination.c_str();}
|
const char* GetDestination() const {return this->Destination.c_str();}
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
#include "cmake.h"
|
#include "cmake.h"
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// - Fix indentation of generated code
|
|
||||||
// - Consolidate component/configuration checks across multiple
|
// - Consolidate component/configuration checks across multiple
|
||||||
// install generators
|
// install generators
|
||||||
// - Skip IF(EXISTS) checks if nothing is done with the installed file
|
// - Skip IF(EXISTS) checks if nothing is done with the installed file
|
||||||
@ -49,12 +48,15 @@ cmInstallTargetGenerator
|
|||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void cmInstallTargetGenerator::GenerateScript(std::ostream& os)
|
void cmInstallTargetGenerator::GenerateScript(std::ostream& os)
|
||||||
{
|
{
|
||||||
|
// Track indentation.
|
||||||
|
Indent indent;
|
||||||
|
|
||||||
// Begin this block of installation.
|
// Begin this block of installation.
|
||||||
std::string component_test = "NOT CMAKE_INSTALL_COMPONENT OR "
|
std::string component_test = "NOT CMAKE_INSTALL_COMPONENT OR "
|
||||||
"\"${CMAKE_INSTALL_COMPONENT}\" MATCHES \"^(";
|
"\"${CMAKE_INSTALL_COMPONENT}\" MATCHES \"^(";
|
||||||
component_test += this->Component;
|
component_test += this->Component;
|
||||||
component_test += ")$\"";
|
component_test += ")$\"";
|
||||||
os << "IF(" << component_test << ")\n";
|
os << indent << "IF(" << component_test << ")\n";
|
||||||
|
|
||||||
// Compute the build tree directory from which to copy the target.
|
// Compute the build tree directory from which to copy the target.
|
||||||
std::string fromDir;
|
std::string fromDir;
|
||||||
@ -74,7 +76,8 @@ void cmInstallTargetGenerator::GenerateScript(std::ostream& os)
|
|||||||
if(this->ConfigurationTypes->empty())
|
if(this->ConfigurationTypes->empty())
|
||||||
{
|
{
|
||||||
this->GenerateScriptForConfig(os, fromDir.c_str(),
|
this->GenerateScriptForConfig(os, fromDir.c_str(),
|
||||||
this->ConfigurationName);
|
this->ConfigurationName,
|
||||||
|
indent.Next());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -82,18 +85,48 @@ void cmInstallTargetGenerator::GenerateScript(std::ostream& os)
|
|||||||
this->ConfigurationTypes->begin();
|
this->ConfigurationTypes->begin();
|
||||||
i != this->ConfigurationTypes->end(); ++i)
|
i != this->ConfigurationTypes->end(); ++i)
|
||||||
{
|
{
|
||||||
this->GenerateScriptForConfig(os, fromDir.c_str(), i->c_str());
|
this->GenerateScriptForConfig(os, fromDir.c_str(), i->c_str(),
|
||||||
|
indent.Next());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// End this block of installation.
|
// End this block of installation.
|
||||||
os << "ENDIF(" << component_test << ")\n";
|
os << indent << "ENDIF(" << component_test << ")\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
static std::string cmInstallTargetGeneratorEncodeConfig(const char* config)
|
||||||
|
{
|
||||||
|
std::string result;
|
||||||
|
for(const char* c = config; *c; ++c)
|
||||||
|
{
|
||||||
|
if(*c >= 'a' && *c <= 'z')
|
||||||
|
{
|
||||||
|
result += "[";
|
||||||
|
result += *c + ('A' - 'a');
|
||||||
|
result += *c;
|
||||||
|
result += "]";
|
||||||
|
}
|
||||||
|
else if(*c >= 'A' && *c <= 'Z')
|
||||||
|
{
|
||||||
|
result += "[";
|
||||||
|
result += *c;
|
||||||
|
result += *c + ('a' - 'A');
|
||||||
|
result += "]";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result += *c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void cmInstallTargetGenerator::GenerateScriptForConfig(std::ostream& os,
|
void cmInstallTargetGenerator::GenerateScriptForConfig(std::ostream& os,
|
||||||
const char* fromDir,
|
const char* fromDir,
|
||||||
const char* config)
|
const char* config,
|
||||||
|
Indent const& indent)
|
||||||
{
|
{
|
||||||
// Compute the per-configuration directory containing the files.
|
// Compute the per-configuration directory containing the files.
|
||||||
std::string fromDirConfig = fromDir;
|
std::string fromDirConfig = fromDir;
|
||||||
@ -121,13 +154,30 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(std::ostream& os,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Begin this configuration block.
|
// Generate a per-configuration block.
|
||||||
config_test = "\"${CMAKE_INSTALL_CONFIG_NAME}\" MATCHES \"^(";
|
config_test = "\"${CMAKE_INSTALL_CONFIG_NAME}\" MATCHES \"^(";
|
||||||
config_test += config;
|
config_test += cmInstallTargetGeneratorEncodeConfig(config);
|
||||||
config_test += ")$\"";
|
config_test += ")$\"";
|
||||||
os << " IF(" << config_test << ")\n";
|
os << indent << "IF(" << config_test << ")\n";
|
||||||
|
this->GenerateScriptForConfigDir(os, fromDirConfig.c_str(), config,
|
||||||
|
indent.Next());
|
||||||
|
os << indent << "ENDIF(" << config_test << ")\n";
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->GenerateScriptForConfigDir(os, fromDirConfig.c_str(), config,
|
||||||
|
indent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
void
|
||||||
|
cmInstallTargetGenerator
|
||||||
|
::GenerateScriptForConfigDir(std::ostream& os,
|
||||||
|
const char* fromDirConfig,
|
||||||
|
const char* config,
|
||||||
|
Indent const& indent)
|
||||||
|
{
|
||||||
// Compute the list of files to install for this target.
|
// Compute the list of files to install for this target.
|
||||||
std::vector<std::string> files;
|
std::vector<std::string> files;
|
||||||
std::string literal_args;
|
std::string literal_args;
|
||||||
@ -231,7 +281,8 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(std::ostream& os,
|
|||||||
optional, no_properties,
|
optional, no_properties,
|
||||||
this->FilePermissions.c_str(), no_dir_permissions,
|
this->FilePermissions.c_str(), no_dir_permissions,
|
||||||
no_configurations, no_component,
|
no_configurations, no_component,
|
||||||
no_rename, literal_args.c_str());
|
no_rename, literal_args.c_str(),
|
||||||
|
indent);
|
||||||
|
|
||||||
std::string toFullPath = "$ENV{DESTDIR}";
|
std::string toFullPath = "$ENV{DESTDIR}";
|
||||||
toFullPath += this->Destination;
|
toFullPath += this->Destination;
|
||||||
@ -239,17 +290,11 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(std::ostream& os,
|
|||||||
toFullPath += this->GetInstallFilename(this->Target, config,
|
toFullPath += this->GetInstallFilename(this->Target, config,
|
||||||
this->ImportLibrary, false);
|
this->ImportLibrary, false);
|
||||||
|
|
||||||
os << " IF(EXISTS \"" << toFullPath << "\")\n";
|
os << indent << "IF(EXISTS \"" << toFullPath << "\")\n";
|
||||||
this->AddInstallNamePatchRule(os, config, toFullPath);
|
this->AddInstallNamePatchRule(os, indent.Next(), config, toFullPath);
|
||||||
this->AddRanlibRule(os, type, toFullPath);
|
this->AddRanlibRule(os, indent.Next(), type, toFullPath);
|
||||||
this->AddStripRule(os, type, toFullPath);
|
this->AddStripRule(os, indent.Next(), type, toFullPath);
|
||||||
os << " ENDIF(EXISTS \"" << toFullPath << "\")\n";
|
os << indent << "ENDIF(EXISTS \"" << toFullPath << "\")\n";
|
||||||
|
|
||||||
if(config && *config)
|
|
||||||
{
|
|
||||||
// End this configuration block.
|
|
||||||
os << " ENDIF(" << config_test << ")\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
@ -321,8 +366,8 @@ std::string cmInstallTargetGenerator::GetInstallFilename(cmTarget* target,
|
|||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void
|
void
|
||||||
cmInstallTargetGenerator
|
cmInstallTargetGenerator
|
||||||
::AddInstallNamePatchRule(std::ostream& os, const char* config,
|
::AddInstallNamePatchRule(std::ostream& os, Indent const& indent,
|
||||||
std::string const& toFullPath)
|
const char* config, std::string const& toFullPath)
|
||||||
{
|
{
|
||||||
if(this->ImportLibrary ||
|
if(this->ImportLibrary ||
|
||||||
!(this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
|
!(this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
|
||||||
@ -411,25 +456,27 @@ cmInstallTargetGenerator
|
|||||||
// install_name value and references.
|
// install_name value and references.
|
||||||
if(!new_id.empty() || !install_name_remap.empty())
|
if(!new_id.empty() || !install_name_remap.empty())
|
||||||
{
|
{
|
||||||
os << " EXECUTE_PROCESS(COMMAND \"" << installNameTool;
|
os << indent << "EXECUTE_PROCESS(COMMAND \"" << installNameTool;
|
||||||
os << "\"";
|
os << "\"";
|
||||||
if(!new_id.empty())
|
if(!new_id.empty())
|
||||||
{
|
{
|
||||||
os << "\n -id \"" << new_id << "\"";
|
os << "\n" << indent << " -id \"" << new_id << "\"";
|
||||||
}
|
}
|
||||||
for(std::map<cmStdString, cmStdString>::const_iterator
|
for(std::map<cmStdString, cmStdString>::const_iterator
|
||||||
i = install_name_remap.begin();
|
i = install_name_remap.begin();
|
||||||
i != install_name_remap.end(); ++i)
|
i != install_name_remap.end(); ++i)
|
||||||
{
|
{
|
||||||
os << "\n -change \"" << i->first << "\" \"" << i->second << "\"";
|
os << "\n" << indent << " -change \""
|
||||||
|
<< i->first << "\" \"" << i->second << "\"";
|
||||||
}
|
}
|
||||||
os << "\n \"" << toFullPath << "\")\n";
|
os << "\n" << indent << " \"" << toFullPath << "\")\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void
|
void
|
||||||
cmInstallTargetGenerator::AddStripRule(std::ostream& os,
|
cmInstallTargetGenerator::AddStripRule(std::ostream& os,
|
||||||
|
Indent const& indent,
|
||||||
cmTarget::TargetType type,
|
cmTarget::TargetType type,
|
||||||
const std::string& toFullPath)
|
const std::string& toFullPath)
|
||||||
{
|
{
|
||||||
@ -453,16 +500,17 @@ cmInstallTargetGenerator::AddStripRule(std::ostream& os,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
os << " IF(CMAKE_INSTALL_DO_STRIP)\n";
|
os << indent << "IF(CMAKE_INSTALL_DO_STRIP)\n";
|
||||||
os << " EXECUTE_PROCESS(COMMAND \""
|
os << indent << " EXECUTE_PROCESS(COMMAND \""
|
||||||
<< this->Target->GetMakefile()->GetDefinition("CMAKE_STRIP")
|
<< this->Target->GetMakefile()->GetDefinition("CMAKE_STRIP")
|
||||||
<< "\" \"" << toFullPath << "\")\n";
|
<< "\" \"" << toFullPath << "\")\n";
|
||||||
os << " ENDIF(CMAKE_INSTALL_DO_STRIP)\n";
|
os << indent << "ENDIF(CMAKE_INSTALL_DO_STRIP)\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void
|
void
|
||||||
cmInstallTargetGenerator::AddRanlibRule(std::ostream& os,
|
cmInstallTargetGenerator::AddRanlibRule(std::ostream& os,
|
||||||
|
Indent const& indent,
|
||||||
cmTarget::TargetType type,
|
cmTarget::TargetType type,
|
||||||
const std::string& toFullPath)
|
const std::string& toFullPath)
|
||||||
{
|
{
|
||||||
@ -486,6 +534,6 @@ cmInstallTargetGenerator::AddRanlibRule(std::ostream& os,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
os << " EXECUTE_PROCESS(COMMAND \""
|
os << indent << "EXECUTE_PROCESS(COMMAND \""
|
||||||
<< ranlib << "\" \"" << toFullPath << "\")\n";
|
<< ranlib << "\" \"" << toFullPath << "\")\n";
|
||||||
}
|
}
|
||||||
|
@ -43,15 +43,24 @@ public:
|
|||||||
const std::vector<std::string>& GetConfigurations() const {return this->Configurations;}
|
const std::vector<std::string>& GetConfigurations() const {return this->Configurations;}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
typedef cmInstallGeneratorIndent Indent;
|
||||||
virtual void GenerateScript(std::ostream& os);
|
virtual void GenerateScript(std::ostream& os);
|
||||||
void GenerateScriptForConfig(std::ostream& os,
|
void GenerateScriptForConfig(std::ostream& os,
|
||||||
const char* fromDir,
|
const char* fromDir,
|
||||||
const char* config);
|
const char* config,
|
||||||
void AddInstallNamePatchRule(std::ostream& os, const char* config,
|
Indent const& indent);
|
||||||
|
void GenerateScriptForConfigDir(std::ostream& os,
|
||||||
|
const char* fromDirConfig,
|
||||||
|
const char* config,
|
||||||
|
Indent const& indent);
|
||||||
|
void AddInstallNamePatchRule(std::ostream& os, Indent const& indent,
|
||||||
|
const char* config,
|
||||||
const std::string& toFullPath);
|
const std::string& toFullPath);
|
||||||
void AddStripRule(std::ostream& os, cmTarget::TargetType type,
|
void AddStripRule(std::ostream& os, Indent const& indent,
|
||||||
|
cmTarget::TargetType type,
|
||||||
const std::string& toFullPath);
|
const std::string& toFullPath);
|
||||||
void AddRanlibRule(std::ostream& os, cmTarget::TargetType type,
|
void AddRanlibRule(std::ostream& os, Indent const& indent,
|
||||||
|
cmTarget::TargetType type,
|
||||||
const std::string& toFullPath);
|
const std::string& toFullPath);
|
||||||
|
|
||||||
cmTarget* Target;
|
cmTarget* Target;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user