MCPcopy Create free account
hub / github.com/Kitware/CMake / cmGetFilenameComponentCommand

Function cmGetFilenameComponentCommand

Source/cmGetFilenameComponentCommand.cxx:13–141  ·  view source on GitHub ↗

cmGetFilenameComponentCommand

Source from the content-addressed store, hash-verified

11
12// cmGetFilenameComponentCommand
13bool cmGetFilenameComponentCommand(std::vector<std::string> const& args,
14 cmExecutionStatus& status)
15{
16 if (args.size() < 3) {
17 status.SetError("called with incorrect number of arguments");
18 cmSystemTools::SetFatalErrorOccurred();
19 return false;
20 }
21
22 // Check and see if the value has been stored in the cache
23 // already, if so use that value
24 if (args.size() >= 4 && args.back() == "CACHE") {
25 cmValue cacheValue = status.GetMakefile().GetDefinition(args.front());
26 if (cacheValue && !cmIsNOTFOUND(*cacheValue)) {
27 return true;
28 }
29 }
30
31 std::string result;
32 std::string filename = args[1];
33 if (filename.find("[HKEY") != std::string::npos) {
34 // Check the registry as the target application would view it.
35 cmSystemTools::KeyWOW64 view = cmSystemTools::KeyWOW64_32;
36 cmSystemTools::KeyWOW64 other_view = cmSystemTools::KeyWOW64_64;
37 if (status.GetMakefile().PlatformIs64Bit()) {
38 view = cmSystemTools::KeyWOW64_64;
39 other_view = cmSystemTools::KeyWOW64_32;
40 }
41 cmSystemTools::ExpandRegistryValues(filename, view);
42 if (filename.find("/registry") != std::string::npos) {
43 std::string other = args[1];
44 cmSystemTools::ExpandRegistryValues(other, other_view);
45 if (other.find("/registry") == std::string::npos) {
46 filename = other;
47 }
48 }
49 }
50 std::string storeArgs;
51 std::string programArgs;
52 if (args[2] == "DIRECTORY" || args[2] == "PATH") {
53 result = cmSystemTools::GetFilenamePath(filename);
54 } else if (args[2] == "NAME") {
55 result = cmSystemTools::GetFilenameName(filename);
56 } else if (args[2] == "PROGRAM") {
57 for (unsigned int i = 2; i < args.size(); ++i) {
58 if (args[i] == "PROGRAM_ARGS") {
59 i++;
60 if (i < args.size()) {
61 storeArgs = args[i];
62 }
63 }
64 }
65
66 // First assume the path to the program was specified with no
67 // arguments and with no quoting or escaping for spaces.
68 // Only bother doing this if there is non-whitespace.
69 if (!cmTrimWhitespace(filename).empty()) {
70 result = cmSystemTools::FindProgram(filename);

Callers

nothing calls this directly

Calls 15

cmIsNOTFOUNDFunction · 0.85
cmTrimWhitespaceFunction · 0.85
GetRealPathFunction · 0.85
PlatformIs64BitMethod · 0.80
FileExistsFunction · 0.50
sizeMethod · 0.45
SetErrorMethod · 0.45
backMethod · 0.45
GetDefinitionMethod · 0.45
GetMakefileMethod · 0.45
frontMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…