cmake/Source/cmInstallTargetsCommand.cxx

59 lines
1.6 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 "cmInstallTargetsCommand.h"
2018-01-26 17:06:56 +01:00
#include <unordered_map>
2017-04-14 19:02:05 +02:00
#include <utility>
2020-02-01 23:06:01 +01:00
#include "cmExecutionStatus.h"
2017-04-14 19:02:05 +02:00
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
#include "cmTarget.h"
2020-02-01 23:06:01 +01:00
bool cmInstallTargetsCommand(std::vector<std::string> const& args,
cmExecutionStatus& status)
{
2016-07-09 11:21:54 +02:00
if (args.size() < 2) {
2020-02-01 23:06:01 +01:00
status.SetError("called with incorrect number of arguments");
return false;
2016-07-09 11:21:54 +02:00
}
2020-02-01 23:06:01 +01:00
cmMakefile& mf = status.GetMakefile();
// Enable the install target.
2020-02-01 23:06:01 +01:00
mf.GetGlobalGenerator()->EnableInstallTarget();
2020-02-01 23:06:01 +01:00
cmMakefile::cmTargetMap& tgts = mf.GetTargets();
auto s = args.begin();
++s;
std::string runtime_dir = "/bin";
2016-07-09 11:21:54 +02:00
for (; s != args.end(); ++s) {
if (*s == "RUNTIME_DIRECTORY") {
++s;
2016-07-09 11:21:54 +02:00
if (s == args.end()) {
2020-02-01 23:06:01 +01:00
status.SetError("called with RUNTIME_DIRECTORY but no actual "
"directory");
return false;
2016-07-09 11:21:54 +02:00
}
runtime_dir = *s;
2016-07-09 11:21:54 +02:00
} else {
2020-02-01 23:06:01 +01:00
auto ti = tgts.find(*s);
2016-10-30 18:24:19 +01:00
if (ti != tgts.end()) {
2019-11-11 23:01:05 +01:00
ti->second.SetInstallPath(args[0]);
ti->second.SetRuntimeInstallPath(runtime_dir);
2016-10-30 18:24:19 +01:00
ti->second.SetHaveInstallRule(true);
} else {
std::string str = "Cannot find target: \"" + *s + "\" to install.";
2020-02-01 23:06:01 +01:00
status.SetError(str);
2016-10-30 18:24:19 +01:00
return false;
}
}
2016-07-09 11:21:54 +02:00
}
2020-02-01 23:06:01 +01:00
mf.GetGlobalGenerator()->AddInstallComponent(
mf.GetSafeDefinition("CMAKE_INSTALL_DEFAULT_COMPONENT_NAME"));
return true;
}