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