cmExportFileGenerator.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. #ifndef cmExportFileGenerator_h
  11. #define cmExportFileGenerator_h
  12. #include "cmCommand.h"
  13. #include "cmGeneratorExpression.h"
  14. /** \class cmExportFileGenerator
  15. * \brief Generate a file exporting targets from a build or install tree.
  16. *
  17. * cmExportFileGenerator is the superclass for
  18. * cmExportBuildFileGenerator and cmExportInstallFileGenerator. It
  19. * contains common code generation routines for the two kinds of
  20. * export implementations.
  21. */
  22. class cmExportFileGenerator
  23. {
  24. public:
  25. cmExportFileGenerator();
  26. virtual ~cmExportFileGenerator() {}
  27. /** Set the full path to the export file to generate. */
  28. void SetExportFile(const char* mainFile);
  29. /** Set the namespace in which to place exported target names. */
  30. void SetNamespace(const char* ns) { this->Namespace = ns; }
  31. /** Add a configuration to be exported. */
  32. void AddConfiguration(const char* config);
  33. /** Actually generate the export file. Returns whether there was an
  34. error. */
  35. bool GenerateImportFile();
  36. protected:
  37. typedef std::map<cmStdString, cmStdString> ImportPropertyMap;
  38. // Generate per-configuration target information to the given output
  39. // stream.
  40. void GenerateImportConfig(std::ostream& os, const char* config,
  41. std::vector<std::string> &missingTargets);
  42. // Methods to implement export file code generation.
  43. void GenerateImportHeaderCode(std::ostream& os, const char* config = 0);
  44. void GenerateImportFooterCode(std::ostream& os);
  45. void GenerateImportVersionCode(std::ostream& os);
  46. void GenerateImportTargetCode(std::ostream& os, cmTarget* target);
  47. void GenerateImportPropertyCode(std::ostream& os, const char* config,
  48. cmTarget* target,
  49. ImportPropertyMap const& properties);
  50. void GenerateImportedFileChecksCode(std::ostream& os, cmTarget* target,
  51. ImportPropertyMap const& properties,
  52. const std::set<std::string>& importedLocations);
  53. void GenerateImportedFileCheckLoop(std::ostream& os);
  54. void GenerateMissingTargetsCheckCode(std::ostream& os,
  55. const std::vector<std::string>& missingTargets);
  56. void GenerateExpectedTargetsCode(std::ostream& os,
  57. const std::string &expectedTargets);
  58. // Collect properties with detailed information about targets beyond
  59. // their location on disk.
  60. void SetImportDetailProperties(const char* config,
  61. std::string const& suffix, cmTarget* target,
  62. ImportPropertyMap& properties,
  63. std::vector<std::string>& missingTargets);
  64. void SetImportLinkProperty(std::string const& suffix,
  65. cmTarget* target, const char* propName,
  66. std::vector<std::string> const& libs,
  67. ImportPropertyMap& properties,
  68. std::vector<std::string>& missingTargets);
  69. /** Each subclass knows how to generate its kind of export file. */
  70. virtual bool GenerateMainFile(std::ostream& os) = 0;
  71. /** Each subclass knows where the target files are located. */
  72. virtual void GenerateImportTargetsConfig(std::ostream& os,
  73. const char* config,
  74. std::string const& suffix,
  75. std::vector<std::string> &missingTargets) = 0;
  76. /** Each subclass knows how to deal with a target that is missing from an
  77. * export set. */
  78. virtual void HandleMissingTarget(std::string& link_libs,
  79. std::vector<std::string>& missingTargets,
  80. cmMakefile* mf,
  81. cmTarget* depender,
  82. cmTarget* dependee) = 0;
  83. void PopulateInterfaceProperty(const char *,
  84. cmTarget *target,
  85. cmGeneratorExpression::PreprocessContext,
  86. ImportPropertyMap &properties,
  87. std::vector<std::string> &missingTargets);
  88. void PopulateInterfaceProperty(const char *propName, cmTarget *target,
  89. ImportPropertyMap &properties);
  90. void PopulateCompatibleInterfaceProperties(cmTarget *target,
  91. ImportPropertyMap &properties);
  92. void GenerateInterfaceProperties(cmTarget *target, std::ostream& os,
  93. const ImportPropertyMap &properties);
  94. void PopulateIncludeDirectoriesInterface(
  95. cmTarget *target,
  96. cmGeneratorExpression::PreprocessContext preprocessRule,
  97. ImportPropertyMap &properties,
  98. std::vector<std::string> &missingTargets);
  99. void SetImportLinkInterface(const char* config, std::string const& suffix,
  100. cmGeneratorExpression::PreprocessContext preprocessRule,
  101. cmTarget* target, ImportPropertyMap& properties,
  102. std::vector<std::string>& missingTargets);
  103. enum FreeTargetsReplace {
  104. ReplaceFreeTargets,
  105. NoReplaceFreeTargets
  106. };
  107. void ResolveTargetsInGeneratorExpressions(std::string &input,
  108. cmTarget* target,
  109. std::vector<std::string> &missingTargets,
  110. FreeTargetsReplace replace = NoReplaceFreeTargets);
  111. // The namespace in which the exports are placed in the generated file.
  112. std::string Namespace;
  113. // The set of configurations to export.
  114. std::vector<std::string> Configurations;
  115. // The file to generate.
  116. std::string MainImportFile;
  117. std::string FileDir;
  118. std::string FileBase;
  119. std::string FileExt;
  120. bool AppendMode;
  121. // The set of targets included in the export.
  122. std::set<cmTarget*> ExportedTargets;
  123. private:
  124. void PopulateInterfaceProperty(const char *, const char *,
  125. cmTarget *target,
  126. cmGeneratorExpression::PreprocessContext,
  127. ImportPropertyMap &properties,
  128. std::vector<std::string> &missingTargets);
  129. bool AddTargetNamespace(std::string &input, cmTarget* target,
  130. std::vector<std::string> &missingTargets);
  131. void ResolveTargetsInGeneratorExpression(std::string &input,
  132. cmTarget* target,
  133. std::vector<std::string> &missingTargets);
  134. virtual void ReplaceInstallPrefix(std::string &input);
  135. virtual std::string InstallNameDir(cmTarget* target,
  136. const std::string& config) = 0;
  137. };
  138. #endif