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:
@@ -31,7 +31,7 @@
|
||||
#include <utils/EntityManager.h>
|
||||
#include <utils/Path.h>
|
||||
|
||||
#include <getopt/getopt.h>
|
||||
#include <utils/getopt.h>
|
||||
|
||||
#include <filamentapp/Config.h>
|
||||
#include <filamentapp/FilamentApp.h>
|
||||
@@ -108,15 +108,15 @@ static void printUsage(char* name) {
|
||||
|
||||
static int handleCommandLineArgments(int argc, char* argv[], Config* config) {
|
||||
static constexpr const char* OPTSTR = "ha:";
|
||||
static const struct option OPTIONS[] = {
|
||||
{ "help", no_argument, nullptr, 'h' },
|
||||
{ "api", required_argument, nullptr, 'a' },
|
||||
{ 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' },
|
||||
{ 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 != nullptr ? optarg : "");
|
||||
while ((opt = utils::getopt::getopt_long(argc, argv, OPTSTR, OPTIONS, &option_index)) >= 0) {
|
||||
std::string arg(utils::getopt::optarg != nullptr ? utils::getopt::optarg : "");
|
||||
switch (opt) {
|
||||
default:
|
||||
case 'h':
|
||||
@@ -128,7 +128,7 @@ static int handleCommandLineArgments(int argc, char* argv[], Config* config) {
|
||||
}
|
||||
}
|
||||
|
||||
return optind;
|
||||
return utils::getopt::optind;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
Reference in New Issue
Block a user