diff --git a/CMakeLists.txt b/CMakeLists.txt index e5f2444165..9d6494998d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -869,6 +869,12 @@ endfunction() # Sub-projects # ================================================================================================== +include(CheckSymbolExists) +check_symbol_exists(getopt_long "getopt.h" HAS_SYSTEM_GETOPT) +if (NOT HAS_SYSTEM_GETOPT) + add_subdirectory(${EXTERNAL}/getopt) +endif() + # Common to all platforms add_subdirectory(${EXTERNAL}/libgtest/tnt) add_subdirectory(${LIBRARIES}/camutils) @@ -904,7 +910,6 @@ add_subdirectory(${EXTERNAL}/cgltf/tnt) add_subdirectory(${EXTERNAL}/draco/tnt) add_subdirectory(${EXTERNAL}/jsmn/tnt) add_subdirectory(${EXTERNAL}/stb/tnt) -add_subdirectory(${EXTERNAL}/getopt) add_subdirectory(${EXTERNAL}/perfetto/tnt) add_subdirectory(${EXTERNAL}/basisu/tnt) diff --git a/filament/backend/CMakeLists.txt b/filament/backend/CMakeLists.txt index 2b6b316610..5e0ae99b47 100644 --- a/filament/backend/CMakeLists.txt +++ b/filament/backend/CMakeLists.txt @@ -616,7 +616,6 @@ if (FILAMENT_BUILD_TESTING) set(BACKEND_TEST_LIBS absl::str_format backend - getopt gtest imageio filamat @@ -725,7 +724,6 @@ if (FILAMENT_BUILD_TESTING) target_link_libraries(metal_utils_test PRIVATE backend - getopt gtest ) diff --git a/filament/backend/test/Arguments.cpp b/filament/backend/test/Arguments.cpp index 35ba3f35c1..639515cd02 100644 --- a/filament/backend/test/Arguments.cpp +++ b/filament/backend/test/Arguments.cpp @@ -16,7 +16,7 @@ #include "PlatformRunner.h" -#include +#include #include #include @@ -30,18 +30,18 @@ TestArguments parseArguments(int argc, char* argv[]) { // The first colon in OPTSTR turns on silent error reporting. This is important, as the // arguments may also contain gtest parameters we don't know about. static constexpr const char* OPTSTR = ":a:kc"; - static const struct option OPTIONS[] = { - { "api", required_argument, nullptr, 'a' }, - { "headless_only", no_argument, nullptr, 'k' }, - { "ci", no_argument, nullptr, 'c' }, - { nullptr, 0, nullptr, 0 } // termination of the option list + static const utils::getopt::option OPTIONS[] = { + { "api", utils::getopt::required_argument, nullptr, 'a' }, + { "headless_only", utils::getopt::no_argument, nullptr, 'k' }, + { "ci", utils::getopt::no_argument, nullptr, 'c' }, + { nullptr, 0, nullptr, 0 } // termination of the utils::getopt::option list }; int opt; int optionIndex = 0; - while ((opt = getopt_long(argc, argv, OPTSTR, OPTIONS, &optionIndex)) >= 0) { - std::string arg(optarg ? optarg : ""); + while ((opt = utils::getopt::getopt_long(argc, argv, OPTSTR, OPTIONS, &optionIndex)) >= 0) { + std::string arg(utils::getopt::optarg ? utils::getopt::optarg : ""); switch (opt) { case 'a': if (arg == "opengl") { diff --git a/libs/filament-matp/CMakeLists.txt b/libs/filament-matp/CMakeLists.txt index e7199d709d..b3797b532e 100644 --- a/libs/filament-matp/CMakeLists.txt +++ b/libs/filament-matp/CMakeLists.txt @@ -44,7 +44,7 @@ target_include_directories(${TARGET} PUBLIC ${PUBLIC_HDR_DIR}) target_include_directories(${TARGET} PRIVATE ${filamat_SOURCE_DIR}/src) set_target_properties(${TARGET} PROPERTIES FOLDER Libs) -target_link_libraries(${TARGET} getopt filamat filabridge utils) +target_link_libraries(${TARGET} filamat filabridge utils) # ================================================================================================== # Installation diff --git a/libs/filamentapp/CMakeLists.txt b/libs/filamentapp/CMakeLists.txt index 265930bfad..67b16dae5a 100644 --- a/libs/filamentapp/CMakeLists.txt +++ b/libs/filamentapp/CMakeLists.txt @@ -52,7 +52,7 @@ set(LIBS filament filament-iblprefilter geometry - getopt + image imageio imgui diff --git a/libs/utils/CMakeLists.txt b/libs/utils/CMakeLists.txt index 70815fc7eb..db2faba36d 100644 --- a/libs/utils/CMakeLists.txt +++ b/libs/utils/CMakeLists.txt @@ -12,6 +12,7 @@ set(PUBLIC_HDR_DIR include) file(GLOB_RECURSE PUBLIC_HDRS ${PUBLIC_HDR_DIR}/${TARGET}/*.h) set(DIST_HDRS + ${PUBLIC_HDR_DIR}/${TARGET}/getopt.h ${PUBLIC_HDR_DIR}/${TARGET}/algorithm.h ${PUBLIC_HDR_DIR}/${TARGET}/bitset.h ${PUBLIC_HDR_DIR}/${TARGET}/CallStack.h @@ -122,6 +123,11 @@ endif() include_directories(${PUBLIC_HDR_DIR}) add_library(${TARGET} STATIC ${PUBLIC_HDRS} ${SRCS}) +if (HAS_SYSTEM_GETOPT) + target_compile_definitions(${TARGET} PUBLIC HAS_SYSTEM_GETOPT) +else() + target_link_libraries(${TARGET} PUBLIC getopt) +endif() target_include_directories(${TARGET} PUBLIC ${PUBLIC_HDR_DIR}) set_target_properties(${TARGET} PROPERTIES FOLDER Libs) target_link_libraries(${TARGET} PUBLIC tsl) diff --git a/libs/utils/include/utils/getopt.h b/libs/utils/include/utils/getopt.h new file mode 100644 index 0000000000..27fa92bae1 --- /dev/null +++ b/libs/utils/include/utils/getopt.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2026 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef UTILS_GETOPT_H +#define UTILS_GETOPT_H + +// If system has getopt, we just include it +#if defined(HAS_SYSTEM_GETOPT) +#include +#else +#include +#endif + +#ifdef __cplusplus + +#undef no_argument +#undef required_argument +#undef optional_argument + +// This is an aliasing of getopt to prevent compilation conflicts with the system getop (if +// it exists). Please refer to third_party/getopt for API details. +namespace utils { +namespace getopt { + using ::getopt; + using ::optarg; + using ::optind; + using ::opterr; + using ::optopt; + using ::option; + using ::getopt_long; + using ::getopt_long_only; + + constexpr int no_argument = 0; + constexpr int required_argument = 1; + constexpr int optional_argument = 2; +} +} +#endif // __cplusplus + +#endif // UTILS_GETOPT_H diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 9015104988..1799575dd6 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -228,7 +228,6 @@ add_library(samples-common STATIC ) target_include_directories(samples-common PRIVATE - ${ROOT_DIR}/third_party/getopt/include ) target_link_libraries(samples-common filament) diff --git a/samples/common/arguments.cpp b/samples/common/arguments.cpp index 4238601543..84bba06cf9 100644 --- a/samples/common/arguments.cpp +++ b/samples/common/arguments.cpp @@ -20,7 +20,7 @@ #include -#include +#include #include #include @@ -73,16 +73,16 @@ filament::Engine::Backend parseArgumentsForBackend(int argc, char* argv[]) { // The first colon in OPTSTR turns on silent error reporting. This is important, as the // arguments may also contain gtest parameters we don't know about. static constexpr const char* OPTSTR = "ha:"; - static const struct option OPTIONS[] = { - { "help", no_argument, nullptr, 'h' }, - { "api", required_argument, nullptr, 'a' }, + static const utils::getopt::option OPTIONS[] = { + { "help", utils::getopt::no_argument, nullptr, 'h' }, + { "api", utils::getopt::required_argument, nullptr, 'a' }, { nullptr, 0, nullptr, 0 } }; int opt; int optionIndex = 0; - while ((opt = getopt_long(argc, argv, OPTSTR, OPTIONS, &optionIndex)) >= 0) { - std::string arg(optarg ? optarg : ""); + while ((opt = utils::getopt::getopt_long(argc, argv, OPTSTR, OPTIONS, &optionIndex)) >= 0) { + std::string arg(utils::getopt::optarg ? utils::getopt::optarg : ""); switch (opt) { default: case 'h': diff --git a/samples/frame_generator.cpp b/samples/frame_generator.cpp index aeeee141b0..95cf6175c5 100644 --- a/samples/frame_generator.cpp +++ b/samples/frame_generator.cpp @@ -68,7 +68,7 @@ #include #include -#include +#include #include #include @@ -151,7 +151,7 @@ static void printUsage(char* name) { " Prints this message\n\n" "API_USAGE" " --ibl=, -i \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=, -m \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. diff --git a/samples/gltf_instances.cpp b/samples/gltf_instances.cpp index cb0eb932c8..64aa81a0ac 100644 --- a/samples/gltf_instances.cpp +++ b/samples/gltf_instances.cpp @@ -36,7 +36,7 @@ #include -#include +#include #include @@ -112,19 +112,19 @@ static void printUsage(char* name) { static int handleCommandLineArguments(int argc, char* argv[], App* app) { static constexpr const char* OPTSTR = "ha:i:un:m:"; - static const struct option OPTIONS[] = { - { "help", no_argument, nullptr, 'h' }, - { "api", required_argument, nullptr, 'a' }, - { "ibl", required_argument, nullptr, 'i' }, - { "num", required_argument, nullptr, 'n' }, - { "animate", required_argument, nullptr, 'm' }, - { "ubershader", no_argument, nullptr, 'u' }, + 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' }, + { "num", utils::getopt::required_argument, nullptr, 'n' }, + { "animate", utils::getopt::required_argument, nullptr, 'm' }, + { "ubershader", utils::getopt::no_argument, nullptr, 'u' }, { 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': @@ -147,7 +147,7 @@ static int handleCommandLineArguments(int argc, char* argv[], App* app) { break; } } - return optind; + return utils::getopt::optind; } static std::ifstream::pos_type getFileSize(const char* filename) { diff --git a/samples/gltf_viewer.cpp b/samples/gltf_viewer.cpp index 82df3bddb0..46a091c8cc 100644 --- a/samples/gltf_viewer.cpp +++ b/samples/gltf_viewer.cpp @@ -46,7 +46,7 @@ #include -#include +#include #include #include @@ -219,29 +219,29 @@ static std::ifstream::pos_type getFileSize(const char* filename) { static int handleCommandLineArguments(int argc, char* argv[], App* app) { static constexpr const char* OPTSTR = "ha:f:i:usc:rt:y:b:evg:dw:"; - static const struct option OPTIONS[] = { - { "help", no_argument, nullptr, 'h' }, - { "api", required_argument, nullptr, 'a' }, - { "feature-level", required_argument, nullptr, 'f' }, - { "batch", required_argument, nullptr, 'b' }, - { "headless", no_argument, nullptr, 'e' }, - { "ibl", required_argument, nullptr, 'i' }, - { "ubershader", no_argument, nullptr, 'u' }, - { "actual-size", no_argument, nullptr, 's' }, - { "camera", required_argument, nullptr, 'c' }, - { "eyes", required_argument, nullptr, 'y' }, - { "recompute-aabb", no_argument, nullptr, 'r' }, - { "settings", required_argument, nullptr, 't' }, - { "split-view", no_argument, nullptr, 'v' }, - { "vulkan-gpu-hint", required_argument, nullptr, 'g' }, - { "screenshot-as-ppm", no_argument, nullptr, 'd' }, - { "webgpu-backend", required_argument, nullptr, 'w' }, + static const utils::getopt::option OPTIONS[] = { + { "help", utils::getopt::no_argument, nullptr, 'h' }, + { "api", utils::getopt::required_argument, nullptr, 'a' }, + { "feature-level", utils::getopt::required_argument, nullptr, 'f' }, + { "batch", utils::getopt::required_argument, nullptr, 'b' }, + { "headless", utils::getopt::no_argument, nullptr, 'e' }, + { "ibl", utils::getopt::required_argument, nullptr, 'i' }, + { "ubershader", utils::getopt::no_argument, nullptr, 'u' }, + { "actual-size", utils::getopt::no_argument, nullptr, 's' }, + { "camera", utils::getopt::required_argument, nullptr, 'c' }, + { "eyes", utils::getopt::required_argument, nullptr, 'y' }, + { "recompute-aabb", utils::getopt::no_argument, nullptr, 'r' }, + { "settings", utils::getopt::required_argument, nullptr, 't' }, + { "split-view", utils::getopt::no_argument, nullptr, 'v' }, + { "vulkan-gpu-hint", utils::getopt::required_argument, nullptr, 'g' }, + { "screenshot-as-ppm", utils::getopt::no_argument, nullptr, 'd' }, + { "webgpu-backend", utils::getopt::required_argument, nullptr, 'w' }, { nullptr, 0, nullptr, 0 } }; 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': @@ -327,7 +327,7 @@ static int handleCommandLineArguments(int argc, char* argv[], App* app) { std::cerr << "--headless is allowed only when --batch is present." << std::endl; app->config.headless = false; } - return optind; + return utils::getopt::optind; } static bool loadSettings(const char* filename, Settings* out) { diff --git a/samples/heightfield.cpp b/samples/heightfield.cpp index d5ffce6dec..16bbf3734f 100644 --- a/samples/heightfield.cpp +++ b/samples/heightfield.cpp @@ -34,7 +34,7 @@ #include #include -#include +#include #include @@ -123,15 +123,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': @@ -143,7 +143,7 @@ static int handleCommandLineArgments(int argc, char* argv[], Config* config) { } } - return optind; + return utils::getopt::optind; } template diff --git a/samples/helloasync.cpp b/samples/helloasync.cpp index b4cd2db5b2..2d98d15933 100644 --- a/samples/helloasync.cpp +++ b/samples/helloasync.cpp @@ -37,7 +37,7 @@ #include #include -#include +#include #include @@ -94,15 +94,15 @@ static void printUsage(char* name) { static int handleCommandLineArguments(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' }, + static const utils::getopt::option OPTIONS[] = { + { "help", utils::getopt::no_argument, nullptr, 'h' }, + { "api", utils::getopt::required_argument, nullptr, 'a' }, { 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': @@ -113,7 +113,7 @@ static int handleCommandLineArguments(int argc, char* argv[], Config& config) { break; } } - return optind; + return utils::getopt::optind; } struct App { diff --git a/samples/hellomorphing.cpp b/samples/hellomorphing.cpp index bae7fbbcd1..e8e9437ba4 100644 --- a/samples/hellomorphing.cpp +++ b/samples/hellomorphing.cpp @@ -31,7 +31,7 @@ #include #include -#include +#include #include #include @@ -113,15 +113,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': @@ -133,7 +133,7 @@ static int handleCommandLineArgments(int argc, char* argv[], Config* config) { } } - return optind; + return utils::getopt::optind; } int main(int argc, char** argv) { diff --git a/samples/hellopbr.cpp b/samples/hellopbr.cpp index c5b0af2d4b..6f1f383e4e 100644 --- a/samples/hellopbr.cpp +++ b/samples/hellopbr.cpp @@ -31,7 +31,7 @@ #include #include -#include +#include #include #include // for printing usage/help @@ -80,15 +80,15 @@ static void printUsage(char* name) { static int handleCommandLineArguments(int argc, char* argv[], App* app) { static constexpr const char* OPTSTR = "ha:"; - static const struct option OPTIONS[] = { - { "help", no_argument, nullptr, 'h' }, - { "api", required_argument, nullptr, 'a' }, + static const utils::getopt::option OPTIONS[] = { + { "help", utils::getopt::no_argument, nullptr, 'h' }, + { "api", utils::getopt::required_argument, nullptr, 'a' }, { 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': @@ -99,7 +99,7 @@ static int handleCommandLineArguments(int argc, char* argv[], App* app) { break; } } - return optind; + return utils::getopt::optind; } int main(int argc, char** argv) { diff --git a/samples/helloskinning.cpp b/samples/helloskinning.cpp index 879462953c..8d8b076ed1 100644 --- a/samples/helloskinning.cpp +++ b/samples/helloskinning.cpp @@ -37,7 +37,7 @@ #include #include -#include +#include #include "generated/resources/resources.h" @@ -89,15 +89,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': @@ -109,7 +109,7 @@ static int handleCommandLineArgments(int argc, char* argv[], Config* config) { } } - return optind; + return utils::getopt::optind; } diff --git a/samples/helloskinningbuffer.cpp b/samples/helloskinningbuffer.cpp index bbec994516..aa735b0708 100644 --- a/samples/helloskinningbuffer.cpp +++ b/samples/helloskinningbuffer.cpp @@ -31,7 +31,7 @@ #include #include -#include +#include #include #include @@ -116,15 +116,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': @@ -136,7 +136,7 @@ static int handleCommandLineArgments(int argc, char* argv[], Config* config) { } } - return optind; + return utils::getopt::optind; } int main(int argc, char** argv) { diff --git a/samples/helloskinningbuffer_morebones.cpp b/samples/helloskinningbuffer_morebones.cpp index 2cd719767b..8d0ad74363 100644 --- a/samples/helloskinningbuffer_morebones.cpp +++ b/samples/helloskinningbuffer_morebones.cpp @@ -31,7 +31,7 @@ #include #include -#include +#include #include #include @@ -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) { diff --git a/samples/hellostereo.cpp b/samples/hellostereo.cpp index cf81e192ba..668aa62636 100644 --- a/samples/hellostereo.cpp +++ b/samples/hellostereo.cpp @@ -39,7 +39,7 @@ #include #include -#include +#include #include #include @@ -108,17 +108,17 @@ static void printUsage(char* name) { static int handleCommandLineArguments(int argc, char* argv[], App* app) { static constexpr const char* OPTSTR = "ha:y:m:"; - static const struct option OPTIONS[] = { - { "help", no_argument, nullptr, 'h' }, - { "api", required_argument, nullptr, 'a' }, - { "eyes", required_argument, nullptr, 'y' }, - { "samples", required_argument, nullptr, 'm'}, + static const utils::getopt::option OPTIONS[] = { + { "help", utils::getopt::no_argument, nullptr, 'h' }, + { "api", utils::getopt::required_argument, nullptr, 'a' }, + { "eyes", utils::getopt::required_argument, nullptr, 'y' }, + { "samples", 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': @@ -156,7 +156,7 @@ static int handleCommandLineArguments(int argc, char* argv[], App* app) { } } } - return optind; + return utils::getopt::optind; } int main(int argc, char** argv) { diff --git a/samples/hellotriangle.cpp b/samples/hellotriangle.cpp index 1a24ba1095..2274d8275c 100644 --- a/samples/hellotriangle.cpp +++ b/samples/hellotriangle.cpp @@ -33,7 +33,7 @@ #include #include -#include +#include #include #include @@ -94,15 +94,15 @@ static void printUsage(char* name) { static int handleCommandLineArguments(int argc, char* argv[], App* app) { static constexpr const char* OPTSTR = "ha:"; - static const struct option OPTIONS[] = { - { "help", no_argument, nullptr, 'h' }, - { "api", required_argument, nullptr, 'a' }, + static const utils::getopt::option OPTIONS[] = { + { "help", utils::getopt::no_argument, nullptr, 'h' }, + { "api", utils::getopt::required_argument, nullptr, 'a' }, { 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': @@ -113,7 +113,7 @@ static int handleCommandLineArguments(int argc, char* argv[], App* app) { break; } } - return optind; + return utils::getopt::optind; } int main(int argc, char** argv) { diff --git a/samples/hellouvmorphing.cpp b/samples/hellouvmorphing.cpp index b7a71c94a0..dbf6051ffe 100644 --- a/samples/hellouvmorphing.cpp +++ b/samples/hellouvmorphing.cpp @@ -36,7 +36,7 @@ #include #include -#include +#include #include #include @@ -105,13 +105,13 @@ static void printUsage(char* name) { static int handleCommandLineArguments(int argc, char* argv[], App* app) { static constexpr const char* OPTSTR = "ha:p"; - static const struct option OPTIONS[] = { { "help", no_argument, nullptr, 'h' }, - { "api", required_argument, nullptr, 'a' }, { "positions", no_argument, nullptr, 'p' }, + static const utils::getopt::option OPTIONS[] = { { "help", utils::getopt::no_argument, nullptr, 'h' }, + { "api", utils::getopt::required_argument, nullptr, 'a' }, { "positions", utils::getopt::no_argument, nullptr, 'p' }, { 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': @@ -125,7 +125,7 @@ static int handleCommandLineArguments(int argc, char* argv[], App* app) { break; } } - return optind; + return utils::getopt::optind; } int main(int argc, char** argv) { diff --git a/samples/hybrid_instancing.cpp b/samples/hybrid_instancing.cpp index 18b671759c..799766e90e 100644 --- a/samples/hybrid_instancing.cpp +++ b/samples/hybrid_instancing.cpp @@ -66,7 +66,7 @@ #include #include -#include +#include #include #include @@ -392,16 +392,16 @@ static void printUsage(char* name) { // Parses command-line arguments. static int handleCommandLineArguments(int const argc, char* argv[], App* app) { static constexpr const char* OPTSTR = "he:a:c:"; - static constexpr option OPTIONS[] = { - { "help", no_argument, nullptr, 'h' }, - { "api", required_argument, nullptr, 'a' }, - { "emitters", required_argument, nullptr, 'e' }, - { "camera", required_argument, nullptr, 'c' }, + static constexpr utils::getopt::option OPTIONS[] = { + { "help", utils::getopt::no_argument, nullptr, 'h' }, + { "api", utils::getopt::required_argument, nullptr, 'a' }, + { "emitters", utils::getopt::required_argument, nullptr, 'e' }, + { "camera", utils::getopt::required_argument, nullptr, 'c' }, { nullptr, 0, nullptr, 0 } }; int opt; int option_index = 0; - while ((opt = getopt_long(argc, argv, OPTSTR, OPTIONS, &option_index)) >= 0) { - const std::string arg(optarg ? optarg : ""); + while ((opt = utils::getopt::getopt_long(argc, argv, OPTSTR, OPTIONS, &option_index)) >= 0) { + const std::string arg(utils::getopt::optarg ? utils::getopt::optarg : ""); switch (opt) { default: case 'h': @@ -427,7 +427,7 @@ static int handleCommandLineArguments(int const argc, char* argv[], App* app) { break; } } - return optind; + return utils::getopt::optind; } // Resets a particle to a new random state. diff --git a/samples/image_viewer.cpp b/samples/image_viewer.cpp index dfb8c3c811..026ee36094 100644 --- a/samples/image_viewer.cpp +++ b/samples/image_viewer.cpp @@ -38,7 +38,7 @@ #include -#include +#include #include #include @@ -119,16 +119,16 @@ static void printUsage(char* name) { static int handleCommandLineArguments(int argc, char* argv[], App* app) { static constexpr const char* OPTSTR = "ha:c:"; - static const struct option OPTIONS[] = { - { "help", no_argument, nullptr, 'h' }, - { "api", required_argument, nullptr, 'a' }, - { "camera", required_argument, nullptr, 'c' }, + static const utils::getopt::option OPTIONS[] = { + { "help", utils::getopt::no_argument, nullptr, 'h' }, + { "api", utils::getopt::required_argument, nullptr, 'a' }, + { "camera", utils::getopt::required_argument, nullptr, 'c' }, { 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': @@ -148,7 +148,7 @@ static int handleCommandLineArguments(int argc, char* argv[], App* app) { break; } } - return optind; + return utils::getopt::optind; } static constexpr float4 sFullScreenTriangleVertices[3] = { diff --git a/samples/lightbulb.cpp b/samples/lightbulb.cpp index daed586068..57ffb4b27c 100644 --- a/samples/lightbulb.cpp +++ b/samples/lightbulb.cpp @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include @@ -111,22 +111,22 @@ static void printUsage(char* name) { static int handleCommandLineArgments(int argc, char* argv[], Config* config) { static constexpr const char* OPTSTR = "hi:vs:mdcpa:"; - 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' }, - { "more-lights", no_argument, nullptr, 'm' }, - { "disco", no_argument, nullptr, 'd' }, - { "clear-coat", no_argument, nullptr, 'c' }, - { "shadow-plane", no_argument, nullptr, 'p' }, - { 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' }, + { "more-lights", utils::getopt::no_argument, nullptr, 'm' }, + { "disco", utils::getopt::no_argument, nullptr, 'd' }, + { "clear-coat", utils::getopt::no_argument, nullptr, 'c' }, + { "shadow-plane", utils::getopt::no_argument, nullptr, 'p' }, + { 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': @@ -162,7 +162,7 @@ static int handleCommandLineArgments(int argc, char* argv[], Config* config) { } } - return optind; + return utils::getopt::optind; } #pragma clang diagnostic push diff --git a/samples/material_sandbox.cpp b/samples/material_sandbox.cpp index 72ab6de5c3..dfe2faed4e 100644 --- a/samples/material_sandbox.cpp +++ b/samples/material_sandbox.cpp @@ -21,7 +21,7 @@ #include #include -#include +#include #include @@ -127,22 +127,22 @@ static void printUsage(char* name) { static int handleCommandLineArgments(int argc, char* argv[], Config* config) { static constexpr const char* OPTSTR = "ha:vps:i:d:c:"; - 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' }, - { "shadow-plane", no_argument, nullptr, 'p' }, - { "single", no_argument, nullptr, 'n' }, - { "dirt", required_argument, nullptr, 'd' }, - { "camera", required_argument, nullptr, 'c' }, - { 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' }, + { "shadow-plane", utils::getopt::no_argument, nullptr, 'p' }, + { "single", utils::getopt::no_argument, nullptr, 'n' }, + { "dirt", utils::getopt::required_argument, nullptr, 'd' }, + { "camera", utils::getopt::required_argument, nullptr, 'c' }, + { 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': @@ -187,7 +187,7 @@ static int handleCommandLineArgments(int argc, char* argv[], Config* config) { } } - return optind; + return utils::getopt::optind; } static void cleanup(Engine* engine, View*, Scene*) { diff --git a/samples/materialinstancestress.cpp b/samples/materialinstancestress.cpp index b941350eb4..92a178b6e1 100644 --- a/samples/materialinstancestress.cpp +++ b/samples/materialinstancestress.cpp @@ -33,7 +33,7 @@ #include -#include +#include #include @@ -97,15 +97,15 @@ static void printUsage(char* name) { static int handleCommandLineArguments(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' }, + static const utils::getopt::option OPTIONS[] = { + { "help", utils::getopt::no_argument, nullptr, 'h' }, + { "api", utils::getopt::required_argument, nullptr, 'a' }, { 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': @@ -116,7 +116,7 @@ static int handleCommandLineArguments(int argc, char* argv[], Config* config) { break; } } - return optind; + return utils::getopt::optind; } static void removeObjects(Engine* engine, Scene* scene, App& app, int count) { diff --git a/samples/rendertarget.cpp b/samples/rendertarget.cpp index f1ff104b9a..084d316e43 100644 --- a/samples/rendertarget.cpp +++ b/samples/rendertarget.cpp @@ -37,7 +37,7 @@ #include #include -#include +#include #include @@ -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) { diff --git a/samples/sample_cloth.cpp b/samples/sample_cloth.cpp index cff2907640..4495b0ac3a 100644 --- a/samples/sample_cloth.cpp +++ b/samples/sample_cloth.cpp @@ -21,7 +21,7 @@ #include #include -#include +#include #include @@ -76,7 +76,7 @@ static void printUsage(char* name) { " Prints this message\n\n" "API_USAGE" " --ibl=, -i \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" @@ -95,18 +95,18 @@ static void printUsage(char* name) { static int handleCommandLineArgments(int argc, char* argv[], Config* config) { static constexpr const char* OPTSTR = "ha:i:vs:"; - static const struct option OPTIONS[] = { - { "help", no_argument, 0, 'h' }, - { "api", required_argument, 0, 'a' }, - { "ibl", required_argument, 0, 'i' }, - { "split-view", no_argument, 0, 'v' }, - { "scale", required_argument, 0, 's' }, - { 0, 0, 0, 0 } // termination of the option list + static const utils::getopt::option OPTIONS[] = { + { "help", utils::getopt::no_argument, 0, 'h' }, + { "api", utils::getopt::required_argument, 0, 'a' }, + { "ibl", utils::getopt::required_argument, 0, 'i' }, + { "split-view", utils::getopt::no_argument, 0, 'v' }, + { "scale", utils::getopt::required_argument, 0, 's' }, + { 0, 0, 0, 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': @@ -133,7 +133,7 @@ static int handleCommandLineArgments(int argc, char* argv[], Config* config) { } } - return optind; + return utils::getopt::optind; } static void cleanup(Engine* engine, View* view, Scene* scene) { diff --git a/samples/sample_full_pbr.cpp b/samples/sample_full_pbr.cpp index 8d48af3854..cbc036d229 100644 --- a/samples/sample_full_pbr.cpp +++ b/samples/sample_full_pbr.cpp @@ -39,7 +39,7 @@ #include #include -#include +#include #include @@ -106,7 +106,7 @@ static void printUsage(char* name) { " Prints this message\n\n" "API_USAGE" " --ibl=, -i \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" @@ -140,21 +140,21 @@ static void printUsage(char* name) { static int handleCommandLineArgments(int argc, char* argv[], Config* config) { static constexpr const char* OPTSTR = "ha:i:vs:m:cA"; - 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' }, - { "material", required_argument, nullptr, 'm' }, - { "clear-coat", no_argument, nullptr, 'c' }, - { "anisotropy", no_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' }, + { "ibl", utils::getopt::required_argument, nullptr, 'i' }, + { "split-view", utils::getopt::no_argument, nullptr, 'v' }, + { "scale", utils::getopt::required_argument, nullptr, 's' }, + { "material", utils::getopt::required_argument, nullptr, 'm' }, + { "clear-coat", utils::getopt::no_argument, nullptr, 'c' }, + { "anisotropy", utils::getopt::no_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 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': @@ -190,7 +190,7 @@ static int handleCommandLineArgments(int argc, char* argv[], Config* config) { } } - return optind; + return utils::getopt::optind; } static void cleanup(Engine* engine, View*, Scene*) { diff --git a/samples/sample_normal_map.cpp b/samples/sample_normal_map.cpp index ef33a9a560..ad7c5f2179 100644 --- a/samples/sample_normal_map.cpp +++ b/samples/sample_normal_map.cpp @@ -21,7 +21,7 @@ #include #include -#include +#include #include @@ -82,7 +82,7 @@ static void printUsage(char* name) { " Prints this message\n\n" "API_USAGE" " --ibl=, -i \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*) { diff --git a/samples/skinningtest.cpp b/samples/skinningtest.cpp index b1e6903ac1..e3ad6d7e97 100644 --- a/samples/skinningtest.cpp +++ b/samples/skinningtest.cpp @@ -32,7 +32,7 @@ #include #include -#include +#include #include #include @@ -160,15 +160,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': @@ -180,7 +180,7 @@ static int handleCommandLineArgments(int argc, char* argv[], Config* config) { } } - return optind; + return utils::getopt::optind; } int main(int argc, char** argv) { diff --git a/samples/suzanne.cpp b/samples/suzanne.cpp index 4eb5486520..cc24b9545b 100644 --- a/samples/suzanne.cpp +++ b/samples/suzanne.cpp @@ -37,7 +37,7 @@ #include #include -#include +#include #include @@ -90,15 +90,15 @@ static void printUsage(char* name) { static int handleCommandLineArguments(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' }, + static const utils::getopt::option OPTIONS[] = { + { "help", utils::getopt::no_argument, nullptr, 'h' }, + { "api", utils::getopt::required_argument, nullptr, 'a' }, { 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': @@ -109,7 +109,7 @@ static int handleCommandLineArguments(int argc, char* argv[], Config* config) { break; } } - return optind; + return utils::getopt::optind; } static Texture* loadNormalMap(Engine* engine, const uint8_t* normals, size_t nbytes) { diff --git a/samples/texturedquad.cpp b/samples/texturedquad.cpp index 37e82dc828..31fd7d101d 100644 --- a/samples/texturedquad.cpp +++ b/samples/texturedquad.cpp @@ -36,7 +36,7 @@ #include #include -#include +#include #include @@ -103,15 +103,15 @@ static void printUsage(char* name) { static int handleCommandLineArguments(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' }, + static const utils::getopt::option OPTIONS[] = { + { "help", utils::getopt::no_argument, nullptr, 'h' }, + { "api", utils::getopt::required_argument, nullptr, 'a' }, { 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': @@ -122,7 +122,7 @@ static int handleCommandLineArguments(int argc, char* argv[], Config& config) { break; } } - return optind; + return utils::getopt::optind; } int main(int argc, char** argv) { diff --git a/samples/viewtest.cpp b/samples/viewtest.cpp index 46ecb8bc59..0ce80dd28d 100644 --- a/samples/viewtest.cpp +++ b/samples/viewtest.cpp @@ -28,7 +28,7 @@ #include -#include +#include #include #include @@ -72,15 +72,15 @@ static void printUsage(char* name) { static int handleCommandLineArguments(int argc, char* argv[], App* app) { static constexpr const char* OPTSTR = "ha:f:i:usc:rt:b:ev"; - static const struct option OPTIONS[] = { - { "help", no_argument, nullptr, 'h' }, - { "api", required_argument, nullptr, 'a' }, + static const utils::getopt::option OPTIONS[] = { + { "help", utils::getopt::no_argument, nullptr, 'h' }, + { "api", utils::getopt::required_argument, nullptr, 'a' }, { 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': @@ -91,7 +91,7 @@ static int handleCommandLineArguments(int argc, char* argv[], App* app) { break; } } - return optind; + return utils::getopt::optind; } int main(int argc, char** argv) { diff --git a/tools/cmgen/CMakeLists.txt b/tools/cmgen/CMakeLists.txt index c0a255831e..df456235a1 100644 --- a/tools/cmgen/CMakeLists.txt +++ b/tools/cmgen/CMakeLists.txt @@ -7,12 +7,12 @@ set(TARGET cmgen) # Sources and headers # ================================================================================================== set(HDRS - src/ProgressUpdater.h + src/ProgressUpdater.h ) set(SRCS - src/cmgen.cpp - src/ProgressUpdater.cpp + src/cmgen.cpp + src/ProgressUpdater.cpp ) # ================================================================================================== @@ -20,28 +20,28 @@ set(SRCS # ================================================================================================== add_executable(${TARGET} ${HDRS} ${SRCS}) -target_link_libraries(${TARGET} PRIVATE ibl imageio getopt) +target_link_libraries(${TARGET} PRIVATE ibl imageio ) set_target_properties(${TARGET} PROPERTIES FOLDER Tools) # ================================================================================================== # Compile options and optimizations # ================================================================================================== if (MSVC) - target_compile_options(${TARGET} PRIVATE /fp:fast) + target_compile_options(${TARGET} PRIVATE /fp:fast) else() - target_compile_options(${TARGET} PRIVATE -ffast-math -fno-finite-math-only) + target_compile_options(${TARGET} PRIVATE -ffast-math -fno-finite-math-only) endif() if (MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W0 /Zc:__cplusplus") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W0 /Zc:__cplusplus") endif() # ================================================================================================= # Licenses # ================================================================================================== -set(MODULE_LICENSES getopt libpng tinyexr libz) +set(MODULE_LICENSES libpng tinyexr libz) set(GENERATION_ROOT ${CMAKE_CURRENT_BINARY_DIR}/generated) -list_licenses(${GENERATION_ROOT}/licenses/licenses.inc ${MODULE_LICENSES}) +list_licenses(${GENERATION_ROOT}/licenses/licenses.inc "${MODULE_LICENSES}") target_include_directories(${TARGET} PRIVATE ${GENERATION_ROOT}) # ================================================================================================== @@ -53,7 +53,7 @@ install(TARGETS ${TARGET} RUNTIME DESTINATION bin) # Tests # ================================================================================================== if (FILAMENT_BUILD_TESTING AND NOT ANDROID) - add_executable(test_${TARGET} tests/test_cmgen.cpp) - target_link_libraries(test_${TARGET} PRIVATE imageio gtest) - set_target_properties(test_${TARGET} PROPERTIES FOLDER Tests) + add_executable(test_${TARGET} tests/test_cmgen.cpp) + target_link_libraries(test_${TARGET} PRIVATE imageio gtest) + set_target_properties(test_${TARGET} PROPERTIES FOLDER Tests) endif() diff --git a/tools/cmgen/src/cmgen.cpp b/tools/cmgen/src/cmgen.cpp index 33ba4656f7..722e5737c3 100644 --- a/tools/cmgen/src/cmgen.cpp +++ b/tools/cmgen/src/cmgen.cpp @@ -44,7 +44,7 @@ #include -#include +#include using namespace filament::math; @@ -245,35 +245,35 @@ static void license() { static int handleCommandLineArgments(int argc, char* argv[]) { static constexpr const char* OPTSTR = "hqidt:f:c:s:x:w:S:"; - static const struct option OPTIONS[] = { - { "help", no_argument, nullptr, 'h' }, - { "license", no_argument, nullptr, 'l' }, - { "quiet", no_argument, nullptr, 'q' }, - { "type", required_argument, nullptr, 't' }, - { "format", required_argument, nullptr, 'f' }, - { "compression", required_argument, nullptr, 'c' }, - { "size", required_argument, nullptr, 's' }, - { "extract", required_argument, nullptr, 'e' }, - { "extract-blur", required_argument, nullptr, 'r' }, - { "sh", optional_argument, nullptr, 'z' }, - { "sh-output", required_argument, nullptr, 'o' }, - { "sh-irradiance", no_argument, nullptr, 'i' }, - { "sh-shader", no_argument, nullptr, 'b' }, - { "sh-window", required_argument, nullptr, 'w' }, - { "clamp", no_argument, nullptr, 'K' }, - { "ibl-is-mipmap", required_argument, nullptr, 'y' }, - { "ibl-ld", required_argument, nullptr, 'p' }, - { "ibl-irradiance", required_argument, nullptr, 'P' }, - { "ibl-dfg", required_argument, nullptr, 'a' }, - { "ibl-dfg-multiscatter", no_argument, nullptr, 'u' }, - { "ibl-dfg-cloth", no_argument, nullptr, 'C' }, - { "ibl-no-prefilter", no_argument, nullptr, 'n' }, - { "ibl-min-lod-size", required_argument, nullptr, 'S' }, - { "ibl-samples", required_argument, nullptr, 'k' }, - { "deploy", required_argument, nullptr, 'x' }, - { "no-mirror", no_argument, nullptr, 'm' }, - { "debug", no_argument, nullptr, 'd' }, - { nullptr, 0, nullptr, 0 } // termination of the option list + static const utils::getopt::option OPTIONS[] = { + { "help", utils::getopt::no_argument, nullptr, 'h' }, + { "license", utils::getopt::no_argument, nullptr, 'l' }, + { "quiet", utils::getopt::no_argument, nullptr, 'q' }, + { "type", utils::getopt::required_argument, nullptr, 't' }, + { "format", utils::getopt::required_argument, nullptr, 'f' }, + { "compression", utils::getopt::required_argument, nullptr, 'c' }, + { "size", utils::getopt::required_argument, nullptr, 's' }, + { "extract", utils::getopt::required_argument, nullptr, 'e' }, + { "extract-blur", utils::getopt::required_argument, nullptr, 'r' }, + { "sh", utils::getopt::optional_argument, nullptr, 'z' }, + { "sh-output", utils::getopt::required_argument, nullptr, 'o' }, + { "sh-irradiance", utils::getopt::no_argument, nullptr, 'i' }, + { "sh-shader", utils::getopt::no_argument, nullptr, 'b' }, + { "sh-window", utils::getopt::required_argument, nullptr, 'w' }, + { "clamp", utils::getopt::no_argument, nullptr, 'K' }, + { "ibl-is-mipmap", utils::getopt::required_argument, nullptr, 'y' }, + { "ibl-ld", utils::getopt::required_argument, nullptr, 'p' }, + { "ibl-irradiance", utils::getopt::required_argument, nullptr, 'P' }, + { "ibl-dfg", utils::getopt::required_argument, nullptr, 'a' }, + { "ibl-dfg-multiscatter", utils::getopt::no_argument, nullptr, 'u' }, + { "ibl-dfg-cloth", utils::getopt::no_argument, nullptr, 'C' }, + { "ibl-no-prefilter", utils::getopt::no_argument, nullptr, 'n' }, + { "ibl-min-lod-size", utils::getopt::required_argument, nullptr, 'S' }, + { "ibl-samples", utils::getopt::required_argument, nullptr, 'k' }, + { "deploy", utils::getopt::required_argument, nullptr, 'x' }, + { "no-mirror", utils::getopt::no_argument, nullptr, 'm' }, + { "debug", utils::getopt::no_argument, nullptr, 'd' }, + { nullptr, 0, nullptr, 0 } // termination of the utils::getopt::option list }; int opt; int option_index = 0; @@ -281,8 +281,8 @@ static int handleCommandLineArgments(int argc, char* argv[]) { bool format_specified = false; bool type_specified = false; bool ktx_format_requested = false; - 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': @@ -471,7 +471,7 @@ static int handleCommandLineArgments(int argc, char* argv[]) { if (num_sh_bands && g_sh_compute) { g_sh_compute = (size_t) num_sh_bands; } - return optind; + return utils::getopt::optind; } int main(int argc, char* argv[]) { @@ -617,7 +617,7 @@ int main(int argc, char* argv[]) { levels.push_back(std::move(cml)); } - // we mirror by default -- the mirror option in fact un-mirrors. + // we mirror by default -- the mirror utils::getopt::option in fact un-mirrors. g_mirror = !g_mirror; if (g_mirror) { if (!g_quiet) { diff --git a/tools/cso-lut/CMakeLists.txt b/tools/cso-lut/CMakeLists.txt index f117a58a5f..bf9dd3603f 100644 --- a/tools/cso-lut/CMakeLists.txt +++ b/tools/cso-lut/CMakeLists.txt @@ -15,20 +15,20 @@ set(SRCS src/main.cpp) # ================================================================================================== add_executable(${TARGET} ${HDRS} ${SRCS}) -target_link_libraries(${TARGET} PRIVATE imageio getopt) +target_link_libraries(${TARGET} PRIVATE imageio ) set_target_properties(${TARGET} PROPERTIES FOLDER Tools) # ================================================================================================== # Compile options and optimizations # ================================================================================================== if (NOT LINUX) - target_compile_options(${TARGET} PRIVATE ) + target_compile_options(${TARGET} PRIVATE ) endif() # ================================================================================================= # Licenses # ================================================================================================== -set(MODULE_LICENSES getopt libpng tinyexr libz) +set(MODULE_LICENSES libpng tinyexr libz) set(GENERATION_ROOT ${CMAKE_CURRENT_BINARY_DIR}/generated) -list_licenses(${GENERATION_ROOT}/licenses/licenses.inc ${MODULE_LICENSES}) +list_licenses(${GENERATION_ROOT}/licenses/licenses.inc "${MODULE_LICENSES}") target_include_directories(${TARGET} PRIVATE ${GENERATION_ROOT}) diff --git a/tools/cso-lut/src/main.cpp b/tools/cso-lut/src/main.cpp index e8a7c2bb74..9cc41aa197 100644 --- a/tools/cso-lut/src/main.cpp +++ b/tools/cso-lut/src/main.cpp @@ -31,7 +31,7 @@ #include #include -#include +#include using namespace filament::math; using namespace image; @@ -90,20 +90,20 @@ static void license() { static int handleArguments(int argc, char* argv[]) { static constexpr const char* OPTSTR = "hc:f:g"; - static const struct option OPTIONS[] = { - { "help", no_argument, nullptr, 'h' }, - { "license", no_argument, nullptr, 's' }, - { "ground-truth", no_argument, nullptr, 'g' }, - { "format", required_argument, nullptr, 'f' }, - { "compression", required_argument, nullptr, 'c' }, - { nullptr, 0, nullptr, 0 } // termination of the option list + static const utils::getopt::option OPTIONS[] = { + { "help", utils::getopt::no_argument, nullptr, 'h' }, + { "license", utils::getopt::no_argument, nullptr, 's' }, + { "ground-truth", utils::getopt::no_argument, nullptr, 'g' }, + { "format", utils::getopt::required_argument, nullptr, 'f' }, + { "compression", utils::getopt::required_argument, nullptr, 'c' }, + { nullptr, 0, nullptr, 0 } // termination of the utils::getopt::option list }; int opt; int optionIndex = 0; - while ((opt = getopt_long(argc, argv, OPTSTR, OPTIONS, &optionIndex)) >= 0) { - std::string arg(optarg ? optarg : ""); + while ((opt = utils::getopt::getopt_long(argc, argv, OPTSTR, OPTIONS, &optionIndex)) >= 0) { + std::string arg(utils::getopt::optarg ? utils::getopt::optarg : ""); switch (opt) { default: case 'h': @@ -145,7 +145,7 @@ static int handleArguments(int argc, char* argv[]) { } } - return optind; + return utils::getopt::optind; } static bool isIncludeFile(const Path& filename) { diff --git a/tools/diffimg/CMakeLists.txt b/tools/diffimg/CMakeLists.txt index f5748510e3..f9aeb0ec01 100644 --- a/tools/diffimg/CMakeLists.txt +++ b/tools/diffimg/CMakeLists.txt @@ -6,12 +6,12 @@ set(TARGET diffimg) add_executable(${TARGET} main.cpp) target_link_libraries(${TARGET} PRIVATE - getopt - imagediff - imageio - imageio-lite - image - utils + + imagediff + imageio + imageio-lite + image + utils ) set_target_properties(${TARGET} PROPERTIES FOLDER Tools) @@ -19,9 +19,9 @@ set_target_properties(${TARGET} PROPERTIES FOLDER Tools) # ================================================================================================= # Licenses # ================================================================================================== -set(MODULE_LICENSES getopt) +set(MODULE_LICENSES ) set(GENERATION_ROOT ${CMAKE_CURRENT_BINARY_DIR}/generated) -list_licenses(${GENERATION_ROOT}/licenses/licenses.inc ${MODULE_LICENSES}) +list_licenses(${GENERATION_ROOT}/licenses/licenses.inc "${MODULE_LICENSES}") target_include_directories(${TARGET} PRIVATE ${GENERATION_ROOT}) # ================================================================================================== diff --git a/tools/diffimg/main.cpp b/tools/diffimg/main.cpp index 1f8b13e8db..ed0cef9c0e 100644 --- a/tools/diffimg/main.cpp +++ b/tools/diffimg/main.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include using namespace utils; using namespace image; @@ -126,11 +126,11 @@ static void saveDiffImage(const Path& path, const LinearImage& image) { } int main(int argc, char** argv) { - static struct option longOptions[] = { - {"config", required_argument, 0, 'c'}, - {"mask", required_argument, 0, 'm'}, - {"diff", required_argument, 0, 'd'}, - {"help", no_argument, 0, 'h'}, + static utils::getopt::option longOptions[] = { + {"config", utils::getopt::required_argument, 0, 'c'}, + {"mask", utils::getopt::required_argument, 0, 'm'}, + {"diff", utils::getopt::required_argument, 0, 'd'}, + {"help", utils::getopt::no_argument, 0, 'h'}, {0, 0, 0, 0} }; @@ -140,16 +140,16 @@ int main(int argc, char** argv) { int opt; int optionIndex = 0; - while ((opt = getopt_long(argc, argv, "c:m:d:h", longOptions, &optionIndex)) != -1) { + while ((opt = utils::getopt::getopt_long(argc, argv, "c:m:d:h", longOptions, &optionIndex)) != -1) { switch (opt) { case 'c': - configPath = Path(optarg); + configPath = Path(utils::getopt::optarg); break; case 'm': - maskPath = Path(optarg); + maskPath = Path(utils::getopt::optarg); break; case 'd': - diffPath = Path(optarg); + diffPath = Path(utils::getopt::optarg); break; case 'h': printUsage(argv[0]); @@ -160,14 +160,14 @@ int main(int argc, char** argv) { } } - if (optind + 2 > argc) { + if (utils::getopt::optind + 2 > argc) { std::cerr << "Error: Missing arguments." << std::endl; printUsage(argv[0]); return 1; } - Path refPath(argv[optind]); - Path candPath(argv[optind + 1]); + Path refPath(argv[utils::getopt::optind]); + Path candPath(argv[utils::getopt::optind + 1]); LinearImage refImg = loadImage(refPath); if (!refImg.isValid()) return 1; diff --git a/tools/filamesh/CMakeLists.txt b/tools/filamesh/CMakeLists.txt index 680262dcc9..7097628162 100644 --- a/tools/filamesh/CMakeLists.txt +++ b/tools/filamesh/CMakeLists.txt @@ -7,37 +7,37 @@ set(TARGET filamesh) # Sources # ================================================================================================== set(SRCS - src/MeshWriter.cpp - src/MeshWriter.h - src/main.cpp) + src/MeshWriter.cpp + src/MeshWriter.h + src/main.cpp) # ================================================================================================== # Target definitions # ================================================================================================== add_executable(${TARGET} ${SRCS}) -target_link_libraries(${TARGET} PRIVATE assimp getopt filameshio meshoptimizer) +target_link_libraries(${TARGET} PRIVATE assimp filameshio meshoptimizer) set_target_properties(${TARGET} PROPERTIES FOLDER Tools) # ================================================================================================== # Compile options and optimizations # ================================================================================================== if(NOT MSVC) - target_compile_options(${TARGET} PRIVATE -Wno-deprecated-register) + target_compile_options(${TARGET} PRIVATE -Wno-deprecated-register) - if (NOT LINUX) - target_compile_options(${TARGET} PRIVATE - -Wno-address-of-packed-member - ) - endif() + if (NOT LINUX) + target_compile_options(${TARGET} PRIVATE + -Wno-address-of-packed-member + ) + endif() endif() # ================================================================================================= # Licenses # ================================================================================================== -set(MODULE_LICENSES getopt libassimp meshoptimizer) +set(MODULE_LICENSES libassimp meshoptimizer) set(GENERATION_ROOT ${CMAKE_CURRENT_BINARY_DIR}/generated) -list_licenses(${GENERATION_ROOT}/licenses/licenses.inc ${MODULE_LICENSES}) +list_licenses(${GENERATION_ROOT}/licenses/licenses.inc "${MODULE_LICENSES}") target_include_directories(${TARGET} PRIVATE ${GENERATION_ROOT}) # ================================================================================================== diff --git a/tools/filamesh/src/main.cpp b/tools/filamesh/src/main.cpp index 541d7ff7a3..6ce4b8a5d4 100644 --- a/tools/filamesh/src/main.cpp +++ b/tools/filamesh/src/main.cpp @@ -30,7 +30,7 @@ #include -#include +#include using namespace filamesh; using namespace filament::math; @@ -296,20 +296,20 @@ static void license() { static int handleArguments(int argc, char* argv[]) { static constexpr const char* OPTSTR = "hilcg"; - static const struct option OPTIONS[] = { - { "help", no_argument, 0, 'h' }, - { "license", no_argument, 0, 'l' }, - { "interleaved", no_argument, 0, 'i' }, - { "compress", no_argument, 0, 'c' }, - { "ignore-uv1", no_argument, 0, 'g' }, - { 0, 0, 0, 0 } // termination of the option list + static const utils::getopt::option OPTIONS[] = { + { "help", utils::getopt::no_argument, 0, 'h' }, + { "license", utils::getopt::no_argument, 0, 'l' }, + { "interleaved", utils::getopt::no_argument, 0, 'i' }, + { "compress", utils::getopt::no_argument, 0, 'c' }, + { "ignore-uv1", utils::getopt::no_argument, 0, 'g' }, + { 0, 0, 0, 0 } // termination of the utils::getopt::option list }; int opt; int optionIndex = 0; - while ((opt = getopt_long(argc, argv, OPTSTR, OPTIONS, &optionIndex)) >= 0) { - // std::string arg(optarg ? optarg : ""); + while ((opt = utils::getopt::getopt_long(argc, argv, OPTSTR, OPTIONS, &optionIndex)) >= 0) { + // std::string arg(utils::getopt::optarg ? utils::getopt::optarg : ""); switch (opt) { default: case 'h': @@ -332,7 +332,7 @@ static int handleArguments(int argc, char* argv[]) { } } - return optind; + return utils::getopt::optind; } int main(int argc, char* argv[]) { diff --git a/tools/glslminifier/CMakeLists.txt b/tools/glslminifier/CMakeLists.txt index 4938ea3bee..4b63f2d1c6 100644 --- a/tools/glslminifier/CMakeLists.txt +++ b/tools/glslminifier/CMakeLists.txt @@ -12,15 +12,15 @@ set(SRCS src/main.cpp src/GlslMinify.cpp) # Target definitions # ================================================================================================== add_executable(${TARGET} ${SRCS}) -target_link_libraries(${TARGET} PRIVATE utils getopt) +target_link_libraries(${TARGET} PRIVATE utils ) set_target_properties(${TARGET} PROPERTIES FOLDER Tools) # ================================================================================================= # Licenses # ================================================================================================== -set(MODULE_LICENSES getopt) +set(MODULE_LICENSES ) set(GENERATION_ROOT ${CMAKE_CURRENT_BINARY_DIR}/generated) -list_licenses(${GENERATION_ROOT}/licenses/licenses.inc ${MODULE_LICENSES}) +list_licenses(${GENERATION_ROOT}/licenses/licenses.inc "${MODULE_LICENSES}") target_include_directories(${TARGET} PRIVATE ${GENERATION_ROOT}) # ================================================================================================== @@ -32,11 +32,11 @@ install(TARGETS ${TARGET} RUNTIME DESTINATION bin) # Tests # ================================================================================================== if (FILAMENT_BUILD_TESTING AND NOT ANDROID) - add_executable(test_${TARGET} - src/GlslMinify.cpp - tests/test_glslminifier.cpp - ) - target_include_directories(test_${TARGET} PRIVATE src) - target_link_libraries(test_${TARGET} PRIVATE gtest) - set_target_properties(test_${TARGET} PROPERTIES FOLDER Tests) + add_executable(test_${TARGET} + src/GlslMinify.cpp + tests/test_glslminifier.cpp + ) + target_include_directories(test_${TARGET} PRIVATE src) + target_link_libraries(test_${TARGET} PRIVATE gtest) + set_target_properties(test_${TARGET} PROPERTIES FOLDER Tests) endif() diff --git a/tools/glslminifier/src/GlslMinify.cpp b/tools/glslminifier/src/GlslMinify.cpp index 6a20e4a4af..e958ab8c7a 100644 --- a/tools/glslminifier/src/GlslMinify.cpp +++ b/tools/glslminifier/src/GlslMinify.cpp @@ -42,7 +42,7 @@ const static regex emptyLinesRegex(R"regex((\n|\r\n)+)regex"); // Indentation: // (^|\n) match the beginning of the file, or a newline character (C++14 does not support -// the multiline option, unfortunately) +// the multiline utils::getopt::option, unfortunately) // [ \t]+ match at least one leading space or tab character const static regex indentationRegex(R"regex((^|\n)[ \t]+)regex"); diff --git a/tools/glslminifier/src/main.cpp b/tools/glslminifier/src/main.cpp index a6d2f565c0..a69f3faae0 100644 --- a/tools/glslminifier/src/main.cpp +++ b/tools/glslminifier/src/main.cpp @@ -18,7 +18,7 @@ #include -#include +#include #include #include @@ -56,7 +56,7 @@ Options: #if defined(GL_GOOGLE_cpp_style_line_directive) #line 0 "foobar.h" #endif - This option is meant to be used with -Onone optimization. + This utils::getopt::option is meant to be used with -Onone optimization. Example: GLSLMINIFIER -o output.fs.min input.fs @@ -86,20 +86,20 @@ static void license() { static int handleArguments(int argc, char* argv[]) { static constexpr const char* OPTSTR = "hLo:O:l:"; - static const struct option OPTIONS[] = { - { "help", no_argument, nullptr, 'h' }, - { "license", no_argument, nullptr, 'L' }, - { "output", required_argument, nullptr, 'o' }, - { "optimization", required_argument, nullptr, 'O' }, - { "line", required_argument, nullptr, 'l' }, - { nullptr, 0, nullptr, 0 } // termination of the option list + static const utils::getopt::option OPTIONS[] = { + { "help", utils::getopt::no_argument, nullptr, 'h' }, + { "license", utils::getopt::no_argument, nullptr, 'L' }, + { "output", utils::getopt::required_argument, nullptr, 'o' }, + { "optimization", utils::getopt::required_argument, nullptr, 'O' }, + { "line", utils::getopt::required_argument, nullptr, 'l' }, + { nullptr, 0, nullptr, 0 } // termination of the utils::getopt::option list }; int opt; int optionIndex = 0; - while ((opt = getopt_long(argc, argv, OPTSTR, OPTIONS, &optionIndex)) >= 0) { - std::string arg(optarg ? optarg : ""); + while ((opt = utils::getopt::getopt_long(argc, argv, OPTSTR, OPTIONS, &optionIndex)) >= 0) { + std::string arg(utils::getopt::optarg ? utils::getopt::optarg : ""); switch (opt) { default: case 'h': @@ -109,7 +109,7 @@ static int handleArguments(int argc, char* argv[]) { license(); exit(0); case 'o': - g_outputFile = optarg; + g_outputFile = utils::getopt::optarg; g_writeToStdOut = false; break; case 'O': @@ -126,7 +126,7 @@ static int handleArguments(int argc, char* argv[]) { } } - return optind; + return utils::getopt::optind; } int main(int argc, char* argv[]) { diff --git a/tools/matc/CMakeLists.txt b/tools/matc/CMakeLists.txt index 6711f10d66..712a29036b 100644 --- a/tools/matc/CMakeLists.txt +++ b/tools/matc/CMakeLists.txt @@ -10,16 +10,16 @@ set(TARGET matlang) # Sources and headers # ================================================================================================== set(HDRS - src/matc/CommandlineConfig.h - src/matc/Compiler.h - src/matc/MaterialCompiler.h - ) + src/matc/CommandlineConfig.h + src/matc/Compiler.h + src/matc/MaterialCompiler.h + ) set(SRCS - src/matc/Compiler.cpp - src/matc/CommandlineConfig.cpp - src/matc/MaterialCompiler.cpp - ) + src/matc/Compiler.cpp + src/matc/CommandlineConfig.cpp + src/matc/MaterialCompiler.cpp + ) # ================================================================================================== # Target definitions @@ -29,15 +29,15 @@ add_library(${TARGET} STATIC ${SRCS} ${HDRS}) target_include_directories(${TARGET} PUBLIC src) target_include_directories(${TARGET} PRIVATE ${filamat_SOURCE_DIR}/src) -target_link_libraries(${TARGET} getopt filamat filabridge utils matp) +target_link_libraries(${TARGET} filamat filabridge utils matp) set_target_properties(${TARGET} PROPERTIES FOLDER Tools) # ================================================================================================= # Licenses # ================================================================================================== -set(MODULE_LICENSES getopt glslang spirv-cross spirv-tools smol-v) +set(MODULE_LICENSES glslang spirv-cross spirv-tools smol-v) set(GENERATION_ROOT ${CMAKE_CURRENT_BINARY_DIR}/generated) -list_licenses(${GENERATION_ROOT}/licenses/licenses.inc ${MODULE_LICENSES}) +list_licenses(${GENERATION_ROOT}/licenses/licenses.inc "${MODULE_LICENSES}") target_include_directories(${TARGET} PRIVATE ${GENERATION_ROOT}) # ================================================================================================== diff --git a/tools/matc/src/matc/CommandlineConfig.cpp b/tools/matc/src/matc/CommandlineConfig.cpp index 8dd5c6c10d..c5f7a51dcb 100644 --- a/tools/matc/src/matc/CommandlineConfig.cpp +++ b/tools/matc/src/matc/CommandlineConfig.cpp @@ -24,7 +24,7 @@ #include -#include +#include #include #include @@ -42,36 +42,36 @@ using namespace filament; namespace matc { static constexpr const char* OPTSTR = "hLxo:f:dm:a:l:p:D:T:P:OSEr:vV:gtwF1RW:"; -static const option OPTIONS[] = { - { "help", no_argument, nullptr, 'h' }, - { "license", no_argument, nullptr, 'L' }, - { "output", required_argument, nullptr, 'o' }, - { "output-format", required_argument, nullptr, 'f' }, - { "debug", no_argument, nullptr, 'd' }, - { "variant-filter", required_argument, nullptr, 'V' }, - { "platform", required_argument, nullptr, 'p' }, - { "optimize", no_argument, nullptr, 'x' }, // for backward compatibility - { "optimize", no_argument, nullptr, 'O' }, // for backward compatibility - { "optimize-size", no_argument, nullptr, 'S' }, - { "optimize-none", no_argument, nullptr, 'g' }, - { "preprocessor-only", no_argument, nullptr, 'E' }, - { "api", required_argument, nullptr, 'a' }, - { "feature-level", required_argument, nullptr, 'l' }, - { "no-essl1", no_argument, nullptr, '1' }, - { "define", required_argument, nullptr, 'D' }, - { "template", required_argument, nullptr, 'T' }, - { "material-parameter",required_argument, nullptr, 'P' }, - { "reflect", required_argument, nullptr, 'r' }, - { "print", no_argument, nullptr, 't' }, - { "version", no_argument, nullptr, 'v' }, - { "raw", no_argument, nullptr, 'w' }, - { "no-sampler-validation", no_argument, nullptr, 'F' }, - { "save-raw-variants", no_argument, nullptr, 'R' }, - { "workarounds", required_argument, nullptr, 'W' }, - { "no-insert-line-directives", no_argument, nullptr, 'n' }, - { "no-insert-line-directive-check", no_argument, nullptr, 'N' }, - { "include-source-mat", no_argument, nullptr, 'm' }, - { nullptr, 0, nullptr, 0 } // termination of the option list +static const utils::getopt::option OPTIONS[] = { + { "help", utils::getopt::no_argument, nullptr, 'h' }, + { "license", utils::getopt::no_argument, nullptr, 'L' }, + { "output", utils::getopt::required_argument, nullptr, 'o' }, + { "output-format", utils::getopt::required_argument, nullptr, 'f' }, + { "debug", utils::getopt::no_argument, nullptr, 'd' }, + { "variant-filter", utils::getopt::required_argument, nullptr, 'V' }, + { "platform", utils::getopt::required_argument, nullptr, 'p' }, + { "optimize", utils::getopt::no_argument, nullptr, 'x' }, // for backward compatibility + { "optimize", utils::getopt::no_argument, nullptr, 'O' }, // for backward compatibility + { "optimize-size", utils::getopt::no_argument, nullptr, 'S' }, + { "optimize-none", utils::getopt::no_argument, nullptr, 'g' }, + { "preprocessor-only", utils::getopt::no_argument, nullptr, 'E' }, + { "api", utils::getopt::required_argument, nullptr, 'a' }, + { "feature-level", utils::getopt::required_argument, nullptr, 'l' }, + { "no-essl1", utils::getopt::no_argument, nullptr, '1' }, + { "define", utils::getopt::required_argument, nullptr, 'D' }, + { "template", utils::getopt::required_argument, nullptr, 'T' }, + { "material-parameter",utils::getopt::required_argument, nullptr, 'P' }, + { "reflect", utils::getopt::required_argument, nullptr, 'r' }, + { "print", utils::getopt::no_argument, nullptr, 't' }, + { "version", utils::getopt::no_argument, nullptr, 'v' }, + { "raw", utils::getopt::no_argument, nullptr, 'w' }, + { "no-sampler-validation", utils::getopt::no_argument, nullptr, 'F' }, + { "save-raw-variants", utils::getopt::no_argument, nullptr, 'R' }, + { "workarounds", utils::getopt::required_argument, nullptr, 'W' }, + { "no-insert-line-directives", utils::getopt::no_argument, nullptr, 'n' }, + { "no-insert-line-directive-check", utils::getopt::no_argument, nullptr, 'N' }, + { "include-source-mat", utils::getopt::no_argument, nullptr, 'm' }, + { nullptr, 0, nullptr, 0 } // termination of the utils::getopt::option list }; // A list of options that may contain PII(Personally Identifiable Information) data. @@ -230,7 +230,7 @@ static UserVariantFilterMask parseVariantFilter(const std::string& arg) { CommandlineConfig::CommandlineConfig(int const argc, char** argv) : Config(), mArgc(argc), mArgv(argv) { // Add aliases for some optimization flags. We do this by pre-processing the arguments, - // since getopt has trouble with short options that are longer than one character (e.g. -Os). + // since utils::getopt::getopt has trouble with short options that are longer than one character (e.g. -Os). for (int i = 1; i < mArgc; i++) { if (mArgv[i]) { if (strcmp(mArgv[i], "-Os") == 0) { @@ -273,8 +273,8 @@ bool CommandlineConfig::parse() { int opt; int option_index = 0; - while ((opt = getopt_long(mArgc, mArgv, OPTSTR, OPTIONS, &option_index)) >= 0) { - std::string const arg(optarg ? optarg : ""); + while ((opt = utils::getopt::getopt_long(mArgc, mArgv, OPTSTR, OPTIONS, &option_index)) >= 0) { + std::string const arg(utils::getopt::optarg ? utils::getopt::optarg : ""); switch (opt) { default: case 'h': @@ -415,12 +415,12 @@ bool CommandlineConfig::parse() { } } - if (mArgc - optind > 1) { + if (mArgc - utils::getopt::optind > 1) { std::cerr << "Only one input file should be specified on the command line." << std::endl; return false; } - if (mArgc - optind > 0) { - mInput = new FilesystemInput(mArgv[optind]); + if (mArgc - utils::getopt::optind > 0) { + mInput = new FilesystemInput(mArgv[utils::getopt::optind]); } return true; @@ -430,23 +430,23 @@ bool CommandlineConfig::parse() { // name, and any options found in PII_OPTIONS due to potential PII data. std::string CommandlineConfig::toPIISafeString() const noexcept { std::string result; - optind = 1; // Reset getopt's internal index before parsing + utils::getopt::optind = 1; // Reset utils::getopt::getopt's internal index before parsing while (true) { - // getopt_long will only set `long_index` if a long option is parsed. + // utils::getopt::getopt_long will only set `long_index` if a long utils::getopt::option is parsed. int long_index = -1; - int const opt = getopt_long(mArgc, mArgv, OPTSTR, OPTIONS, &long_index); + int const opt = utils::getopt::getopt_long(mArgc, mArgv, OPTSTR, OPTIONS, &long_index); if (opt == -1) { break; // End of options } - // Find the matched option. - const struct option* matched_option = nullptr; + // Find the matched utils::getopt::option. + const utils::getopt::option* matched_option = nullptr; if (long_index != -1) { - // A long option was parsed (e.g., --help) + // A long utils::getopt::option was parsed (e.g., --help) matched_option = &OPTIONS[long_index]; } else if (opt > 0) { - // A short option was parsed (e.g., -h) + // A short utils::getopt::option was parsed (e.g., -h) for (int i = 0; OPTIONS[i].name != nullptr; ++i) { if (OPTIONS[i].val == opt) { matched_option = &OPTIONS[i]; @@ -456,17 +456,17 @@ std::string CommandlineConfig::toPIISafeString() const noexcept { } if (!matched_option) { - std::cerr << "Failed to find the matched option: long_index=" << long_index + std::cerr << "Failed to find the matched utils::getopt::option: long_index=" << long_index << ", opt=" << opt << std::endl; continue; } - // Skip if it's a PII option. + // Skip if it's a PII utils::getopt::option. if (isPIIOption(matched_option->name)) { continue; } - // Reconstruct the option. + // Reconstruct the utils::getopt::option. if (long_index != -1) { result += "--"; result += matched_option->name; @@ -478,8 +478,8 @@ std::string CommandlineConfig::toPIISafeString() const noexcept { } // Add an argument if available. - if (optarg && matched_option->has_arg != no_argument) { - result += optarg; + if (utils::getopt::optarg && matched_option->has_arg != utils::getopt::no_argument) { + result += utils::getopt::optarg; result += " "; } } diff --git a/tools/matedit/CMakeLists.txt b/tools/matedit/CMakeLists.txt index 2c1b24711e..1c7b9053f1 100644 --- a/tools/matedit/CMakeLists.txt +++ b/tools/matedit/CMakeLists.txt @@ -7,8 +7,8 @@ set(TARGET matedit) # Sources and headers # ================================================================================================== set(SRCS - src/main.cpp - src/ExternalCompile.cpp + src/main.cpp + src/ExternalCompile.cpp ) # ================================================================================================== @@ -18,16 +18,16 @@ add_executable(${TARGET} ${SRCS}) target_include_directories(${TARGET} PRIVATE ${filamat_SOURCE_DIR}/src) -target_link_libraries(${TARGET} matdbg getopt) +target_link_libraries(${TARGET} matdbg ) set_target_properties(${TARGET} PROPERTIES FOLDER Tools) # ================================================================================================= # Licenses # ================================================================================================== -set(MODULE_LICENSES getopt) +set(MODULE_LICENSES ) set(GENERATION_ROOT ${CMAKE_CURRENT_BINARY_DIR}/generated) -list_licenses(${GENERATION_ROOT}/licenses/licenses.inc ${MODULE_LICENSES}) +list_licenses(${GENERATION_ROOT}/licenses/licenses.inc "${MODULE_LICENSES}") target_include_directories(${TARGET} PRIVATE ${GENERATION_ROOT}) # ================================================================================================== diff --git a/tools/matedit/src/main.cpp b/tools/matedit/src/main.cpp index 50b4791fba..98e2101b7f 100644 --- a/tools/matedit/src/main.cpp +++ b/tools/matedit/src/main.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include #include "ExternalCompile.h" @@ -85,7 +85,7 @@ static void printUsage(const char* name) { " is guaranteed to have a .metallib extension.\n" "\n" " This command will remove the text-based shaders when writing the output material file, unless\n" - " the --preserve-text-shaders option is specified.\n" + " the --preserve-text-shaders utils::getopt::option is specified.\n" "\n" " If script exits with a non-zero exit code, MATEDIT will terminate with error. Multiple\n" " invocations of script may be launched in parallel.\n" @@ -114,21 +114,21 @@ static void license() { static int handleArguments(int argc, char* argv[], Config* config) { static constexpr const char* OPTSTR = "hli:o:t:p"; - static const struct option OPTIONS[] = { - { "help", no_argument, nullptr, 'h' }, - { "license", no_argument, nullptr, 'l' }, - { "input", required_argument, nullptr, 'i' }, - { "output", required_argument, nullptr, 'o' }, - { "type", required_argument, nullptr, 't' }, - { "preserve-text-shaders", no_argument, nullptr, 'p' }, - { nullptr, 0, nullptr, 0 } // termination of the option list + static const utils::getopt::option OPTIONS[] = { + { "help", utils::getopt::no_argument, nullptr, 'h' }, + { "license", utils::getopt::no_argument, nullptr, 'l' }, + { "input", utils::getopt::required_argument, nullptr, 'i' }, + { "output", utils::getopt::required_argument, nullptr, 'o' }, + { "type", utils::getopt::required_argument, nullptr, 't' }, + { "preserve-text-shaders", utils::getopt::no_argument, nullptr, 'p' }, + { nullptr, 0, nullptr, 0 } // termination of the utils::getopt::option list }; int opt; int optionIndex = 0; - while ((opt = getopt_long(argc, argv, OPTSTR, OPTIONS, &optionIndex)) >= 0) { - std::string arg(optarg ? optarg : ""); + while ((opt = utils::getopt::getopt_long(argc, argv, OPTSTR, OPTIONS, &optionIndex)) >= 0) { + std::string arg(utils::getopt::optarg ? utils::getopt::optarg : ""); switch (opt) { default: case 'h': @@ -158,7 +158,7 @@ static int handleArguments(int argc, char* argv[], Config* config) { } } - return optind; + return utils::getopt::optind; } int main(int argc, char* argv[]) { diff --git a/tools/matinfo/CMakeLists.txt b/tools/matinfo/CMakeLists.txt index 917d464fb9..d25e83cf56 100644 --- a/tools/matinfo/CMakeLists.txt +++ b/tools/matinfo/CMakeLists.txt @@ -13,7 +13,7 @@ set(SRCS src/main.cpp) # ================================================================================================== add_executable(${TARGET} ${SRCS}) -target_link_libraries(${TARGET} matdbg filaflat backend_headers getopt) +target_link_libraries(${TARGET} matdbg filaflat backend_headers ) # glslang contains a copy of the SPIRV headers, so let's just use those. The leading ".." in the # following variable refers to the project name that we define in glslang/tnt, and the trailing ".." @@ -25,9 +25,9 @@ set_target_properties(${TARGET} PROPERTIES FOLDER Tools) # ================================================================================================= # Licenses # ================================================================================================== -set(MODULE_LICENSES getopt glslang smol-v) +set(MODULE_LICENSES glslang smol-v) set(GENERATION_ROOT ${CMAKE_CURRENT_BINARY_DIR}/generated) -list_licenses(${GENERATION_ROOT}/licenses/licenses.inc ${MODULE_LICENSES}) +list_licenses(${GENERATION_ROOT}/licenses/licenses.inc "${MODULE_LICENSES}") target_include_directories(${TARGET} PRIVATE ${GENERATION_ROOT}) # ================================================================================================== diff --git a/tools/matinfo/src/main.cpp b/tools/matinfo/src/main.cpp index 1a9c65aa47..316e9e4fc2 100644 --- a/tools/matinfo/src/main.cpp +++ b/tools/matinfo/src/main.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include #include @@ -133,33 +133,33 @@ static void license() { static int handleArguments(int argc, char* argv[], Config* config) { static constexpr const char* OPTSTR = "hla:g:G:s:v:b:m:b:w:u:UXxyz"; constexpr int DUMP_METAL_LIBRARY_OPTION = 1000; - static const struct option OPTIONS[] = { - { "help", no_argument, nullptr, 'h' }, - { "license", no_argument, nullptr, 'l' }, - { "analyze-spirv", required_argument, nullptr, 'a' }, - { "print-glsl", required_argument, nullptr, 'g' }, - { "print-essl1", required_argument, nullptr, 'G' }, - { "print-spirv", required_argument, nullptr, 's' }, - { "print-vkglsl", required_argument, nullptr, 'v' }, - { "print-metal", required_argument, nullptr, 'm' }, - { "print-wgsl", required_argument, nullptr, 'u' }, - { "print-dic-glsl", no_argument, nullptr, 'x' }, - { "print-dic-essl1", no_argument, nullptr, 'X' }, - { "print-dic-metal", no_argument, nullptr, 'y' }, - { "print-dic-wgsl", no_argument, nullptr, 'U' }, - { "print-dic-vk", no_argument, nullptr, 'z' }, - { "dump-binary", required_argument, nullptr, 'b' }, // backwards compatibility - { "dump-spirv-binary", required_argument, nullptr, 'b' }, - { "dump-metal-library", required_argument, nullptr, DUMP_METAL_LIBRARY_OPTION }, - { "web-server", required_argument, nullptr, 'w' }, - { nullptr, 0, nullptr, 0 } // termination of the option list + static const utils::getopt::option OPTIONS[] = { + { "help", utils::getopt::no_argument, nullptr, 'h' }, + { "license", utils::getopt::no_argument, nullptr, 'l' }, + { "analyze-spirv", utils::getopt::required_argument, nullptr, 'a' }, + { "print-glsl", utils::getopt::required_argument, nullptr, 'g' }, + { "print-essl1", utils::getopt::required_argument, nullptr, 'G' }, + { "print-spirv", utils::getopt::required_argument, nullptr, 's' }, + { "print-vkglsl", utils::getopt::required_argument, nullptr, 'v' }, + { "print-metal", utils::getopt::required_argument, nullptr, 'm' }, + { "print-wgsl", utils::getopt::required_argument, nullptr, 'u' }, + { "print-dic-glsl", utils::getopt::no_argument, nullptr, 'x' }, + { "print-dic-essl1", utils::getopt::no_argument, nullptr, 'X' }, + { "print-dic-metal", utils::getopt::no_argument, nullptr, 'y' }, + { "print-dic-wgsl", utils::getopt::no_argument, nullptr, 'U' }, + { "print-dic-vk", utils::getopt::no_argument, nullptr, 'z' }, + { "dump-binary", utils::getopt::required_argument, nullptr, 'b' }, // backwards compatibility + { "dump-spirv-binary", utils::getopt::required_argument, nullptr, 'b' }, + { "dump-metal-library", utils::getopt::required_argument, nullptr, DUMP_METAL_LIBRARY_OPTION }, + { "web-server", utils::getopt::required_argument, nullptr, 'w' }, + { nullptr, 0, nullptr, 0 } // termination of the utils::getopt::option list }; int opt; int optionIndex = 0; - while ((opt = getopt_long(argc, argv, OPTSTR, OPTIONS, &optionIndex)) >= 0) { - std::string arg(optarg ? optarg : ""); + while ((opt = utils::getopt::getopt_long(argc, argv, OPTSTR, OPTIONS, &optionIndex)) >= 0) { + std::string arg(utils::getopt::optarg ? utils::getopt::optarg : ""); switch (opt) { default: case 'h': @@ -230,7 +230,7 @@ static int handleArguments(int argc, char* argv[], Config* config) { } } - return optind; + return utils::getopt::optind; } template diff --git a/tools/mipgen/CMakeLists.txt b/tools/mipgen/CMakeLists.txt index ea58e32a43..ed9d8306c0 100644 --- a/tools/mipgen/CMakeLists.txt +++ b/tools/mipgen/CMakeLists.txt @@ -12,15 +12,15 @@ set(SRCS src/main.cpp) # Target definitions # ================================================================================================== add_executable(${TARGET} ${SRCS}) -target_link_libraries(${TARGET} PRIVATE imageio getopt) +target_link_libraries(${TARGET} PRIVATE imageio ) set_target_properties(${TARGET} PROPERTIES FOLDER Tools) # ================================================================================================= # Licenses # ================================================================================================== -set(MODULE_LICENSES getopt libpng tinyexr libz stb) +set(MODULE_LICENSES libpng tinyexr libz stb) set(GENERATION_ROOT ${CMAKE_CURRENT_BINARY_DIR}/generated) -list_licenses(${GENERATION_ROOT}/licenses/licenses.inc ${MODULE_LICENSES}) +list_licenses(${GENERATION_ROOT}/licenses/licenses.inc "${MODULE_LICENSES}") target_include_directories(${TARGET} PRIVATE ${GENERATION_ROOT}) # ================================================================================================== diff --git a/tools/mipgen/src/main.cpp b/tools/mipgen/src/main.cpp index c7afabf6de..c34ddb44f8 100644 --- a/tools/mipgen/src/main.cpp +++ b/tools/mipgen/src/main.cpp @@ -26,7 +26,7 @@ #include -#include +#include #include #include @@ -152,27 +152,27 @@ static void license() { static int handleArguments(int argc, char* argv[]) { static constexpr const char* OPTSTR = "hLlgpf:c:k:saqm:"; - static const struct option OPTIONS[] = { - { "help", no_argument, 0, 'h' }, - { "license", no_argument, 0, 'L' }, - { "linear", no_argument, 0, 'l' }, - { "grayscale", no_argument, 0, 'g' }, - { "page", no_argument, 0, 'p' }, - { "format", required_argument, 0, 'f' }, - { "compression", required_argument, 0, 'c' }, - { "kernel", required_argument, 0, 'k' }, - { "strip-alpha", no_argument, 0, 's' }, - { "add-alpha", no_argument, 0, 'a' }, - { "quiet", no_argument, 0, 'q' }, - { "mip-levels", required_argument, 0, 'm' }, - { 0, 0, 0, 0 } // termination of the option list + static const utils::getopt::option OPTIONS[] = { + { "help", utils::getopt::no_argument, 0, 'h' }, + { "license", utils::getopt::no_argument, 0, 'L' }, + { "linear", utils::getopt::no_argument, 0, 'l' }, + { "grayscale", utils::getopt::no_argument, 0, 'g' }, + { "page", utils::getopt::no_argument, 0, 'p' }, + { "format", utils::getopt::required_argument, 0, 'f' }, + { "compression", utils::getopt::required_argument, 0, 'c' }, + { "kernel", utils::getopt::required_argument, 0, 'k' }, + { "strip-alpha", utils::getopt::no_argument, 0, 's' }, + { "add-alpha", utils::getopt::no_argument, 0, 'a' }, + { "quiet", utils::getopt::no_argument, 0, 'q' }, + { "mip-levels", utils::getopt::required_argument, 0, 'm' }, + { 0, 0, 0, 0 } // termination of the utils::getopt::option list }; int opt; int optionIndex = 0; - while ((opt = getopt_long(argc, argv, OPTSTR, OPTIONS, &optionIndex)) >= 0) { - std::string arg(optarg ? optarg : ""); + while ((opt = utils::getopt::getopt_long(argc, argv, OPTSTR, OPTIONS, &optionIndex)) >= 0) { + std::string arg(utils::getopt::optarg ? utils::getopt::optarg : ""); switch (opt) { default: case 'h': @@ -262,7 +262,7 @@ static int handleArguments(int argc, char* argv[]) { } } - return optind; + return utils::getopt::optind; } int main(int argc, char* argv[]) { diff --git a/tools/normal-blending/CMakeLists.txt b/tools/normal-blending/CMakeLists.txt index 8fbf794315..17218898cc 100644 --- a/tools/normal-blending/CMakeLists.txt +++ b/tools/normal-blending/CMakeLists.txt @@ -15,7 +15,7 @@ set(SRCS src/main.cpp) # ================================================================================================== add_executable(${TARGET} ${HDRS} ${SRCS}) -target_link_libraries(${TARGET} PRIVATE imageio getopt) +target_link_libraries(${TARGET} PRIVATE imageio ) set_target_properties(${TARGET} PROPERTIES FOLDER Tools) @@ -23,15 +23,15 @@ set_target_properties(${TARGET} PROPERTIES FOLDER Tools) # Compile options and optimizations # ================================================================================================== if (NOT LINUX) - target_compile_options(${TARGET} PRIVATE ) + target_compile_options(${TARGET} PRIVATE ) endif() # ================================================================================================= # Licenses # ================================================================================================== -set(MODULE_LICENSES getopt libpng tinyexr libz) +set(MODULE_LICENSES libpng tinyexr libz) set(GENERATION_ROOT ${CMAKE_CURRENT_BINARY_DIR}/generated) -list_licenses(${GENERATION_ROOT}/licenses/licenses.inc ${MODULE_LICENSES}) +list_licenses(${GENERATION_ROOT}/licenses/licenses.inc "${MODULE_LICENSES}") target_include_directories(${TARGET} PRIVATE ${GENERATION_ROOT}) # ================================================================================================== diff --git a/tools/normal-blending/src/main.cpp b/tools/normal-blending/src/main.cpp index e3cadf4451..6fd6edb9bf 100644 --- a/tools/normal-blending/src/main.cpp +++ b/tools/normal-blending/src/main.cpp @@ -25,7 +25,7 @@ #include -#include +#include using namespace filament::math; using namespace image; @@ -85,19 +85,19 @@ static void license() { static int handleArguments(int argc, char* argv[]) { static constexpr const char* OPTSTR = "hf:c:"; - static const struct option OPTIONS[] = { - { "help", no_argument, 0, 'h' }, - { "license", no_argument, 0, 'l' }, - { "format", required_argument, 0, 'f' }, - { "compression", required_argument, 0, 'c' }, - { 0, 0, 0, 0 } // termination of the option list + static const utils::getopt::option OPTIONS[] = { + { "help", utils::getopt::no_argument, 0, 'h' }, + { "license", utils::getopt::no_argument, 0, 'l' }, + { "format", utils::getopt::required_argument, 0, 'f' }, + { "compression", utils::getopt::required_argument, 0, 'c' }, + { 0, 0, 0, 0 } // termination of the utils::getopt::option list }; int opt; int optionIndex = 0; - while ((opt = getopt_long(argc, argv, OPTSTR, OPTIONS, &optionIndex)) >= 0) { - std::string arg(optarg ? optarg : ""); + while ((opt = utils::getopt::getopt_long(argc, argv, OPTSTR, OPTIONS, &optionIndex)) >= 0) { + std::string arg(utils::getopt::optarg ? utils::getopt::optarg : ""); switch (opt) { default: case 'h': @@ -136,7 +136,7 @@ static int handleArguments(int argc, char* argv[]) { } } - return optind; + return utils::getopt::optind; } int main(int argc, char* argv[]) { diff --git a/tools/resgen/CMakeLists.txt b/tools/resgen/CMakeLists.txt index 300007336a..c2e0e3b2c3 100644 --- a/tools/resgen/CMakeLists.txt +++ b/tools/resgen/CMakeLists.txt @@ -12,15 +12,15 @@ set(SRCS src/main.cpp) # Target definitions # ================================================================================================== add_executable(${TARGET} ${SRCS}) -target_link_libraries(${TARGET} PRIVATE utils getopt zstd) +target_link_libraries(${TARGET} PRIVATE utils zstd) set_target_properties(${TARGET} PROPERTIES FOLDER Tools) # ================================================================================================= # Licenses # ================================================================================================== -set(MODULE_LICENSES getopt zstd) +set(MODULE_LICENSES zstd) set(GENERATION_ROOT ${CMAKE_CURRENT_BINARY_DIR}/generated) -list_licenses(${GENERATION_ROOT}/licenses/licenses.inc ${MODULE_LICENSES}) +list_licenses(${GENERATION_ROOT}/licenses/licenses.inc "${MODULE_LICENSES}") target_include_directories(${TARGET} PRIVATE ${GENERATION_ROOT}) # ================================================================================================== diff --git a/tools/resgen/src/main.cpp b/tools/resgen/src/main.cpp index cdc7add704..273e109f5d 100644 --- a/tools/resgen/src/main.cpp +++ b/tools/resgen/src/main.cpp @@ -16,7 +16,7 @@ #include -#include +#include #include #include @@ -149,27 +149,27 @@ static std::string& replaceAll(std::string& context, const std::string& from, co return context; } -// Parses command-line arguments using getopt and populates the AppConfig struct. +// Parses command-line arguments using utils::getopt::getopt and populates the AppConfig struct. static AppConfig handleArguments(int const argc, char* argv[]) { static constexpr const char* OPTSTR = "hLp:x:ktcqjzZ"; - static const option OPTIONS[] = { - { "help", no_argument, nullptr, 'h' }, - { "license", no_argument, nullptr, 'L' }, - { "package", required_argument, nullptr, 'p' }, - { "deploy", required_argument, nullptr, 'x' }, - { "keep", no_argument, nullptr, 'k' }, - { "text", no_argument, nullptr, 't' }, - { "cfile", no_argument, nullptr, 'c' }, - { "quiet", no_argument, nullptr, 'q' }, - { "json", no_argument, nullptr, 'j' }, - { "compress", no_argument, nullptr, 'z' }, - { "compress-package", no_argument, nullptr, 'Z' }, + static const utils::getopt::option OPTIONS[] = { + { "help", utils::getopt::no_argument, nullptr, 'h' }, + { "license", utils::getopt::no_argument, nullptr, 'L' }, + { "package", utils::getopt::required_argument, nullptr, 'p' }, + { "deploy", utils::getopt::required_argument, nullptr, 'x' }, + { "keep", utils::getopt::no_argument, nullptr, 'k' }, + { "text", utils::getopt::no_argument, nullptr, 't' }, + { "cfile", utils::getopt::no_argument, nullptr, 'c' }, + { "quiet", utils::getopt::no_argument, nullptr, 'q' }, + { "json", utils::getopt::no_argument, nullptr, 'j' }, + { "compress", utils::getopt::no_argument, nullptr, 'z' }, + { "compress-package", utils::getopt::no_argument, nullptr, 'Z' }, { nullptr, 0, nullptr, 0 } }; AppConfig config; int opt; - while ((opt = getopt_long(argc, argv, OPTSTR, OPTIONS, nullptr)) >= 0) { + while ((opt = utils::getopt::getopt_long(argc, argv, OPTSTR, OPTIONS, nullptr)) >= 0) { switch (opt) { case 'h': printUsage(argv[0]); @@ -178,10 +178,10 @@ static AppConfig handleArguments(int const argc, char* argv[]) { license(); std::exit(0); case 'p': - config.packageName = optarg; + config.packageName = utils::getopt::optarg; break; case 'x': - config.deployDir = optarg; + config.deployDir = utils::getopt::optarg; break; case 'k': config.keepExtension = true; @@ -216,7 +216,7 @@ static AppConfig handleArguments(int const argc, char* argv[]) { } // Treat remaining arguments as input file paths. - for (int i = optind; i < argc; ++i) { + for (int i = utils::getopt::optind; i < argc; ++i) { config.inputPaths.emplace_back(argv[i]); } diff --git a/tools/rgb-to-lmsr/CMakeLists.txt b/tools/rgb-to-lmsr/CMakeLists.txt index 01b2cbd758..d23d5c0d0d 100644 --- a/tools/rgb-to-lmsr/CMakeLists.txt +++ b/tools/rgb-to-lmsr/CMakeLists.txt @@ -13,14 +13,14 @@ set(SRCS src/main.cpp) # ================================================================================================== add_executable(${TARGET} ${SRCS}) -target_link_libraries(${TARGET} getopt utils math) +target_link_libraries(${TARGET} utils math) set_target_properties(${TARGET} PROPERTIES FOLDER Tools) # ================================================================================================= # Licenses # ================================================================================================== -set(MODULE_LICENSES getopt) +set(MODULE_LICENSES ) set(GENERATION_ROOT ${CMAKE_CURRENT_BINARY_DIR}/generated) -list_licenses(${GENERATION_ROOT}/licenses/licenses.inc ${MODULE_LICENSES}) +list_licenses(${GENERATION_ROOT}/licenses/licenses.inc "${MODULE_LICENSES}") target_include_directories(${TARGET} PRIVATE ${GENERATION_ROOT}) diff --git a/tools/rgb-to-lmsr/src/main.cpp b/tools/rgb-to-lmsr/src/main.cpp index 8d4f3cd15f..f6bfe9231b 100644 --- a/tools/rgb-to-lmsr/src/main.cpp +++ b/tools/rgb-to-lmsr/src/main.cpp @@ -18,7 +18,7 @@ #include #include -#include +#include #include @@ -66,18 +66,18 @@ static void license() { static int handleArguments(int argc, char* argv[]) { static constexpr const char* OPTSTR = "hln"; - static const struct option OPTIONS[] = { - { "help", no_argument, nullptr, 'h' }, - { "license", no_argument, nullptr, 'l' }, - { "normalize", no_argument, nullptr, 'n' }, - { nullptr, 0, nullptr, 0 } // termination of the option list + static const utils::getopt::option OPTIONS[] = { + { "help", utils::getopt::no_argument, nullptr, 'h' }, + { "license", utils::getopt::no_argument, nullptr, 'l' }, + { "normalize", utils::getopt::no_argument, nullptr, 'n' }, + { nullptr, 0, nullptr, 0 } // termination of the utils::getopt::option list }; int opt; int optionIndex = 0; - while ((opt = getopt_long(argc, argv, OPTSTR, OPTIONS, &optionIndex)) >= 0) { - std::string arg(optarg ? optarg : ""); + while ((opt = utils::getopt::getopt_long(argc, argv, OPTSTR, OPTIONS, &optionIndex)) >= 0) { + std::string arg(utils::getopt::optarg ? utils::getopt::optarg : ""); switch (opt) { default: case 'h': @@ -92,7 +92,7 @@ static int handleArguments(int argc, char* argv[]) { } } - return optind; + return utils::getopt::optind; } // CIE 1931 reflectance spectrum for Rec.709 from 390nm to 790nm diff --git a/tools/roughness-prefilter/CMakeLists.txt b/tools/roughness-prefilter/CMakeLists.txt index 9addaa1e91..553059ed46 100644 --- a/tools/roughness-prefilter/CMakeLists.txt +++ b/tools/roughness-prefilter/CMakeLists.txt @@ -15,7 +15,7 @@ set(SRCS src/main.cpp) # ================================================================================================== add_executable(${TARGET} ${HDRS} ${SRCS}) -target_link_libraries(${TARGET} PRIVATE imageio getopt) +target_link_libraries(${TARGET} PRIVATE imageio ) set_target_properties(${TARGET} PROPERTIES FOLDER Tools) @@ -23,15 +23,15 @@ set_target_properties(${TARGET} PROPERTIES FOLDER Tools) # Compile options and optimizations # ================================================================================================== if (NOT LINUX) - target_compile_options(${TARGET} PRIVATE ) + target_compile_options(${TARGET} PRIVATE ) endif() # ================================================================================================= # Licenses # ================================================================================================== -set(MODULE_LICENSES getopt libpng tinyexr libz) +set(MODULE_LICENSES libpng tinyexr libz) set(GENERATION_ROOT ${CMAKE_CURRENT_BINARY_DIR}/generated) -list_licenses(${GENERATION_ROOT}/licenses/licenses.inc ${MODULE_LICENSES}) +list_licenses(${GENERATION_ROOT}/licenses/licenses.inc "${MODULE_LICENSES}") target_include_directories(${TARGET} PRIVATE ${GENERATION_ROOT}) # ================================================================================================== diff --git a/tools/roughness-prefilter/src/main.cpp b/tools/roughness-prefilter/src/main.cpp index e6ed1d74b8..6c167a4b50 100644 --- a/tools/roughness-prefilter/src/main.cpp +++ b/tools/roughness-prefilter/src/main.cpp @@ -33,7 +33,7 @@ #include #include -#include +#include using namespace filament::math; using namespace image; @@ -108,22 +108,22 @@ static void license() { static int handleArguments(int argc, char* argv[]) { static constexpr const char* OPTSTR = "hr:c:f:m:l"; - static const struct option OPTIONS[] = { - { "help", no_argument, nullptr, 'h' }, - { "license", no_argument, nullptr, 's' }, - { "format", required_argument, nullptr, 'f' }, - { "compression", required_argument, nullptr, 'c' }, - { "roughness", required_argument, nullptr, 'r' }, - { "roughness-map", required_argument, nullptr, 'm' }, - { "linear", no_argument, nullptr, 'l' }, - { nullptr, 0, nullptr, 0 } // termination of the option list + static const utils::getopt::option OPTIONS[] = { + { "help", utils::getopt::no_argument, nullptr, 'h' }, + { "license", utils::getopt::no_argument, nullptr, 's' }, + { "format", utils::getopt::required_argument, nullptr, 'f' }, + { "compression", utils::getopt::required_argument, nullptr, 'c' }, + { "roughness", utils::getopt::required_argument, nullptr, 'r' }, + { "roughness-map", utils::getopt::required_argument, nullptr, 'm' }, + { "linear", utils::getopt::no_argument, nullptr, 'l' }, + { nullptr, 0, nullptr, 0 } // termination of the utils::getopt::option list }; int opt; int optionIndex = 0; - while ((opt = getopt_long(argc, argv, OPTSTR, OPTIONS, &optionIndex)) >= 0) { - std::string arg(optarg ? optarg : ""); + while ((opt = utils::getopt::getopt_long(argc, argv, OPTSTR, OPTIONS, &optionIndex)) >= 0) { + std::string arg(utils::getopt::optarg ? utils::getopt::optarg : ""); switch (opt) { default: case 'h': @@ -183,7 +183,7 @@ static int handleArguments(int argc, char* argv[]) { } } - return optind; + return utils::getopt::optind; } inline bool isPOT(size_t x) { diff --git a/tools/specgen/CMakeLists.txt b/tools/specgen/CMakeLists.txt index b54e7033a5..a0d044a72a 100644 --- a/tools/specgen/CMakeLists.txt +++ b/tools/specgen/CMakeLists.txt @@ -12,15 +12,15 @@ set(SRCS specgen.cpp) # Target definitions # ================================================================================================== add_executable(${TARGET} ${SRCS}) -target_link_libraries(${TARGET} PRIVATE getopt math utils) +target_link_libraries(${TARGET} PRIVATE math utils) set_target_properties(${TARGET} PROPERTIES FOLDER Tools) # ================================================================================================= # Licenses # ================================================================================================== -set(MODULE_LICENSES getopt libpng tinyexr libz stb) +set(MODULE_LICENSES libpng tinyexr libz stb) set(GENERATION_ROOT ${CMAKE_CURRENT_BINARY_DIR}/generated) -list_licenses(${GENERATION_ROOT}/licenses/licenses.inc ${MODULE_LICENSES}) +list_licenses(${GENERATION_ROOT}/licenses/licenses.inc "${MODULE_LICENSES}") target_include_directories(${TARGET} PRIVATE ${GENERATION_ROOT}) # ================================================================================================== diff --git a/tools/specgen/specgen.cpp b/tools/specgen/specgen.cpp index 79424341e7..b22f4d4f29 100644 --- a/tools/specgen/specgen.cpp +++ b/tools/specgen/specgen.cpp @@ -109,7 +109,7 @@ #include #include -#include +#include #include #include @@ -430,38 +430,38 @@ static void printUsage(const char* name) { int main(int argc, char* argv[]) { Config config; - static const option long_options[] = { - { "n", required_argument, nullptr, 'n' }, - { "mode", required_argument, nullptr, 'm' }, - { "min", required_argument, nullptr, 's' }, - { "max", required_argument, nullptr, 'e' }, - { "dispersion", required_argument, nullptr, 'p' }, - { "lut", no_argument, nullptr, 'l' }, - { "analytic", no_argument, nullptr, 'a' }, - { "no-correct", no_argument, nullptr, 'c' }, - { "debug", no_argument, nullptr, 'd' }, - { "format", required_argument, nullptr, 'f' }, - { "help", no_argument, nullptr, 'h' }, + static const utils::getopt::option long_options[] = { + { "n", utils::getopt::required_argument, nullptr, 'n' }, + { "mode", utils::getopt::required_argument, nullptr, 'm' }, + { "min", utils::getopt::required_argument, nullptr, 's' }, + { "max", utils::getopt::required_argument, nullptr, 'e' }, + { "dispersion", utils::getopt::required_argument, nullptr, 'p' }, + { "lut", utils::getopt::no_argument, nullptr, 'l' }, + { "analytic", utils::getopt::no_argument, nullptr, 'a' }, + { "no-correct", utils::getopt::no_argument, nullptr, 'c' }, + { "debug", utils::getopt::no_argument, nullptr, 'd' }, + { "format", utils::getopt::required_argument, nullptr, 'f' }, + { "help", utils::getopt::no_argument, nullptr, 'h' }, { nullptr, 0, nullptr, 0 } }; int opt; - while ((opt = getopt_long(argc, argv, "n:m:s:e:p:lacdf:h", long_options, nullptr)) != -1) { + while ((opt = utils::getopt::getopt_long(argc, argv, "n:m:s:e:p:lacdf:h", long_options, nullptr)) != -1) { switch (opt) { case 'n': - config.n = std::atoi(optarg); + config.n = std::atoi(utils::getopt::optarg); break; case 'm': - config.mode = optarg; + config.mode = utils::getopt::optarg; break; case 's': - config.minLambda = std::atof(optarg); + config.minLambda = std::atof(utils::getopt::optarg); break; case 'e': - config.maxLambda = std::atof(optarg); + config.maxLambda = std::atof(utils::getopt::optarg); break; case 'p': - if (std::string(optarg) == "linear") config.dispersion = DispersionModel::Linear; + if (std::string(utils::getopt::optarg) == "linear") config.dispersion = DispersionModel::Linear; else config.dispersion = DispersionModel::Cauchy; break; case 'l': @@ -477,7 +477,7 @@ int main(int argc, char* argv[]) { config.debug = true; break; case 'f': - config.format = optarg; + config.format = utils::getopt::optarg; break; case 'h': printUsage(argv[0]); diff --git a/tools/specular-color/CMakeLists.txt b/tools/specular-color/CMakeLists.txt index 0aef5d8aa2..c163db96f5 100644 --- a/tools/specular-color/CMakeLists.txt +++ b/tools/specular-color/CMakeLists.txt @@ -13,16 +13,16 @@ set(SRCS src/main.cpp) # ================================================================================================== add_executable(${TARGET} ${SRCS}) -target_link_libraries(${TARGET} getopt utils math) +target_link_libraries(${TARGET} utils math) set_target_properties(${TARGET} PROPERTIES FOLDER Tools) # ================================================================================================= # Licenses # ================================================================================================== -set(MODULE_LICENSES getopt) +set(MODULE_LICENSES ) set(GENERATION_ROOT ${CMAKE_CURRENT_BINARY_DIR}/generated) -list_licenses(${GENERATION_ROOT}/licenses/licenses.inc ${MODULE_LICENSES}) +list_licenses(${GENERATION_ROOT}/licenses/licenses.inc "${MODULE_LICENSES}") target_include_directories(${TARGET} PRIVATE ${GENERATION_ROOT}) # ================================================================================================== diff --git a/tools/specular-color/src/main.cpp b/tools/specular-color/src/main.cpp index cfbf3c14c4..9ea30b0b36 100644 --- a/tools/specular-color/src/main.cpp +++ b/tools/specular-color/src/main.cpp @@ -23,7 +23,7 @@ #include -#include +#include #include #include @@ -71,18 +71,18 @@ static void license() { static int handleArguments(int argc, char* argv[]) { static constexpr const char* OPTSTR = "hla:"; - static const struct option OPTIONS[] = { - { "help", no_argument, nullptr, 'h' }, - { "license", no_argument, nullptr, 'l' }, - { "angle", 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' }, + { "license", utils::getopt::no_argument, nullptr, 'l' }, + { "angle", utils::getopt::required_argument, nullptr, 'a' }, + { nullptr, 0, nullptr, 0 } // termination of the utils::getopt::option list }; int opt; int optionIndex = 0; - while ((opt = getopt_long(argc, argv, OPTSTR, OPTIONS, &optionIndex)) >= 0) { - std::string arg(optarg ? optarg : ""); + while ((opt = utils::getopt::getopt_long(argc, argv, OPTSTR, OPTIONS, &optionIndex)) >= 0) { + std::string arg(utils::getopt::optarg ? utils::getopt::optarg : ""); switch (opt) { default: case 'h': @@ -97,7 +97,7 @@ static int handleArguments(int argc, char* argv[]) { } } - return optind; + return utils::getopt::optind; } // CIE 2006 10-deg color matching functions (CMFs), from 390nm to 830nm, at 1nm intervals @@ -802,7 +802,7 @@ static Reflectance computeColor(const std::vector& samples) { xyz.f82 = XYZ_to_sRGB(xyz.f82); // Rescale values that are outside of the sRGB gamut (gold for instance) - // We should provide an option to compute f0 in wide gamut color spaces + // We should provide an utils::getopt::option to compute f0 in wide gamut color spaces if (any(greaterThan(xyz.f0, float3{1.0f}))) xyz.f0 *= 1.0f / max(xyz.f0); if (any(greaterThan(xyz.f82, float3{1.0f}))) xyz.f82 *= 1.0f / max(xyz.f82); diff --git a/tools/uberz/CMakeLists.txt b/tools/uberz/CMakeLists.txt index 8f43412000..1d26ffe3e2 100644 --- a/tools/uberz/CMakeLists.txt +++ b/tools/uberz/CMakeLists.txt @@ -7,21 +7,21 @@ set(TARGET uberz) # Source files # ================================================================================================== set(SRCS - src/main.cpp) + src/main.cpp) # ================================================================================================== # Target definitions # ================================================================================================== add_executable(${TARGET} ${SRCS}) -target_link_libraries(${TARGET} PRIVATE getopt uberzlib) +target_link_libraries(${TARGET} PRIVATE uberzlib) set_target_properties(${TARGET} PROPERTIES FOLDER Tools) # ================================================================================================= # Licenses # ================================================================================================== -set(MODULE_LICENSES getopt) +set(MODULE_LICENSES ) set(GENERATION_ROOT ${CMAKE_CURRENT_BINARY_DIR}/generated) -list_licenses(${GENERATION_ROOT}/licenses/licenses.inc ${MODULE_LICENSES}) +list_licenses(${GENERATION_ROOT}/licenses/licenses.inc "${MODULE_LICENSES}") target_include_directories(${TARGET} PRIVATE ${GENERATION_ROOT}) # ================================================================================================== diff --git a/tools/uberz/src/main.cpp b/tools/uberz/src/main.cpp index 0677ef16bf..45e51c8af3 100644 --- a/tools/uberz/src/main.cpp +++ b/tools/uberz/src/main.cpp @@ -16,7 +16,7 @@ #include -#include +#include #include #include @@ -113,22 +113,22 @@ static void insertMapEntry(std::string assignment, StringMap& map, std::string d static int handleArguments(int argc, char* argv[]) { static constexpr const char* OPTSTR = "ahLqvo:T:"; - static const struct option OPTIONS[] = { - { "append", no_argument, 0, 'a' }, - { "help", no_argument, 0, 'h' }, - { "license", no_argument, 0, 'L' }, - { "quiet", no_argument, 0, 'q' }, - { "verbose", no_argument, 0, 'v' }, - { "output", required_argument, 0, 'o' }, - { "template", required_argument, 0, 'T' }, - { 0, 0, 0, 0 } // termination of the option list + static const utils::getopt::option OPTIONS[] = { + { "append", utils::getopt::no_argument, 0, 'a' }, + { "help", utils::getopt::no_argument, 0, 'h' }, + { "license", utils::getopt::no_argument, 0, 'L' }, + { "quiet", utils::getopt::no_argument, 0, 'q' }, + { "verbose", utils::getopt::no_argument, 0, 'v' }, + { "output", utils::getopt::required_argument, 0, 'o' }, + { "template", utils::getopt::required_argument, 0, 'T' }, + { 0, 0, 0, 0 } // termination of the utils::getopt::option list }; int opt; int optionIndex = 0; - while ((opt = getopt_long(argc, argv, OPTSTR, OPTIONS, &optionIndex)) >= 0) { - std::string arg(optarg ? optarg : ""); + while ((opt = utils::getopt::getopt_long(argc, argv, OPTSTR, OPTIONS, &optionIndex)) >= 0) { + std::string arg(utils::getopt::optarg ? utils::getopt::optarg : ""); switch (opt) { default: case 'a': @@ -141,10 +141,10 @@ static int handleArguments(int argc, char* argv[]) { license(); exit(0); case 'o': - g_outputFile = optarg; + g_outputFile = utils::getopt::optarg; break; case 'T': - insertMapEntry(optarg, g_templateMap, "missing"); + insertMapEntry(utils::getopt::optarg, g_templateMap, "missing"); break; case 'q': g_quietMode = true; @@ -155,7 +155,7 @@ static int handleArguments(int argc, char* argv[]) { } } - return optind; + return utils::getopt::optind; } static size_t getFileSize(const char* filename) {