cmExportFileGenerator.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. // Methods to implement export file code generation.
  42. void GenerateImportHeaderCode(std::ostream& os, const char* config = 0);
  43. void GenerateImportFooterCode(std::ostream& os);
  44. void GenerateImportVersionCode(std::ostream& os);
  45. void GenerateImportTargetCode(std::ostream& os, cmTarget* target);
  46. void GenerateImportPropertyCode(std::ostream& os, const char* config,
  47. cmTarget* target,
  48. ImportPropertyMap const& properties);
  49. void GenerateImportedFileChecksCode(std::ostream& os, cmTarget* target,
  50. ImportPropertyMap const& properties,
  51. const std::set<std::string>& importedLocations);
  52. void GenerateImportedFileCheckLoop(std::ostream& os);
  53. void GenerateMissingTargetsCheckCode(std::ostream& os,
  54. const std::vector<std::string>& missingTargets);
  55. void GenerateExpectedTargetsCode(std::ostream& os,
  56. const std::string &expectedTargets);
  57. // Collect properties with detailed information about targets beyond
  58. // their location on disk.
  59. void SetImportDetailProperties(const char* config,
  60. std::string const& suffix, cmTarget* target,
  61. ImportPropertyMap& properties,
  62. std::vector<std::string>& missingTargets);
  63. void SetImportLinkProperty(std::string const& suffix,
  64. cmTarget* target, const char* propName,
  65. std::vector<std::string> const& libs,
  66. ImportPropertyMap& properties,
  67. std::vector<std::string>& missingTargets);
  68. /** Each subclass knows how to generate its kind of export file. */
  69. virtual bool GenerateMainFile(std::ostream& os) = 0;
  70. /** Each subclass knows where the target files are located. */
  71. virtual void GenerateImportTargetsConfig(std::ostream& os,
  72. const char* config,
  73. std::string const& suffix) = 0;
  74. /** Each subclass knows how to deal with a target that is missing from an
  75. * export set. */
  76. virtual void HandleMissingTarget(std::string& link_libs,
  77. std::vector<std::string>& missingTargets,
  78. cmMakefile* mf,
  79. cmTarget* depender,
  80. cmTarget* dependee) = 0;
  81. void PopulateInterfaceProperty(const char *,
  82. cmTarget *target,
  83. cmGeneratorExpression::PreprocessContext,
  84. ImportPropertyMap &properties,
  85. std::vector<std::string> &missingTargets);
  86. void GenerateInterfaceProperties(cmTarget *target, std::ostream& os,
  87. const ImportPropertyMap &properties);
  88. void SetImportLinkInterface(const char* config, std::string const& suffix,
  89. cmGeneratorExpression::PreprocessContext preprocessRule,
  90. cmTarget* target, ImportPropertyMap& properties,
  91. std::vector<std::string>& missingTargets);
  92. enum FreeTargetsReplace {
  93. ReplaceFreeTargets,
  94. NoReplaceFreeTargets
  95. };
  96. void ResolveTargetsInGeneratorExpressions(std::string &input,
  97. cmTarget* target,
  98. std::vector<std::string> &missingTargets,
  99. FreeTargetsReplace replace = NoReplaceFreeTargets);
  100. // The namespace in which the exports are placed in the generated file.
  101. std::string Namespace;
  102. // The set of configurations to export.
  103. std::vector<std::string> Configurations;
  104. // The file to generate.
  105. std::string MainImportFile;
  106. std::string FileDir;
  107. std::string FileBase;
  108. std::string FileExt;
  109. bool AppendMode;
  110. // The set of targets included in the export.
  111. std::set<cmTarget*> ExportedTargets;
  112. private:
  113. void PopulateInterfaceProperty(const char *, const char *,
  114. cmTarget *target,
  115. cmGeneratorExpression::PreprocessContext,
  116. ImportPropertyMap &properties,
  117. std::vector<std::string> &missingTargets);
  118. bool AddTargetNamespace(std::string &input, cmTarget* target,
  119. std::vector<std::string> &missingTargets);
  120. void ResolveTargetsInGeneratorExpression(std::string &input,
  121. cmTarget* target,
  122. std::vector<std::string> &missingTargets);
  123. };
  124. #endif