cmExportBuildFileGenerator.cxx 4.9 KB

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