packaging: Initial packaging
[platform/upstream/cmake.git] / Source / cmExportFileGenerator.h
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #ifndef cmExportFileGenerator_h
13 #define cmExportFileGenerator_h
14
15 #include "cmCommand.h"
16 #include "cmGeneratorExpression.h"
17
18 class cmTargetExport;
19
20 /** \class cmExportFileGenerator
21  * \brief Generate a file exporting targets from a build or install tree.
22  *
23  * cmExportFileGenerator is the superclass for
24  * cmExportBuildFileGenerator and cmExportInstallFileGenerator.  It
25  * contains common code generation routines for the two kinds of
26  * export implementations.
27  */
28 class cmExportFileGenerator
29 {
30 public:
31   cmExportFileGenerator();
32   virtual ~cmExportFileGenerator() {}
33
34   /** Set the full path to the export file to generate.  */
35   void SetExportFile(const char* mainFile);
36
37   /** Set the namespace in which to place exported target names.  */
38   void SetNamespace(const char* ns) { this->Namespace = ns; }
39
40   void SetExportOld(bool exportOld) { this->ExportOld = exportOld; }
41
42   /** Add a configuration to be exported.  */
43   void AddConfiguration(const char* config);
44
45   /** Actually generate the export file.  Returns whether there was an
46       error.  */
47   bool GenerateImportFile();
48 protected:
49
50   typedef std::map<cmStdString, cmStdString> ImportPropertyMap;
51
52   // Generate per-configuration target information to the given output
53   // stream.
54   void GenerateImportConfig(std::ostream& os, const char* config,
55                             std::vector<std::string> &missingTargets);
56
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* target);
62   void GenerateImportPropertyCode(std::ostream& os, const char* config,
63                                   cmTarget* 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
72   void GenerateExpectedTargetsCode(std::ostream& os,
73                                           const std::string &expectedTargets);
74
75   // Collect properties with detailed information about targets beyond
76   // their location on disk.
77   void SetImportDetailProperties(const char* config,
78                                  std::string const& suffix, cmTarget* target,
79                                  ImportPropertyMap& properties,
80                                  std::vector<std::string>& missingTargets);
81   void SetImportLinkProperty(std::string const& suffix,
82                              cmTarget* target, const char* propName,
83                              std::vector<std::string> const& libs,
84                              ImportPropertyMap& properties,
85                              std::vector<std::string>& missingTargets);
86
87   /** Each subclass knows how to generate its kind of export file.  */
88   virtual bool GenerateMainFile(std::ostream& os) = 0;
89
90   /** Each subclass knows where the target files are located.  */
91   virtual void GenerateImportTargetsConfig(std::ostream& os,
92                                            const char* config,
93                                            std::string const& suffix,
94                             std::vector<std::string> &missingTargets) = 0;
95
96   /** Each subclass knows how to deal with a target that is  missing from an
97    *  export set.  */
98   virtual void HandleMissingTarget(std::string& link_libs,
99                                    std::vector<std::string>& missingTargets,
100                                    cmMakefile* mf,
101                                    cmTarget* depender,
102                                    cmTarget* dependee) = 0;
103   void PopulateInterfaceProperty(const char *,
104                                  cmTarget *target,
105                                  cmGeneratorExpression::PreprocessContext,
106                                  ImportPropertyMap &properties,
107                                  std::vector<std::string> &missingTargets);
108   bool PopulateInterfaceLinkLibrariesProperty(cmTarget *target,
109                                  cmGeneratorExpression::PreprocessContext,
110                                  ImportPropertyMap &properties,
111                                  std::vector<std::string> &missingTargets);
112   void PopulateInterfaceProperty(const char *propName, cmTarget *target,
113                                  ImportPropertyMap &properties);
114   void PopulateCompatibleInterfaceProperties(cmTarget *target,
115                                  ImportPropertyMap &properties);
116   void GenerateInterfaceProperties(cmTarget *target, std::ostream& os,
117                                    const ImportPropertyMap &properties);
118   void PopulateIncludeDirectoriesInterface(
119                       cmTargetExport *target,
120                       cmGeneratorExpression::PreprocessContext preprocessRule,
121                       ImportPropertyMap &properties,
122                       std::vector<std::string> &missingTargets);
123
124   void SetImportLinkInterface(const char* config, std::string const& suffix,
125                     cmGeneratorExpression::PreprocessContext preprocessRule,
126                     cmTarget* target, ImportPropertyMap& properties,
127                     std::vector<std::string>& missingTargets);
128
129   enum FreeTargetsReplace {
130     ReplaceFreeTargets,
131     NoReplaceFreeTargets
132   };
133
134   void ResolveTargetsInGeneratorExpressions(std::string &input,
135                           cmTarget* target,
136                           std::vector<std::string> &missingTargets,
137                           FreeTargetsReplace replace = NoReplaceFreeTargets);
138
139   void GenerateRequiredCMakeVersion(std::ostream& os,
140                                     const char *versionString);
141
142   // The namespace in which the exports are placed in the generated file.
143   std::string Namespace;
144
145   bool ExportOld;
146
147   // The set of configurations to export.
148   std::vector<std::string> Configurations;
149
150   // The file to generate.
151   std::string MainImportFile;
152   std::string FileDir;
153   std::string FileBase;
154   std::string FileExt;
155   bool AppendMode;
156
157   // The set of targets included in the export.
158   std::set<cmTarget*> ExportedTargets;
159
160 private:
161   void PopulateInterfaceProperty(const char *, const char *,
162                                  cmTarget *target,
163                                  cmGeneratorExpression::PreprocessContext,
164                                  ImportPropertyMap &properties,
165                                  std::vector<std::string> &missingTargets);
166
167   bool AddTargetNamespace(std::string &input, cmTarget* target,
168                           std::vector<std::string> &missingTargets);
169
170   void ResolveTargetsInGeneratorExpression(std::string &input,
171                                     cmTarget* target,
172                                     std::vector<std::string> &missingTargets);
173
174   virtual void ReplaceInstallPrefix(std::string &input);
175
176   virtual std::string InstallNameDir(cmTarget* target,
177                                      const std::string& config) = 0;
178 };
179
180 #endif