cmExportBuildAndroidMKGenerator.cxx 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmExportBuildAndroidMKGenerator.h"
  11. #include "cmExportSet.h"
  12. #include "cmGeneratorTarget.h"
  13. #include "cmGlobalGenerator.h"
  14. #include "cmLocalGenerator.h"
  15. #include "cmMakefile.h"
  16. #include "cmTargetExport.h"
  17. cmExportBuildAndroidMKGenerator::cmExportBuildAndroidMKGenerator()
  18. {
  19. this->LG = CM_NULLPTR;
  20. this->ExportSet = CM_NULLPTR;
  21. }
  22. void cmExportBuildAndroidMKGenerator::GenerateImportHeaderCode(
  23. std::ostream& os, const std::string&)
  24. {
  25. os << "LOCAL_PATH := $(call my-dir)\n\n";
  26. }
  27. void cmExportBuildAndroidMKGenerator::GenerateImportFooterCode(std::ostream&)
  28. {
  29. }
  30. void cmExportBuildAndroidMKGenerator::GenerateExpectedTargetsCode(
  31. std::ostream&, const std::string&)
  32. {
  33. }
  34. void cmExportBuildAndroidMKGenerator::GenerateImportTargetCode(
  35. std::ostream& os, const cmGeneratorTarget* target)
  36. {
  37. std::string targetName = this->Namespace;
  38. targetName += target->GetExportName();
  39. os << "include $(CLEAR_VARS)\n";
  40. os << "LOCAL_MODULE := ";
  41. os << targetName << "\n";
  42. os << "LOCAL_SRC_FILES := ";
  43. std::string path = target->GetLocalGenerator()->ConvertToOutputFormat(
  44. target->GetFullPath(), cmOutputConverter::MAKERULE);
  45. os << path << "\n";
  46. }
  47. void cmExportBuildAndroidMKGenerator::GenerateImportPropertyCode(
  48. std::ostream&, const std::string&, cmGeneratorTarget const*,
  49. ImportPropertyMap const&)
  50. {
  51. }
  52. void cmExportBuildAndroidMKGenerator::GenerateMissingTargetsCheckCode(
  53. std::ostream&, const std::vector<std::string>&)
  54. {
  55. }
  56. void cmExportBuildAndroidMKGenerator::GenerateInterfaceProperties(
  57. const cmGeneratorTarget* target, std::ostream& os,
  58. const ImportPropertyMap& properties)
  59. {
  60. std::string config = "";
  61. if (this->Configurations.size()) {
  62. config = this->Configurations[0];
  63. }
  64. cmExportBuildAndroidMKGenerator::GenerateInterfaceProperties(
  65. target, os, properties, cmExportBuildAndroidMKGenerator::BUILD, config);
  66. }
  67. void cmExportBuildAndroidMKGenerator::GenerateInterfaceProperties(
  68. const cmGeneratorTarget* target, std::ostream& os,
  69. const ImportPropertyMap& properties, GenerateType type,
  70. std::string const& config)
  71. {
  72. const bool newCMP0022Behavior =
  73. target->GetPolicyStatusCMP0022() != cmPolicies::WARN &&
  74. target->GetPolicyStatusCMP0022() != cmPolicies::OLD;
  75. if (!newCMP0022Behavior) {
  76. std::ostringstream w;
  77. if (type == cmExportBuildAndroidMKGenerator::BUILD) {
  78. w << "export(TARGETS ... ANDROID_MK) called with policy CMP0022";
  79. } else {
  80. w << "install( EXPORT_ANDROID_MK ...) called with policy CMP0022";
  81. }
  82. w << " set to OLD for target " << target->Target->GetName() << ". "
  83. << "The export will only work with CMP0022 set to NEW.";
  84. target->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  85. }
  86. if (!properties.empty()) {
  87. os << "LOCAL_CPP_FEATURES := rtti exceptions\n";
  88. for (ImportPropertyMap::const_iterator pi = properties.begin();
  89. pi != properties.end(); ++pi) {
  90. if (pi->first == "INTERFACE_COMPILE_OPTIONS") {
  91. os << "LOCAL_CPP_FEATURES += ";
  92. os << (pi->second) << "\n";
  93. } else if (pi->first == "INTERFACE_LINK_LIBRARIES") {
  94. // need to look at list in pi->second and see if static or shared
  95. // FindTargetToLink
  96. // target->GetLocalGenerator()->FindGeneratorTargetToUse()
  97. // then add to LOCAL_CPPFLAGS
  98. std::vector<std::string> libraries;
  99. cmSystemTools::ExpandListArgument(pi->second, libraries);
  100. std::string staticLibs;
  101. std::string sharedLibs;
  102. std::string ldlibs;
  103. for (std::vector<std::string>::iterator i = libraries.begin();
  104. i != libraries.end(); ++i) {
  105. cmGeneratorTarget* gt =
  106. target->GetLocalGenerator()->FindGeneratorTargetToUse(*i);
  107. if (gt) {
  108. if (gt->GetType() == cmState::SHARED_LIBRARY ||
  109. gt->GetType() == cmState::MODULE_LIBRARY) {
  110. sharedLibs += " " + *i;
  111. } else {
  112. staticLibs += " " + *i;
  113. }
  114. } else {
  115. // evaluate any generator expressions with the current
  116. // build type of the makefile
  117. cmGeneratorExpression ge;
  118. CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(*i);
  119. std::string evaluated =
  120. cge->Evaluate(target->GetLocalGenerator(), config);
  121. bool relpath = false;
  122. if (type == cmExportBuildAndroidMKGenerator::INSTALL) {
  123. relpath = i->substr(0, 3) == "../";
  124. }
  125. // check for full path or if it already has a -l, or
  126. // in the case of an install check for relative paths
  127. // if it is full or a link library then use string directly
  128. if (cmSystemTools::FileIsFullPath(evaluated) ||
  129. evaluated.substr(0, 2) == "-l" || relpath) {
  130. ldlibs += " " + evaluated;
  131. // if it is not a path and does not have a -l then add -l
  132. } else if (!evaluated.empty()) {
  133. ldlibs += " -l" + evaluated;
  134. }
  135. }
  136. }
  137. if (!sharedLibs.empty()) {
  138. os << "LOCAL_SHARED_LIBRARIES :=" << sharedLibs << "\n";
  139. }
  140. if (!staticLibs.empty()) {
  141. os << "LOCAL_STATIC_LIBRARIES :=" << staticLibs << "\n";
  142. }
  143. if (!ldlibs.empty()) {
  144. os << "LOCAL_EXPORT_LDLIBS :=" << ldlibs << "\n";
  145. }
  146. } else if (pi->first == "INTERFACE_INCLUDE_DIRECTORIES") {
  147. std::string includes = pi->second;
  148. std::vector<std::string> includeList;
  149. cmSystemTools::ExpandListArgument(includes, includeList);
  150. os << "LOCAL_EXPORT_C_INCLUDES := ";
  151. std::string end;
  152. for (std::vector<std::string>::iterator i = includeList.begin();
  153. i != includeList.end(); ++i) {
  154. os << end << *i;
  155. end = "\\\n";
  156. }
  157. os << "\n";
  158. } else {
  159. os << "# " << pi->first << " " << (pi->second) << "\n";
  160. }
  161. }
  162. }
  163. switch (target->GetType()) {
  164. case cmState::SHARED_LIBRARY:
  165. case cmState::MODULE_LIBRARY:
  166. os << "include $(PREBUILT_SHARED_LIBRARY)\n";
  167. break;
  168. case cmState::STATIC_LIBRARY:
  169. os << "include $(PREBUILT_STATIC_LIBRARY)\n";
  170. break;
  171. case cmState::EXECUTABLE:
  172. case cmState::UTILITY:
  173. case cmState::OBJECT_LIBRARY:
  174. case cmState::GLOBAL_TARGET:
  175. case cmState::INTERFACE_LIBRARY:
  176. case cmState::UNKNOWN_LIBRARY:
  177. break;
  178. }
  179. os << "\n";
  180. }