cmInstallGenerator.cxx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. //----------------------------------------------------------------------------
  13. cmInstallGenerator
  14. ::cmInstallGenerator(const char* destination,
  15. std::vector<std::string> const& configurations,
  16. const char* component):
  17. cmScriptGenerator("CMAKE_INSTALL_CONFIG_NAME", configurations),
  18. Destination(destination? destination:""),
  19. Component(component? component:"")
  20. {
  21. }
  22. //----------------------------------------------------------------------------
  23. cmInstallGenerator
  24. ::~cmInstallGenerator()
  25. {
  26. }
  27. //----------------------------------------------------------------------------
  28. void cmInstallGenerator
  29. ::AddInstallRule(
  30. std::ostream& os,
  31. cmInstallType type,
  32. std::vector<std::string> const& files,
  33. bool optional /* = false */,
  34. const char* permissions_file /* = 0 */,
  35. const char* permissions_dir /* = 0 */,
  36. const char* rename /* = 0 */,
  37. const char* literal_args /* = 0 */,
  38. Indent const& indent
  39. )
  40. {
  41. // Use the FILE command to install the file.
  42. std::string stype;
  43. switch(type)
  44. {
  45. case cmInstallType_DIRECTORY: stype = "DIRECTORY"; break;
  46. case cmInstallType_PROGRAMS: stype = "PROGRAM"; break;
  47. case cmInstallType_EXECUTABLE: stype = "EXECUTABLE"; break;
  48. case cmInstallType_STATIC_LIBRARY: stype = "STATIC_LIBRARY"; break;
  49. case cmInstallType_SHARED_LIBRARY: stype = "SHARED_LIBRARY"; break;
  50. case cmInstallType_MODULE_LIBRARY: stype = "MODULE"; break;
  51. case cmInstallType_FILES: stype = "FILE"; break;
  52. }
  53. os << indent;
  54. std::string dest = this->GetInstallDestination();
  55. if (cmSystemTools::FileIsFullPath(dest.c_str()))
  56. {
  57. os << "list(APPEND CPACK_ABSOLUTE_DESTINATION_FILES\n";
  58. os << indent << " \"";
  59. for(std::vector<std::string>::const_iterator fi = files.begin();
  60. fi != files.end(); ++fi)
  61. {
  62. if (fi!=files.begin())
  63. {
  64. os << ";";
  65. }
  66. os << dest << "/";
  67. if (rename && *rename)
  68. {
  69. os << rename;
  70. }
  71. else
  72. {
  73. os << cmSystemTools::GetFilenameName(*fi);
  74. }
  75. }
  76. os << "\")\n";
  77. }
  78. os << "FILE(INSTALL DESTINATION \"" << dest << "\" TYPE " << stype.c_str();
  79. if(optional)
  80. {
  81. os << " OPTIONAL";
  82. }
  83. if(permissions_file && *permissions_file)
  84. {
  85. os << " PERMISSIONS" << permissions_file;
  86. }
  87. if(permissions_dir && *permissions_dir)
  88. {
  89. os << " DIR_PERMISSIONS" << permissions_dir;
  90. }
  91. if(rename && *rename)
  92. {
  93. os << " RENAME \"" << rename << "\"";
  94. }
  95. os << " FILES";
  96. if(files.size() == 1)
  97. {
  98. os << " \"" << files[0] << "\"";
  99. }
  100. else
  101. {
  102. for(std::vector<std::string>::const_iterator fi = files.begin();
  103. fi != files.end(); ++fi)
  104. {
  105. os << "\n" << indent << " \"" << *fi << "\"";
  106. }
  107. os << "\n" << indent << " ";
  108. if(!(literal_args && *literal_args))
  109. {
  110. os << " ";
  111. }
  112. }
  113. if(literal_args && *literal_args)
  114. {
  115. os << literal_args;
  116. }
  117. os << ")\n";
  118. }
  119. //----------------------------------------------------------------------------
  120. std::string
  121. cmInstallGenerator::CreateComponentTest(const char* component)
  122. {
  123. std::string result = "NOT CMAKE_INSTALL_COMPONENT OR "
  124. "\"${CMAKE_INSTALL_COMPONENT}\" STREQUAL \"";
  125. result += component;
  126. result += "\"";
  127. return result;
  128. }
  129. //----------------------------------------------------------------------------
  130. void cmInstallGenerator::GenerateScript(std::ostream& os)
  131. {
  132. // Track indentation.
  133. Indent indent;
  134. // Begin this block of installation.
  135. std::string component_test =
  136. this->CreateComponentTest(this->Component.c_str());
  137. os << indent << "IF(" << component_test << ")\n";
  138. // Generate the script possibly with per-configuration code.
  139. this->GenerateScriptConfigs(os, indent.Next());
  140. // End this block of installation.
  141. os << indent << "ENDIF(" << component_test << ")\n\n";
  142. }
  143. //----------------------------------------------------------------------------
  144. bool cmInstallGenerator::InstallsForConfig(const char* config)
  145. {
  146. return this->GeneratesForConfig(config);
  147. }
  148. //----------------------------------------------------------------------------
  149. std::string cmInstallGenerator::GetInstallDestination() const
  150. {
  151. std::string result;
  152. if(!this->Destination.empty() &&
  153. !cmSystemTools::FileIsFullPath(this->Destination.c_str()))
  154. {
  155. result = "${CMAKE_INSTALL_PREFIX}/";
  156. }
  157. result += this->Destination;
  158. return result;
  159. }