2006-07-11 19:41:38 +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 "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"
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
// 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
|
|
|
|
{
|
|
|
|
script += this->EscapeForShell(commandLine[j].c_str(),
|
|
|
|
escapeAllowMakeVars);
|
|
|
|
}
|
2006-09-21 23:14:06 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return script;
|
|
|
|
}
|
2007-02-17 00:12:17 +03:00
|
|
|
|