cmake/Source/cmGlobalVisualStudio71Generator.cxx

230 lines
8.4 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmGlobalVisualStudio71Generator.h"
2016-07-09 11:21:54 +02:00
2017-04-14 19:02:05 +02:00
#include "cmDocumentationEntry.h"
2016-10-30 18:24:19 +01:00
#include "cmGeneratorTarget.h"
#include "cmLocalVisualStudio7Generator.h"
#include "cmMakefile.h"
#include "cmake.h"
2016-07-09 11:21:54 +02:00
cmGlobalVisualStudio71Generator::cmGlobalVisualStudio71Generator(
cmake* cm, const std::string& platformName)
2015-08-17 11:37:30 +02:00
: cmGlobalVisualStudio7Generator(cm, platformName)
{
this->ProjectConfigurationSectionName = "ProjectConfiguration";
}
2016-07-09 11:21:54 +02:00
void cmGlobalVisualStudio71Generator::WriteSLNFile(
std::ostream& fout, cmLocalGenerator* root,
std::vector<cmLocalGenerator*>& generators)
2013-03-16 19:13:01 +02:00
{
2015-08-17 11:37:30 +02:00
std::vector<std::string> configs;
root->GetMakefile()->GetConfigurations(configs);
// Write out the header for a SLN file
this->WriteSLNHeader(fout);
2009-10-04 10:30:41 +03:00
// Collect all targets under this root generator and the transitive
// closure of their dependencies.
TargetDependSet projectTargets;
TargetDependSet originalTargets;
this->GetTargetSets(projectTargets, originalTargets, root, generators);
2016-07-09 11:21:54 +02:00
OrderedTargetDependSet orderedProjectTargets(
projectTargets, this->GetStartupProjectName(root));
2009-10-04 10:30:41 +03:00
2016-07-09 11:21:54 +02:00
// Generate the targets specification to a string. We will put this in
// the actual .sln file later. As a side effect, this method also
// populates the set of folders.
std::ostringstream targetsSlnString;
this->WriteTargetsToSolution(targetsSlnString, root, orderedProjectTargets);
2010-11-13 01:00:53 +02:00
2016-07-09 11:21:54 +02:00
// Generate folder specification.
2010-11-13 01:00:53 +02:00
bool useFolderProperty = this->UseFolderProperty();
2016-07-09 11:21:54 +02:00
if (useFolderProperty) {
2010-11-13 01:00:53 +02:00
this->WriteFolders(fout);
2016-07-09 11:21:54 +02:00
}
// Now write the actual target specification content.
2017-07-20 19:35:53 +02:00
fout << targetsSlnString.str();
2010-11-13 01:00:53 +02:00
// Write out the configurations information for the solution
fout << "Global\n";
// Write out the configurations for the solution
2015-08-17 11:37:30 +02:00
this->WriteSolutionConfigurations(fout, configs);
fout << "\tGlobalSection(" << this->ProjectConfigurationSectionName
<< ") = postSolution\n";
// Write out the configurations for all the targets in the project
2015-08-17 11:37:30 +02:00
this->WriteTargetConfigurations(fout, configs, orderedProjectTargets);
fout << "\tEndGlobalSection\n";
2010-11-13 01:00:53 +02:00
2016-07-09 11:21:54 +02:00
if (useFolderProperty) {
2010-11-13 01:00:53 +02:00
// Write out project folders
fout << "\tGlobalSection(NestedProjects) = preSolution\n";
this->WriteFoldersContent(fout);
fout << "\tEndGlobalSection\n";
2016-07-09 11:21:54 +02:00
}
2010-11-13 01:00:53 +02:00
2013-03-16 19:13:01 +02:00
// Write out global sections
this->WriteSLNGlobalSections(fout, root);
// Write the footer for the SLN file
this->WriteSLNFooter(fout);
}
2016-07-09 11:21:54 +02:00
void cmGlobalVisualStudio71Generator::WriteSolutionConfigurations(
std::ostream& fout, std::vector<std::string> const& configs)
{
fout << "\tGlobalSection(SolutionConfiguration) = preSolution\n";
2016-07-09 11:21:54 +02:00
for (std::vector<std::string>::const_iterator i = configs.begin();
i != configs.end(); ++i) {
fout << "\t\t" << *i << " = " << *i << "\n";
2016-07-09 11:21:54 +02:00
}
fout << "\tEndGlobalSection\n";
}
// Write a dsp file into the SLN file,
2013-03-16 19:13:01 +02:00
// Note, that dependencies from executables to
// the libraries it uses are also done here
2016-07-09 11:21:54 +02:00
void cmGlobalVisualStudio71Generator::WriteProject(std::ostream& fout,
const std::string& dspname,
const char* dir,
cmGeneratorTarget const* t)
{
// check to see if this is a fortran build
const char* ext = ".vcproj";
2013-03-16 19:13:01 +02:00
const char* project =
"Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"";
2016-07-09 11:21:54 +02:00
if (this->TargetIsFortranOnly(t)) {
2013-03-16 19:13:01 +02:00
ext = ".vfproj";
project = "Project(\"{6989167D-11E4-40FE-8C1A-2192A86A7E90}\") = \"";
2016-07-09 11:21:54 +02:00
}
2017-04-14 19:02:05 +02:00
if (this->TargetIsCSharpOnly(t)) {
ext = ".csproj";
project = "Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"";
}
2016-03-13 13:35:51 +01:00
const char* targetExt = t->GetProperty("GENERATOR_FILE_NAME_EXT");
2016-07-09 11:21:54 +02:00
if (targetExt) {
2009-10-04 10:30:41 +03:00
ext = targetExt;
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
2010-11-13 01:00:53 +02:00
std::string guid = this->GetGUID(dspname);
2016-07-09 11:21:54 +02:00
fout << project << dspname << "\", \"" << this->ConvertToSolutionPath(dir)
<< (dir[0] ? "\\" : "") << dspname << ext << "\", \"{" << guid
<< "}\"\n";
fout << "\tProjectSection(ProjectDependencies) = postProject\n";
this->WriteProjectDepends(fout, dspname, dir, t);
fout << "\tEndProjectSection\n";
2013-03-16 19:13:01 +02:00
2016-07-09 11:21:54 +02:00
fout << "EndProject\n";
2010-11-13 01:00:53 +02:00
2016-03-13 13:35:51 +01:00
UtilityDependsMap::iterator ui = this->UtilityDepends.find(t);
2016-07-09 11:21:54 +02:00
if (ui != this->UtilityDepends.end()) {
2010-11-13 01:00:53 +02:00
const char* uname = ui->second.c_str();
2016-07-09 11:21:54 +02:00
/* clang-format off */
2010-11-13 01:00:53 +02:00
fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
<< uname << "\", \""
2011-01-16 11:35:12 +01:00
<< this->ConvertToSolutionPath(dir) << (dir[0]? "\\":"")
<< uname << ".vcproj" << "\", \"{"
2010-11-13 01:00:53 +02:00
<< this->GetGUID(uname) << "}\"\n"
<< "\tProjectSection(ProjectDependencies) = postProject\n"
<< "\t\t{" << guid << "} = {" << guid << "}\n"
<< "\tEndProjectSection\n"
<< "EndProject\n";
2016-07-09 11:21:54 +02:00
/* clang-format on */
}
}
// Write a dsp file into the SLN file,
2013-03-16 19:13:01 +02:00
// Note, that dependencies from executables to
// the libraries it uses are also done here
2016-07-09 11:21:54 +02:00
void cmGlobalVisualStudio71Generator::WriteProjectDepends(
std::ostream& fout, const std::string&, const char*,
cmGeneratorTarget const* target)
{
2016-03-13 13:35:51 +01:00
VSDependSet const& depends = this->VSTargetDepends[target];
2016-07-09 11:21:54 +02:00
for (VSDependSet::const_iterator di = depends.begin(); di != depends.end();
++di) {
2010-11-13 01:00:53 +02:00
const char* name = di->c_str();
std::string guid = this->GetGUID(name);
2016-07-09 11:21:54 +02:00
if (guid.empty()) {
2010-11-13 01:00:53 +02:00
std::string m = "Target: ";
2016-03-13 13:35:51 +01:00
m += target->GetName();
2010-11-13 01:00:53 +02:00
m += " depends on unknown target: ";
m += name;
cmSystemTools::Error(m.c_str());
}
2016-07-09 11:21:54 +02:00
fout << "\t\t{" << guid << "} = {" << guid << "}\n";
}
}
// Write a dsp file into the SLN file, Note, that dependencies from
// executables to the libraries it uses are also done here
2016-07-09 11:21:54 +02:00
void cmGlobalVisualStudio71Generator::WriteExternalProject(
std::ostream& fout, const std::string& name, const char* location,
const char* typeGuid, const std::set<std::string>& depends)
2013-03-16 19:13:01 +02:00
{
2012-06-27 20:52:58 +03:00
fout << "Project(\"{"
2014-08-03 19:52:23 +02:00
<< (typeGuid ? typeGuid : this->ExternalProjectType(location))
2016-07-09 11:21:54 +02:00
<< "}\") = \"" << name << "\", \""
<< this->ConvertToSolutionPath(location) << "\", \"{"
2016-07-09 11:21:54 +02:00
<< this->GetGUID(name) << "}\"\n";
2013-03-16 19:13:01 +02:00
// write out the dependencies here VS 7.1 includes dependencies with the
// project instead of in the global section
2016-07-09 11:21:54 +02:00
if (!depends.empty()) {
fout << "\tProjectSection(ProjectDependencies) = postProject\n";
2015-04-27 22:25:09 +02:00
std::set<std::string>::const_iterator it;
2016-07-09 11:21:54 +02:00
for (it = depends.begin(); it != depends.end(); ++it) {
if (!it->empty()) {
fout << "\t\t{" << this->GetGUID(it->c_str()) << "} = {"
<< this->GetGUID(it->c_str()) << "}\n";
}
2013-03-16 19:13:01 +02:00
}
2016-07-09 11:21:54 +02:00
fout << "\tEndProjectSection\n";
}
fout << "EndProject\n";
}
// Write a dsp file into the SLN file, Note, that dependencies from
// executables to the libraries it uses are also done here
2016-07-09 11:21:54 +02:00
void cmGlobalVisualStudio71Generator::WriteProjectConfigurations(
2017-07-20 19:35:53 +02:00
std::ostream& fout, const std::string& name, cmGeneratorTarget const& target,
2015-08-17 11:37:30 +02:00
std::vector<std::string> const& configs,
2013-03-16 19:13:01 +02:00
const std::set<std::string>& configsPartOfDefaultBuild,
2015-04-27 22:25:09 +02:00
std::string const& platformMapping)
{
2015-04-27 22:25:09 +02:00
const std::string& platformName =
!platformMapping.empty() ? platformMapping : this->GetPlatformName();
std::string guid = this->GetGUID(name);
2016-07-09 11:21:54 +02:00
for (std::vector<std::string>::const_iterator i = configs.begin();
i != configs.end(); ++i) {
2017-09-21 19:03:52 +02:00
std::vector<std::string> mapConfig;
const char* dstConfig = i->c_str();
if (target.GetProperty("EXTERNAL_MSPROJECT")) {
if (const char* m = target.GetProperty("MAP_IMPORTED_CONFIG_" +
cmSystemTools::UpperCase(*i))) {
cmSystemTools::ExpandListArgument(m, mapConfig);
if (!mapConfig.empty()) {
dstConfig = mapConfig[0].c_str();
}
}
2017-07-20 19:35:53 +02:00
}
fout << "\t\t{" << guid << "}." << *i << ".ActiveCfg = " << dstConfig
<< "|" << platformName << std::endl;
2016-07-09 11:21:54 +02:00
std::set<std::string>::const_iterator ci =
configsPartOfDefaultBuild.find(*i);
if (!(ci == configsPartOfDefaultBuild.end())) {
2017-07-20 19:35:53 +02:00
fout << "\t\t{" << guid << "}." << *i << ".Build.0 = " << dstConfig
<< "|" << platformName << std::endl;
}
2016-07-09 11:21:54 +02:00
}
}
// ouput standard header for dsw file
void cmGlobalVisualStudio71Generator::WriteSLNHeader(std::ostream& fout)
{
fout << "Microsoft Visual Studio Solution File, Format Version 8.00\n";
}