cmExportBuildFileGenerator.cxx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. {
  21. std::string expectedTargets;
  22. std::string sep;
  23. for(std::vector<cmTarget*>::const_iterator
  24. tei = this->Exports->begin();
  25. tei != this->Exports->end(); ++tei)
  26. {
  27. expectedTargets += sep + this->Namespace + (*tei)->GetName();
  28. sep = " ";
  29. }
  30. this->GenerateExpectedTargetsCode(os, expectedTargets);
  31. }
  32. // Create all the imported targets.
  33. for(std::vector<cmTarget*>::const_iterator
  34. tei = this->Exports->begin();
  35. tei != this->Exports->end(); ++tei)
  36. {
  37. cmTarget* te = *tei;
  38. if(this->ExportedTargets.insert(te).second)
  39. {
  40. this->GenerateImportTargetCode(os, te);
  41. }
  42. else
  43. {
  44. if(this->ExportCommand && this->ExportCommand->ErrorMessage.empty())
  45. {
  46. cmOStringStream e;
  47. e << "given target \"" << te->GetName() << "\" more than once.";
  48. this->ExportCommand->ErrorMessage = e.str();
  49. }
  50. return false;
  51. }
  52. }
  53. // Generate import file content for each configuration.
  54. for(std::vector<std::string>::const_iterator
  55. ci = this->Configurations.begin();
  56. ci != this->Configurations.end(); ++ci)
  57. {
  58. this->GenerateImportConfig(os, ci->c_str());
  59. }
  60. return true;
  61. }
  62. //----------------------------------------------------------------------------
  63. void
  64. cmExportBuildFileGenerator
  65. ::GenerateImportTargetsConfig(std::ostream& os,
  66. const char* config, std::string const& suffix)
  67. {
  68. for(std::vector<cmTarget*>::const_iterator
  69. tei = this->Exports->begin();
  70. tei != this->Exports->end(); ++tei)
  71. {
  72. // Collect import properties for this target.
  73. cmTarget* target = *tei;
  74. ImportPropertyMap properties;
  75. this->SetImportLocationProperty(config, suffix, target, properties);
  76. if(!properties.empty())
  77. {
  78. // Get the rest of the target details.
  79. std::vector<std::string> missingTargets;
  80. this->SetImportDetailProperties(config, suffix,
  81. target, properties, missingTargets);
  82. // TOOD: PUBLIC_HEADER_LOCATION
  83. // This should wait until the build feature propagation stuff
  84. // is done. Then this can be a propagated include directory.
  85. // this->GenerateImportProperty(config, te->HeaderGenerator,
  86. // properties);
  87. // Generate code in the export file.
  88. this->GenerateMissingTargetsCheckCode(os, missingTargets);
  89. this->GenerateImportPropertyCode(os, config, target, properties);
  90. }
  91. }
  92. }
  93. //----------------------------------------------------------------------------
  94. void
  95. cmExportBuildFileGenerator
  96. ::SetImportLocationProperty(const char* config, std::string const& suffix,
  97. cmTarget* target, ImportPropertyMap& properties)
  98. {
  99. // Get the makefile in which to lookup target information.
  100. cmMakefile* mf = target->GetMakefile();
  101. // Add the main target file.
  102. {
  103. std::string prop = "IMPORTED_LOCATION";
  104. prop += suffix;
  105. std::string value;
  106. if(target->IsFrameworkOnApple() || target->IsAppBundleOnApple())
  107. {
  108. value = target->GetFullPath(config, false);
  109. }
  110. else
  111. {
  112. value = target->GetFullPath(config, false, true);
  113. }
  114. properties[prop] = value;
  115. }
  116. // Check whether this is a DLL platform.
  117. bool dll_platform =
  118. (mf->IsOn("WIN32") || mf->IsOn("CYGWIN") || mf->IsOn("MINGW"));
  119. // Add the import library for windows DLLs.
  120. if(dll_platform &&
  121. (target->GetType() == cmTarget::SHARED_LIBRARY ||
  122. target->IsExecutableWithExports()) &&
  123. mf->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
  124. {
  125. std::string prop = "IMPORTED_IMPLIB";
  126. prop += suffix;
  127. std::string value = target->GetFullPath(config, true);
  128. target->GetImplibGNUtoMS(value, value,
  129. "${CMAKE_IMPORT_LIBRARY_SUFFIX}");
  130. properties[prop] = value;
  131. }
  132. }
  133. //----------------------------------------------------------------------------
  134. void
  135. cmExportBuildFileGenerator::HandleMissingTarget(
  136. std::string& link_libs, std::vector<std::string>&,
  137. cmMakefile*, cmTarget* depender, cmTarget* dependee)
  138. {
  139. // The target is not in the export.
  140. if(!this->AppendMode)
  141. {
  142. // We are not appending, so all exported targets should be
  143. // known here. This is probably user-error.
  144. this->ComplainAboutMissingTarget(depender, dependee);
  145. }
  146. // Assume the target will be exported by another command.
  147. // Append it with the export namespace.
  148. link_libs += this->Namespace;
  149. link_libs += dependee->GetName();
  150. }
  151. //----------------------------------------------------------------------------
  152. void
  153. cmExportBuildFileGenerator
  154. ::ComplainAboutMissingTarget(cmTarget* depender,
  155. cmTarget* dependee)
  156. {
  157. if(!this->ExportCommand || !this->ExportCommand->ErrorMessage.empty())
  158. {
  159. return;
  160. }
  161. cmOStringStream e;
  162. e << "called with target \"" << depender->GetName()
  163. << "\" which requires target \"" << dependee->GetName()
  164. << "\" that is not in the export list.\n"
  165. << "If the required target is not easy to reference in this call, "
  166. << "consider using the APPEND option with multiple separate calls.";
  167. this->ExportCommand->ErrorMessage = e.str();
  168. }