cmake/Source/cmLinkDirectoriesCommand.cxx

85 lines
2.5 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmLinkDirectoriesCommand.h"
2017-04-14 19:02:05 +02:00
#include <sstream>
2020-02-01 23:06:01 +01:00
#include "cmExecutionStatus.h"
2018-10-28 12:09:07 +01:00
#include "cmGeneratorExpression.h"
2017-04-14 19:02:05 +02:00
#include "cmMakefile.h"
2019-11-11 23:01:05 +01:00
#include "cmMessageType.h"
2017-04-14 19:02:05 +02:00
#include "cmPolicies.h"
2020-02-01 23:06:01 +01:00
#include "cmStringAlgorithms.h"
2017-04-14 19:02:05 +02:00
#include "cmSystemTools.h"
2020-02-01 23:06:01 +01:00
static void AddLinkDir(cmMakefile& mf, std::string const& dir,
std::vector<std::string>& directories);
2017-04-14 19:02:05 +02:00
2020-02-01 23:06:01 +01:00
bool cmLinkDirectoriesCommand(std::vector<std::string> const& args,
cmExecutionStatus& status)
{
2016-10-30 18:24:19 +01:00
if (args.empty()) {
return true;
2016-07-09 11:21:54 +02:00
}
2020-02-01 23:06:01 +01:00
cmMakefile& mf = status.GetMakefile();
bool before = mf.IsOn("CMAKE_LINK_DIRECTORIES_BEFORE");
2018-10-28 12:09:07 +01:00
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) {
2020-02-01 23:06:01 +01:00
AddLinkDir(mf, *i, directories);
2016-07-09 11:21:54 +02:00
}
2018-10-28 12:09:07 +01:00
2020-02-01 23:06:01 +01:00
mf.AddLinkDirectory(cmJoin(directories, ";"), before);
2018-10-28 12:09:07 +01:00
return true;
}
2020-02-01 23:06:01 +01:00
static void AddLinkDir(cmMakefile& mf, std::string const& dir,
std::vector<std::string>& directories)
2010-03-17 14:00:29 +02:00
{
std::string unixPath = dir;
cmSystemTools::ConvertToUnixSlashes(unixPath);
2018-10-28 12:09:07 +01:00
if (!cmSystemTools::FileIsFullPath(unixPath) &&
!cmGeneratorExpression::StartsWithGeneratorExpression(unixPath)) {
2010-03-17 14:00:29 +02:00
bool convertToAbsolute = false;
2015-04-27 22:25:09 +02:00
std::ostringstream e;
2016-07-09 11:21:54 +02:00
/* clang-format off */
2010-03-17 14:00:29 +02:00
e << "This command specifies the relative path\n"
<< " " << unixPath << "\n"
<< "as a link directory.\n";
2016-07-09 11:21:54 +02:00
/* clang-format on */
2020-02-01 23:06:01 +01:00
switch (mf.GetPolicyStatus(cmPolicies::CMP0015)) {
2010-03-17 14:00:29 +02:00
case cmPolicies::WARN:
2015-08-17 11:37:30 +02:00
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0015);
2020-02-01 23:06:01 +01:00
mf.IssueMessage(MessageType::AUTHOR_WARNING, e.str());
2018-10-28 12:09:07 +01:00
break;
2010-03-17 14:00:29 +02:00
case cmPolicies::OLD:
// OLD behavior does not convert
break;
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::REQUIRED_ALWAYS:
2015-08-17 11:37:30 +02:00
e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0015);
2020-02-01 23:06:01 +01:00
mf.IssueMessage(MessageType::FATAL_ERROR, e.str());
2017-07-20 19:35:53 +02:00
CM_FALLTHROUGH;
2010-03-17 14:00:29 +02:00
case cmPolicies::NEW:
// NEW behavior converts
convertToAbsolute = true;
break;
2016-07-09 11:21:54 +02:00
}
if (convertToAbsolute) {
2020-02-01 23:06:01 +01:00
unixPath = cmStrCat(mf.GetCurrentSourceDirectory(), '/', unixPath);
2010-03-17 14:00:29 +02:00
}
2016-07-09 11:21:54 +02:00
}
2018-10-28 12:09:07 +01:00
directories.push_back(unixPath);
2010-03-17 14:00:29 +02:00
}