cmExportTryCompileFileGenerator.cxx 4.2 KB

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