2004-07-05 20:16:33 +04:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
Program: CMake - Cross-Platform Makefile Generator
|
|
|
|
Module: $RCSfile$
|
|
|
|
Language: C++
|
|
|
|
Date: $Date$
|
|
|
|
Version: $Revision$
|
|
|
|
|
|
|
|
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
|
|
|
|
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
|
|
|
|
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
PURPOSE. See the above copyright notices for more information.
|
|
|
|
|
|
|
|
=========================================================================*/
|
|
|
|
#include "windows.h" // this must be first to define GetCurrentDirectory
|
|
|
|
#include "cmGlobalVisualStudio8Generator.h"
|
|
|
|
#include "cmLocalVisualStudio7Generator.h"
|
|
|
|
#include "cmMakefile.h"
|
|
|
|
#include "cmake.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cmGlobalVisualStudio8Generator::cmGlobalVisualStudio8Generator()
|
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
this->FindMakeProgramFile = "CMakeVS8FindMake.cmake";
|
|
|
|
this->ProjectConfigurationSectionName = "ProjectConfigurationPlatforms";
|
2006-03-30 22:49:56 +04:00
|
|
|
this->PlatformName = "Win32";
|
2004-07-05 20:16:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///! Create a local generator appropriate to this Global Generator
|
|
|
|
cmLocalGenerator *cmGlobalVisualStudio8Generator::CreateLocalGenerator()
|
|
|
|
{
|
|
|
|
cmLocalVisualStudio7Generator *lg = new cmLocalVisualStudio7Generator;
|
|
|
|
lg->SetVersion8();
|
|
|
|
lg->SetGlobalGenerator(this);
|
|
|
|
return lg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ouput standard header for dsw file
|
|
|
|
void cmGlobalVisualStudio8Generator::WriteSLNHeader(std::ostream& fout)
|
|
|
|
{
|
|
|
|
fout << "Microsoft Visual Studio Solution File, Format Version 9.00\n";
|
2005-11-22 21:37:42 +03:00
|
|
|
fout << "# Visual Studio 2005\n";
|
2004-07-05 20:16:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2006-05-11 19:47:03 +04:00
|
|
|
void cmGlobalVisualStudio8Generator
|
|
|
|
::GetDocumentation(cmDocumentationEntry& entry) const
|
2004-07-05 20:16:33 +04:00
|
|
|
{
|
|
|
|
entry.name = this->GetName();
|
|
|
|
entry.brief = "Generates Visual Studio .NET 2005 project files.";
|
|
|
|
entry.full = "";
|
|
|
|
}
|
2005-12-13 22:21:28 +03:00
|
|
|
|
2006-05-06 04:54:53 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmGlobalVisualStudio8Generator::AddPlatformDefinitions(cmMakefile* mf)
|
|
|
|
{
|
|
|
|
mf->AddDefinition("MSVC80", "1");
|
|
|
|
}
|
|
|
|
|
2005-12-13 22:21:28 +03:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmGlobalVisualStudio8Generator::Configure()
|
|
|
|
{
|
|
|
|
this->cmGlobalVisualStudio7Generator::Configure();
|
|
|
|
this->CreateGUID(CMAKE_CHECK_BUILD_SYSTEM_TARGET);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmGlobalVisualStudio8Generator::Generate()
|
|
|
|
{
|
|
|
|
// Add a special target on which all other targets depend that
|
|
|
|
// checks the build system and optionally re-runs CMake.
|
2006-02-08 18:58:36 +03:00
|
|
|
const char* no_working_directory = 0;
|
2005-12-13 22:21:28 +03:00
|
|
|
std::vector<std::string> no_depends;
|
|
|
|
std::map<cmStdString, std::vector<cmLocalGenerator*> >::iterator it;
|
2006-03-15 19:02:08 +03:00
|
|
|
for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it)
|
2005-12-13 22:21:28 +03:00
|
|
|
{
|
|
|
|
std::vector<cmLocalGenerator*>& generators = it->second;
|
|
|
|
if(!generators.empty())
|
|
|
|
{
|
|
|
|
// Add the build-system check target to the first local
|
|
|
|
// generator of this project.
|
|
|
|
cmLocalVisualStudio7Generator* lg =
|
|
|
|
static_cast<cmLocalVisualStudio7Generator*>(generators[0]);
|
|
|
|
cmMakefile* mf = lg->GetMakefile();
|
|
|
|
std::string cmake_command = mf->GetRequiredDefinition("CMAKE_COMMAND");
|
2006-09-28 21:55:26 +04:00
|
|
|
cmCustomCommandLines noCommandLines;
|
2005-12-13 22:21:28 +03:00
|
|
|
mf->AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET, true,
|
2006-09-28 21:55:26 +04:00
|
|
|
no_working_directory, no_depends,
|
|
|
|
noCommandLines);
|
2006-02-15 00:32:20 +03:00
|
|
|
cmTarget* tgt = mf->FindTarget(CMAKE_CHECK_BUILD_SYSTEM_TARGET);
|
|
|
|
if(!tgt)
|
|
|
|
{
|
2006-05-11 19:47:03 +04:00
|
|
|
cmSystemTools::Error("Error adding target "
|
|
|
|
CMAKE_CHECK_BUILD_SYSTEM_TARGET);
|
2006-02-15 00:32:20 +03:00
|
|
|
continue;
|
|
|
|
}
|
2005-12-13 22:21:28 +03:00
|
|
|
|
|
|
|
// Add a custom rule to re-run CMake if any input files changed.
|
|
|
|
const char* suppRegenRule =
|
|
|
|
mf->GetDefinition("CMAKE_SUPPRESS_REGENERATION");
|
|
|
|
if(!cmSystemTools::IsOn(suppRegenRule))
|
|
|
|
{
|
|
|
|
// Collect the input files used to generate all targets in this
|
|
|
|
// project.
|
|
|
|
std::vector<std::string> listFiles;
|
|
|
|
for(unsigned int j = 0; j < generators.size(); ++j)
|
|
|
|
{
|
|
|
|
cmMakefile* lmf = generators[j]->GetMakefile();
|
|
|
|
listFiles.insert(listFiles.end(), lmf->GetListFiles().begin(),
|
|
|
|
lmf->GetListFiles().end());
|
|
|
|
}
|
|
|
|
// Sort the list of input files and remove duplicates.
|
2006-05-11 19:47:03 +04:00
|
|
|
std::sort(listFiles.begin(), listFiles.end(),
|
|
|
|
std::less<std::string>());
|
2005-12-13 22:21:28 +03:00
|
|
|
std::vector<std::string>::iterator new_end =
|
|
|
|
std::unique(listFiles.begin(), listFiles.end());
|
|
|
|
listFiles.erase(new_end, listFiles.end());
|
|
|
|
|
|
|
|
// Create a rule to re-run CMake.
|
|
|
|
const char* dsprule = mf->GetRequiredDefinition("CMAKE_COMMAND");
|
|
|
|
cmCustomCommandLine commandLine;
|
|
|
|
commandLine.push_back(dsprule);
|
|
|
|
std::string argH = "-H";
|
|
|
|
argH += lg->Convert(mf->GetHomeDirectory(),
|
|
|
|
cmLocalGenerator::START_OUTPUT,
|
2006-09-21 23:14:06 +04:00
|
|
|
cmLocalGenerator::UNCHANGED, true);
|
2005-12-13 22:21:28 +03:00
|
|
|
commandLine.push_back(argH);
|
|
|
|
std::string argB = "-B";
|
|
|
|
argB += lg->Convert(mf->GetHomeOutputDirectory(),
|
|
|
|
cmLocalGenerator::START_OUTPUT,
|
2006-09-21 23:14:06 +04:00
|
|
|
cmLocalGenerator::UNCHANGED, true);
|
2005-12-13 22:21:28 +03:00
|
|
|
commandLine.push_back(argB);
|
|
|
|
cmCustomCommandLines commandLines;
|
|
|
|
commandLines.push_back(commandLine);
|
|
|
|
|
|
|
|
// Add the rule. Note that we cannot use the CMakeLists.txt
|
|
|
|
// file as the main dependency because it would get
|
|
|
|
// overwritten by the AddVCProjBuildRule of the ALL_BUILD
|
|
|
|
// target.
|
|
|
|
const char* no_main_dependency = 0;
|
2006-02-08 18:58:36 +03:00
|
|
|
const char* no_working_directory = 0;
|
2005-12-13 22:21:28 +03:00
|
|
|
mf->AddCustomCommandToOutput(
|
|
|
|
CMAKE_CHECK_BUILD_SYSTEM_TARGET ".vcproj.cmake", listFiles,
|
2006-04-11 19:06:19 +04:00
|
|
|
no_main_dependency, commandLines, "Checking Build System",
|
|
|
|
no_working_directory, true);
|
2006-05-11 19:47:03 +04:00
|
|
|
if(cmSourceFile* file = mf->GetSource(CMAKE_CHECK_BUILD_SYSTEM_TARGET
|
|
|
|
".vcproj.cmake.rule"))
|
2006-02-15 00:32:20 +03:00
|
|
|
{
|
|
|
|
tgt->GetSourceFiles().push_back(file);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-05-11 19:47:03 +04:00
|
|
|
cmSystemTools::Error("Error adding rule for "
|
|
|
|
CMAKE_CHECK_BUILD_SYSTEM_TARGET
|
|
|
|
".vcproj.cmake");
|
2006-02-15 00:32:20 +03:00
|
|
|
}
|
2005-12-13 22:21:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now perform the main generation.
|
|
|
|
this->cmGlobalVisualStudio7Generator::Generate();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmGlobalVisualStudio8Generator::WriteSLNFile(
|
|
|
|
std::ostream& fout, cmLocalGenerator* root,
|
|
|
|
std::vector<cmLocalGenerator*>& generators)
|
|
|
|
{
|
|
|
|
// Make all targets depend on their respective project's build
|
|
|
|
// system check target.
|
|
|
|
unsigned int i;
|
|
|
|
for(i = 0; i < generators.size(); ++i)
|
|
|
|
{
|
|
|
|
if(this->IsExcluded(root, generators[i]))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
cmMakefile* mf = generators[i]->GetMakefile();
|
|
|
|
std::vector<std::string> dspnames =
|
|
|
|
static_cast<cmLocalVisualStudio7Generator*>(generators[i])
|
|
|
|
->GetCreatedProjectNames();
|
2005-12-14 02:23:37 +03:00
|
|
|
cmTargets& tgts = mf->GetTargets();
|
2005-12-13 22:21:28 +03:00
|
|
|
for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
|
|
|
|
{
|
|
|
|
if(l->first == CMAKE_CHECK_BUILD_SYSTEM_TARGET)
|
|
|
|
{
|
|
|
|
for(unsigned int j = 0; j < generators.size(); ++j)
|
|
|
|
{
|
|
|
|
// Every target in all generators should depend on this target.
|
|
|
|
cmMakefile* lmf = generators[j]->GetMakefile();
|
|
|
|
cmTargets &atgts = lmf->GetTargets();
|
|
|
|
for(cmTargets::iterator al = atgts.begin(); al != atgts.end(); ++al)
|
|
|
|
{
|
|
|
|
al->second.AddUtility(l->first.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now write the solution file.
|
2006-02-14 23:35:34 +03:00
|
|
|
this->cmGlobalVisualStudio71Generator::WriteSLNFile(fout, root, generators);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
cmGlobalVisualStudio8Generator
|
|
|
|
::WriteSolutionConfigurations(std::ostream& fout)
|
|
|
|
{
|
|
|
|
fout << "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n";
|
2006-03-15 19:02:08 +03:00
|
|
|
for(std::vector<std::string>::iterator i = this->Configurations.begin();
|
|
|
|
i != this->Configurations.end(); ++i)
|
2006-02-14 23:35:34 +03:00
|
|
|
{
|
2006-03-30 22:49:56 +04:00
|
|
|
fout << "\t\t" << *i << "|" << this->PlatformName << " = " << *i << "|"
|
|
|
|
<< this->PlatformName << "\n";
|
2006-02-14 23:35:34 +03:00
|
|
|
}
|
|
|
|
fout << "\tEndGlobalSection\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
cmGlobalVisualStudio8Generator
|
2006-09-29 00:40:35 +04:00
|
|
|
::WriteProjectConfigurations(std::ostream& fout, const char* name,
|
2006-11-09 17:57:23 +03:00
|
|
|
bool partOfDefaultBuild)
|
2006-02-14 23:35:34 +03:00
|
|
|
{
|
|
|
|
std::string guid = this->GetGUID(name);
|
2006-03-15 19:02:08 +03:00
|
|
|
for(std::vector<std::string>::iterator i = this->Configurations.begin();
|
|
|
|
i != this->Configurations.end(); ++i)
|
2006-02-14 23:35:34 +03:00
|
|
|
{
|
2006-09-29 00:40:35 +04:00
|
|
|
fout << "\t\t{" << guid << "}." << *i
|
|
|
|
<< "|" << this->PlatformName << ".ActiveCfg = "
|
2006-05-11 19:47:03 +04:00
|
|
|
<< *i << "|" << this->PlatformName << "\n";
|
2006-11-09 17:57:23 +03:00
|
|
|
if(partOfDefaultBuild)
|
2006-02-14 23:35:34 +03:00
|
|
|
{
|
2006-09-29 00:40:35 +04:00
|
|
|
fout << "\t\t{" << guid << "}." << *i
|
|
|
|
<< "|" << this->PlatformName << ".Build.0 = "
|
2006-05-11 19:47:03 +04:00
|
|
|
<< *i << "|" << this->PlatformName << "\n";
|
2006-02-14 23:35:34 +03:00
|
|
|
}
|
|
|
|
}
|
2005-12-13 22:21:28 +03:00
|
|
|
}
|