utils: refactor getopt into utils namespace (#9796)

On certain linux, macOS environment, there is already a system
getopt. This often creates conflict when compiling filament.
Here we alias utils::getopt to either the system getopt (if
present) or third_party/getopt.

Fixes #7551
This commit is contained in:
Powei Feng
2026-03-13 17:22:44 -07:00
committed by GitHub
parent 497a1cc42d
commit 749b03ed2a
68 changed files with 716 additions and 654 deletions

View File

@@ -37,7 +37,7 @@
#include <filamentapp/Config.h>
#include <filamentapp/FilamentApp.h>
#include <getopt/getopt.h>
#include <utils/getopt.h>
#include <iostream>
@@ -149,16 +149,16 @@ static void printUsage(char* name) {
static int handleCommandLineArguments(int argc, char* argv[], App* app) {
static constexpr const char* OPTSTR = "ha:m:";
static const struct option OPTIONS[] = {
{ "help", no_argument, nullptr, 'h' },
{ "api", required_argument, nullptr, 'a' },
{ "mode", required_argument, nullptr, 'm' },
static const utils::getopt::option OPTIONS[] = {
{ "help", utils::getopt::no_argument, nullptr, 'h' },
{ "api", utils::getopt::required_argument, nullptr, 'a' },
{ "mode", utils::getopt::required_argument, nullptr, 'm' },
{ nullptr, 0, nullptr, 0 }
};
int opt;
int option_index = 0;
while ((opt = getopt_long(argc, argv, OPTSTR, OPTIONS, &option_index)) >= 0) {
std::string arg(optarg ? optarg : "");
while ((opt = utils::getopt::getopt_long(argc, argv, OPTSTR, OPTIONS, &option_index)) >= 0) {
std::string arg(utils::getopt::optarg ? utils::getopt::optarg : "");
switch (opt) {
default:
case 'h':
@@ -179,7 +179,7 @@ static int handleCommandLineArguments(int argc, char* argv[], App* app) {
break;
}
}
return optind;
return utils::getopt::optind;
}
int main(int argc, char** argv) {