cmExportTryCompileFileGenerator.cxx 4.2 KB

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