cmExportBuildFileGenerator.cxx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  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 "cmExportBuildFileGenerator.h"
  11. #include "cmExportCommand.h"
  12. //----------------------------------------------------------------------------
  13. cmExportBuildFileGenerator::cmExportBuildFileGenerator()
  14. {
  15. this->ExportCommand = 0;
  16. }
  17. //----------------------------------------------------------------------------
  18. bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os)
  19. {
  20. // Create all the imported targets.
  21. for(std::vector<cmTarget*>::const_iterator
  22. tei = this->Exports->begin();
  23. tei != this->Exports->end(); ++tei)
  24. {
  25. cmTarget* te = *tei;
  26. if(this->ExportedTargets.insert(te).second)
  27. {
  28. this->GenerateImportTargetCode(os, te);
  29. }
  30. else
  31. {
  32. if(this->ExportCommand && this->ExportCommand->ErrorMessage.empty())
  33. {
  34. cmOStringStream e;
  35. e << "given target \"" << te->GetName() << "\" more than once.";
  36. this->ExportCommand->ErrorMessage = e.str();
  37. }
  38. return false;
  39. }
  40. }
  41. // Generate import file content for each configuration.
  42. for(std::vector<std::string>::const_iterator
  43. ci = this->Configurations.begin();
  44. ci != this->Configurations.end(); ++ci)
  45. {
  46. this->GenerateImportConfig(os, ci->c_str());
  47. }
  48. return true;
  49. }
  50. //----------------------------------------------------------------------------
  51. void
  52. cmExportBuildFileGenerator
  53. ::GenerateImportTargetsConfig(std::ostream& os,
  54. const char* config, std::string const& suffix)
  55. {
  56. for(std::vector<cmTarget*>::const_iterator
  57. tei = this->Exports->begin();
  58. tei != this->Exports->end(); ++tei)
  59. {
  60. // Collect import properties for this target.
  61. cmTarget* target = *tei;
  62. ImportPropertyMap properties;
  63. this->SetImportLocationProperty(config, suffix, target, properties);
  64. if(!properties.empty())
  65. {
  66. // Get the rest of the target details.
  67. this->SetImportDetailProperties(config, suffix,
  68. target, properties);
  69. // TOOD: PUBLIC_HEADER_LOCATION
  70. // This should wait until the build feature propagation stuff
  71. // is done. Then this can be a propagated include directory.
  72. // this->GenerateImportProperty(config, te->HeaderGenerator,
  73. // properties);
  74. // Generate code in the export file.
  75. this->GenerateImportPropertyCode(os, config, target, properties);
  76. }
  77. }
  78. }
  79. //----------------------------------------------------------------------------
  80. void
  81. cmExportBuildFileGenerator
  82. ::SetImportLocationProperty(const char* config, std::string const& suffix,
  83. cmTarget* target, ImportPropertyMap& properties)
  84. {
  85. // Get the makefile in which to lookup target information.
  86. cmMakefile* mf = target->GetMakefile();
  87. // Add the main target file.
  88. {
  89. std::string prop = "IMPORTED_LOCATION";
  90. prop += suffix;
  91. std::string value;
  92. if(target->IsFrameworkOnApple() || target->IsAppBundleOnApple())
  93. {
  94. value = target->GetFullPath(config, false);
  95. }
  96. else
  97. {
  98. value = target->GetFullPath(config, false, true);
  99. }
  100. properties[prop] = value;
  101. }
  102. // Check whether this is a DLL platform.
  103. bool dll_platform =
  104. (mf->IsOn("WIN32") || mf->IsOn("CYGWIN") || mf->IsOn("MINGW"));
  105. // Add the import library for windows DLLs.
  106. if(dll_platform &&
  107. (target->GetType() == cmTarget::SHARED_LIBRARY ||
  108. target->IsExecutableWithExports()) &&
  109. mf->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
  110. {
  111. std::string prop = "IMPORTED_IMPLIB";
  112. prop += suffix;
  113. std::string value = target->GetFullPath(config, true);
  114. properties[prop] = value;
  115. }
  116. }
  117. //----------------------------------------------------------------------------
  118. void
  119. cmExportBuildFileGenerator
  120. ::ComplainAboutMissingTarget(cmTarget* depender,
  121. cmTarget* dependee)
  122. {
  123. if(!this->ExportCommand || !this->ExportCommand->ErrorMessage.empty())
  124. {
  125. return;
  126. }
  127. cmOStringStream e;
  128. e << "called with target \"" << depender->GetName()
  129. << "\" which requires target \"" << dependee->GetName()
  130. << "\" that is not in the export list.\n"
  131. << "If the required target is not easy to reference in this call, "
  132. << "consider using the APPEND option with multiple separate calls.";
  133. this->ExportCommand->ErrorMessage = e.str();
  134. }