You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

240 lines
7.0 KiB

  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmInstallGenerator.h"
  14. #include "cmSystemTools.h"
  15. #include "cmTarget.h"
  16. //----------------------------------------------------------------------------
  17. cmInstallGenerator
  18. ::cmInstallGenerator(const char* destination,
  19. std::vector<std::string> const& configurations,
  20. const char* component):
  21. Destination(destination? destination:""),
  22. Configurations(configurations),
  23. Component(component? component:""),
  24. ConfigurationName(0),
  25. ConfigurationTypes(0)
  26. {
  27. }
  28. //----------------------------------------------------------------------------
  29. cmInstallGenerator
  30. ::~cmInstallGenerator()
  31. {
  32. }
  33. //----------------------------------------------------------------------------
  34. void
  35. cmInstallGenerator
  36. ::Generate(std::ostream& os, const char* config,
  37. std::vector<std::string> const& configurationTypes)
  38. {
  39. this->ConfigurationName = config;
  40. this->ConfigurationTypes = &configurationTypes;
  41. this->GenerateScript(os);
  42. this->ConfigurationName = 0;
  43. this->ConfigurationTypes = 0;
  44. }
  45. //----------------------------------------------------------------------------
  46. void cmInstallGenerator
  47. ::AddInstallRule(
  48. std::ostream& os,
  49. const char* dest,
  50. int type,
  51. std::vector<std::string> const& files,
  52. bool optional /* = false */,
  53. const char* properties /* = 0 */,
  54. const char* permissions_file /* = 0 */,
  55. const char* permissions_dir /* = 0 */,
  56. const char* rename /* = 0 */,
  57. const char* literal_args /* = 0 */,
  58. cmInstallGeneratorIndent const& indent
  59. )
  60. {
  61. // Use the FILE command to install the file.
  62. std::string stype;
  63. switch(type)
  64. {
  65. case cmTarget::INSTALL_DIRECTORY:stype = "DIRECTORY"; break;
  66. case cmTarget::INSTALL_PROGRAMS: stype = "PROGRAM"; break;
  67. case cmTarget::EXECUTABLE: stype = "EXECUTABLE"; break;
  68. case cmTarget::STATIC_LIBRARY: stype = "STATIC_LIBRARY"; break;
  69. case cmTarget::SHARED_LIBRARY: stype = "SHARED_LIBRARY"; break;
  70. case cmTarget::MODULE_LIBRARY: stype = "MODULE"; break;
  71. case cmTarget::INSTALL_FILES:
  72. default: stype = "FILE"; break;
  73. }
  74. os << indent;
  75. os << "FILE(INSTALL DESTINATION \"" << dest << "\" TYPE " << stype.c_str();
  76. if(optional)
  77. {
  78. os << " OPTIONAL";
  79. }
  80. if(properties && *properties)
  81. {
  82. os << " PROPERTIES" << properties;
  83. }
  84. if(permissions_file && *permissions_file)
  85. {
  86. os << " PERMISSIONS" << permissions_file;
  87. }
  88. if(permissions_dir && *permissions_dir)
  89. {
  90. os << " DIR_PERMISSIONS" << permissions_dir;
  91. }
  92. if(rename && *rename)
  93. {
  94. os << " RENAME \"" << rename << "\"";
  95. }
  96. os << " FILES";
  97. if(files.size() == 1)
  98. {
  99. os << " \"" << files[0] << "\"";
  100. }
  101. else
  102. {
  103. for(std::vector<std::string>::const_iterator fi = files.begin();
  104. fi != files.end(); ++fi)
  105. {
  106. os << "\n" << indent << " \"" << *fi << "\"";
  107. }
  108. os << "\n" << indent << " ";
  109. if(!(literal_args && *literal_args))
  110. {
  111. os << " ";
  112. }
  113. }
  114. if(literal_args && *literal_args)
  115. {
  116. os << literal_args;
  117. }
  118. os << ")\n";
  119. }
  120. //----------------------------------------------------------------------------
  121. static void cmInstallGeneratorEncodeConfig(const char* config,
  122. std::string& result)
  123. {
  124. for(const char* c = config; *c; ++c)
  125. {
  126. if(*c >= 'a' && *c <= 'z')
  127. {
  128. result += "[";
  129. result += *c + ('A' - 'a');
  130. result += *c;
  131. result += "]";
  132. }
  133. else if(*c >= 'A' && *c <= 'Z')
  134. {
  135. result += "[";
  136. result += *c;
  137. result += *c + ('a' - 'A');
  138. result += "]";
  139. }
  140. else
  141. {
  142. result += *c;
  143. }
  144. }
  145. }
  146. //----------------------------------------------------------------------------
  147. std::string
  148. cmInstallGenerator::CreateConfigTest(const char* config)
  149. {
  150. std::string result = "\"${CMAKE_INSTALL_CONFIG_NAME}\" MATCHES \"^(";
  151. if(config && *config)
  152. {
  153. cmInstallGeneratorEncodeConfig(config, result);
  154. }
  155. result += ")$\"";
  156. return result;
  157. }
  158. //----------------------------------------------------------------------------
  159. std::string
  160. cmInstallGenerator::CreateConfigTest(std::vector<std::string> const& configs)
  161. {
  162. std::string result = "\"${CMAKE_INSTALL_CONFIG_NAME}\" MATCHES \"^(";
  163. const char* sep = "";
  164. for(std::vector<std::string>::const_iterator ci = configs.begin();
  165. ci != configs.end(); ++ci)
  166. {
  167. result += sep;
  168. sep = "|";
  169. cmInstallGeneratorEncodeConfig(ci->c_str(), result);
  170. }
  171. result += ")$\"";
  172. return result;
  173. }
  174. //----------------------------------------------------------------------------
  175. std::string
  176. cmInstallGenerator::CreateComponentTest(const char* component)
  177. {
  178. std::string result = "NOT CMAKE_INSTALL_COMPONENT OR "
  179. "\"${CMAKE_INSTALL_COMPONENT}\" MATCHES \"^(";
  180. result += component;
  181. result += ")$\"";
  182. return result;
  183. }
  184. //----------------------------------------------------------------------------
  185. void cmInstallGenerator::GenerateScript(std::ostream& os)
  186. {
  187. // Track indentation.
  188. Indent indent;
  189. // Begin this block of installation.
  190. std::string component_test =
  191. this->CreateComponentTest(this->Component.c_str());
  192. os << indent << "IF(" << component_test << ")\n";
  193. // Generate the script possibly with per-configuration code.
  194. this->GenerateScriptConfigs(os, indent.Next());
  195. // End this block of installation.
  196. os << indent << "ENDIF(" << component_test << ")\n\n";
  197. }
  198. //----------------------------------------------------------------------------
  199. void
  200. cmInstallGenerator::GenerateScriptConfigs(std::ostream& os,
  201. Indent const& indent)
  202. {
  203. if(this->Configurations.empty())
  204. {
  205. // This rule is for all configurations.
  206. this->GenerateScriptActions(os, indent);
  207. }
  208. else
  209. {
  210. // Generate a per-configuration block.
  211. std::string config_test = this->CreateConfigTest(this->Configurations);
  212. os << indent << "IF(" << config_test << ")\n";
  213. this->GenerateScriptActions(os, indent.Next());
  214. os << indent << "ENDIF(" << config_test << ")\n";
  215. }
  216. }
  217. //----------------------------------------------------------------------------
  218. void cmInstallGenerator::GenerateScriptActions(std::ostream&, Indent const&)
  219. {
  220. // No actions for this generator.
  221. }