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

Function HandleReadMachoCommand

Source/cmFileCommand_ReadMacho.cxx:17–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15#include <cmext/string_view>
16
17bool HandleReadMachoCommand(std::vector<std::string> const& args,
18 cmExecutionStatus& status)
19{
20 if (args.size() < 4) {
21 status.SetError("READ_MACHO must be called with at least three additional "
22 "arguments.");
23 return false;
24 }
25
26 std::string const& fileNameArg = args[1];
27
28 struct Arguments
29 {
30 std::string Architectures;
31 std::string Error;
32 };
33
34 static auto const parser =
35 cmArgumentParser<Arguments>{}
36 .Bind("ARCHITECTURES"_s, &Arguments::Architectures)
37 .Bind("CAPTURE_ERROR"_s, &Arguments::Error);
38 Arguments const arguments = parser.Parse(cmMakeRange(args).advance(2),
39 /*unparsedArguments=*/nullptr);
40
41 if (!arguments.Architectures.empty()) {
42 // always return something sensible for ARCHITECTURES
43 status.GetMakefile().AddDefinition(arguments.Architectures, "unknown"_s);
44 }
45 if (!cmSystemTools::FileExists(fileNameArg, true)) {
46 if (arguments.Error.empty()) {
47 status.SetError(cmStrCat("READ_MACHO given FILE \"", fileNameArg,
48 "\" that does not exist."));
49 return false;
50 }
51 status.GetMakefile().AddDefinition(
52 arguments.Error, cmStrCat(fileNameArg, " does not exist"));
53 return true;
54 }
55
56#if defined(CMake_USE_MACH_PARSER)
57 cmMachO macho(fileNameArg.c_str());
58 if (!macho) {
59 if (arguments.Error.empty()) {
60 status.SetError(cmStrCat("READ_MACHO given FILE:\n ", fileNameArg,
61 "\nthat is not a valid Macho-O file."));
62 return false;
63 }
64 status.GetMakefile().AddDefinition(
65 arguments.Error, cmStrCat(fileNameArg, " is not a valid Macho-O file"));
66 return true;
67 } else if (!macho.GetErrorMessage().empty()) {
68 if (arguments.Error.empty()) {
69 status.SetError(cmStrCat(
70 "READ_MACHO given FILE:\n ", fileNameArg,
71 "\nthat is not a supported Macho-O file: ", macho.GetErrorMessage()));
72 return false;
73 }
74 status.GetMakefile().AddDefinition(

Callers

nothing calls this directly

Calls 15

cmMakeRangeFunction · 0.85
c_strMethod · 0.80
GetArchitecturesMethod · 0.80
cmStrCatFunction · 0.70
cmJoinFunction · 0.70
FileExistsFunction · 0.50
sizeMethod · 0.45
SetErrorMethod · 0.45
BindMethod · 0.45
ParseMethod · 0.45
advanceMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…