cmake/Source/cmGlobalVisualStudio71Generator.cxx

229 lines
8.2 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
2022-03-29 21:10:50 +02:00
#include <map>
#include <sstream>
2016-10-30 18:24:19 +01:00
#include "cmGeneratorTarget.h"
2022-03-29 21:10:50 +02:00
#include "cmGlobalGenerator.h"
#include "cmGlobalVisualStudioGenerator.h"
2023-07-02 19:51:09 +02:00
#include "cmList.h"
2022-03-29 21:10:50 +02:00
#include "cmListFileCache.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
2022-03-29 21:10:50 +02:00
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
class cmake;
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
{
2021-09-14 00:13:48 +02:00
std::vector<std::string> configs =
root->GetMakefile()->GetGeneratorConfigs(cmMakefile::ExcludeEmptyConfig);
2015-08-17 11:37:30 +02:00
// 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";
2018-04-23 21:13:27 +02:00
for (std::string const& i : configs) {
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,
2020-08-30 11:54:41 +02:00
const std::string& dir,
2016-07-09 11:21:54 +02:00
cmGeneratorTarget const* t)
{
// check to see if this is a fortran build
2020-08-30 11:54:41 +02:00
std::string ext = ".vcproj";
2013-03-16 19:13:01 +02:00
const char* project =
2023-05-23 16:38:00 +02:00
R"(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";
2023-05-23 16:38:00 +02:00
project = R"(Project("{6989167D-11E4-40FE-8C1A-2192A86A7E90}") = ")";
2016-07-09 11:21:54 +02:00
}
2018-11-29 20:27:00 +01:00
if (t->IsCSharpOnly()) {
2017-04-14 19:02:05 +02:00
ext = ".csproj";
2023-05-23 16:38:00 +02:00
project = R"(Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = ")";
2017-04-14 19:02:05 +02:00
}
2021-11-20 13:41:27 +01:00
cmValue targetExt = t->GetProperty("GENERATOR_FILE_NAME_EXT");
2016-07-09 11:21:54 +02:00
if (targetExt) {
2020-08-30 11:54:41 +02: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)
2020-08-30 11:54:41 +02:00
<< (!dir.empty() ? "\\" : "") << dspname << ext << "\", \"{" << guid
2016-07-09 11:21:54 +02:00
<< "}\"\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
2023-05-23 16:38:00 +02:00
auto 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 */
2023-05-23 16:38:00 +02:00
fout << R"(Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = ")"
2010-11-13 01:00:53 +02:00
<< 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(
2020-08-30 11:54:41 +02:00
std::ostream& fout, const std::string&, const std::string&,
2016-07-09 11:21:54 +02:00
cmGeneratorTarget const* target)
{
2016-03-13 13:35:51 +01:00
VSDependSet const& depends = this->VSTargetDepends[target];
2018-04-23 21:13:27 +02:00
for (std::string const& name : depends) {
2010-11-13 01:00:53 +02:00
std::string guid = this->GetGUID(name);
2016-07-09 11:21:54 +02:00
if (guid.empty()) {
2020-02-01 23:06:01 +01:00
std::string m = cmStrCat("Target: ", target->GetName(),
" depends on unknown target: ", name);
2019-11-11 23:01:05 +01:00
cmSystemTools::Error(m);
}
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(
2020-08-30 11:54:41 +02:00
std::ostream& fout, const std::string& name, const std::string& location,
2021-11-20 13:41:27 +01:00
cmValue typeGuid, const std::set<BT<std::pair<std::string, bool>>>& depends)
2013-03-16 19:13:01 +02:00
{
2012-06-27 20:52:58 +03:00
fout << "Project(\"{"
2023-05-23 16:38:00 +02:00
<< (typeGuid ? *typeGuid
: std::string(
cmGlobalVisualStudio71Generator::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";
2020-08-30 11:54:41 +02:00
for (BT<std::pair<std::string, bool>> const& it : depends) {
std::string const& dep = it.Value.first;
2022-08-04 22:12:04 +02:00
if (this->IsDepInSolution(dep)) {
2019-11-11 23:01:05 +01:00
fout << "\t\t{" << this->GetGUID(dep) << "} = {" << this->GetGUID(dep)
2018-04-23 21:13:27 +02:00
<< "}\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);
2018-04-23 21:13:27 +02:00
for (std::string const& i : configs) {
2023-07-02 19:51:09 +02:00
cmList mapConfig;
2018-04-23 21:13:27 +02:00
const char* dstConfig = i.c_str();
2017-09-21 19:03:52 +02:00
if (target.GetProperty("EXTERNAL_MSPROJECT")) {
2021-11-20 13:41:27 +01:00
if (cmValue m = target.GetProperty("MAP_IMPORTED_CONFIG_" +
cmSystemTools::UpperCase(i))) {
2023-07-02 19:51:09 +02:00
mapConfig.assign(*m);
2017-09-21 19:03:52 +02:00
if (!mapConfig.empty()) {
dstConfig = mapConfig[0].c_str();
}
}
2017-07-20 19:35:53 +02:00
}
2018-04-23 21:13:27 +02:00
fout << "\t\t{" << guid << "}." << i << ".ActiveCfg = " << dstConfig << "|"
<< platformName << std::endl;
2023-05-23 16:38:00 +02:00
auto ci = configsPartOfDefaultBuild.find(i);
2016-07-09 11:21:54 +02:00
if (!(ci == configsPartOfDefaultBuild.end())) {
2018-04-23 21:13:27 +02:00
fout << "\t\t{" << guid << "}." << i << ".Build.0 = " << dstConfig << "|"
<< platformName << std::endl;
}
2016-07-09 11:21:54 +02:00
}
}