1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #include "cmGlobalVisualStudio71Generator.h"
4
5 #include "cmDocumentationEntry.h"
6 #include "cmGeneratorTarget.h"
7 #include "cmLocalVisualStudio7Generator.h"
8 #include "cmMakefile.h"
9 #include "cmMessageType.h"
10
cmGlobalVisualStudio71Generator(cmake * cm,const std::string & platformName)11 cmGlobalVisualStudio71Generator::cmGlobalVisualStudio71Generator(
12 cmake* cm, const std::string& platformName)
13 : cmGlobalVisualStudio7Generator(cm, platformName)
14 {
15 this->ProjectConfigurationSectionName = "ProjectConfiguration";
16 }
17
WriteSLNFile(std::ostream & fout,cmLocalGenerator * root,std::vector<cmLocalGenerator * > & generators)18 void cmGlobalVisualStudio71Generator::WriteSLNFile(
19 std::ostream& fout, cmLocalGenerator* root,
20 std::vector<cmLocalGenerator*>& generators)
21 {
22 std::vector<std::string> configs =
23 root->GetMakefile()->GetGeneratorConfigs(cmMakefile::ExcludeEmptyConfig);
24
25 // Write out the header for a SLN file
26 this->WriteSLNHeader(fout);
27
28 // Collect all targets under this root generator and the transitive
29 // closure of their dependencies.
30 TargetDependSet projectTargets;
31 TargetDependSet originalTargets;
32 this->GetTargetSets(projectTargets, originalTargets, root, generators);
33 OrderedTargetDependSet orderedProjectTargets(
34 projectTargets, this->GetStartupProjectName(root));
35
36 // Generate the targets specification to a string. We will put this in
37 // the actual .sln file later. As a side effect, this method also
38 // populates the set of folders.
39 std::ostringstream targetsSlnString;
40 this->WriteTargetsToSolution(targetsSlnString, root, orderedProjectTargets);
41
42 // Generate folder specification.
43 bool useFolderProperty = this->UseFolderProperty();
44 if (useFolderProperty) {
45 this->WriteFolders(fout);
46 }
47
48 // Now write the actual target specification content.
49 fout << targetsSlnString.str();
50
51 // Write out the configurations information for the solution
52 fout << "Global\n";
53 // Write out the configurations for the solution
54 this->WriteSolutionConfigurations(fout, configs);
55 fout << "\tGlobalSection(" << this->ProjectConfigurationSectionName
56 << ") = postSolution\n";
57 // Write out the configurations for all the targets in the project
58 this->WriteTargetConfigurations(fout, configs, orderedProjectTargets);
59 fout << "\tEndGlobalSection\n";
60
61 if (useFolderProperty) {
62 // Write out project folders
63 fout << "\tGlobalSection(NestedProjects) = preSolution\n";
64 this->WriteFoldersContent(fout);
65 fout << "\tEndGlobalSection\n";
66 }
67
68 // Write out global sections
69 this->WriteSLNGlobalSections(fout, root);
70
71 // Write the footer for the SLN file
72 this->WriteSLNFooter(fout);
73 }
74
WriteSolutionConfigurations(std::ostream & fout,std::vector<std::string> const & configs)75 void cmGlobalVisualStudio71Generator::WriteSolutionConfigurations(
76 std::ostream& fout, std::vector<std::string> const& configs)
77 {
78 fout << "\tGlobalSection(SolutionConfiguration) = preSolution\n";
79 for (std::string const& i : configs) {
80 fout << "\t\t" << i << " = " << i << "\n";
81 }
82 fout << "\tEndGlobalSection\n";
83 }
84
85 // Write a dsp file into the SLN file,
86 // Note, that dependencies from executables to
87 // the libraries it uses are also done here
WriteProject(std::ostream & fout,const std::string & dspname,const std::string & dir,cmGeneratorTarget const * t)88 void cmGlobalVisualStudio71Generator::WriteProject(std::ostream& fout,
89 const std::string& dspname,
90 const std::string& dir,
91 cmGeneratorTarget const* t)
92 {
93 // check to see if this is a fortran build
94 std::string ext = ".vcproj";
95 const char* project =
96 "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"";
97 if (this->TargetIsFortranOnly(t)) {
98 ext = ".vfproj";
99 project = "Project(\"{6989167D-11E4-40FE-8C1A-2192A86A7E90}\") = \"";
100 }
101 if (t->IsCSharpOnly()) {
102 ext = ".csproj";
103 project = "Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"";
104 }
105 cmValue targetExt = t->GetProperty("GENERATOR_FILE_NAME_EXT");
106 if (targetExt) {
107 ext = *targetExt;
108 }
109
110 std::string guid = this->GetGUID(dspname);
111 fout << project << dspname << "\", \"" << this->ConvertToSolutionPath(dir)
112 << (!dir.empty() ? "\\" : "") << dspname << ext << "\", \"{" << guid
113 << "}\"\n";
114 fout << "\tProjectSection(ProjectDependencies) = postProject\n";
115 this->WriteProjectDepends(fout, dspname, dir, t);
116 fout << "\tEndProjectSection\n";
117
118 fout << "EndProject\n";
119
120 UtilityDependsMap::iterator ui = this->UtilityDepends.find(t);
121 if (ui != this->UtilityDepends.end()) {
122 const char* uname = ui->second.c_str();
123 /* clang-format off */
124 fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
125 << uname << "\", \""
126 << this->ConvertToSolutionPath(dir) << (dir[0]? "\\":"")
127 << uname << ".vcproj" << "\", \"{"
128 << this->GetGUID(uname) << "}\"\n"
129 << "\tProjectSection(ProjectDependencies) = postProject\n"
130 << "\t\t{" << guid << "} = {" << guid << "}\n"
131 << "\tEndProjectSection\n"
132 << "EndProject\n";
133 /* clang-format on */
134 }
135 }
136
137 // Write a dsp file into the SLN file,
138 // Note, that dependencies from executables to
139 // the libraries it uses are also done here
WriteProjectDepends(std::ostream & fout,const std::string &,const std::string &,cmGeneratorTarget const * target)140 void cmGlobalVisualStudio71Generator::WriteProjectDepends(
141 std::ostream& fout, const std::string&, const std::string&,
142 cmGeneratorTarget const* target)
143 {
144 VSDependSet const& depends = this->VSTargetDepends[target];
145 for (std::string const& name : depends) {
146 std::string guid = this->GetGUID(name);
147 if (guid.empty()) {
148 std::string m = cmStrCat("Target: ", target->GetName(),
149 " depends on unknown target: ", name);
150 cmSystemTools::Error(m);
151 }
152 fout << "\t\t{" << guid << "} = {" << guid << "}\n";
153 }
154 }
155
156 // Write a dsp file into the SLN file, Note, that dependencies from
157 // executables to the libraries it uses are also done here
WriteExternalProject(std::ostream & fout,const std::string & name,const std::string & location,cmValue typeGuid,const std::set<BT<std::pair<std::string,bool>>> & depends)158 void cmGlobalVisualStudio71Generator::WriteExternalProject(
159 std::ostream& fout, const std::string& name, const std::string& location,
160 cmValue typeGuid, const std::set<BT<std::pair<std::string, bool>>>& depends)
161 {
162 fout << "Project(\"{"
163 << (typeGuid ? typeGuid
164 : std::string(this->ExternalProjectType(location)))
165 << "}\") = \"" << name << "\", \""
166 << this->ConvertToSolutionPath(location) << "\", \"{"
167 << this->GetGUID(name) << "}\"\n";
168
169 // write out the dependencies here VS 7.1 includes dependencies with the
170 // project instead of in the global section
171 if (!depends.empty()) {
172 fout << "\tProjectSection(ProjectDependencies) = postProject\n";
173 for (BT<std::pair<std::string, bool>> const& it : depends) {
174 std::string const& dep = it.Value.first;
175 if (!dep.empty()) {
176 fout << "\t\t{" << this->GetGUID(dep) << "} = {" << this->GetGUID(dep)
177 << "}\n";
178 }
179 }
180 fout << "\tEndProjectSection\n";
181 }
182
183 fout << "EndProject\n";
184 }
185
186 // Write a dsp file into the SLN file, Note, that dependencies from
187 // executables to the libraries it uses are also done here
WriteProjectConfigurations(std::ostream & fout,const std::string & name,cmGeneratorTarget const & target,std::vector<std::string> const & configs,const std::set<std::string> & configsPartOfDefaultBuild,std::string const & platformMapping)188 void cmGlobalVisualStudio71Generator::WriteProjectConfigurations(
189 std::ostream& fout, const std::string& name, cmGeneratorTarget const& target,
190 std::vector<std::string> const& configs,
191 const std::set<std::string>& configsPartOfDefaultBuild,
192 std::string const& platformMapping)
193 {
194 const std::string& platformName =
195 !platformMapping.empty() ? platformMapping : this->GetPlatformName();
196 std::string guid = this->GetGUID(name);
197 for (std::string const& i : configs) {
198 std::vector<std::string> mapConfig;
199 const char* dstConfig = i.c_str();
200 if (target.GetProperty("EXTERNAL_MSPROJECT")) {
201 if (cmValue m = target.GetProperty("MAP_IMPORTED_CONFIG_" +
202 cmSystemTools::UpperCase(i))) {
203 cmExpandList(*m, mapConfig);
204 if (!mapConfig.empty()) {
205 dstConfig = mapConfig[0].c_str();
206 }
207 }
208 }
209 fout << "\t\t{" << guid << "}." << i << ".ActiveCfg = " << dstConfig << "|"
210 << platformName << std::endl;
211 std::set<std::string>::const_iterator ci =
212 configsPartOfDefaultBuild.find(i);
213 if (!(ci == configsPartOfDefaultBuild.end())) {
214 fout << "\t\t{" << guid << "}." << i << ".Build.0 = " << dstConfig << "|"
215 << platformName << std::endl;
216 }
217 }
218 }
219