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