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"
|
2016-04-29 16:40:20 +03:00
|
|
|
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmCustomCommandGenerator.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"
|
2008-01-15 19:56:41 +03:00
|
|
|
#include "windows.h"
|
2006-07-11 19:41:38 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmLocalVisualStudioGenerator::cmLocalVisualStudioGenerator(
|
|
|
|
cmGlobalGenerator* gg, cmMakefile* mf)
|
2015-08-02 12:41:51 +03:00
|
|
|
: 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(
|
2016-05-16 17:34:04 +03:00
|
|
|
std::map<cmSourceFile const*, std::string>& mapping,
|
|
|
|
cmGeneratorTarget const* gt)
|
2014-03-11 20:37:26 +04:00
|
|
|
{
|
2015-10-23 19:26:38 +03:00
|
|
|
std::string dir_max = this->ComputeLongestObjectDirectory(gt);
|
2014-03-11 20:37:26 +04:00
|
|
|
|
|
|
|
// Count the number of object files with each name. Note that
|
|
|
|
// windows file names are not case sensitive.
|
|
|
|
std::map<std::string, int> counts;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::map<cmSourceFile const*, std::string>::iterator si =
|
|
|
|
mapping.begin();
|
|
|
|
si != mapping.end(); ++si) {
|
2014-03-11 20:37:26 +04:00
|
|
|
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;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-03-11 20:37:26 +04:00
|
|
|
|
|
|
|
// For all source files producing duplicate names we need unique
|
|
|
|
// object name computation.
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::map<cmSourceFile const*, std::string>::iterator si =
|
|
|
|
mapping.begin();
|
|
|
|
si != mapping.end(); ++si) {
|
2014-03-11 20:37:26 +04:00
|
|
|
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);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (counts[cmSystemTools::LowerCase(objectName)] > 1) {
|
2014-03-11 20:37:26 +04:00
|
|
|
const_cast<cmGeneratorTarget*>(gt)->AddExplicitObjectName(sf);
|
|
|
|
objectName = this->GetObjectFileNameWithoutTarget(*sf, dir_max);
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
si->second = objectName;
|
|
|
|
}
|
2014-03-11 20:37:26 +04:00
|
|
|
}
|
|
|
|
|
2016-06-28 17:17:52 +03:00
|
|
|
CM_AUTO_PTR<cmCustomCommand>
|
2015-10-23 19:26:40 +03:00
|
|
|
cmLocalVisualStudioGenerator::MaybeCreateImplibDir(cmGeneratorTarget* 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
|
|
|
{
|
2016-06-28 17:17:52 +03:00
|
|
|
CM_AUTO_PTR<cmCustomCommand> pcc;
|
2009-06-16 19:44:07 +04:00
|
|
|
|
|
|
|
// 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.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (target->GetType() != cmState::EXECUTABLE &&
|
|
|
|
!(isFortran && target->GetType() == cmState::SHARED_LIBRARY)) {
|
|
|
|
return pcc;
|
|
|
|
}
|
2015-10-23 19:26:40 +03:00
|
|
|
std::string outDir = target->GetDirectory(config, false);
|
|
|
|
std::string impDir = target->GetDirectory(config, true);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (impDir == outDir) {
|
|
|
|
return pcc;
|
|
|
|
}
|
2009-06-16 19:44:07 +04:00
|
|
|
|
|
|
|
// 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);
|
2016-05-16 17:34:04 +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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cmLocalVisualStudioGenerator::ConstructScript(
|
|
|
|
cmCustomCommandGenerator const& ccg, 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();
|
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;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (useLocal) {
|
2011-04-11 18:07:40 +04:00
|
|
|
check_error += "if %errorlevel% neq 0 goto :cmEnd";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2011-04-11 18:07:40 +04:00
|
|
|
check_error += "if errorlevel 1 goto ";
|
|
|
|
check_error += this->GetReportErrorLabel();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
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.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (useLocal) {
|
2011-04-11 18:07:40 +04:00
|
|
|
script += newline;
|
|
|
|
newline = newline_text;
|
|
|
|
script += "setlocal";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-04-08 18:40:57 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!workingDirectory.empty()) {
|
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 ";
|
2016-08-27 14:44:57 +03:00
|
|
|
script += this->ConvertToOutputFormat(
|
|
|
|
cmSystemTools::CollapseFullPath(workingDirectory), SHELL);
|
2011-04-08 18:40:57 +04:00
|
|
|
script += check_error;
|
2007-12-18 02:38:19 +03:00
|
|
|
|
|
|
|
// Change the working drive.
|
2016-05-16 17:34:04 +03: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;
|
2006-09-21 23:14:06 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03: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.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Makefile->GetDefinition("MSVC_IDE")) {
|
2006-09-21 23:14:06 +04:00
|
|
|
const char* extraPath =
|
|
|
|
this->Makefile->GetDefinition("CMAKE_MSVCIDE_RUN_PATH");
|
2016-05-16 17:34:04 +03:00
|
|
|
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%";
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-04-08 18:40:57 +04:00
|
|
|
|
2006-09-21 23:14:06 +04:00
|
|
|
// Write each command on a single line.
|
2016-05-16 17:34:04 +03:00
|
|
|
for (unsigned int c = 0; c < ccg.GetNumberOfCommands(); ++c) {
|
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;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmd.size() > 4) {
|
|
|
|
suffix = cmSystemTools::LowerCase(cmd.substr(cmd.size() - 4));
|
|
|
|
if (suffix == ".bat" || suffix == ".cmd") {
|
2011-11-18 19:15:58 +04:00
|
|
|
script += "call ";
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-11-18 19:15:58 +04:00
|
|
|
|
2016-08-27 14:44:54 +03:00
|
|
|
if (workingDirectory.empty()) {
|
|
|
|
script += this->Convert(cmd.c_str(), START_OUTPUT, SHELL);
|
|
|
|
} else {
|
2016-08-27 14:44:55 +03:00
|
|
|
script += this->ConvertToOutputFormat(cmd.c_str(), SHELL);
|
2016-08-27 14:44:54 +03:00
|
|
|
}
|
2010-12-08 00:23:38 +03:00
|
|
|
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;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-03-12 00:54:57 +03:00
|
|
|
|
2011-04-08 18:40:57 +04:00
|
|
|
// Close the local context.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (useLocal) {
|
2011-04-11 18:07:40 +04:00
|
|
|
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();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-04-08 18:40:57 +04:00
|
|
|
|
2006-09-21 23:14:06 +04:00
|
|
|
return script;
|
|
|
|
}
|