
This patch is generated by a python script that uses regular expressions to search for string concatenation patterns of the kind ``` std::string str = <ARG0>; str += <ARG1>; str += <ARG2>; ... ``` and replaces them with a single `cmStrCat` call ``` std::string str = cmStrCat(<ARG0>, <ARG1>, <ARG2>, ...); ``` If any `<ARGX>` is itself a concatenated string of the kind ``` a + b + c + ...; ``` then `<ARGX>` is split into multiple arguments for the `cmStrCat` call. If there's a sequence of literals in the `<ARGX>`, then all literals in the sequence are concatenated and merged into a single literal argument for the `cmStrCat` call. Single character strings are converted to single char arguments for the `cmStrCat` call. `std::to_string(...)` wrappings are removed from `cmStrCat` arguments, because it supports numeric types as well as string types. `arg.substr(x)` arguments to `cmStrCat` are replaced with `cm::string_view(arg).substr(x)`
85 lines
2.4 KiB
C++
85 lines
2.4 KiB
C++
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
|
#include "cmLinkDirectoriesCommand.h"
|
|
|
|
#include <sstream>
|
|
|
|
#include "cmGeneratorExpression.h"
|
|
#include "cmMakefile.h"
|
|
#include "cmMessageType.h"
|
|
#include "cmPolicies.h"
|
|
#include "cmStringAlgorithms.h"
|
|
#include "cmSystemTools.h"
|
|
|
|
class cmExecutionStatus;
|
|
|
|
// cmLinkDirectoriesCommand
|
|
bool cmLinkDirectoriesCommand::InitialPass(
|
|
std::vector<std::string> const& args, cmExecutionStatus&)
|
|
{
|
|
if (args.empty()) {
|
|
return true;
|
|
}
|
|
|
|
bool before = this->Makefile->IsOn("CMAKE_LINK_DIRECTORIES_BEFORE");
|
|
|
|
auto i = args.cbegin();
|
|
if ((*i) == "BEFORE") {
|
|
before = true;
|
|
++i;
|
|
} else if ((*i) == "AFTER") {
|
|
before = false;
|
|
++i;
|
|
}
|
|
|
|
std::vector<std::string> directories;
|
|
for (; i != args.cend(); ++i) {
|
|
this->AddLinkDir(*i, directories);
|
|
}
|
|
|
|
this->Makefile->AddLinkDirectory(cmJoin(directories, ";"), before);
|
|
|
|
return true;
|
|
}
|
|
|
|
void cmLinkDirectoriesCommand::AddLinkDir(
|
|
std::string const& dir, std::vector<std::string>& directories)
|
|
{
|
|
std::string unixPath = dir;
|
|
cmSystemTools::ConvertToUnixSlashes(unixPath);
|
|
if (!cmSystemTools::FileIsFullPath(unixPath) &&
|
|
!cmGeneratorExpression::StartsWithGeneratorExpression(unixPath)) {
|
|
bool convertToAbsolute = false;
|
|
std::ostringstream e;
|
|
/* clang-format off */
|
|
e << "This command specifies the relative path\n"
|
|
<< " " << unixPath << "\n"
|
|
<< "as a link directory.\n";
|
|
/* clang-format on */
|
|
switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0015)) {
|
|
case cmPolicies::WARN:
|
|
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0015);
|
|
this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, e.str());
|
|
break;
|
|
case cmPolicies::OLD:
|
|
// OLD behavior does not convert
|
|
break;
|
|
case cmPolicies::REQUIRED_IF_USED:
|
|
case cmPolicies::REQUIRED_ALWAYS:
|
|
e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0015);
|
|
this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
|
|
CM_FALLTHROUGH;
|
|
case cmPolicies::NEW:
|
|
// NEW behavior converts
|
|
convertToAbsolute = true;
|
|
break;
|
|
}
|
|
if (convertToAbsolute) {
|
|
std::string tmp =
|
|
cmStrCat(this->Makefile->GetCurrentSourceDirectory(), '/', unixPath);
|
|
unixPath = tmp;
|
|
}
|
|
}
|
|
directories.push_back(unixPath);
|
|
}
|