mirror of
https://github.com/reactos/CMake.git
synced 2025-01-10 05:31:02 +00:00
86578eccf2
Per-source copyright/license notice headers that spell out copyright holder names and years are hard to maintain and often out-of-date or plain wrong. Precise contributor information is already maintained automatically by the version control tool. Ultimately it is the receiver of a file who is responsible for determining its licensing status, and per-source notices are merely a convenience. Therefore it is simpler and more accurate for each source to have a generic notice of the license name and references to more detailed information on copyright holders and full license terms. Our `Copyright.txt` file now contains a list of Contributors whose names appeared source-level copyright notices. It also references version control history for more precise information. Therefore we no longer need to spell out the list of Contributors in each source file notice. Replace CMake per-source copyright/license notice headers with a short description of the license and links to `Copyright.txt` and online information available from "https://cmake.org/licensing". The online URL also handles cases of modules being copied out of our source into other projects, so we can drop our notices about replacing links with full license text. Run the `Utilities/Scripts/filter-notices.bash` script to perform the majority of the replacements mechanically. Manually fix up shebang lines and trailing newlines in a few files. Manually update the notices in a few files that the script does not handle.
233 lines
7.1 KiB
C++
233 lines
7.1 KiB
C++
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
|
#include "cmLocalVisualStudioGenerator.h"
|
|
|
|
#include "cmCustomCommandGenerator.h"
|
|
#include "cmGeneratorTarget.h"
|
|
#include "cmGlobalGenerator.h"
|
|
#include "cmMakefile.h"
|
|
#include "cmSourceFile.h"
|
|
#include "cmSystemTools.h"
|
|
#include "windows.h"
|
|
|
|
cmLocalVisualStudioGenerator::cmLocalVisualStudioGenerator(
|
|
cmGlobalGenerator* gg, cmMakefile* mf)
|
|
: cmLocalGenerator(gg, mf)
|
|
{
|
|
}
|
|
|
|
cmLocalVisualStudioGenerator::~cmLocalVisualStudioGenerator()
|
|
{
|
|
}
|
|
|
|
cmGlobalVisualStudioGenerator::VSVersion
|
|
cmLocalVisualStudioGenerator::GetVersion() const
|
|
{
|
|
cmGlobalVisualStudioGenerator* gg =
|
|
static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator);
|
|
return gg->GetVersion();
|
|
}
|
|
|
|
void cmLocalVisualStudioGenerator::ComputeObjectFilenames(
|
|
std::map<cmSourceFile const*, std::string>& mapping,
|
|
cmGeneratorTarget const* gt)
|
|
{
|
|
std::string dir_max = this->ComputeLongestObjectDirectory(gt);
|
|
|
|
// 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 += this->GlobalGenerator->GetLanguageOutputExtension(*sf);
|
|
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 += this->GlobalGenerator->GetLanguageOutputExtension(*sf);
|
|
if (counts[cmSystemTools::LowerCase(objectName)] > 1) {
|
|
const_cast<cmGeneratorTarget*>(gt)->AddExplicitObjectName(sf);
|
|
objectName = this->GetObjectFileNameWithoutTarget(*sf, dir_max);
|
|
}
|
|
si->second = objectName;
|
|
}
|
|
}
|
|
|
|
CM_AUTO_PTR<cmCustomCommand>
|
|
cmLocalVisualStudioGenerator::MaybeCreateImplibDir(cmGeneratorTarget* target,
|
|
const std::string& config,
|
|
bool isFortran)
|
|
{
|
|
CM_AUTO_PTR<cmCustomCommand> pcc;
|
|
|
|
// If an executable exports symbols then VS wants to create an
|
|
// import library but forgets to create the output directory.
|
|
// The Intel Fortran plugin always forgets to the directory.
|
|
if (target->GetType() != cmState::EXECUTABLE &&
|
|
!(isFortran && target->GetType() == cmState::SHARED_LIBRARY)) {
|
|
return pcc;
|
|
}
|
|
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(cmSystemTools::GetCMakeCommand());
|
|
command.push_back("-E");
|
|
command.push_back("make_directory");
|
|
command.push_back(impDir);
|
|
std::vector<std::string> no_output;
|
|
std::vector<std::string> no_byproducts;
|
|
std::vector<std::string> no_depends;
|
|
cmCustomCommandLines commands;
|
|
commands.push_back(command);
|
|
pcc.reset(new cmCustomCommand(0, no_output, no_byproducts, no_depends,
|
|
commands, 0, 0));
|
|
pcc->SetEscapeOldStyle(false);
|
|
pcc->SetEscapeAllowMakeVars(true);
|
|
return pcc;
|
|
}
|
|
|
|
const char* cmLocalVisualStudioGenerator::ReportErrorLabel() const
|
|
{
|
|
return ":VCReportError";
|
|
}
|
|
|
|
const char* cmLocalVisualStudioGenerator::GetReportErrorLabel() const
|
|
{
|
|
return this->ReportErrorLabel();
|
|
}
|
|
|
|
std::string cmLocalVisualStudioGenerator::ConstructScript(
|
|
cmCustomCommandGenerator const& ccg, const std::string& newline_text)
|
|
{
|
|
bool useLocal = this->CustomCommandUseLocal();
|
|
std::string workingDirectory = ccg.GetWorkingDirectory();
|
|
|
|
// Avoid leading or trailing newlines.
|
|
std::string newline = "";
|
|
|
|
// Line to check for error between commands.
|
|
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();
|
|
}
|
|
|
|
// Store the script in a string.
|
|
std::string script;
|
|
|
|
// Open a local context.
|
|
if (useLocal) {
|
|
script += newline;
|
|
newline = newline_text;
|
|
script += "setlocal";
|
|
}
|
|
|
|
if (!workingDirectory.empty()) {
|
|
// Change the working directory.
|
|
script += newline;
|
|
newline = newline_text;
|
|
script += "cd ";
|
|
script += this->ConvertToOutputFormat(
|
|
cmSystemTools::CollapseFullPath(workingDirectory), SHELL);
|
|
script += check_error;
|
|
|
|
// Change the working drive.
|
|
if (workingDirectory.size() > 1 && workingDirectory[1] == ':') {
|
|
script += newline;
|
|
newline = newline_text;
|
|
script += workingDirectory[0];
|
|
script += workingDirectory[1];
|
|
script += check_error;
|
|
}
|
|
}
|
|
|
|
// 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 (unsigned int c = 0; c < ccg.GetNumberOfCommands(); ++c) {
|
|
// Start a new line.
|
|
script += newline;
|
|
newline = newline_text;
|
|
|
|
// Add this command line.
|
|
std::string cmd = ccg.GetCommand(c);
|
|
|
|
// 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 ";
|
|
}
|
|
}
|
|
|
|
if (workingDirectory.empty()) {
|
|
script += this->ConvertToOutputFormat(
|
|
this->ConvertToRelativePath(this->GetCurrentBinaryDirectory(), cmd),
|
|
cmOutputConverter::SHELL);
|
|
} else {
|
|
script += this->ConvertToOutputFormat(cmd.c_str(), SHELL);
|
|
}
|
|
ccg.AppendArguments(c, script);
|
|
|
|
// 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.
|
|
script += check_error;
|
|
}
|
|
|
|
// Close the local context.
|
|
if (useLocal) {
|
|
script += newline;
|
|
script += ":cmEnd";
|
|
script += newline;
|
|
script += "endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone";
|
|
script += newline;
|
|
script += ":cmErrorLevel";
|
|
script += newline;
|
|
script += "exit /b %1";
|
|
script += newline;
|
|
script += ":cmDone";
|
|
script += newline;
|
|
script += "if %errorlevel% neq 0 goto ";
|
|
script += this->GetReportErrorLabel();
|
|
}
|
|
|
|
return script;
|
|
}
|