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

@@ -21,7 +21,7 @@
#include <map>
#include <vector>
#include <getopt/getopt.h>
#include <utils/getopt.h>
#include <utils/Path.h>
@@ -82,7 +82,7 @@ static void printUsage(char* name) {
" Prints this message\n\n"
"API_USAGE"
" --ibl=<path to cmgen IBL>, -i <path>\n"
" Applies an IBL generated by cmgen's deploy option\n\n"
" Applies an IBL generated by cmgen's deploy utils::getopt::option\n\n"
" --split-view, -v\n"
" Splits the window into 4 views\n\n"
" --scale=[number], -s [number]\n"
@@ -107,21 +107,21 @@ static void printUsage(char* name) {
static int handleCommandLineArgments(int argc, char* argv[], Config* config) {
static constexpr const char* OPTSTR = "ha:i:vs:n:a:c:b:";
static const struct option OPTIONS[] = {
{ "help", no_argument, nullptr, 'h' },
{ "api", required_argument, nullptr, 'a' },
{ "ibl", required_argument, nullptr, 'i' },
{ "split-view", no_argument, nullptr, 'v' },
{ "scale", required_argument, nullptr, 's' },
{ "normal-map", required_argument, nullptr, 'n' },
{ "clear-coat-normal-map", required_argument, nullptr, 'c' },
{ "basecolor-map", required_argument, nullptr, 'b' },
{ nullptr, 0, nullptr, 0 } // termination of the option list
static const utils::getopt::option OPTIONS[] = {
{ "help", utils::getopt::no_argument, nullptr, 'h' },
{ "api", utils::getopt::required_argument, nullptr, 'a' },
{ "ibl", utils::getopt::required_argument, nullptr, 'i' },
{ "split-view", utils::getopt::no_argument, nullptr, 'v' },
{ "scale", utils::getopt::required_argument, nullptr, 's' },
{ "normal-map", utils::getopt::required_argument, nullptr, 'n' },
{ "clear-coat-normal-map", utils::getopt::required_argument, nullptr, 'c' },
{ "basecolor-map", utils::getopt::required_argument, nullptr, 'b' },
{ nullptr, 0, nullptr, 0 } // termination of the utils::getopt::option list
};
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':
@@ -157,7 +157,7 @@ static int handleCommandLineArgments(int argc, char* argv[], Config* config) {
}
}
return optind;
return utils::getopt::optind;
}
static void cleanup(Engine* engine, View*, Scene*) {