cmExportTryCompileFileGenerator.cxx 4.4 KB

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