cmExportFileGenerator.h 7.8 KB

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