From 2f7e45ceaf5a8c2b6474eb9c91e1f344bdb729c0 Mon Sep 17 00:00:00 2001 From: Caleb Schilly Date: Wed, 20 Dec 2023 12:59:12 -0500 Subject: [PATCH] #2175: link vt with yaml-cpp --- cmake/link_vt.cmake | 19 ++++++++++++++++ src/vt/configs/arguments/args.cc | 37 ++++++++++++++------------------ 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/cmake/link_vt.cmake b/cmake/link_vt.cmake index b85f79dff0..78423f5d43 100644 --- a/cmake/link_vt.cmake +++ b/cmake/link_vt.cmake @@ -28,6 +28,7 @@ function(link_target_with_vt) LINK_FCONTEXT LINK_CHECKPOINT LINK_CLI11 + LINK_YAMLCPP LINK_DL LINK_ZOLTAN LINK_FORT @@ -203,6 +204,24 @@ function(link_target_with_vt) ) endif() + if (NOT DEFINED ARG_LINK_YAMLCPP AND ${ARG_DEFAULT_LINK_SET} OR ARG_LINK_YAMLCPP) + if (${ARG_DEBUG_LINK}) + message(STATUS "link_target_with_vt: yaml-cpp=${ARG_LINK_YAMLCPP}") + endif() + + # Find the yaml-cpp package + find_package(yaml-cpp REQUIRED) + + # Link with yaml-cpp + target_link_libraries(${ARG_TARGET} PUBLIC ${ARG_BUILD_TYPE} yaml-cpp) + + # Include yaml-cpp headers + target_include_directories(${ARG_TARGET} PUBLIC + $ + $ + ) + endif() + if (${vt_mimalloc_enabled}) if (${ARG_DEBUG_LINK}) message(STATUS "link_target_with_vt: mimalloc=${vt_mimalloc_enabled}") diff --git a/src/vt/configs/arguments/args.cc b/src/vt/configs/arguments/args.cc index 1db16fd60f..089b640be2 100644 --- a/src/vt/configs/arguments/args.cc +++ b/src/vt/configs/arguments/args.cc @@ -88,6 +88,8 @@ void postParseTransform(AppConfig& appConfig) { } } +void parse_yaml(std::string& config_file, AppConfig& appConfig); + std::tuple parseArguments( CLI::App& app, int& argc, char**& argv, AppConfig& appConfig ) { @@ -125,20 +127,20 @@ std::tuple parseArguments( // Dispatch to CLI or yaml-cpp for config file std::string config_file; - app.add_option("--vt_input_config", config_file, "Read in a yaml, toml, or ini config file for VT") - if (config_file) { - config_ending = config_file.substr(config_file.size()-4) - if (config_ending == ".yml") | (config_ending == "yaml") { + app.add_option("--vt_input_config", config_file, "Read in a yaml, toml, or ini config file for VT"); + if (!config_file.empty()) { + std::string config_ending = config_file.substr(config_file.size()-4); + if (config_ending == ".yml" || config_ending == "yaml") { // use yaml-cpp parse_yaml(config_file, appConfig); - } else if (config_ending == ".ini") | (config_ending == "toml") { + } else if (config_ending == ".ini" || config_ending == "toml") { // use CLI parser app.set_config( "--vt_input_CLI_config", config_file, "Read in a config file with CLI library", false // not required - ) + ); } } @@ -199,27 +201,20 @@ std::tuple parseArguments( void parse_yaml(std::string& config_file, AppConfig& appConfig) { // Assume input yaml is structured the same as --vt-help - auto yaml_input = YAML::LoadAllFromFile(config_file); + auto yaml_input = YAML::LoadFile(config_file); // Output control YAML::Node output_control = yaml_input["Output Control"]; - auto quiet = "Quiet the output from vt (only errors, warnings)"; - auto always = "Colorize output (default)"; - auto never = "Do not colorize output (overrides --vt_color)"; - appConfig.vt_color = output_control["vt_color"].as(always); - appConfig.vt_no_color = output_control["vt_no_color"].as(never); - appConfig.vt_quiet = output_control["vt_quiet"].as(quiet); + appConfig.vt_color = output_control["vt_color"].as(false); + appConfig.vt_no_color = output_control["vt_no_color"].as(false); + appConfig.vt_quiet = output_control["vt_quiet"].as(false); // Signal handling YAML::Node signal_handling = yaml_input["Signal Handling"]; - auto no_sigint = "Do not register signal handler for SIGINT"; - auto no_sigsegv = "Do not register signal handler for SIGSEGV"; - auto no_sigbus = "Do not register signal handler for SIGBUS"; - auto no_terminate = "Do not register handler for std::terminate"; - appConfig.vt_no_sigint = signal_handling["vt_no_SIGINT"].as(no_sigint); - appConfig.vt_no_sigsegv = signal_handling["vt_no_SIGSEGV"].as(no_sigsegv); - appConfig.vt_no_sigbus = signal_handling["vt_no_SIGBUS"].as(no_sigbus); - appConfig.vt_no_terminate = signal_handling["vt_no_terminate"].as(no_terminate); + appConfig.vt_no_sigint = signal_handling["vt_no_SIGINT"].as(false); + appConfig.vt_no_sigsegv = signal_handling["vt_no_SIGSEGV"].as(false); + appConfig.vt_no_sigbus = signal_handling["vt_no_SIGBUS"].as(false); + appConfig.vt_no_terminate = signal_handling["vt_no_terminate"].as(false); } void addColorArgs(CLI::App& app, AppConfig& appConfig) {