cmExportFileGenerator.h 8.4 KB

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