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"
|
2010-12-08 00:23:38 +03:00
|
|
|
#include "cmCustomCommandGenerator.h"
|
2008-01-15 19:56:41 +03:00
|
|
|
#include "windows.h"
|
2006-07-11 19:41:38 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2015-04-28 08:50:52 +03:00
|
|
|
cmLocalVisualStudioGenerator
|
|
|
|
::cmLocalVisualStudioGenerator(VSVersion v, cmLocalGenerator* parent)
|
|
|
|
: cmLocalGenerator(parent)
|
2006-07-11 19:41:38 +04:00
|
|
|
{
|
2006-09-21 23:14:06 +04:00
|
|
|
this->WindowsShell = true;
|
2006-09-27 21:43:46 +04:00
|
|
|
this->WindowsVSIDE = true;
|
2011-11-11 02:17:41 +04:00
|
|
|
this->Version = v;
|
2006-07-11 19:41:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
cmLocalVisualStudioGenerator::~cmLocalVisualStudioGenerator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-03-11 20:37:26 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmLocalVisualStudioGenerator::ComputeObjectFilenames(
|
|
|
|
std::map<cmSourceFile const*, std::string>& mapping,
|
|
|
|
cmGeneratorTarget const* gt)
|
|
|
|
{
|
|
|
|
std::string dir_max = this->ComputeLongestObjectDirectory(*gt->Target);
|
|
|
|
|
|
|
|
// Count the number of object files with each name. Note that
|
|
|
|
// windows file names are not case sensitive.
|
|
|
|
std::map<std::string, int> counts;
|
|
|
|
|
|
|
|
for(std::map<cmSourceFile const*, std::string>::iterator
|
|
|
|
si = mapping.begin(); si != mapping.end(); ++si)
|
|
|
|
{
|
|
|
|
cmSourceFile const* sf = si->first;
|
|
|
|
std::string objectNameLower = cmSystemTools::LowerCase(
|
|
|
|
cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath()));
|
|
|
|
objectNameLower += ".obj";
|
|
|
|
counts[objectNameLower] += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For all source files producing duplicate names we need unique
|
|
|
|
// object name computation.
|
|
|
|
|
|
|
|
for(std::map<cmSourceFile const*, std::string>::iterator
|
|
|
|
si = mapping.begin(); si != mapping.end(); ++si)
|
|
|
|
{
|
|
|
|
cmSourceFile const* sf = si->first;
|
|
|
|
std::string objectName =
|
|
|
|
cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath());
|
|
|
|
objectName += ".obj";
|
|
|
|
if(counts[cmSystemTools::LowerCase(objectName)] > 1)
|
|
|
|
{
|
|
|
|
const_cast<cmGeneratorTarget*>(gt)->AddExplicitObjectName(sf);
|
|
|
|
objectName = this->GetObjectFileNameWithoutTarget(*sf, dir_max);
|
|
|
|
}
|
|
|
|
si->second = objectName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-16 19:44:07 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
cmsys::auto_ptr<cmCustomCommand>
|
|
|
|
cmLocalVisualStudioGenerator::MaybeCreateImplibDir(cmTarget& target,
|
2014-02-10 07:48:34 +04:00
|
|
|
const std::string& config,
|
2011-02-11 00:17:44 +03:00
|
|
|
bool isFortran)
|
2009-06-16 19:44:07 +04:00
|
|
|
{
|
|
|
|
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.
|
2011-02-11 00:17:44 +03:00
|
|
|
// The Intel Fortran plugin always forgets to the directory.
|
|
|
|
if(target.GetType() != cmTarget::EXECUTABLE &&
|
|
|
|
!(isFortran && target.GetType() == cmTarget::SHARED_LIBRARY))
|
|
|
|
{ return pcc; }
|
2009-06-16 19:44:07 +04:00
|
|
|
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;
|
2014-11-14 02:54:52 +03:00
|
|
|
std::vector<std::string> no_byproducts;
|
2009-06-16 19:44:07 +04:00
|
|
|
std::vector<std::string> no_depends;
|
|
|
|
cmCustomCommandLines commands;
|
|
|
|
commands.push_back(command);
|
2014-11-14 02:54:52 +03:00
|
|
|
pcc.reset(new cmCustomCommand(0, no_output, no_byproducts,
|
|
|
|
no_depends, commands, 0, 0));
|
2009-06-16 19:44:07 +04:00
|
|
|
pcc->SetEscapeOldStyle(false);
|
|
|
|
pcc->SetEscapeAllowMakeVars(true);
|
|
|
|
return pcc;
|
|
|
|
}
|
|
|
|
|
2010-12-17 19:11:55 +03:00
|
|
|
//----------------------------------------------------------------------------
|
2011-04-08 18:40:57 +04:00
|
|
|
const char* cmLocalVisualStudioGenerator::ReportErrorLabel() const
|
2010-12-17 19:11:55 +03:00
|
|
|
{
|
2011-04-08 18:40:57 +04:00
|
|
|
return ":VCReportError";
|
2010-12-17 19:11:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2011-04-08 18:40:57 +04:00
|
|
|
const char* cmLocalVisualStudioGenerator::GetReportErrorLabel() const
|
2010-12-17 19:11:55 +03:00
|
|
|
{
|
2011-04-08 18:40:57 +04:00
|
|
|
return this->ReportErrorLabel();
|
2010-12-17 19:11:55 +03:00
|
|
|
}
|
|
|
|
|
2006-09-21 23:14:06 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
std::string
|
|
|
|
cmLocalVisualStudioGenerator
|
2014-03-10 23:47:19 +04:00
|
|
|
::ConstructScript(cmCustomCommandGenerator const& ccg,
|
2014-02-22 04:05:55 +04:00
|
|
|
const std::string& newline_text)
|
2006-09-21 23:14:06 +04:00
|
|
|
{
|
2011-04-11 18:07:40 +04:00
|
|
|
bool useLocal = this->CustomCommandUseLocal();
|
2014-03-10 23:47:19 +04:00
|
|
|
std::string workingDirectory = ccg.GetWorkingDirectory();
|
2014-03-10 21:53:57 +04:00
|
|
|
RelativeRoot relativeRoot = workingDirectory.empty()? START_OUTPUT : NONE;
|
2010-12-07 21:44:54 +03:00
|
|
|
|
2011-04-11 18:07:40 +04:00
|
|
|
// Avoid leading or trailing newlines.
|
2014-02-22 04:05:55 +04:00
|
|
|
std::string newline = "";
|
2011-04-11 18:07:40 +04:00
|
|
|
|
2011-04-08 18:40:57 +04:00
|
|
|
// Line to check for error between commands.
|
2011-04-11 18:07:40 +04:00
|
|
|
std::string check_error = newline_text;
|
|
|
|
if(useLocal)
|
|
|
|
{
|
|
|
|
check_error += "if %errorlevel% neq 0 goto :cmEnd";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
check_error += "if errorlevel 1 goto ";
|
|
|
|
check_error += this->GetReportErrorLabel();
|
|
|
|
}
|
2006-10-25 20:27:17 +04:00
|
|
|
|
2006-09-21 23:14:06 +04:00
|
|
|
// Store the script in a string.
|
|
|
|
std::string script;
|
2011-04-08 18:40:57 +04:00
|
|
|
|
|
|
|
// Open a local context.
|
2011-04-11 18:07:40 +04:00
|
|
|
if(useLocal)
|
|
|
|
{
|
|
|
|
script += newline;
|
|
|
|
newline = newline_text;
|
|
|
|
script += "setlocal";
|
|
|
|
}
|
2011-04-08 18:40:57 +04:00
|
|
|
|
2014-03-10 21:53:57 +04:00
|
|
|
if(!workingDirectory.empty())
|
2006-09-21 23:14:06 +04:00
|
|
|
{
|
2007-12-18 02:38:19 +03:00
|
|
|
// Change the working directory.
|
2006-10-25 20:27:17 +04:00
|
|
|
script += newline;
|
2011-04-11 18:07:40 +04:00
|
|
|
newline = newline_text;
|
2006-09-21 23:14:06 +04:00
|
|
|
script += "cd ";
|
2010-04-02 22:09:06 +04:00
|
|
|
script += this->Convert(workingDirectory, FULL, SHELL);
|
2011-04-08 18:40:57 +04:00
|
|
|
script += check_error;
|
2007-12-18 02:38:19 +03:00
|
|
|
|
|
|
|
// Change the working drive.
|
2014-03-10 21:53:57 +04:00
|
|
|
if(workingDirectory.size() > 1 && workingDirectory[1] == ':')
|
2007-12-18 02:38:19 +03:00
|
|
|
{
|
|
|
|
script += newline;
|
2011-04-11 18:07:40 +04:00
|
|
|
newline = newline_text;
|
2007-12-18 02:38:19 +03:00
|
|
|
script += workingDirectory[0];
|
|
|
|
script += workingDirectory[1];
|
2011-04-08 18:40:57 +04:00
|
|
|
script += check_error;
|
2007-12-18 02:38:19 +03:00
|
|
|
}
|
2006-09-21 23:14:06 +04:00
|
|
|
}
|
2011-04-08 18:40:57 +04:00
|
|
|
|
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;
|
2011-04-11 18:07:40 +04:00
|
|
|
newline = newline_text;
|
2006-09-21 23:14:06 +04:00
|
|
|
script += "set PATH=";
|
|
|
|
script += extraPath;
|
|
|
|
script += ";%PATH%";
|
|
|
|
}
|
|
|
|
}
|
2011-04-08 18:40:57 +04:00
|
|
|
|
2006-09-21 23:14:06 +04:00
|
|
|
// Write each command on a single line.
|
2010-12-08 00:23:38 +03:00
|
|
|
for(unsigned int c = 0; c < ccg.GetNumberOfCommands(); ++c)
|
2006-09-21 23:14:06 +04:00
|
|
|
{
|
2006-10-25 20:27:17 +04:00
|
|
|
// Start a new line.
|
|
|
|
script += newline;
|
2011-04-11 18:07:40 +04:00
|
|
|
newline = newline_text;
|
2006-10-25 20:27:17 +04:00
|
|
|
|
2010-12-08 00:23:38 +03:00
|
|
|
// Add this command line.
|
|
|
|
std::string cmd = ccg.GetCommand(c);
|
2011-11-18 19:15:58 +04:00
|
|
|
|
|
|
|
// Use "call " before any invocations of .bat or .cmd files
|
|
|
|
// invoked as custom commands.
|
|
|
|
//
|
|
|
|
std::string suffix;
|
|
|
|
if (cmd.size() > 4)
|
|
|
|
{
|
|
|
|
suffix = cmSystemTools::LowerCase(cmd.substr(cmd.size()-4));
|
|
|
|
if (suffix == ".bat" || suffix == ".cmd")
|
|
|
|
{
|
|
|
|
script += "call ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-08 00:23:38 +03:00
|
|
|
script += this->Convert(cmd.c_str(), relativeRoot, SHELL);
|
|
|
|
ccg.AppendArguments(c, script);
|
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.
|
2011-04-08 18:40:57 +04:00
|
|
|
script += check_error;
|
2006-09-21 23:14:06 +04:00
|
|
|
}
|
2010-03-12 00:54:57 +03:00
|
|
|
|
2011-04-08 18:40:57 +04:00
|
|
|
// Close the local context.
|
2011-04-11 18:07:40 +04:00
|
|
|
if(useLocal)
|
|
|
|
{
|
|
|
|
script += newline;
|
|
|
|
script += ":cmEnd";
|
|
|
|
script += newline;
|
2011-04-11 19:48:08 +04:00
|
|
|
script += "endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone";
|
|
|
|
script += newline;
|
|
|
|
script += ":cmErrorLevel";
|
|
|
|
script += newline;
|
|
|
|
script += "exit /b %1";
|
|
|
|
script += newline;
|
|
|
|
script += ":cmDone";
|
2011-04-11 18:07:40 +04:00
|
|
|
script += newline;
|
2011-04-11 19:48:08 +04:00
|
|
|
script += "if %errorlevel% neq 0 goto ";
|
2011-04-11 18:07:40 +04:00
|
|
|
script += this->GetReportErrorLabel();
|
|
|
|
}
|
2011-04-08 18:40:57 +04:00
|
|
|
|
2006-09-21 23:14:06 +04:00
|
|
|
return script;
|
|
|
|
}
|