[cmake-commits] king committed cmInstallGenerator.cxx 1.11 1.12
cmInstallGenerator.h 1.10 1.11 cmInstallTargetGenerator.cxx
1.39 1.40 cmInstallTargetGenerator.h 1.15 1.16
cmake-commits at cmake.org
cmake-commits at cmake.org
Mon Jul 2 11:02:54 EDT 2007
Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv27084
Modified Files:
cmInstallGenerator.cxx cmInstallGenerator.h
cmInstallTargetGenerator.cxx cmInstallTargetGenerator.h
Log Message:
ENH: Improved indentation of generated cmake_install.cmake code.
Index: cmInstallTargetGenerator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmInstallTargetGenerator.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- cmInstallTargetGenerator.h 28 Jun 2007 20:11:18 -0000 1.15
+++ cmInstallTargetGenerator.h 2 Jul 2007 15:02:52 -0000 1.16
@@ -43,15 +43,24 @@
const std::vector<std::string>& GetConfigurations() const {return this->Configurations;}
protected:
+ typedef cmInstallGeneratorIndent Indent;
virtual void GenerateScript(std::ostream& os);
void GenerateScriptForConfig(std::ostream& os,
const char* fromDir,
- const char* config);
- void AddInstallNamePatchRule(std::ostream& os, const char* config,
+ 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);
- void AddStripRule(std::ostream& os, cmTarget::TargetType type,
+ void AddStripRule(std::ostream& os, Indent const& indent,
+ cmTarget::TargetType type,
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);
cmTarget* Target;
Index: cmInstallGenerator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmInstallGenerator.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- cmInstallGenerator.h 28 Jun 2007 20:11:18 -0000 1.10
+++ cmInstallGenerator.h 2 Jul 2007 15:02:52 -0000 1.11
@@ -21,6 +21,32 @@
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
* \brief Support class for generating install scripts.
*
@@ -46,7 +72,8 @@
= std::vector<std::string>(),
const char* component = 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();}
Index: cmInstallGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmInstallGenerator.cxx,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- cmInstallGenerator.cxx 28 Jun 2007 20:11:18 -0000 1.11
+++ cmInstallGenerator.cxx 2 Jul 2007 15:02:52 -0000 1.12
@@ -60,7 +60,8 @@
std::vector<std::string> const& configurations,
const char* component /* = 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.
@@ -76,6 +77,7 @@
case cmTarget::INSTALL_FILES:
default: stype = "FILE"; break;
}
+ os << indent;
os << "FILE(INSTALL DESTINATION \"" << dest << "\" TYPE " << stype.c_str();
if(optional)
{
@@ -120,9 +122,9 @@
for(std::vector<std::string>::const_iterator fi = files.begin();
fi != files.end(); ++fi)
{
- os << "\n \"" << *fi << "\"";
+ os << "\n" << indent << " \"" << *fi << "\"";
}
- os << "\n ";
+ os << "\n" << indent << " ";
if(!(literal_args && *literal_args))
{
os << " ";
Index: cmInstallTargetGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmInstallTargetGenerator.cxx,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- cmInstallTargetGenerator.cxx 28 Jun 2007 20:11:18 -0000 1.39
+++ cmInstallTargetGenerator.cxx 2 Jul 2007 15:02:52 -0000 1.40
@@ -22,7 +22,6 @@
#include "cmake.h"
// TODO:
-// - Fix indentation of generated code
// - Consolidate component/configuration checks across multiple
// install generators
// - Skip IF(EXISTS) checks if nothing is done with the installed file
@@ -49,12 +48,15 @@
//----------------------------------------------------------------------------
void cmInstallTargetGenerator::GenerateScript(std::ostream& os)
{
+ // Track indentation.
+ Indent indent;
+
// Begin this block of installation.
std::string component_test = "NOT CMAKE_INSTALL_COMPONENT OR "
"\"${CMAKE_INSTALL_COMPONENT}\" MATCHES \"^(";
component_test += this->Component;
component_test += ")$\"";
- os << "IF(" << component_test << ")\n";
+ os << indent << "IF(" << component_test << ")\n";
// Compute the build tree directory from which to copy the target.
std::string fromDir;
@@ -74,7 +76,8 @@
if(this->ConfigurationTypes->empty())
{
this->GenerateScriptForConfig(os, fromDir.c_str(),
- this->ConfigurationName);
+ this->ConfigurationName,
+ indent.Next());
}
else
{
@@ -82,18 +85,48 @@
this->ConfigurationTypes->begin();
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.
- 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,
const char* fromDir,
- const char* config)
+ const char* config,
+ Indent const& indent)
{
// Compute the per-configuration directory containing the files.
std::string fromDirConfig = fromDir;
@@ -121,13 +154,30 @@
}
}
- // Begin this configuration block.
+ // Generate a per-configuration block.
config_test = "\"${CMAKE_INSTALL_CONFIG_NAME}\" MATCHES \"^(";
- config_test += config;
+ config_test += cmInstallTargetGeneratorEncodeConfig(config);
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.
std::vector<std::string> files;
std::string literal_args;
@@ -231,7 +281,8 @@
optional, no_properties,
this->FilePermissions.c_str(), no_dir_permissions,
no_configurations, no_component,
- no_rename, literal_args.c_str());
+ no_rename, literal_args.c_str(),
+ indent);
std::string toFullPath = "$ENV{DESTDIR}";
toFullPath += this->Destination;
@@ -239,17 +290,11 @@
toFullPath += this->GetInstallFilename(this->Target, config,
this->ImportLibrary, false);
- os << " IF(EXISTS \"" << toFullPath << "\")\n";
- this->AddInstallNamePatchRule(os, config, toFullPath);
- this->AddRanlibRule(os, type, toFullPath);
- this->AddStripRule(os, type, toFullPath);
- os << " ENDIF(EXISTS \"" << toFullPath << "\")\n";
-
- if(config && *config)
- {
- // End this configuration block.
- os << " ENDIF(" << config_test << ")\n";
- }
+ os << indent << "IF(EXISTS \"" << toFullPath << "\")\n";
+ this->AddInstallNamePatchRule(os, indent.Next(), config, toFullPath);
+ this->AddRanlibRule(os, indent.Next(), type, toFullPath);
+ this->AddStripRule(os, indent.Next(), type, toFullPath);
+ os << indent << "ENDIF(EXISTS \"" << toFullPath << "\")\n";
}
//----------------------------------------------------------------------------
@@ -321,8 +366,8 @@
//----------------------------------------------------------------------------
void
cmInstallTargetGenerator
-::AddInstallNamePatchRule(std::ostream& os, const char* config,
- std::string const& toFullPath)
+::AddInstallNamePatchRule(std::ostream& os, Indent const& indent,
+ const char* config, std::string const& toFullPath)
{
if(this->ImportLibrary ||
!(this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
@@ -411,25 +456,27 @@
// install_name value and references.
if(!new_id.empty() || !install_name_remap.empty())
{
- os << " EXECUTE_PROCESS(COMMAND \"" << installNameTool;
+ os << indent << "EXECUTE_PROCESS(COMMAND \"" << installNameTool;
os << "\"";
if(!new_id.empty())
{
- os << "\n -id \"" << new_id << "\"";
+ os << "\n" << indent << " -id \"" << new_id << "\"";
}
for(std::map<cmStdString, cmStdString>::const_iterator
i = install_name_remap.begin();
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
cmInstallTargetGenerator::AddStripRule(std::ostream& os,
+ Indent const& indent,
cmTarget::TargetType type,
const std::string& toFullPath)
{
@@ -453,16 +500,17 @@
return;
}
- os << " IF(CMAKE_INSTALL_DO_STRIP)\n";
- os << " EXECUTE_PROCESS(COMMAND \""
+ os << indent << "IF(CMAKE_INSTALL_DO_STRIP)\n";
+ os << indent << " EXECUTE_PROCESS(COMMAND \""
<< this->Target->GetMakefile()->GetDefinition("CMAKE_STRIP")
<< "\" \"" << toFullPath << "\")\n";
- os << " ENDIF(CMAKE_INSTALL_DO_STRIP)\n";
+ os << indent << "ENDIF(CMAKE_INSTALL_DO_STRIP)\n";
}
//----------------------------------------------------------------------------
void
cmInstallTargetGenerator::AddRanlibRule(std::ostream& os,
+ Indent const& indent,
cmTarget::TargetType type,
const std::string& toFullPath)
{
@@ -486,6 +534,6 @@
return;
}
- os << " EXECUTE_PROCESS(COMMAND \""
+ os << indent << "EXECUTE_PROCESS(COMMAND \""
<< ranlib << "\" \"" << toFullPath << "\")\n";
}
More information about the Cmake-commits
mailing list