cmExportInstallAndroidMKGenerator.cxx 3.6 KB

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