1
0

cmInstallExportAndroidMKGenerator.cxx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. 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::string const& config : this->ConfigurationTypes) {
  61. this->EFGen->AddConfiguration(config);
  62. }
  63. }
  64. this->EFGen->GenerateImportFile();
  65. // Perform the main install script generation.
  66. this->cmInstallGenerator::GenerateScript(os);
  67. }
  68. void cmInstallExportAndroidMKGenerator::GenerateScriptConfigs(
  69. std::ostream& os, Indent const& indent)
  70. {
  71. // Create the main install rules first.
  72. this->cmInstallGenerator::GenerateScriptConfigs(os, indent);
  73. // Now create a configuration-specific install rule for the import
  74. // file of each configuration.
  75. std::vector<std::string> files;
  76. for (auto const& pair : this->EFGen->GetConfigImportFiles()) {
  77. files.push_back(pair.second);
  78. std::string config_test = this->CreateConfigTest(pair.first);
  79. os << indent << "if(" << config_test << ")\n";
  80. this->AddInstallRule(os, this->Destination, cmInstallType_FILES, files,
  81. false, this->FilePermissions.c_str(), nullptr,
  82. nullptr, nullptr, indent.Next());
  83. os << indent << "endif()\n";
  84. files.clear();
  85. }
  86. }
  87. void cmInstallExportAndroidMKGenerator::GenerateScriptActions(
  88. std::ostream& os, Indent const& indent)
  89. {
  90. // Remove old per-configuration export files if the main changes.
  91. std::string installedDir = "$ENV{DESTDIR}";
  92. installedDir += this->ConvertToAbsoluteDestination(this->Destination);
  93. installedDir += "/";
  94. std::string installedFile = installedDir;
  95. installedFile += this->FileName;
  96. os << indent << "if(EXISTS \"" << installedFile << "\")\n";
  97. Indent indentN = indent.Next();
  98. Indent indentNN = indentN.Next();
  99. Indent indentNNN = indentNN.Next();
  100. /* clang-format off */
  101. os << indentN << "file(DIFFERENT EXPORT_FILE_CHANGED FILES\n"
  102. << indentN << " \"" << installedFile << "\"\n"
  103. << indentN << " \"" << this->MainImportFile << "\")\n";
  104. os << indentN << "if(EXPORT_FILE_CHANGED)\n";
  105. os << indentNN << "file(GLOB OLD_CONFIG_FILES \"" << installedDir
  106. << this->EFGen->GetConfigImportFileGlob() << "\")\n";
  107. os << indentNN << "if(OLD_CONFIG_FILES)\n";
  108. os << indentNNN << "message(STATUS \"Old export file \\\"" << installedFile
  109. << "\\\" will be replaced. Removing files [${OLD_CONFIG_FILES}].\")\n";
  110. os << indentNNN << "file(REMOVE ${OLD_CONFIG_FILES})\n";
  111. os << indentNN << "endif()\n";
  112. os << indentN << "endif()\n";
  113. os << indent << "endif()\n";
  114. /* clang-format on */
  115. // Install the main export file.
  116. std::vector<std::string> files;
  117. files.push_back(this->MainImportFile);
  118. this->AddInstallRule(os, this->Destination, cmInstallType_FILES, files,
  119. false, this->FilePermissions.c_str(), nullptr, nullptr,
  120. nullptr, indent);
  121. }