1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
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
15 #include "cmCommand.h"
16 #include "cmGeneratorExpression.h"
20 /** \class cmExportFileGenerator
21 * \brief Generate a file exporting targets from a build or install tree.
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.
28 class cmExportFileGenerator
31 cmExportFileGenerator();
32 virtual ~cmExportFileGenerator() {}
34 /** Set the full path to the export file to generate. */
35 void SetExportFile(const char* mainFile);
37 /** Set the namespace in which to place exported target names. */
38 void SetNamespace(const char* ns) { this->Namespace = ns; }
40 void SetExportOld(bool exportOld) { this->ExportOld = exportOld; }
42 /** Add a configuration to be exported. */
43 void AddConfiguration(const char* config);
45 /** Actually generate the export file. Returns whether there was an
47 bool GenerateImportFile();
50 typedef std::map<cmStdString, cmStdString> ImportPropertyMap;
52 // Generate per-configuration target information to the given output
54 void GenerateImportConfig(std::ostream& os, const char* config,
55 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* target);
62 void GenerateImportPropertyCode(std::ostream& os, const char* config,
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);
72 void GenerateExpectedTargetsCode(std::ostream& os,
73 const std::string &expectedTargets);
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);
87 /** Each subclass knows how to generate its kind of export file. */
88 virtual bool GenerateMainFile(std::ostream& os) = 0;
90 /** Each subclass knows where the target files are located. */
91 virtual void GenerateImportTargetsConfig(std::ostream& os,
93 std::string const& suffix,
94 std::vector<std::string> &missingTargets) = 0;
96 /** Each subclass knows how to deal with a target that is missing from an
98 virtual void HandleMissingTarget(std::string& link_libs,
99 std::vector<std::string>& missingTargets,
102 cmTarget* dependee) = 0;
103 void PopulateInterfaceProperty(const char *,
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);
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);
129 enum FreeTargetsReplace {
134 void ResolveTargetsInGeneratorExpressions(std::string &input,
136 std::vector<std::string> &missingTargets,
137 FreeTargetsReplace replace = NoReplaceFreeTargets);
139 void GenerateRequiredCMakeVersion(std::ostream& os,
140 const char *versionString);
142 // The namespace in which the exports are placed in the generated file.
143 std::string Namespace;
147 // The set of configurations to export.
148 std::vector<std::string> Configurations;
150 // The file to generate.
151 std::string MainImportFile;
153 std::string FileBase;
157 // The set of targets included in the export.
158 std::set<cmTarget*> ExportedTargets;
161 void PopulateInterfaceProperty(const char *, const char *,
163 cmGeneratorExpression::PreprocessContext,
164 ImportPropertyMap &properties,
165 std::vector<std::string> &missingTargets);
167 bool AddTargetNamespace(std::string &input, cmTarget* target,
168 std::vector<std::string> &missingTargets);
170 void ResolveTargetsInGeneratorExpression(std::string &input,
172 std::vector<std::string> &missingTargets);
174 virtual void ReplaceInstallPrefix(std::string &input);
176 virtual std::string InstallNameDir(cmTarget* target,
177 const std::string& config) = 0;