diff options
author | Brad King <brad.king@kitware.com> | 2007-07-02 15:02:52 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2007-07-02 15:02:52 (GMT) |
commit | c83ae4673d1bdf72bf27eb6e60c877b1156a672a (patch) | |
tree | 53d89845aec8f5fbf25bf45317bed251658cf128 /Source/cmInstallTargetGenerator.cxx | |
parent | c8b263c674d9c75232b4317b57259b1bbff88016 (diff) | |
download | CMake-c83ae4673d1bdf72bf27eb6e60c877b1156a672a.zip CMake-c83ae4673d1bdf72bf27eb6e60c877b1156a672a.tar.gz CMake-c83ae4673d1bdf72bf27eb6e60c877b1156a672a.tar.bz2 |
ENH: Improved indentation of generated cmake_install.cmake code.
Diffstat (limited to 'Source/cmInstallTargetGenerator.cxx')
-rw-r--r-- | Source/cmInstallTargetGenerator.cxx | 110 |
1 files changed, 79 insertions, 31 deletions
diff --git a/Source/cmInstallTargetGenerator.cxx b/Source/cmInstallTargetGenerator.cxx index d2135ce..9df0a04 100644 --- a/Source/cmInstallTargetGenerator.cxx +++ b/Source/cmInstallTargetGenerator.cxx @@ -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 @@ cmInstallTargetGenerator //---------------------------------------------------------------------------- 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 @@ void cmInstallTargetGenerator::GenerateScript(std::ostream& os) if(this->ConfigurationTypes->empty()) { this->GenerateScriptForConfig(os, fromDir.c_str(), - this->ConfigurationName); + this->ConfigurationName, + indent.Next()); } else { @@ -82,18 +85,48 @@ void cmInstallTargetGenerator::GenerateScript(std::ostream& os) 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 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(std::ostream& os, } } - // 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 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(std::ostream& os, 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 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(std::ostream& os, 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 @@ std::string cmInstallTargetGenerator::GetInstallFilename(cmTarget* target, //---------------------------------------------------------------------------- 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 @@ cmInstallTargetGenerator // 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 @@ cmInstallTargetGenerator::AddStripRule(std::ostream& os, 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 @@ cmInstallTargetGenerator::AddRanlibRule(std::ostream& os, return; } - os << " EXECUTE_PROCESS(COMMAND \"" + os << indent << "EXECUTE_PROCESS(COMMAND \"" << ranlib << "\" \"" << toFullPath << "\")\n"; } |