cmExportTryCompileFileGenerator.cxx 4.3 KB

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