234{
235 llvm::cl::OptionCategory category("mayaflux-signatures options");
236 llvm::cl::opt<std::string> root("root",
237 llvm::cl::desc("Repository root holding src/"),
238 llvm::cl::value_desc("dir"), llvm::cl::init("."), llvm::cl::cat(category));
239 llvm::cl::opt<std::string> registry("registry",
240 llvm::cl::desc("Registry header (default: <root>/src/MayaFlux/API/Proxy/Registry.hpp)"),
241 llvm::cl::value_desc("file"), llvm::cl::cat(category));
242 llvm::cl::opt<std::string> output("output",
243 llvm::cl::desc("Directory the generated files are written to (default: <root>/src/MayaFlux/API/Proxy/Generated)"),
244 llvm::cl::value_desc("dir"), llvm::cl::cat(category));
245 llvm::cl::opt<std::string> build_path("p",
246 llvm::cl::desc("Directory holding compile_commands.json"),
247 llvm::cl::value_desc("dir"), llvm::cl::init("build"), llvm::cl::cat(category));
248 llvm::cl::opt<std::string> translation_unit("translation-unit",
249 llvm::cl::desc("Source file whose compile command is borrowed (default: <root>/src/MayaFlux/API/Proxy/Creator.cpp)"),
250 llvm::cl::value_desc("file"), llvm::cl::cat(category));
251 llvm::cl::opt<std::string> resource_dir("resource-dir",
252 llvm::cl::desc("Clang resource directory holding the builtin headers"),
254 llvm::cl::cat(category));
255 llvm::cl::list<std::string> extra_args("extra-arg",
256 llvm::cl::desc("Extra Clang argument added to the scan"),
257 llvm::cl::value_desc("argument"), llvm::cl::cat(category));
258 llvm::cl::opt<bool> check("check",
259 llvm::cl::desc("Write nothing; exit 1 when a generated file is out of date"),
260 llvm::cl::cat(category));
261 llvm::cl::opt<bool> functions("functions",
262 llvm::cl::desc("Write a Name.signatures.hpp sidecar beside each header that holds MF_DESCRIBE_FUNCTION "
263 "requests, instead of the Creator methods. A header with requests must not use its own sidecar"),
264 llvm::cl::cat(category));
265 llvm::cl::opt<bool> no_insert_include("no-insert-include",
266 llvm::cl::desc("With --functions, report a missing sidecar include instead of inserting it"),
267 llvm::cl::cat(category));
268 llvm::cl::opt<bool> build("build",
269 llvm::cl::desc("Build step: write the Creator files and mark them modified, or with --functions the "
270 "sidecar of the one header given, inserting its include when missing. Needs "
271 "--translation-unit (defaulted) with a compile database, or --compile-arg"),
272 llvm::cl::cat(category));
273 llvm::cl::list<std::string> compile_args("compile-arg",
274 llvm::cl::desc("With --build: one argument of the whole compile command, used instead of the database"),
275 llvm::cl::value_desc("argument"), llvm::cl::cat(category));
276 llvm::cl::opt<std::string> depfile("depfile",
277 llvm::cl::desc("With --build: write a depfile of the registry and the headers the scan read"),
278 llvm::cl::value_desc("file"), llvm::cl::cat(category));
279 llvm::cl::opt<std::string> depfile_target("depfile-target",
280 llvm::cl::desc("With --build: the target named in the depfile (default: CreatorIncludes.hpp in the output)"),
281 llvm::cl::value_desc("path"), llvm::cl::cat(category));
282 llvm::cl::list<std::string> paths(llvm::cl::Positional,
283 llvm::cl::desc("<path>... (with --functions: headers or directories searched, default src/MayaFlux)"),
284 llvm::cl::cat(category));
285
286 llvm::cl::HideUnrelatedOptions(category);
287 llvm::cl::ParseCommandLineOptions(argc, argv,
288 "Writes the Creator proxy's methods from the public constructors of the registered classes, or with "
289 "--functions the parameter names of the functions named by MF_DESCRIBE_FUNCTION.\n");
290
291 Config config;
292 config.root = root.getValue();
293 const std::filesystem::path proxy = config.root / "src/MayaFlux/API/Proxy";
294 config.registry = registry.empty() ? proxy / "Registry.hpp" : std::filesystem::path(registry.getValue());
295 config.output = output.empty() ? proxy / "Generated" : std::filesystem::path(output.getValue());
296 config.build_path = build_path.getValue();
297 config.translation_unit = translation_unit.empty() ? proxy / "Creator.cpp" : std::filesystem::path(translation_unit.getValue());
298 config.resource_dir = resource_dir.getValue();
299 config.extra_args.assign(extra_args.begin(), extra_args.end());
300 config.check = check;
301 config.functions = functions;
302 config.insert_includes = !no_insert_include;
303 config.paths.assign(paths.begin(), paths.end());
304
305 if (build && config.functions) {
306 if (config.check || config.paths.size() != 1) {
307 return fail("--functions --build takes exactly one header, and no --check");
308 }
310 options.
header = config.paths.front();
315 options.
compile_args.assign(compile_args.begin(), compile_args.end());
316 options.
depfile = depfile.getValue();
320 }
321
322 if (build) {
323 if (config.check || !config.paths.empty()) {
324 return fail("--build writes the Creator files; it takes no --check or paths");
325 }
327 options.
root = config.root;
329 options.
output = config.output;
334 options.
compile_args.assign(compile_args.begin(), compile_args.end());
335 options.
depfile = depfile.getValue();
338 }
339
340 return config.functions ? generate_functions(config) : generate(config);
341}
#define MAYAFLUX_REFLECT_RESOURCE_DIR