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
|
2015-08-02 12:41:51 +03:00
|
|
|
::cmLocalVisualStudioGenerator(cmGlobalGenerator* gg, cmMakefile* mf)
|
|
|
|
: cmLocalGenerator(gg, mf)
|
2006-07-11 19:41:38 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
cmLocalVisualStudioGenerator::~cmLocalVisualStudioGenerator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-05-17 12:33:09 +03:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
cmGlobalVisualStudioGenerator::VSVersion
|
|
|
|
cmLocalVisualStudioGenerator::GetVersion() const
|
|
|
|
{
|
|
|
|
cmGlobalVisualStudioGenerator* gg =
|
|
|
|
static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator);
|
|
|
|
return gg->GetVersion();
|
|
|
|
}
|
|
|
|
|
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()));
|
2015-08-18 18:17:52 +03:00
|
|
|
objectNameLower += this->GlobalGenerator->GetLanguageOutputExtension(*sf);
|
2014-03-11 20:37:26 +04:00
|
|
|
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());
|
2015-08-18 18:17:52 +03:00
|
|
|
objectName += this->GlobalGenerator->GetLanguageOutputExtension(*sf);
|
2014-03-11 20:37:26 +04:00
|
|
|
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; }
|
2014-10-20 22:31:47 +04:00
|
|
|
cmGeneratorTarget* gt =
|
|
|
|
this->GetGlobalGenerator()->GetGeneratorTarget(&target);
|
|
|
|
std::string outDir = gt->GetDirectory(config, false);
|
|
|
|
std::string impDir = gt->GetDirectory(config, true);
|
2009-06-16 19:44:07 +04:00
|
|
|
if(impDir == outDir) { return pcc; }
|
|
|
|
|
|
|
|
// Add a pre-build event to create the directory.
|
|
|
|
cmCustomCommandLine command;
|
2015-05-20 16:10:52 +03:00
|
|
|
command.push_back(cmSystemTools::GetCMakeCommand());
|
2009-06-16 19:44:07 +04:00
|
|
|
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;
|
|
|
|
}
|