/src/CMake/Source/cmGetDirectoryPropertyCommand.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 "cmGetDirectoryPropertyCommand.h" |
4 | | |
5 | | #include "cmExecutionStatus.h" |
6 | | #include "cmGlobalGenerator.h" |
7 | | #include "cmMakefile.h" |
8 | | #include "cmSystemTools.h" |
9 | | #include "cmValue.h" |
10 | | |
11 | | namespace { |
12 | | void StoreResult(cmMakefile& makefile, std::string const& variable, |
13 | | cmValue prop); |
14 | | } |
15 | | |
16 | | // cmGetDirectoryPropertyCommand |
17 | | bool cmGetDirectoryPropertyCommand(std::vector<std::string> const& args, |
18 | | cmExecutionStatus& status) |
19 | 0 | { |
20 | 0 | if (args.size() < 2) { |
21 | 0 | status.SetError("called with incorrect number of arguments"); |
22 | 0 | return false; |
23 | 0 | } |
24 | | |
25 | 0 | auto i = args.begin(); |
26 | 0 | std::string const& variable = *i; |
27 | 0 | ++i; |
28 | | |
29 | | // get the directory argument if there is one |
30 | 0 | cmMakefile* dir = &status.GetMakefile(); |
31 | 0 | if (*i == "DIRECTORY") { |
32 | 0 | ++i; |
33 | 0 | if (i == args.end()) { |
34 | 0 | status.SetError( |
35 | 0 | "DIRECTORY argument provided without subsequent arguments"); |
36 | 0 | return false; |
37 | 0 | } |
38 | 0 | std::string sd = cmSystemTools::CollapseFullPath( |
39 | 0 | *i, status.GetMakefile().GetCurrentSourceDirectory()); |
40 | | |
41 | | // lookup the makefile from the directory name |
42 | 0 | dir = status.GetMakefile().GetGlobalGenerator()->FindMakefile(sd); |
43 | 0 | if (!dir) { |
44 | 0 | status.SetError( |
45 | 0 | "DIRECTORY argument provided but requested directory not found. " |
46 | 0 | "This could be because the directory argument was invalid or, " |
47 | 0 | "it is valid but has not been processed yet."); |
48 | 0 | return false; |
49 | 0 | } |
50 | 0 | ++i; |
51 | 0 | if (i == args.end()) { |
52 | 0 | status.SetError("called with incorrect number of arguments"); |
53 | 0 | return false; |
54 | 0 | } |
55 | 0 | } |
56 | | |
57 | | // OK, now we have the directory to process, we just get the requested |
58 | | // information out of it |
59 | | |
60 | 0 | if (*i == "DEFINITION") { |
61 | 0 | ++i; |
62 | 0 | if (i == args.end()) { |
63 | 0 | status.SetError("A request for a variable definition was made without " |
64 | 0 | "providing the name of the variable to get."); |
65 | 0 | return false; |
66 | 0 | } |
67 | 0 | std::string const& output = dir->GetSafeDefinition(*i); |
68 | 0 | status.GetMakefile().AddDefinition(variable, output); |
69 | 0 | return true; |
70 | 0 | } |
71 | | |
72 | 0 | if (i->empty()) { |
73 | 0 | status.SetError("given empty string for the property name to get"); |
74 | 0 | return false; |
75 | 0 | } |
76 | | |
77 | 0 | StoreResult(status.GetMakefile(), variable, dir->GetProperty(*i)); |
78 | 0 | return true; |
79 | 0 | } |
80 | | |
81 | | namespace { |
82 | | void StoreResult(cmMakefile& makefile, std::string const& variable, |
83 | | cmValue prop) |
84 | 0 | { |
85 | 0 | makefile.AddDefinition(variable, prop); |
86 | 0 | } |
87 | | } |