cmInstallGenerator.cxx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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()) os << ";";
  65. os << dest << cmSystemTools::ConvertToOutputPath("/");
  66. if (rename && *rename)
  67. {
  68. os << rename;
  69. }
  70. else
  71. {
  72. os << cmSystemTools::GetFilenameName(*fi);
  73. }
  74. }
  75. os << "\")\n";
  76. }
  77. os << "FILE(INSTALL DESTINATION \"" << dest << "\" TYPE " << stype.c_str();
  78. if(optional)
  79. {
  80. os << " OPTIONAL";
  81. }
  82. if(permissions_file && *permissions_file)
  83. {
  84. os << " PERMISSIONS" << permissions_file;
  85. }
  86. if(permissions_dir && *permissions_dir)
  87. {
  88. os << " DIR_PERMISSIONS" << permissions_dir;
  89. }
  90. if(rename && *rename)
  91. {
  92. os << " RENAME \"" << rename << "\"";
  93. }
  94. os << " FILES";
  95. if(files.size() == 1)
  96. {
  97. os << " \"" << files[0] << "\"";
  98. }
  99. else
  100. {
  101. for(std::vector<std::string>::const_iterator fi = files.begin();
  102. fi != files.end(); ++fi)
  103. {
  104. os << "\n" << indent << " \"" << *fi << "\"";
  105. }
  106. os << "\n" << indent << " ";
  107. if(!(literal_args && *literal_args))
  108. {
  109. os << " ";
  110. }
  111. }
  112. if(literal_args && *literal_args)
  113. {
  114. os << literal_args;
  115. }
  116. os << ")\n";
  117. }
  118. //----------------------------------------------------------------------------
  119. std::string
  120. cmInstallGenerator::CreateComponentTest(const char* component)
  121. {
  122. std::string result = "NOT CMAKE_INSTALL_COMPONENT OR "
  123. "\"${CMAKE_INSTALL_COMPONENT}\" STREQUAL \"";
  124. result += component;
  125. result += "\"";
  126. return result;
  127. }
  128. //----------------------------------------------------------------------------
  129. void cmInstallGenerator::GenerateScript(std::ostream& os)
  130. {
  131. // Track indentation.
  132. Indent indent;
  133. // Begin this block of installation.
  134. std::string component_test =
  135. this->CreateComponentTest(this->Component.c_str());
  136. os << indent << "IF(" << component_test << ")\n";
  137. // Generate the script possibly with per-configuration code.
  138. this->GenerateScriptConfigs(os, indent.Next());
  139. // End this block of installation.
  140. os << indent << "ENDIF(" << component_test << ")\n\n";
  141. }
  142. //----------------------------------------------------------------------------
  143. bool cmInstallGenerator::InstallsForConfig(const char* config)
  144. {
  145. return this->GeneratesForConfig(config);
  146. }
  147. //----------------------------------------------------------------------------
  148. std::string cmInstallGenerator::GetInstallDestination() const
  149. {
  150. std::string result;
  151. if(!this->Destination.empty() &&
  152. !cmSystemTools::FileIsFullPath(this->Destination.c_str()))
  153. {
  154. result = "${CMAKE_INSTALL_PREFIX}/";
  155. }
  156. result += this->Destination;
  157. return result;
  158. }