cmExportInstallAndroidMKGenerator.cxx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 "cmExportInstallAndroidMKGenerator.h"
  4. #include <cstddef>
  5. #include <memory>
  6. #include <sstream>
  7. #include <vector>
  8. #include "cmExportSet.h"
  9. #include "cmGeneratorExpression.h"
  10. #include "cmGeneratorTarget.h"
  11. #include "cmInstallExportGenerator.h"
  12. #include "cmInstallTargetGenerator.h"
  13. #include "cmStateTypes.h"
  14. #include "cmStringAlgorithms.h"
  15. #include "cmSystemTools.h"
  16. #include "cmTarget.h"
  17. #include "cmTargetExport.h"
  18. cmExportInstallAndroidMKGenerator::cmExportInstallAndroidMKGenerator(
  19. cmInstallExportGenerator* iegen)
  20. : cmExportInstallFileGenerator(iegen)
  21. {
  22. }
  23. void cmExportInstallAndroidMKGenerator::ReportDuplicateTarget(
  24. std::string const& targetName) const
  25. {
  26. std::ostringstream e;
  27. e << "install(EXPORT_ANDROID_MK \"" << this->GetExportSet()->GetName()
  28. << "\" ...) "
  29. << "includes target \"" << targetName
  30. << "\" more than once in the export set.";
  31. this->ReportError(e.str());
  32. }
  33. bool cmExportInstallAndroidMKGenerator::GenerateMainFile(std::ostream& os)
  34. {
  35. std::vector<cmTargetExport const*> allTargets;
  36. {
  37. auto visitor = [&](cmTargetExport const* te) { allTargets.push_back(te); };
  38. if (!this->CollectExports(visitor)) {
  39. return false;
  40. }
  41. }
  42. // Create all the imported targets.
  43. for (cmTargetExport const* te : allTargets) {
  44. cmGeneratorTarget const* gt = te->Target;
  45. this->GenerateImportTargetCode(os, gt, this->GetExportTargetType(te));
  46. ImportPropertyMap properties;
  47. if (!this->PopulateInterfaceProperties(te, properties)) {
  48. return false;
  49. }
  50. this->PopulateInterfaceLinkLibrariesProperty(
  51. gt, cmGeneratorExpression::InstallInterface, properties);
  52. this->GenerateInterfaceProperties(gt, os, properties);
  53. }
  54. return true;
  55. }
  56. void cmExportInstallAndroidMKGenerator::GenerateImportHeaderCode(
  57. std::ostream& os, std::string const&)
  58. {
  59. std::string installDir = this->IEGen->GetDestination();
  60. os << "LOCAL_PATH := $(call my-dir)\n";
  61. size_t numDotDot = cmSystemTools::CountChar(installDir.c_str(), '/');
  62. numDotDot += installDir.empty() ? 0 : 1;
  63. std::string path;
  64. for (size_t n = 0; n < numDotDot; n++) {
  65. path += "/..";
  66. }
  67. os << "_IMPORT_PREFIX := $(LOCAL_PATH)" << path << "\n\n";
  68. for (std::unique_ptr<cmTargetExport> const& te :
  69. this->IEGen->GetExportSet()->GetTargetExports()) {
  70. // Collect import properties for this target.
  71. if (te->Target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  72. continue;
  73. }
  74. std::string dest;
  75. if (te->LibraryGenerator) {
  76. dest = te->LibraryGenerator->GetDestination("");
  77. }
  78. if (te->ArchiveGenerator) {
  79. dest = te->ArchiveGenerator->GetDestination("");
  80. }
  81. te->Target->Target->SetProperty("__dest", dest);
  82. }
  83. }
  84. void cmExportInstallAndroidMKGenerator::GenerateImportTargetCode(
  85. std::ostream& os, cmGeneratorTarget const* target,
  86. cmStateEnums::TargetType /*targetType*/)
  87. {
  88. std::string targetName = cmStrCat(this->Namespace, target->GetExportName());
  89. os << "include $(CLEAR_VARS)\n";
  90. os << "LOCAL_MODULE := ";
  91. os << targetName << "\n";
  92. os << "LOCAL_SRC_FILES := $(_IMPORT_PREFIX)/";
  93. os << target->Target->GetSafeProperty("__dest") << "/";
  94. std::string config;
  95. if (!this->Configurations.empty()) {
  96. config = this->Configurations[0];
  97. }
  98. os << target->GetFullName(config) << "\n";
  99. }