cmInstallExportAndroidMKGenerator.cxx 5.1 KB

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