35936433e1
CMake-SourceFile2-bp and CMake-SourceFile2-b-mp1 to trunk. This commit is surrounded by tags CMake-SourceFile2-b-mp1-pre and CMake-SourceFile2-b-mp1-post on the trunk. The changes re-implement cmSourceFile and the use of it to allow instances to be created much earlier. The use of cmSourceFileLocation allows locating a source file referenced by a user to be much simpler and more robust. The two SetName methods are no longer needed so some duplicate code has been removed. The strange "SourceName" stuff is gone. Code that created cmSourceFile instances on the stack and then sent them to cmMakefile::AddSource has been simplified and converted to getting cmSourceFile instances from cmMakefile. The CPluginAPI has preserved the old API through a compatibility interface. Source lists are gone. Targets now get real instances of cmSourceFile right away instead of storing a list of strings until the final pass. TraceVSDependencies has been re-written to avoid the use of SourceName. It is now called TraceDependencies since it is not just for VS. It is now implemented with a helper object which makes the code simpler.
185 lines
5.7 KiB
C++
185 lines
5.7 KiB
C++
/*=========================================================================
|
|
|
|
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"
|
|
#include "cmGlobalGenerator.h"
|
|
#include "cmMakefile.h"
|
|
#include "cmSourceFile.h"
|
|
#include "cmSystemTools.h"
|
|
|
|
//----------------------------------------------------------------------------
|
|
cmLocalVisualStudioGenerator::cmLocalVisualStudioGenerator()
|
|
{
|
|
this->WindowsShell = true;
|
|
this->WindowsVSIDE = true;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
cmLocalVisualStudioGenerator::~cmLocalVisualStudioGenerator()
|
|
{
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool cmLocalVisualStudioGenerator::SourceFileCompiles(const cmSourceFile* sf)
|
|
{
|
|
// 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;
|
|
}
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
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;
|
|
for(unsigned int i = 0; i < sourceGroups.size(); ++i)
|
|
{
|
|
cmSourceGroup sg = sourceGroups[i];
|
|
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;
|
|
if(this->SourceFileCompiles(sf))
|
|
{
|
|
std::string objectName =
|
|
cmSystemTools::LowerCase(
|
|
cmSystemTools::GetFilenameWithoutLastExtension(
|
|
sf->GetFullPath()));
|
|
objectName += ".obj";
|
|
objectNameCounts[objectName] += 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
// For all source files producing duplicate names we need unique
|
|
// object name computation.
|
|
for(unsigned int i = 0; i < sourceGroups.size(); ++i)
|
|
{
|
|
cmSourceGroup sg = sourceGroups[i];
|
|
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;
|
|
if(this->SourceFileCompiles(sf))
|
|
{
|
|
std::string objectName =
|
|
cmSystemTools::LowerCase(
|
|
cmSystemTools::GetFilenameWithoutLastExtension(
|
|
sf->GetFullPath()));
|
|
objectName += ".obj";
|
|
if(objectNameCounts[objectName] > 1)
|
|
{
|
|
this->NeedObjectName.insert(sf);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
std::string
|
|
cmLocalVisualStudioGenerator
|
|
::ConstructScript(const cmCustomCommandLines& commandLines,
|
|
const char* workingDirectory,
|
|
const char* configName,
|
|
bool escapeOldStyle,
|
|
bool escapeAllowMakeVars,
|
|
const char* newline_text)
|
|
{
|
|
// Avoid leading or trailing newlines.
|
|
const char* newline = "";
|
|
|
|
// Store the script in a string.
|
|
std::string script;
|
|
if(workingDirectory)
|
|
{
|
|
script += newline;
|
|
newline = newline_text;
|
|
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)
|
|
{
|
|
script += newline;
|
|
newline = newline_text;
|
|
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)
|
|
{
|
|
// Start a new line.
|
|
script += newline;
|
|
newline = newline_text;
|
|
|
|
// Start with the command name.
|
|
const cmCustomCommandLine& commandLine = *cl;
|
|
std::string commandName = this->GetRealLocation(commandLine[0].c_str(),
|
|
configName);
|
|
if(!workingDirectory)
|
|
{
|
|
script += this->Convert(commandName.c_str(),START_OUTPUT,SHELL);
|
|
}
|
|
else
|
|
{
|
|
script += this->Convert(commandName.c_str(),NONE,SHELL);
|
|
}
|
|
|
|
// Add the arguments.
|
|
for(unsigned int j=1;j < commandLine.size(); ++j)
|
|
{
|
|
script += " ";
|
|
if(escapeOldStyle)
|
|
{
|
|
script += this->EscapeForShellOldStyle(commandLine[j].c_str());
|
|
}
|
|
else
|
|
{
|
|
script += this->EscapeForShell(commandLine[j].c_str(),
|
|
escapeAllowMakeVars);
|
|
}
|
|
}
|
|
}
|
|
return script;
|
|
}
|
|
|