cmExportFileGenerator.h 8.3 KB

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