cmExportTryCompileFileGenerator.cxx 4.5 KB

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