cmExportFileGenerator.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. /** \class cmExportFileGenerator
  14. * \brief Generate a file exporting targets from a build or install tree.
  15. *
  16. * cmExportFileGenerator is the superclass for
  17. * cmExportBuildFileGenerator and cmExportInstallFileGenerator. It
  18. * contains common code generation routines for the two kinds of
  19. * export implementations.
  20. */
  21. class cmExportFileGenerator
  22. {
  23. public:
  24. cmExportFileGenerator();
  25. virtual ~cmExportFileGenerator() {}
  26. /** Set the full path to the export file to generate. */
  27. void SetExportFile(const char* mainFile);
  28. /** Set the namespace in which to place exported target names. */
  29. void SetNamespace(const char* ns) { this->Namespace = ns; }
  30. /** Add a configuration to be exported. */
  31. void AddConfiguration(const char* config);
  32. /** Actually generate the export file. Returns whether there was an
  33. error. */
  34. bool GenerateImportFile();
  35. protected:
  36. typedef std::map<cmStdString, cmStdString> ImportPropertyMap;
  37. // Generate per-configuration target information to the given output
  38. // stream.
  39. void GenerateImportConfig(std::ostream& os, const char* config);
  40. // Methods to implement export file code generation.
  41. void GenerateImportHeaderCode(std::ostream& os, const char* config = 0);
  42. void GenerateImportFooterCode(std::ostream& os);
  43. void GenerateImportVersionCode(std::ostream& os);
  44. void GenerateImportTargetCode(std::ostream& os, cmTarget* target);
  45. void GenerateImportPropertyCode(std::ostream& os, const char* config,
  46. cmTarget* target,
  47. ImportPropertyMap const& properties);
  48. void GenerateImportedFileChecksCode(std::ostream& os, cmTarget* target,
  49. ImportPropertyMap const& properties,
  50. const std::set<std::string>& importedLocations);
  51. void GenerateImportedFileCheckLoop(std::ostream& os);
  52. void GenerateMissingTargetsCheckCode(std::ostream& os,
  53. const std::vector<std::string>& missingTargets);
  54. // Collect properties with detailed information about targets beyond
  55. // their location on disk.
  56. void SetImportDetailProperties(const char* config,
  57. std::string const& suffix, cmTarget* target,
  58. ImportPropertyMap& properties,
  59. std::vector<std::string>& missingTargets);
  60. void SetImportLinkProperty(std::string const& suffix,
  61. cmTarget* target, const char* propName,
  62. std::vector<std::string> const& libs,
  63. ImportPropertyMap& properties,
  64. std::vector<std::string>& missingTargets);
  65. /** Each subclass knows how to generate its kind of export file. */
  66. virtual bool GenerateMainFile(std::ostream& os) = 0;
  67. /** Each subclass knows where the target files are located. */
  68. virtual void GenerateImportTargetsConfig(std::ostream& os,
  69. const char* config,
  70. std::string const& suffix) = 0;
  71. /** Each subclass knows how to deal with a target that is missing from an
  72. * export set. */
  73. virtual void HandleMissingTarget(std::string& link_libs,
  74. std::vector<std::string>& missingTargets,
  75. cmMakefile* mf,
  76. cmTarget* depender,
  77. cmTarget* dependee) = 0;
  78. // The namespace in which the exports are placed in the generated file.
  79. std::string Namespace;
  80. // The set of configurations to export.
  81. std::vector<std::string> Configurations;
  82. // The file to generate.
  83. std::string MainImportFile;
  84. std::string FileDir;
  85. std::string FileBase;
  86. std::string FileExt;
  87. bool AppendMode;
  88. // The set of targets included in the export.
  89. std::set<cmTarget*> ExportedTargets;
  90. };
  91. #endif