/src/CMake/Source/cmInstallTargetsCommand.cxx
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
2 | | file LICENSE.rst or https://cmake.org/licensing for details. */ |
3 | | #include "cmInstallTargetsCommand.h" |
4 | | |
5 | | #include <unordered_map> |
6 | | #include <utility> |
7 | | |
8 | | #include "cmExecutionStatus.h" |
9 | | #include "cmGlobalGenerator.h" |
10 | | #include "cmMakefile.h" |
11 | | #include "cmTarget.h" |
12 | | |
13 | | bool cmInstallTargetsCommand(std::vector<std::string> const& args, |
14 | | cmExecutionStatus& status) |
15 | 0 | { |
16 | 0 | if (args.size() < 2) { |
17 | 0 | status.SetError("called with incorrect number of arguments"); |
18 | 0 | return false; |
19 | 0 | } |
20 | | |
21 | 0 | cmMakefile& mf = status.GetMakefile(); |
22 | | |
23 | | // Enable the install target. |
24 | 0 | mf.GetGlobalGenerator()->EnableInstallTarget(); |
25 | |
|
26 | 0 | cmMakefile::cmTargetMap& tgts = mf.GetTargets(); |
27 | 0 | auto s = args.begin(); |
28 | 0 | ++s; |
29 | 0 | std::string runtime_dir = "/bin"; |
30 | 0 | for (; s != args.end(); ++s) { |
31 | 0 | if (*s == "RUNTIME_DIRECTORY") { |
32 | 0 | ++s; |
33 | 0 | if (s == args.end()) { |
34 | 0 | status.SetError("called with RUNTIME_DIRECTORY but no actual " |
35 | 0 | "directory"); |
36 | 0 | return false; |
37 | 0 | } |
38 | | |
39 | 0 | runtime_dir = *s; |
40 | 0 | } else { |
41 | 0 | auto ti = tgts.find(*s); |
42 | 0 | if (ti != tgts.end()) { |
43 | 0 | ti->second.SetInstallPath(args[0]); |
44 | 0 | ti->second.SetRuntimeInstallPath(runtime_dir); |
45 | 0 | ti->second.SetHaveInstallRule(true); |
46 | 0 | } else { |
47 | 0 | std::string str = "Cannot find target: \"" + *s + "\" to install."; |
48 | 0 | status.SetError(str); |
49 | 0 | return false; |
50 | 0 | } |
51 | 0 | } |
52 | 0 | } |
53 | | |
54 | 0 | mf.GetGlobalGenerator()->AddInstallComponent( |
55 | 0 | mf.GetSafeDefinition("CMAKE_INSTALL_DEFAULT_COMPONENT_NAME")); |
56 | |
|
57 | 0 | return true; |
58 | 0 | } |