2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2006-07-11 19:41:38 +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.
|
2006-07-11 19:41:38 +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.
|
|
|
|
============================================================================*/
|
2006-07-11 19:41:38 +04:00
|
|
|
#include "cmLocalVisualStudioGenerator.h"
|
2007-02-17 00:12:17 +03:00
|
|
|
#include "cmGlobalGenerator.h"
|
2006-07-11 19:41:38 +04:00
|
|
|
#include "cmMakefile.h"
|
|
|
|
#include "cmSourceFile.h"
|
|
|
|
#include "cmSystemTools.h"
|
2008-01-15 19:56:41 +03:00
|
|
|
#include "windows.h"
|
2006-07-11 19:41:38 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
cmLocalVisualStudioGenerator::cmLocalVisualStudioGenerator()
|
|
|
|
{
|
2006-09-21 23:14:06 +04:00
|
|
|
this->WindowsShell = true;
|
2006-09-27 21:43:46 +04:00
|
|
|
this->WindowsVSIDE = true;
|
2006-07-11 19:41:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
cmLocalVisualStudioGenerator::~cmLocalVisualStudioGenerator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-06-16 19:44:07 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
cmsys::auto_ptr<cmCustomCommand>
|
|
|
|
cmLocalVisualStudioGenerator::MaybeCreateImplibDir(cmTarget& target,
|
|
|
|
const char* config)
|
|
|
|
{
|
|
|
|
cmsys::auto_ptr<cmCustomCommand> pcc;
|
|
|
|
|
|
|
|
// If an executable exports symbols then VS wants to create an
|
|
|
|
// import library but forgets to create the output directory.
|
|
|
|
if(target.GetType() != cmTarget::EXECUTABLE) { return pcc; }
|
|
|
|
std::string outDir = target.GetDirectory(config, false);
|
|
|
|
std::string impDir = target.GetDirectory(config, true);
|
|
|
|
if(impDir == outDir) { return pcc; }
|
|
|
|
|
|
|
|
// Add a pre-build event to create the directory.
|
|
|
|
cmCustomCommandLine command;
|
|
|
|
command.push_back(this->Makefile->GetRequiredDefinition("CMAKE_COMMAND"));
|
|
|
|
command.push_back("-E");
|
|
|
|
command.push_back("make_directory");
|
|
|
|
command.push_back(impDir);
|
|
|
|
std::vector<std::string> no_output;
|
|
|
|
std::vector<std::string> no_depends;
|
|
|
|
cmCustomCommandLines commands;
|
|
|
|
commands.push_back(command);
|
|
|
|
pcc.reset(new cmCustomCommand(no_output, no_depends, commands, 0, 0));
|
|
|
|
pcc->SetEscapeOldStyle(false);
|
|
|
|
pcc->SetEscapeAllowMakeVars(true);
|
|
|
|
return pcc;
|
|
|
|
}
|
|
|
|
|
2006-08-01 18:48:40 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmLocalVisualStudioGenerator::SourceFileCompiles(const cmSourceFile* sf)
|
|
|
|
{
|
2006-08-03 17:26:36 +04:00
|
|
|
// Identify the language of the source file.
|
|
|
|
if(const char* lang = this->GetSourceFileLanguage(*sf))
|
|
|
|
{
|
|
|
|
// Check whether this source will actually be compiled.
|
|
|
|
return (!sf->GetCustomCommand() &&
|
|
|
|
!sf->GetPropertyAsBool("HEADER_FILE_ONLY") &&
|
|
|
|
!sf->GetPropertyAsBool("EXTERNAL_OBJECT"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Unknown source file language. Assume it will not be compiled.
|
|
|
|
return false;
|
|
|
|
}
|
2006-08-01 18:48:40 +04:00
|
|
|
}
|
|
|
|
|
2006-07-11 19:41:38 +04:00
|
|
|
//----------------------------------------------------------------------------
|
2007-08-28 01:05:43 +04:00
|
|
|
void cmLocalVisualStudioGenerator::CountObjectNames(
|
|
|
|
const std::vector<cmSourceGroup>& groups,
|
|
|
|
std::map<cmStdString, int>& counts)
|
2006-07-11 19:41:38 +04:00
|
|
|
{
|
2007-08-28 01:05:43 +04:00
|
|
|
for(unsigned int i = 0; i < groups.size(); ++i)
|
2006-07-11 19:41:38 +04:00
|
|
|
{
|
2007-08-28 01:05:43 +04:00
|
|
|
cmSourceGroup sg = groups[i];
|
2006-07-11 19:41:38 +04:00
|
|
|
std::vector<const cmSourceFile*> const& srcs = sg.GetSourceFiles();
|
|
|
|
for(std::vector<const cmSourceFile*>::const_iterator s = srcs.begin();
|
|
|
|
s != srcs.end(); ++s)
|
|
|
|
{
|
2006-08-01 18:48:40 +04:00
|
|
|
const cmSourceFile* sf = *s;
|
|
|
|
if(this->SourceFileCompiles(sf))
|
2006-07-11 19:41:38 +04:00
|
|
|
{
|
2007-08-28 01:05:43 +04:00
|
|
|
std::string objectName = cmSystemTools::LowerCase(
|
2006-08-08 19:26:59 +04:00
|
|
|
cmSystemTools::GetFilenameWithoutLastExtension(
|
2007-06-18 19:59:23 +04:00
|
|
|
sf->GetFullPath()));
|
2006-07-11 19:41:38 +04:00
|
|
|
objectName += ".obj";
|
2007-08-28 01:05:43 +04:00
|
|
|
counts[objectName] += 1;
|
2006-07-11 19:41:38 +04:00
|
|
|
}
|
|
|
|
}
|
2007-08-28 01:05:43 +04:00
|
|
|
this->CountObjectNames(sg.GetGroupChildren(), counts);
|
2006-07-11 19:41:38 +04:00
|
|
|
}
|
2007-08-28 01:05:43 +04:00
|
|
|
}
|
2006-07-11 19:41:38 +04:00
|
|
|
|
2007-08-28 01:05:43 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmLocalVisualStudioGenerator::InsertNeedObjectNames(
|
|
|
|
const std::vector<cmSourceGroup>& groups,
|
|
|
|
std::map<cmStdString, int>& count)
|
|
|
|
{
|
|
|
|
for(unsigned int i = 0; i < groups.size(); ++i)
|
2006-07-11 19:41:38 +04:00
|
|
|
{
|
2007-08-28 01:05:43 +04:00
|
|
|
cmSourceGroup sg = groups[i];
|
2006-07-11 19:41:38 +04:00
|
|
|
std::vector<const cmSourceFile*> const& srcs = sg.GetSourceFiles();
|
|
|
|
for(std::vector<const cmSourceFile*>::const_iterator s = srcs.begin();
|
|
|
|
s != srcs.end(); ++s)
|
|
|
|
{
|
|
|
|
const cmSourceFile* sf = *s;
|
2006-08-01 18:48:40 +04:00
|
|
|
if(this->SourceFileCompiles(sf))
|
2006-07-11 19:41:38 +04:00
|
|
|
{
|
2007-08-28 01:05:43 +04:00
|
|
|
std::string objectName = cmSystemTools::LowerCase(
|
|
|
|
cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath()));
|
2006-07-11 19:41:38 +04:00
|
|
|
objectName += ".obj";
|
2007-08-28 01:05:43 +04:00
|
|
|
if(count[objectName] > 1)
|
2006-07-11 19:41:38 +04:00
|
|
|
{
|
|
|
|
this->NeedObjectName.insert(sf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-08-28 01:05:43 +04:00
|
|
|
this->InsertNeedObjectNames(sg.GetGroupChildren(), count);
|
2006-07-11 19:41:38 +04:00
|
|
|
}
|
|
|
|
}
|
2006-09-21 23:14:06 +04:00
|
|
|
|
2007-08-28 01:05:43 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmLocalVisualStudioGenerator::ComputeObjectNameRequirements
|
|
|
|
(std::vector<cmSourceGroup> const& sourceGroups)
|
|
|
|
{
|
|
|
|
// Clear the current set of requirements.
|
|
|
|
this->NeedObjectName.clear();
|
|
|
|
|
|
|
|
// Count the number of object files with each name. Note that
|
|
|
|
// windows file names are not case sensitive.
|
|
|
|
std::map<cmStdString, int> objectNameCounts;
|
|
|
|
this->CountObjectNames(sourceGroups, objectNameCounts);
|
|
|
|
|
|
|
|
// For all source files producing duplicate names we need unique
|
|
|
|
// object name computation.
|
|
|
|
this->InsertNeedObjectNames(sourceGroups, objectNameCounts);
|
|
|
|
}
|
|
|
|
|
2006-09-21 23:14:06 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
std::string
|
|
|
|
cmLocalVisualStudioGenerator
|
|
|
|
::ConstructScript(const cmCustomCommandLines& commandLines,
|
|
|
|
const char* workingDirectory,
|
2007-05-09 16:25:45 +04:00
|
|
|
const char* configName,
|
2006-09-27 21:43:46 +04:00
|
|
|
bool escapeOldStyle,
|
|
|
|
bool escapeAllowMakeVars,
|
2006-10-25 20:27:17 +04:00
|
|
|
const char* newline_text)
|
2006-09-21 23:14:06 +04:00
|
|
|
{
|
2006-10-25 20:27:17 +04:00
|
|
|
// Avoid leading or trailing newlines.
|
|
|
|
const char* newline = "";
|
|
|
|
|
2006-09-21 23:14:06 +04:00
|
|
|
// Store the script in a string.
|
|
|
|
std::string script;
|
|
|
|
if(workingDirectory)
|
|
|
|
{
|
2007-12-18 02:38:19 +03:00
|
|
|
// Change the working directory.
|
2006-10-25 20:27:17 +04:00
|
|
|
script += newline;
|
|
|
|
newline = newline_text;
|
2006-09-21 23:14:06 +04:00
|
|
|
script += "cd ";
|
|
|
|
script += this->Convert(workingDirectory, START_OUTPUT, SHELL);
|
2007-12-18 02:38:19 +03:00
|
|
|
|
|
|
|
// Change the working drive.
|
|
|
|
if(workingDirectory[0] && workingDirectory[1] == ':')
|
|
|
|
{
|
|
|
|
script += newline;
|
|
|
|
newline = newline_text;
|
|
|
|
script += workingDirectory[0];
|
|
|
|
script += workingDirectory[1];
|
|
|
|
}
|
2006-09-21 23:14:06 +04:00
|
|
|
}
|
|
|
|
// for visual studio IDE add extra stuff to the PATH
|
|
|
|
// if CMAKE_MSVCIDE_RUN_PATH is set.
|
|
|
|
if(this->Makefile->GetDefinition("MSVC_IDE"))
|
|
|
|
{
|
|
|
|
const char* extraPath =
|
|
|
|
this->Makefile->GetDefinition("CMAKE_MSVCIDE_RUN_PATH");
|
|
|
|
if(extraPath)
|
|
|
|
{
|
2006-10-25 20:27:17 +04:00
|
|
|
script += newline;
|
|
|
|
newline = newline_text;
|
2006-09-21 23:14:06 +04:00
|
|
|
script += "set PATH=";
|
|
|
|
script += extraPath;
|
|
|
|
script += ";%PATH%";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Write each command on a single line.
|
|
|
|
for(cmCustomCommandLines::const_iterator cl = commandLines.begin();
|
|
|
|
cl != commandLines.end(); ++cl)
|
|
|
|
{
|
2006-10-25 20:27:17 +04:00
|
|
|
// Start a new line.
|
|
|
|
script += newline;
|
|
|
|
newline = newline_text;
|
|
|
|
|
2006-09-21 23:14:06 +04:00
|
|
|
// Start with the command name.
|
|
|
|
const cmCustomCommandLine& commandLine = *cl;
|
2007-05-09 16:25:45 +04:00
|
|
|
std::string commandName = this->GetRealLocation(commandLine[0].c_str(),
|
|
|
|
configName);
|
2007-01-19 00:10:21 +03:00
|
|
|
if(!workingDirectory)
|
|
|
|
{
|
2007-05-09 16:25:45 +04:00
|
|
|
script += this->Convert(commandName.c_str(),START_OUTPUT,SHELL);
|
2007-01-19 00:10:21 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-05-09 16:25:45 +04:00
|
|
|
script += this->Convert(commandName.c_str(),NONE,SHELL);
|
2007-01-19 00:10:21 +03:00
|
|
|
}
|
2006-09-21 23:14:06 +04:00
|
|
|
|
|
|
|
// Add the arguments.
|
|
|
|
for(unsigned int j=1;j < commandLine.size(); ++j)
|
|
|
|
{
|
|
|
|
script += " ";
|
2006-09-27 21:43:46 +04:00
|
|
|
if(escapeOldStyle)
|
|
|
|
{
|
|
|
|
script += this->EscapeForShellOldStyle(commandLine[j].c_str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-09-07 18:11:20 +04:00
|
|
|
script += this->EscapeForShell(commandLine[j].c_str(),
|
2006-09-27 21:43:46 +04:00
|
|
|
escapeAllowMakeVars);
|
|
|
|
}
|
2006-09-21 23:14:06 +04:00
|
|
|
}
|
2010-03-12 00:54:57 +03:00
|
|
|
|
|
|
|
// After each custom command, check for an error result.
|
|
|
|
// If there was an error, jump to the VCReportError label,
|
|
|
|
// skipping the run of any subsequent commands in this
|
|
|
|
// sequence.
|
|
|
|
//
|
|
|
|
script += newline_text;
|
|
|
|
script += "if errorlevel 1 goto VCReportError";
|
2006-09-21 23:14:06 +04:00
|
|
|
}
|
2010-03-12 00:54:57 +03:00
|
|
|
|
2006-09-21 23:14:06 +04:00
|
|
|
return script;
|
|
|
|
}
|