cmInstallExportAndroidMKGenerator.cxx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 "cmInstallExportAndroidMKGenerator.h"
  11. #include <stdio.h>
  12. #include "cmExportInstallFileGenerator.h"
  13. #include "cmExportSet.h"
  14. #include "cmGeneratedFileStream.h"
  15. #include "cmGlobalGenerator.h"
  16. #include "cmInstallFilesGenerator.h"
  17. #include "cmInstallTargetGenerator.h"
  18. #include "cmLocalGenerator.h"
  19. #include "cmMakefile.h"
  20. #include "cmake.h"
  21. cmInstallExportAndroidMKGenerator::cmInstallExportAndroidMKGenerator(
  22. cmExportSet* exportSet, const char* destination,
  23. const char* file_permissions, std::vector<std::string> const& configurations,
  24. const char* component, MessageLevel message, bool exclude_from_all,
  25. const char* filename, const char* name_space, bool exportOld)
  26. : cmInstallExportGenerator(exportSet, destination, file_permissions,
  27. configurations, component, message,
  28. exclude_from_all, filename, name_space, exportOld)
  29. {
  30. }
  31. cmInstallExportAndroidMKGenerator::~cmInstallExportAndroidMKGenerator()
  32. {
  33. }
  34. void cmInstallExportAndroidMKGenerator::Compute(cmLocalGenerator* lg)
  35. {
  36. this->LocalGenerator = lg;
  37. this->ExportSet->Compute(lg);
  38. }
  39. void cmInstallExportAndroidMKGenerator::GenerateScript(std::ostream& os)
  40. {
  41. // Skip empty sets.
  42. if (ExportSet->GetTargetExports()->empty()) {
  43. std::ostringstream e;
  44. e << "INSTALL(EXPORT) given unknown export \"" << ExportSet->GetName()
  45. << "\"";
  46. cmSystemTools::Error(e.str().c_str());
  47. return;
  48. }
  49. // Create the temporary directory in which to store the files.
  50. this->ComputeTempDir();
  51. cmSystemTools::MakeDirectory(this->TempDir.c_str());
  52. // Construct a temporary location for the file.
  53. this->MainImportFile = this->TempDir;
  54. this->MainImportFile += "/";
  55. this->MainImportFile += this->FileName;
  56. // Generate the import file for this export set.
  57. this->EFGen->SetExportFile(this->MainImportFile.c_str());
  58. this->EFGen->SetNamespace(this->Namespace);
  59. this->EFGen->SetExportOld(this->ExportOld);
  60. if (this->ConfigurationTypes->empty()) {
  61. if (!this->ConfigurationName.empty()) {
  62. this->EFGen->AddConfiguration(this->ConfigurationName);
  63. } else {
  64. this->EFGen->AddConfiguration("");
  65. }
  66. } else {
  67. for (std::vector<std::string>::const_iterator ci =
  68. this->ConfigurationTypes->begin();
  69. ci != this->ConfigurationTypes->end(); ++ci) {
  70. this->EFGen->AddConfiguration(*ci);
  71. }
  72. }
  73. this->EFGen->GenerateImportFile();
  74. // Perform the main install script generation.
  75. this->cmInstallGenerator::GenerateScript(os);
  76. }
  77. void cmInstallExportAndroidMKGenerator::GenerateScriptConfigs(
  78. std::ostream& os, Indent const& indent)
  79. {
  80. // Create the main install rules first.
  81. this->cmInstallGenerator::GenerateScriptConfigs(os, indent);
  82. // Now create a configuration-specific install rule for the import
  83. // file of each configuration.
  84. std::vector<std::string> files;
  85. for (std::map<std::string, std::string>::const_iterator i =
  86. this->EFGen->GetConfigImportFiles().begin();
  87. i != this->EFGen->GetConfigImportFiles().end(); ++i) {
  88. files.push_back(i->second);
  89. std::string config_test = this->CreateConfigTest(i->first);
  90. os << indent << "if(" << config_test << ")\n";
  91. this->AddInstallRule(os, this->Destination, cmInstallType_FILES, files,
  92. false, this->FilePermissions.c_str(), CM_NULLPTR,
  93. CM_NULLPTR, CM_NULLPTR, indent.Next());
  94. os << indent << "endif()\n";
  95. files.clear();
  96. }
  97. }
  98. void cmInstallExportAndroidMKGenerator::GenerateScriptActions(
  99. std::ostream& os, Indent const& indent)
  100. {
  101. // Remove old per-configuration export files if the main changes.
  102. std::string installedDir = "$ENV{DESTDIR}";
  103. installedDir += this->ConvertToAbsoluteDestination(this->Destination);
  104. installedDir += "/";
  105. std::string installedFile = installedDir;
  106. installedFile += this->FileName;
  107. os << indent << "if(EXISTS \"" << installedFile << "\")\n";
  108. Indent indentN = indent.Next();
  109. Indent indentNN = indentN.Next();
  110. Indent indentNNN = indentNN.Next();
  111. /* clang-format off */
  112. os << indentN << "file(DIFFERENT EXPORT_FILE_CHANGED FILES\n"
  113. << indentN << " \"" << installedFile << "\"\n"
  114. << indentN << " \"" << this->MainImportFile << "\")\n";
  115. os << indentN << "if(EXPORT_FILE_CHANGED)\n";
  116. os << indentNN << "file(GLOB OLD_CONFIG_FILES \"" << installedDir
  117. << this->EFGen->GetConfigImportFileGlob() << "\")\n";
  118. os << indentNN << "if(OLD_CONFIG_FILES)\n";
  119. os << indentNNN << "message(STATUS \"Old export file \\\"" << installedFile
  120. << "\\\" will be replaced. Removing files [${OLD_CONFIG_FILES}].\")\n";
  121. os << indentNNN << "file(REMOVE ${OLD_CONFIG_FILES})\n";
  122. os << indentNN << "endif()\n";
  123. os << indentN << "endif()\n";
  124. os << indent << "endif()\n";
  125. /* clang-format on */
  126. // Install the main export file.
  127. std::vector<std::string> files;
  128. files.push_back(this->MainImportFile);
  129. this->AddInstallRule(os, this->Destination, cmInstallType_FILES, files,
  130. false, this->FilePermissions.c_str(), CM_NULLPTR,
  131. CM_NULLPTR, CM_NULLPTR, indent);
  132. }