QMakeGlobals::ArgumentReturn QMakeGlobals::addCommandLineArguments( QMakeCmdLineParserState &state, QStringList &args, int *pos) { enum { ArgNone, ArgConfig, ArgSpec, ArgXSpec, ArgTmpl, ArgTmplPfx, ArgCache } argState = ArgNone; for (; *pos < args.count(); (*pos)++) { QString arg = args.at(*pos); switch (argState) { case ArgConfig: if (state.after) state.postconfigs << arg; else state.preconfigs << arg; break; case ArgSpec: qmakespec = args[*pos] = cleanSpec(state, arg); break; case ArgXSpec: xqmakespec = args[*pos] = cleanSpec(state, arg); break; case ArgTmpl: user_template = arg; break; case ArgTmplPfx: user_template_prefix = arg; break; case ArgCache: cachefile = args[*pos] = QDir::cleanPath(QDir(state.pwd).absoluteFilePath(arg)); break; default: if (arg.startsWith(QLatin1Char('-'))) { if (arg == QLatin1String("-after")) state.after = true; else if (arg == QLatin1String("-config")) argState = ArgConfig; else if (arg == QLatin1String("-nocache")) do_cache = false; else if (arg == QLatin1String("-cache")) argState = ArgCache; else if (arg == QLatin1String("-platform") || arg == QLatin1String("-spec")) argState = ArgSpec; else if (arg == QLatin1String("-xplatform") || arg == QLatin1String("-xspec")) argState = ArgXSpec; else if (arg == QLatin1String("-template") || arg == QLatin1String("-t")) argState = ArgTmpl; else if (arg == QLatin1String("-template_prefix") || arg == QLatin1String("-tp")) argState = ArgTmplPfx; else if (arg == QLatin1String("-win32")) dir_sep = QLatin1Char('\\'); else if (arg == QLatin1String("-unix")) dir_sep = QLatin1Char('/'); else return ArgumentUnknown; } else if (arg.contains(QLatin1Char('='))) { if (state.after) state.postcmds << arg; else state.precmds << arg; } else { return ArgumentUnknown; } continue; } argState = ArgNone; } if (argState != ArgNone) return ArgumentMalformed; return ArgumentsOk; }
int Option::parseCommandLine(QStringList &args) { QStringList user_configs; bool before = true; args << QString(); // Avoid bounds checking for options which take an argument for (int x = 0; x < args.size() - 1; ) { QString arg = args.at(x); if (arg.size() > 1 && arg.startsWith('-')) { /* options */ QString opt = arg.mid(1); if(opt == "o" || opt == "output") { Option::output.setFileName(args.at(x + 1)); args.erase(args.begin() + x, args.begin() + x + 2); continue; } else if(opt == "after") { before = false; } else if(opt == "t" || opt == "template") { Option::user_template = args.at(++x); } else if(opt == "tp" || opt == "template_prefix") { Option::user_template_prefix = args.at(++x); } else if(opt == "unix") { Option::dir_sep = "/"; } else if(opt == "win32") { Option::dir_sep = "\\"; } else if(opt == "d") { Option::debug_level++; } else if(opt == "version" || opt == "v" || opt == "-version") { fprintf(stdout, "QMake version %s\n" "Using Qt version %s in %s\n", qmake_version(), QT_VERSION_STR, QLibraryInfo::location(QLibraryInfo::LibrariesPath).toLatin1().constData()); #ifdef QMAKE_OPENSOURCE_VERSION fprintf(stdout, "QMake is Open Source software from Nokia Corporation and/or its subsidiary(-ies).\n"); #endif return Option::QMAKE_CMDLINE_BAIL; } else if(opt == "h" || opt == "help") { return Option::QMAKE_CMDLINE_SHOW_USAGE; } else if(opt == "Wall") { Option::warn_level |= WarnAll; } else if(opt == "Wparser") { Option::warn_level |= WarnParser; } else if(opt == "Wlogic") { Option::warn_level |= WarnLogic; } else if(opt == "Wdeprecated") { Option::warn_level |= WarnDeprecated; } else if(opt == "Wnone") { Option::warn_level = WarnNone; } else if(opt == "r" || opt == "recursive") { Option::recursive = true; args.removeAt(x); continue; } else if(opt == "nr" || opt == "norecursive") { Option::recursive = false; args.removeAt(x); continue; } else if(opt == "config") { user_configs += args.at(++x); } else { if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE || Option::qmake_mode == Option::QMAKE_GENERATE_PRL) { if(opt == "nodepend" || opt == "nodepends") { Option::mkfile::do_deps = false; } else if(opt == "nomoc") { Option::mkfile::do_mocs = false; } else if(opt == "nocache") { Option::mkfile::do_cache = false; } else if(opt == "createstub") { Option::mkfile::do_stub_makefile = true; } else if(opt == "nodependheuristics") { Option::mkfile::do_dep_heuristics = false; } else if(opt == "E") { Option::mkfile::do_preprocess = true; } else if(opt == "cache") { Option::mkfile::cachefile = args.at(++x); } else if(opt == "platform" || opt == "spec") { Option::mkfile::qmakespec = args[x] = cleanSpec(args.at(++x)); } else if (opt == "xplatform" || opt == "xspec") { Option::mkfile::xqmakespec = args[x] = cleanSpec(args.at(x)); } else { fprintf(stderr, "***Unknown option -%s\n", opt.toLatin1().constData()); return Option::QMAKE_CMDLINE_SHOW_USAGE | Option::QMAKE_CMDLINE_ERROR; } } else if(Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT) { if(opt == "nopwd") { Option::projfile::do_pwd = false; } else { fprintf(stderr, "***Unknown option -%s\n", opt.toLatin1().constData()); return Option::QMAKE_CMDLINE_SHOW_USAGE | Option::QMAKE_CMDLINE_ERROR; } } } } else { if(arg.indexOf('=') != -1) { if(before) Option::before_user_vars.append(arg); else Option::after_user_vars.append(arg); } else { bool handled = true; if(Option::qmake_mode == Option::QMAKE_QUERY_PROPERTY || Option::qmake_mode == Option::QMAKE_SET_PROPERTY || Option::qmake_mode == Option::QMAKE_UNSET_PROPERTY) { Option::prop::properties.append(arg); } else { QFileInfo fi(arg); if(!fi.makeAbsolute()) //strange arg = fi.filePath(); if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE || Option::qmake_mode == Option::QMAKE_GENERATE_PRL) { if(fi.isDir()) { QString proj = detectProjectFile(arg); if (!proj.isNull()) arg = proj; } Option::mkfile::project_files.append(arg); } else if(Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT) { Option::projfile::project_dirs.append(arg); } else { handled = false; } } if(!handled) { return Option::QMAKE_CMDLINE_SHOW_USAGE | Option::QMAKE_CMDLINE_ERROR; } args.removeAt(x); continue; } } x++; } if (!user_configs.isEmpty()) Option::before_user_vars += "CONFIG += " + user_configs.join(" "); if (Option::mkfile::xqmakespec.isEmpty()) Option::mkfile::xqmakespec = Option::mkfile::qmakespec; args.takeLast(); return Option::QMAKE_CMDLINE_SUCCESS; }