cmExportTryCompileFileGenerator.cxx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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<cmGeneratorTarget const*> emitted;
  26. std::set<cmGeneratorTarget 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).second)
  32. {
  33. emittedDeps.insert(te);
  34. this->GenerateImportTargetCode(os, te);
  35. ImportPropertyMap properties;
  36. #define FIND_TARGETS(PROPERTY) \
  37. this->FindTargets("INTERFACE_" #PROPERTY, te, emittedDeps);
  38. CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(FIND_TARGETS)
  39. #undef FIND_TARGETS
  40. this->PopulateProperties(te, properties, emittedDeps);
  41. this->GenerateInterfaceProperties(te, os, properties);
  42. }
  43. }
  44. return true;
  45. }
  46. std::string cmExportTryCompileFileGenerator::FindTargets(
  47. const std::string& propName,
  48. cmGeneratorTarget const* tgt,
  49. std::set<cmGeneratorTarget 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->Target->GetMakefile());
  64. cmGeneratorTarget gDummyHead(&dummyHead, tgt->GetLocalGenerator());
  65. std::string result = cge->Evaluate(tgt->GetLocalGenerator(), this->Config,
  66. false, &gDummyHead,
  67. tgt, &dagChecker);
  68. const std::set<cmGeneratorTarget const*> &allTargets =
  69. cge->GetAllTargetsSeen();
  70. for(std::set<cmGeneratorTarget const*>::const_iterator li =
  71. allTargets.begin(); li != allTargets.end(); ++li)
  72. {
  73. if(emitted.insert(*li).second)
  74. {
  75. this->Exports.push_back(*li);
  76. }
  77. }
  78. return result;
  79. }
  80. //----------------------------------------------------------------------------
  81. void
  82. cmExportTryCompileFileGenerator::PopulateProperties(
  83. const cmGeneratorTarget* target,
  84. ImportPropertyMap& properties,
  85. std::set<cmGeneratorTarget const*> &emitted)
  86. {
  87. cmPropertyMap props = target->Target->GetProperties();
  88. for(cmPropertyMap::const_iterator i = props.begin(); i != props.end(); ++i)
  89. {
  90. properties[i->first] = i->second.GetValue();
  91. if(i->first.find("IMPORTED_LINK_INTERFACE_LIBRARIES") == 0
  92. || i->first.find("IMPORTED_LINK_DEPENDENT_LIBRARIES") == 0
  93. || i->first.find("INTERFACE_LINK_LIBRARIES") == 0)
  94. {
  95. std::string evalResult = this->FindTargets(i->first,
  96. target, emitted);
  97. std::vector<std::string> depends;
  98. cmSystemTools::ExpandListArgument(evalResult, depends);
  99. for(std::vector<std::string>::const_iterator li = depends.begin();
  100. li != depends.end(); ++li)
  101. {
  102. cmGeneratorTarget *tgt =
  103. target->GetLocalGenerator()->FindGeneratorTargetToUse(*li);
  104. if(tgt && emitted.insert(tgt).second)
  105. {
  106. this->Exports.push_back(tgt);
  107. }
  108. }
  109. }
  110. }
  111. }
  112. std::string
  113. cmExportTryCompileFileGenerator::InstallNameDir(cmGeneratorTarget* target,
  114. const std::string& config)
  115. {
  116. std::string install_name_dir;
  117. cmMakefile* mf = target->Target->GetMakefile();
  118. if(mf->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  119. {
  120. install_name_dir =
  121. target->GetInstallNameDirForBuildTree(config);
  122. }
  123. return install_name_dir;
  124. }