2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2004-07-05 20:16:33 +04:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2004-07-05 20:16:33 +04:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2004-07-05 20:16:33 +04:00
|
|
|
#include "windows.h" // this must be first to define GetCurrentDirectory
|
|
|
|
#include "cmGlobalVisualStudio8Generator.h"
|
|
|
|
#include "cmLocalVisualStudio7Generator.h"
|
|
|
|
#include "cmMakefile.h"
|
|
|
|
#include "cmake.h"
|
2008-03-12 00:25:49 +03:00
|
|
|
#include "cmGeneratedFileStream.h"
|
2004-07-05 20:16:33 +04:00
|
|
|
|
2008-02-15 19:49:58 +03:00
|
|
|
//----------------------------------------------------------------------------
|
2004-07-05 20:16:33 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-02-15 19:49:58 +03:00
|
|
|
//----------------------------------------------------------------------------
|
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();
|
2007-03-12 19:35:11 +03:00
|
|
|
lg->SetExtraFlagTable(this->GetExtraFlagTableVS8());
|
2004-07-05 20:16:33 +04:00
|
|
|
lg->SetGlobalGenerator(this);
|
|
|
|
return lg;
|
|
|
|
}
|
|
|
|
|
2008-02-15 19:49:58 +03:00
|
|
|
//----------------------------------------------------------------------------
|
2004-07-05 20:16:33 +04:00
|
|
|
// 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
|
|
|
{
|
2007-10-22 20:49:09 +04:00
|
|
|
entry.Name = this->GetName();
|
|
|
|
entry.Brief = "Generates Visual Studio .NET 2005 project files.";
|
|
|
|
entry.Full = "";
|
2004-07-05 20:16:33 +04:00
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
|
2007-11-16 15:01:58 +03:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
std::string cmGlobalVisualStudio8Generator::GetUserMacrosDirectory()
|
|
|
|
{
|
2008-01-02 23:53:28 +03:00
|
|
|
// Some VS8 sp0 versions cannot run macros.
|
|
|
|
// See http://support.microsoft.com/kb/928209
|
|
|
|
const char* vc8sp1Registry =
|
2008-01-02 23:55:18 +03:00
|
|
|
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0\\"
|
|
|
|
"InstalledProducts\\KB926601;";
|
2008-01-02 23:53:28 +03:00
|
|
|
const char* vc8exSP1Registry =
|
2008-01-02 23:55:18 +03:00
|
|
|
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0\\"
|
|
|
|
"InstalledProducts\\KB926748;";
|
2008-01-02 23:53:28 +03:00
|
|
|
std::string vc8sp1;
|
|
|
|
if (!cmSystemTools::ReadRegistryValue(vc8sp1Registry, vc8sp1) &&
|
|
|
|
!cmSystemTools::ReadRegistryValue(vc8exSP1Registry, vc8sp1))
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2007-11-16 15:01:58 +03:00
|
|
|
std::string base;
|
|
|
|
std::string path;
|
|
|
|
|
|
|
|
// base begins with the VisualStudioProjectsLocation reg value...
|
|
|
|
if (cmSystemTools::ReadRegistryValue(
|
2007-11-20 19:10:11 +03:00
|
|
|
"HKEY_CURRENT_USER\\Software\\Microsoft\\VisualStudio\\8.0;"
|
|
|
|
"VisualStudioProjectsLocation",
|
2007-11-16 15:01:58 +03:00
|
|
|
base))
|
|
|
|
{
|
|
|
|
cmSystemTools::ConvertToUnixSlashes(base);
|
|
|
|
|
|
|
|
// 8.0 macros folder:
|
|
|
|
path = base + "/VSMacros80";
|
|
|
|
}
|
|
|
|
|
|
|
|
// path is (correctly) still empty if we did not read the base value from
|
|
|
|
// the Registry value
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2008-02-15 19:49:58 +03:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
std::string cmGlobalVisualStudio8Generator::GetUserMacrosRegKeyBase()
|
|
|
|
{
|
|
|
|
return "Software\\Microsoft\\VisualStudio\\8.0\\vsmacros";
|
|
|
|
}
|
|
|
|
|
2005-12-13 22:21:28 +03:00
|
|
|
//----------------------------------------------------------------------------
|
2009-10-19 18:47:34 +04:00
|
|
|
void cmGlobalVisualStudio8Generator::AddCheckTarget()
|
2005-12-13 22:21:28 +03:00
|
|
|
{
|
|
|
|
// 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;
|
2009-10-19 18:47:34 +04:00
|
|
|
std::vector<cmLocalGenerator*> const& generators = this->LocalGenerators;
|
|
|
|
cmLocalVisualStudio7Generator* lg =
|
|
|
|
static_cast<cmLocalVisualStudio7Generator*>(generators[0]);
|
|
|
|
cmMakefile* mf = lg->GetMakefile();
|
|
|
|
|
|
|
|
// Skip the target if no regeneration is to be done.
|
|
|
|
if(mf->IsOn("CMAKE_SUPPRESS_REGENERATION"))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string cmake_command = mf->GetRequiredDefinition("CMAKE_COMMAND");
|
|
|
|
cmCustomCommandLines noCommandLines;
|
|
|
|
cmTarget* tgt =
|
|
|
|
mf->AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET, false,
|
|
|
|
no_working_directory, no_depends,
|
|
|
|
noCommandLines);
|
|
|
|
|
|
|
|
// Create a list of all stamp files for this project.
|
|
|
|
std::vector<std::string> stamps;
|
|
|
|
std::string stampList = cmake::GetCMakeFilesDirectoryPostSlash();
|
|
|
|
stampList += "generate.stamp.list";
|
|
|
|
{
|
|
|
|
std::string stampListFile =
|
|
|
|
generators[0]->GetMakefile()->GetCurrentOutputDirectory();
|
|
|
|
stampListFile += "/";
|
|
|
|
stampListFile += stampList;
|
|
|
|
std::string stampFile;
|
|
|
|
cmGeneratedFileStream fout(stampListFile.c_str());
|
|
|
|
for(std::vector<cmLocalGenerator*>::const_iterator
|
|
|
|
gi = generators.begin(); gi != generators.end(); ++gi)
|
2005-12-13 22:21:28 +03:00
|
|
|
{
|
2009-10-19 18:47:34 +04:00
|
|
|
stampFile = (*gi)->GetMakefile()->GetCurrentOutputDirectory();
|
|
|
|
stampFile += "/";
|
|
|
|
stampFile += cmake::GetCMakeFilesDirectoryPostSlash();
|
|
|
|
stampFile += "generate.stamp";
|
|
|
|
stampFile = generators[0]->Convert(stampFile.c_str(),
|
|
|
|
cmLocalGenerator::START_OUTPUT);
|
|
|
|
fout << stampFile << "\n";
|
|
|
|
stamps.push_back(stampFile);
|
2005-12-13 22:21:28 +03:00
|
|
|
}
|
2009-10-19 18:47:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add a custom rule to re-run CMake if any input files changed.
|
|
|
|
{
|
|
|
|
// 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.
|
|
|
|
std::sort(listFiles.begin(), listFiles.end(),
|
|
|
|
std::less<std::string>());
|
|
|
|
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.
|
|
|
|
std::string stampName = cmake::GetCMakeFilesDirectoryPostSlash();
|
|
|
|
stampName += "generate.stamp";
|
|
|
|
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,
|
|
|
|
cmLocalGenerator::UNCHANGED, true);
|
|
|
|
commandLine.push_back(argH);
|
|
|
|
std::string argB = "-B";
|
|
|
|
argB += lg->Convert(mf->GetHomeOutputDirectory(),
|
|
|
|
cmLocalGenerator::START_OUTPUT,
|
|
|
|
cmLocalGenerator::UNCHANGED, true);
|
|
|
|
commandLine.push_back(argB);
|
|
|
|
commandLine.push_back("--check-stamp-list");
|
|
|
|
commandLine.push_back(stampList.c_str());
|
|
|
|
commandLine.push_back("--vs-solution-file");
|
|
|
|
commandLine.push_back("\"$(SolutionPath)\"");
|
|
|
|
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 CreateVCProjBuildRule.
|
|
|
|
// (this could be avoided with per-target source files)
|
|
|
|
const char* no_main_dependency = 0;
|
|
|
|
const char* no_working_directory = 0;
|
|
|
|
mf->AddCustomCommandToOutput(
|
|
|
|
stamps, listFiles,
|
|
|
|
no_main_dependency, commandLines, "Checking Build System",
|
|
|
|
no_working_directory, true);
|
|
|
|
std::string ruleName = stamps[0];
|
|
|
|
ruleName += ".rule";
|
|
|
|
if(cmSourceFile* file = mf->GetSource(ruleName.c_str()))
|
|
|
|
{
|
|
|
|
tgt->AddSourceFile(file);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cmSystemTools::Error("Error adding rule for ", stamps[0].c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmGlobalVisualStudio8Generator::Generate()
|
|
|
|
{
|
|
|
|
this->AddCheckTarget();
|
2005-12-13 22:21:28 +03:00
|
|
|
|
2009-09-04 20:37:53 +04:00
|
|
|
// All targets depend on the build-system check target.
|
|
|
|
for(std::map<cmStdString,cmTarget *>::const_iterator
|
|
|
|
ti = this->TotalTargets.begin();
|
|
|
|
ti != this->TotalTargets.end(); ++ti)
|
2005-12-13 22:21:28 +03:00
|
|
|
{
|
2009-09-04 20:37:53 +04:00
|
|
|
if(ti->first != CMAKE_CHECK_BUILD_SYSTEM_TARGET)
|
2005-12-13 22:21:28 +03:00
|
|
|
{
|
2009-09-04 20:37:53 +04:00
|
|
|
ti->second->AddUtility(CMAKE_CHECK_BUILD_SYSTEM_TARGET);
|
2005-12-13 22:21:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-04 20:37:53 +04:00
|
|
|
// Now perform the main generation.
|
|
|
|
this->cmGlobalVisualStudio7Generator::Generate();
|
2006-02-14 23:35:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
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
|
|
|
}
|
2007-03-12 19:35:11 +03:00
|
|
|
|
2009-10-21 00:38:37 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmGlobalVisualStudio8Generator::NeedLinkLibraryDependencies(
|
|
|
|
cmTarget& target)
|
|
|
|
{
|
|
|
|
// Look for utility dependencies that magically link.
|
|
|
|
for(std::set<cmStdString>::const_iterator ui =
|
|
|
|
target.GetUtilities().begin();
|
|
|
|
ui != target.GetUtilities().end(); ++ui)
|
|
|
|
{
|
|
|
|
if(cmTarget* depTarget = this->FindTarget(0, ui->c_str()))
|
|
|
|
{
|
|
|
|
if(depTarget->GetProperty("EXTERNAL_MSPROJECT"))
|
|
|
|
{
|
|
|
|
// This utility dependency names an external .vcproj target.
|
|
|
|
// We use LinkLibraryDependencies="true" to link to it without
|
|
|
|
// predicting the .lib file location or name.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-03-12 19:35:11 +03:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
static cmVS7FlagTable cmVS8ExtraFlagTable[] =
|
2007-12-18 01:28:23 +03:00
|
|
|
{
|
|
|
|
{"CallingConvention", "Gd", "cdecl", "0", 0 },
|
|
|
|
{"CallingConvention", "Gr", "fastcall", "1", 0 },
|
|
|
|
{"CallingConvention", "Gz", "stdcall", "2", 0 },
|
|
|
|
|
2007-12-18 16:53:10 +03:00
|
|
|
{"Detect64BitPortabilityProblems", "Wp64",
|
|
|
|
"Detect 64Bit Portability Problems", "true", 0 },
|
2007-12-18 01:28:23 +03:00
|
|
|
{"ErrorReporting", "errorReport:prompt", "Report immediately", "1", 0 },
|
|
|
|
{"ErrorReporting", "errorReport:queue", "Queue for next login", "2", 0 },
|
2007-03-12 19:35:11 +03:00
|
|
|
// Precompiled header and related options. Note that the
|
|
|
|
// UsePrecompiledHeader entries are marked as "Continue" so that the
|
|
|
|
// corresponding PrecompiledHeaderThrough entry can be found.
|
|
|
|
{"UsePrecompiledHeader", "Yu", "Use Precompiled Header", "2",
|
|
|
|
cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
|
|
|
|
{"PrecompiledHeaderThrough", "Yu", "Precompiled Header Name", "",
|
|
|
|
cmVS7FlagTable::UserValueRequired},
|
|
|
|
// There is no YX option in the VS8 IDE.
|
2007-11-16 19:01:23 +03:00
|
|
|
|
|
|
|
// Exception handling mode. If no entries match, it will be FALSE.
|
|
|
|
{"ExceptionHandling", "GX", "enable c++ exceptions", "1", 0},
|
|
|
|
{"ExceptionHandling", "EHsc", "enable c++ exceptions", "1", 0},
|
|
|
|
{"ExceptionHandling", "EHa", "enable SEH exceptions", "2", 0},
|
|
|
|
|
2007-03-12 19:35:11 +03:00
|
|
|
{0,0,0,0,0}
|
|
|
|
};
|
2009-07-29 19:28:55 +04:00
|
|
|
cmIDEFlagTable const* cmGlobalVisualStudio8Generator::GetExtraFlagTableVS8()
|
2007-03-12 19:35:11 +03:00
|
|
|
{
|
|
|
|
return cmVS8ExtraFlagTable;
|
|
|
|
}
|