cmInstallExportAndroidMKGenerator.cxx 4.9 KB

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