cmExportBuildFileGenerator.cxx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. std::vector<std::string> missingTargets;
  68. this->SetImportDetailProperties(config, suffix,
  69. target, properties, missingTargets);
  70. // TOOD: PUBLIC_HEADER_LOCATION
  71. // This should wait until the build feature propagation stuff
  72. // is done. Then this can be a propagated include directory.
  73. // this->GenerateImportProperty(config, te->HeaderGenerator,
  74. // properties);
  75. // Generate code in the export file.
  76. this->GenerateMissingTargetsCheckCode(os, missingTargets);
  77. this->GenerateImportPropertyCode(os, config, target, properties);
  78. }
  79. }
  80. }
  81. //----------------------------------------------------------------------------
  82. void
  83. cmExportBuildFileGenerator
  84. ::SetImportLocationProperty(const char* config, std::string const& suffix,
  85. cmTarget* target, ImportPropertyMap& properties)
  86. {
  87. // Get the makefile in which to lookup target information.
  88. cmMakefile* mf = target->GetMakefile();
  89. // Add the main target file.
  90. {
  91. std::string prop = "IMPORTED_LOCATION";
  92. prop += suffix;
  93. std::string value;
  94. if(target->IsFrameworkOnApple() || target->IsAppBundleOnApple())
  95. {
  96. value = target->GetFullPath(config, false);
  97. }
  98. else
  99. {
  100. value = target->GetFullPath(config, false, true);
  101. }
  102. properties[prop] = value;
  103. }
  104. // Check whether this is a DLL platform.
  105. bool dll_platform =
  106. (mf->IsOn("WIN32") || mf->IsOn("CYGWIN") || mf->IsOn("MINGW"));
  107. // Add the import library for windows DLLs.
  108. if(dll_platform &&
  109. (target->GetType() == cmTarget::SHARED_LIBRARY ||
  110. target->IsExecutableWithExports()) &&
  111. mf->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
  112. {
  113. std::string prop = "IMPORTED_IMPLIB";
  114. prop += suffix;
  115. std::string value = target->GetFullPath(config, true);
  116. target->GetImplibGNUtoMS(value, value,
  117. "${CMAKE_IMPORT_LIBRARY_SUFFIX}");
  118. properties[prop] = value;
  119. }
  120. }
  121. //----------------------------------------------------------------------------
  122. void
  123. cmExportBuildFileGenerator::HandleMissingTarget(
  124. std::string& link_libs, std::vector<std::string>&,
  125. cmMakefile*, cmTarget* depender, cmTarget* dependee)
  126. {
  127. // The target is not in the export.
  128. if(!this->AppendMode)
  129. {
  130. // We are not appending, so all exported targets should be
  131. // known here. This is probably user-error.
  132. this->ComplainAboutMissingTarget(depender, dependee);
  133. }
  134. // Assume the target will be exported by another command.
  135. // Append it with the export namespace.
  136. link_libs += this->Namespace;
  137. link_libs += dependee->GetName();
  138. }
  139. //----------------------------------------------------------------------------
  140. void
  141. cmExportBuildFileGenerator
  142. ::ComplainAboutMissingTarget(cmTarget* depender,
  143. cmTarget* dependee)
  144. {
  145. if(!this->ExportCommand || !this->ExportCommand->ErrorMessage.empty())
  146. {
  147. return;
  148. }
  149. cmOStringStream e;
  150. e << "called with target \"" << depender->GetName()
  151. << "\" which requires target \"" << dependee->GetName()
  152. << "\" that is not in the export list.\n"
  153. << "If the required target is not easy to reference in this call, "
  154. << "consider using the APPEND option with multiple separate calls.";
  155. this->ExportCommand->ErrorMessage = e.str();
  156. }