cmExportBuildFileGenerator.cxx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. this->ExportedTargets.insert(te);
  30. this->GenerateImportTargetCode(os, te);
  31. }
  32. // Generate import file content for each configuration.
  33. for(std::vector<std::string>::const_iterator
  34. ci = this->Configurations.begin();
  35. ci != this->Configurations.end(); ++ci)
  36. {
  37. this->GenerateImportConfig(os, ci->c_str());
  38. }
  39. return true;
  40. }
  41. //----------------------------------------------------------------------------
  42. void
  43. cmExportBuildFileGenerator
  44. ::GenerateImportTargetsConfig(std::ostream& os,
  45. const char* config, std::string const& suffix)
  46. {
  47. for(std::vector<cmTarget*>::const_iterator
  48. tei = this->Exports->begin();
  49. tei != this->Exports->end(); ++tei)
  50. {
  51. // Collect import properties for this target.
  52. cmTarget* target = *tei;
  53. ImportPropertyMap properties;
  54. this->SetImportLocationProperty(config, suffix, target, properties);
  55. if(!properties.empty())
  56. {
  57. // Get the rest of the target details.
  58. this->SetImportDetailProperties(config, suffix,
  59. target, properties);
  60. // TOOD: PUBLIC_HEADER_LOCATION
  61. // This should wait until the build feature propagation stuff
  62. // is done. Then this can be a propagated include directory.
  63. // this->GenerateImportProperty(config, te->HeaderGenerator,
  64. // properties);
  65. // Generate code in the export file.
  66. this->GenerateImportPropertyCode(os, config, target, properties);
  67. }
  68. }
  69. }
  70. //----------------------------------------------------------------------------
  71. void
  72. cmExportBuildFileGenerator
  73. ::SetImportLocationProperty(const char* config, std::string const& suffix,
  74. cmTarget* target, ImportPropertyMap& properties)
  75. {
  76. // Get the makefile in which to lookup target information.
  77. cmMakefile* mf = target->GetMakefile();
  78. // Add the main target file.
  79. {
  80. std::string prop = "IMPORTED_LOCATION";
  81. prop += suffix;
  82. std::string value = target->GetFullPath(config, false);
  83. if(target->IsAppBundleOnApple())
  84. {
  85. value += ".app/Contents/MacOS/";
  86. value += target->GetFullName(config, false);
  87. }
  88. properties[prop] = value;
  89. }
  90. // Check whether this is a DLL platform.
  91. bool dll_platform =
  92. (mf->IsOn("WIN32") || mf->IsOn("CYGWIN") || mf->IsOn("MINGW"));
  93. // Add the import library for windows DLLs.
  94. if(dll_platform &&
  95. (target->GetType() == cmTarget::SHARED_LIBRARY ||
  96. target->IsExecutableWithExports()) &&
  97. mf->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
  98. {
  99. std::string prop = "IMPORTED_IMPLIB";
  100. prop += suffix;
  101. std::string value = target->GetFullPath(config, true);
  102. properties[prop] = value;
  103. }
  104. }
  105. //----------------------------------------------------------------------------
  106. void
  107. cmExportBuildFileGenerator
  108. ::ComplainAboutMissingTarget(cmTarget* target, const char* dep)
  109. {
  110. if(!this->ExportCommand || !this->ExportCommand->ErrorMessage.empty())
  111. {
  112. return;
  113. }
  114. cmOStringStream e;
  115. e << "called with target \"" << target->GetName()
  116. << "\" which links to target \"" << dep
  117. << "\" that is not in the export list.\n"
  118. << "If the link dependency is not part of the public interface "
  119. << "consider setting the LINK_INTERFACE_LIBRARIES property on \""
  120. << target->GetName() << "\". Otherwise add it to the export list. "
  121. << "If the link dependency is not easy to reference in this call, "
  122. << "consider using the APPEND option with multiple separate calls.";
  123. this->ExportCommand->ErrorMessage = e.str();
  124. }