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
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2011-11-11 02:17:41 +04:00
|
|
|
cmLocalVisualStudioGenerator::cmLocalVisualStudioGenerator(VSVersion v)
|
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()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
std::vector<std::string> no_depends;
|
|
|
|
cmCustomCommandLines commands;
|
|
|
|
commands.push_back(command);
|
2010-12-06 22:33:59 +03:00
|
|
|
pcc.reset(new cmCustomCommand(0, no_output, 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;
|
|
|
|
}
|