cmInstallGenerator.cxx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmInstallGenerator.h"
  11. #include "cmSystemTools.h"
  12. #include "cmTarget.h"
  13. //----------------------------------------------------------------------------
  14. cmInstallGenerator
  15. ::cmInstallGenerator(const char* destination,
  16. std::vector<std::string> const& configurations,
  17. const char* component):
  18. cmScriptGenerator("CMAKE_INSTALL_CONFIG_NAME", configurations),
  19. Destination(destination? destination:""),
  20. Component(component? component:"")
  21. {
  22. }
  23. //----------------------------------------------------------------------------
  24. cmInstallGenerator
  25. ::~cmInstallGenerator()
  26. {
  27. }
  28. //----------------------------------------------------------------------------
  29. void cmInstallGenerator
  30. ::AddInstallRule(
  31. std::ostream& os,
  32. int type,
  33. std::vector<std::string> const& files,
  34. bool optional /* = false */,
  35. const char* permissions_file /* = 0 */,
  36. const char* permissions_dir /* = 0 */,
  37. const char* rename /* = 0 */,
  38. const char* literal_args /* = 0 */,
  39. Indent const& indent
  40. )
  41. {
  42. // Use the FILE command to install the file.
  43. std::string stype;
  44. switch(type)
  45. {
  46. case cmTarget::INSTALL_DIRECTORY:stype = "DIRECTORY"; break;
  47. case cmTarget::INSTALL_PROGRAMS: stype = "PROGRAM"; break;
  48. case cmTarget::EXECUTABLE: stype = "EXECUTABLE"; break;
  49. case cmTarget::STATIC_LIBRARY: stype = "STATIC_LIBRARY"; break;
  50. case cmTarget::SHARED_LIBRARY: stype = "SHARED_LIBRARY"; break;
  51. case cmTarget::MODULE_LIBRARY: stype = "MODULE"; break;
  52. case cmTarget::INSTALL_FILES:
  53. default: stype = "FILE"; break;
  54. }
  55. os << indent;
  56. std::string dest = this->GetInstallDestination();
  57. if (cmSystemTools::FileIsFullPath(dest.c_str()))
  58. {
  59. os << "list(APPEND CPACK_ABSOLUTE_DESTINATION_FILES\n";
  60. os << indent << " \"";
  61. for(std::vector<std::string>::const_iterator fi = files.begin();
  62. fi != files.end(); ++fi)
  63. {
  64. if (fi!=files.begin())
  65. {
  66. os << ";";
  67. }
  68. os << dest << "/";
  69. if (rename && *rename)
  70. {
  71. os << rename;
  72. }
  73. else
  74. {
  75. os << cmSystemTools::GetFilenameName(*fi);
  76. }
  77. }
  78. os << "\")\n";
  79. }
  80. os << "FILE(INSTALL DESTINATION \"" << dest << "\" TYPE " << stype.c_str();
  81. if(optional)
  82. {
  83. os << " OPTIONAL";
  84. }
  85. if(permissions_file && *permissions_file)
  86. {
  87. os << " PERMISSIONS" << permissions_file;
  88. }
  89. if(permissions_dir && *permissions_dir)
  90. {
  91. os << " DIR_PERMISSIONS" << permissions_dir;
  92. }
  93. if(rename && *rename)
  94. {
  95. os << " RENAME \"" << rename << "\"";
  96. }
  97. os << " FILES";
  98. if(files.size() == 1)
  99. {
  100. os << " \"" << files[0] << "\"";
  101. }
  102. else
  103. {
  104. for(std::vector<std::string>::const_iterator fi = files.begin();
  105. fi != files.end(); ++fi)
  106. {
  107. os << "\n" << indent << " \"" << *fi << "\"";
  108. }
  109. os << "\n" << indent << " ";
  110. if(!(literal_args && *literal_args))
  111. {
  112. os << " ";
  113. }
  114. }
  115. if(literal_args && *literal_args)
  116. {
  117. os << literal_args;
  118. }
  119. os << ")\n";
  120. }
  121. //----------------------------------------------------------------------------
  122. std::string
  123. cmInstallGenerator::CreateComponentTest(const char* component)
  124. {
  125. std::string result = "NOT CMAKE_INSTALL_COMPONENT OR "
  126. "\"${CMAKE_INSTALL_COMPONENT}\" STREQUAL \"";
  127. result += component;
  128. result += "\"";
  129. return result;
  130. }
  131. //----------------------------------------------------------------------------
  132. void cmInstallGenerator::GenerateScript(std::ostream& os)
  133. {
  134. // Track indentation.
  135. Indent indent;
  136. // Begin this block of installation.
  137. std::string component_test =
  138. this->CreateComponentTest(this->Component.c_str());
  139. os << indent << "IF(" << component_test << ")\n";
  140. // Generate the script possibly with per-configuration code.
  141. this->GenerateScriptConfigs(os, indent.Next());
  142. // End this block of installation.
  143. os << indent << "ENDIF(" << component_test << ")\n\n";
  144. }
  145. //----------------------------------------------------------------------------
  146. bool cmInstallGenerator::InstallsForConfig(const char* config)
  147. {
  148. return this->GeneratesForConfig(config);
  149. }
  150. //----------------------------------------------------------------------------
  151. std::string cmInstallGenerator::GetInstallDestination() const
  152. {
  153. std::string result;
  154. if(!this->Destination.empty() &&
  155. !cmSystemTools::FileIsFullPath(this->Destination.c_str()))
  156. {
  157. result = "${CMAKE_INSTALL_PREFIX}/";
  158. }
  159. result += this->Destination;
  160. return result;
  161. }