1
0

cmExportTryCompileFileGenerator.cxx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2013 Stephen Kelly <[email protected]>
  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 "cmExportTryCompileFileGenerator.h"
  11. #include "cmGeneratedFileStream.h"
  12. #include "cmGlobalGenerator.h"
  13. #include "cmLocalGenerator.h"
  14. #include "cmGeneratorExpressionDAGChecker.h"
  15. //----------------------------------------------------------------------------
  16. cmExportTryCompileFileGenerator::cmExportTryCompileFileGenerator(
  17. cmGlobalGenerator* gg,
  18. const std::vector<std::string>& targets,
  19. cmMakefile* mf)
  20. {
  21. gg->CreateImportedGenerationObjects(mf, targets, this->Exports);
  22. }
  23. bool cmExportTryCompileFileGenerator::GenerateMainFile(std::ostream& os)
  24. {
  25. std::set<cmTarget const*> emitted;
  26. std::set<cmTarget const*> emittedDeps;
  27. while(!this->Exports.empty())
  28. {
  29. cmGeneratorTarget const* te = this->Exports.back();
  30. this->Exports.pop_back();
  31. if (emitted.insert(te->Target).second)
  32. {
  33. emittedDeps.insert(te->Target);
  34. this->GenerateImportTargetCode(os, te->Target);
  35. ImportPropertyMap properties;
  36. #define FIND_TARGETS(PROPERTY) \
  37. this->FindTargets("INTERFACE_" #PROPERTY, te->Target, emittedDeps);
  38. CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(FIND_TARGETS)
  39. #undef FIND_TARGETS
  40. this->PopulateProperties(te->Target, properties, emittedDeps);
  41. this->GenerateInterfaceProperties(te->Target, os, properties);
  42. }
  43. }
  44. return true;
  45. }
  46. std::string cmExportTryCompileFileGenerator::FindTargets(
  47. const std::string& propName,
  48. cmTarget const* tgt,
  49. std::set<cmTarget const*> &emitted)
  50. {
  51. const char *prop = tgt->GetProperty(propName);
  52. if(!prop)
  53. {
  54. return std::string();
  55. }
  56. cmGeneratorExpression ge;
  57. cmGeneratorExpressionDAGChecker dagChecker(
  58. tgt->GetName(),
  59. propName, 0, 0);
  60. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(prop);
  61. cmTarget dummyHead;
  62. dummyHead.SetType(cmState::EXECUTABLE, "try_compile_dummy_exe");
  63. dummyHead.SetMakefile(tgt->GetMakefile());
  64. cmGeneratorTarget* gtgt =
  65. tgt->GetMakefile()->GetGlobalGenerator()->GetGeneratorTarget(tgt);
  66. cmGeneratorTarget gDummyHead(&dummyHead, gtgt->GetLocalGenerator());
  67. std::string result = cge->Evaluate(gtgt->GetLocalGenerator(), this->Config,
  68. false, &gDummyHead,
  69. gtgt, &dagChecker);
  70. const std::set<cmGeneratorTarget const*> &allTargets =
  71. cge->GetAllTargetsSeen();
  72. for(std::set<cmGeneratorTarget const*>::const_iterator li =
  73. allTargets.begin(); li != allTargets.end(); ++li)
  74. {
  75. if(emitted.insert((*li)->Target).second)
  76. {
  77. this->Exports.push_back((*li));
  78. }
  79. }
  80. return result;
  81. }
  82. //----------------------------------------------------------------------------
  83. void
  84. cmExportTryCompileFileGenerator::PopulateProperties(cmTarget const* target,
  85. ImportPropertyMap& properties,
  86. std::set<cmTarget const*> &emitted)
  87. {
  88. cmPropertyMap props = target->GetProperties();
  89. cmGeneratorTarget* gt =
  90. target->GetMakefile()->GetGlobalGenerator()->GetGeneratorTarget(target);
  91. for(cmPropertyMap::const_iterator i = props.begin(); i != props.end(); ++i)
  92. {
  93. properties[i->first] = i->second.GetValue();
  94. if(i->first.find("IMPORTED_LINK_INTERFACE_LIBRARIES") == 0
  95. || i->first.find("IMPORTED_LINK_DEPENDENT_LIBRARIES") == 0
  96. || i->first.find("INTERFACE_LINK_LIBRARIES") == 0)
  97. {
  98. std::string evalResult = this->FindTargets(i->first,
  99. target, emitted);
  100. std::vector<std::string> depends;
  101. cmSystemTools::ExpandListArgument(evalResult, depends);
  102. for(std::vector<std::string>::const_iterator li = depends.begin();
  103. li != depends.end(); ++li)
  104. {
  105. cmGeneratorTarget *tgt =
  106. gt->GetLocalGenerator()->FindGeneratorTargetToUse(*li);
  107. if(tgt && emitted.insert(tgt->Target).second)
  108. {
  109. this->Exports.push_back(tgt);
  110. }
  111. }
  112. }
  113. }
  114. }
  115. std::string
  116. cmExportTryCompileFileGenerator::InstallNameDir(cmGeneratorTarget* target,
  117. const std::string& config)
  118. {
  119. std::string install_name_dir;
  120. cmMakefile* mf = target->Target->GetMakefile();
  121. if(mf->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  122. {
  123. install_name_dir =
  124. target->GetInstallNameDirForBuildTree(config);
  125. }
  126. return install_name_dir;
  127. }