cmExportInstallAndroidMKGenerator.cxx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file LICENSE.rst or https://cmake.org/licensing for details. */
  3. #include "cmExportInstallAndroidMKGenerator.h"
  4. #include <cstddef>
  5. #include <functional>
  6. #include <memory>
  7. #include <sstream>
  8. #include <vector>
  9. #include "cmExportSet.h"
  10. #include "cmGeneratorExpression.h"
  11. #include "cmGeneratorTarget.h"
  12. #include "cmInstallExportGenerator.h"
  13. #include "cmInstallTargetGenerator.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. this->PopulateInterfaceLinkLibrariesProperty(
  52. gt, cmGeneratorExpression::InstallInterface, properties);
  53. this->GenerateInterfaceProperties(gt, os, properties);
  54. }
  55. return true;
  56. }
  57. void cmExportInstallAndroidMKGenerator::GenerateImportHeaderCode(
  58. std::ostream& os, std::string const&)
  59. {
  60. std::string installDir = this->IEGen->GetDestination();
  61. os << "LOCAL_PATH := $(call my-dir)\n";
  62. size_t numDotDot = cmSystemTools::CountChar(installDir.c_str(), '/');
  63. numDotDot += installDir.empty() ? 0 : 1;
  64. std::string path;
  65. for (size_t n = 0; n < numDotDot; n++) {
  66. path += "/..";
  67. }
  68. os << "_IMPORT_PREFIX := $(LOCAL_PATH)" << path << "\n\n";
  69. for (std::unique_ptr<cmTargetExport> const& te :
  70. this->IEGen->GetExportSet()->GetTargetExports()) {
  71. // Collect import properties for this target.
  72. if (te->Target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  73. continue;
  74. }
  75. std::string dest;
  76. if (te->LibraryGenerator) {
  77. dest = te->LibraryGenerator->GetDestination("");
  78. }
  79. if (te->ArchiveGenerator) {
  80. dest = te->ArchiveGenerator->GetDestination("");
  81. }
  82. te->Target->Target->SetProperty("__dest", dest);
  83. }
  84. }
  85. void cmExportInstallAndroidMKGenerator::GenerateImportTargetCode(
  86. std::ostream& os, cmGeneratorTarget const* target,
  87. cmStateEnums::TargetType /*targetType*/)
  88. {
  89. std::string targetName = cmStrCat(this->Namespace, target->GetExportName());
  90. os << "include $(CLEAR_VARS)\n";
  91. os << "LOCAL_MODULE := ";
  92. os << targetName << "\n";
  93. os << "LOCAL_SRC_FILES := $(_IMPORT_PREFIX)/";
  94. os << target->Target->GetSafeProperty("__dest") << "/";
  95. std::string config;
  96. if (!this->Configurations.empty()) {
  97. config = this->Configurations[0];
  98. }
  99. os << target->GetFullName(config) << "\n";
  100. }