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:
@@ -68,7 +68,7 @@
|
||||
#include <math/vec3.h>
|
||||
#include <math/vec4.h>
|
||||
|
||||
#include <getopt/getopt.h>
|
||||
#include <utils/getopt.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
@@ -151,7 +151,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"
|
||||
" --scale=[number], -s [number]\n"
|
||||
" Applies uniform scale\n\n"
|
||||
" --material=<path>, -m <path>\n"
|
||||
@@ -186,25 +186,25 @@ static void printUsage(char* name) {
|
||||
// Parses command line arguments and populates the Config object.
|
||||
static int handleCommandLineArguments(int argc, char* argv[], Config* config) {
|
||||
static constexpr const char* OPTSTR = "ha:s:li:m:c:p:x:yb:S:";
|
||||
static const struct option OPTIONS[] = {
|
||||
{ "help", no_argument, nullptr, 'h' },
|
||||
{ "api", required_argument, nullptr, 'a' },
|
||||
{ "ibl", required_argument, nullptr, 'i' },
|
||||
{ "scale", required_argument, nullptr, 's' },
|
||||
{ "material", required_argument, nullptr, 'm' },
|
||||
{ "params", required_argument, nullptr, 'p' },
|
||||
{ "count", required_argument, nullptr, 'c' },
|
||||
{ "light-on", no_argument, nullptr, 'l' },
|
||||
{ "skybox-off", no_argument, nullptr, 'y' },
|
||||
{ "prefix", required_argument, nullptr, 'x' },
|
||||
{ "clear-color", required_argument, nullptr, 'b' },
|
||||
{ "size", required_argument, nullptr, 'S' },
|
||||
{ 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' },
|
||||
{ "scale", utils::getopt::required_argument, nullptr, 's' },
|
||||
{ "material", utils::getopt::required_argument, nullptr, 'm' },
|
||||
{ "params", utils::getopt::required_argument, nullptr, 'p' },
|
||||
{ "count", utils::getopt::required_argument, nullptr, 'c' },
|
||||
{ "light-on", utils::getopt::no_argument, nullptr, 'l' },
|
||||
{ "skybox-off", utils::getopt::no_argument, nullptr, 'y' },
|
||||
{ "prefix", utils::getopt::required_argument, nullptr, 'x' },
|
||||
{ "clear-color", utils::getopt::required_argument, nullptr, 'b' },
|
||||
{ "size", utils::getopt::required_argument, nullptr, 'S' },
|
||||
{ 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 const arg(optarg ? optarg : "");
|
||||
while ((opt = utils::getopt::getopt_long(argc, argv, OPTSTR, OPTIONS, &option_index)) >= 0) {
|
||||
std::string const arg(utils::getopt::optarg ? utils::getopt::optarg : "");
|
||||
switch (opt) {
|
||||
default:
|
||||
case 'h':
|
||||
@@ -272,7 +272,7 @@ static int handleCommandLineArguments(int argc, char* argv[], Config* config) {
|
||||
}
|
||||
}
|
||||
|
||||
return optind;
|
||||
return utils::getopt::optind;
|
||||
}
|
||||
|
||||
// Cleans up Filament resources (entities, materials, etc.) before exit.
|
||||
|
||||
Reference in New Issue
Block a user