diff options
author | Brad King <brad.king@kitware.com> | 2021-03-04 21:23:52 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-03-05 14:34:59 (GMT) |
commit | 1b33150f7eff42df9d3f926b078de44681755a1d (patch) | |
tree | 8f02255db0c525896027ee6a494ccd6a24356e42 /Source/cmGlobalVisualStudio10Generator.cxx | |
parent | 414b5e0119a99de401e1d7aea61428ec2c9311d5 (diff) | |
download | CMake-1b33150f7eff42df9d3f926b078de44681755a1d.zip CMake-1b33150f7eff42df9d3f926b078de44681755a1d.tar.gz CMake-1b33150f7eff42df9d3f926b078de44681755a1d.tar.bz2 |
cmGlobalVisualStudio10Generator: Generalize flag table lookup interface
Diffstat (limited to 'Source/cmGlobalVisualStudio10Generator.cxx')
-rw-r--r-- | Source/cmGlobalVisualStudio10Generator.cxx | 59 |
1 files changed, 37 insertions, 22 deletions
diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx index 40e30d5..8d68bf6 100644 --- a/Source/cmGlobalVisualStudio10Generator.cxx +++ b/Source/cmGlobalVisualStudio10Generator.cxx @@ -1358,46 +1358,61 @@ static cmIDEFlagTable const* cmLoadFlagTableJson( return ret; } -static std::string cmGetFlagTableName(std::string const& toolsetName, - std::string const& table) +cm::optional<std::string> cmGlobalVisualStudio10Generator::FindFlagTable( + cm::string_view toolsetName, cm::string_view table) const { - return cmSystemTools::GetCMakeRoot() + "/Templates/MSBuild/FlagTables/" + - toolsetName + "_" + table + ".json"; + std::string fullPath = + cmStrCat(cmSystemTools::GetCMakeRoot(), "/Templates/MSBuild/FlagTables/", + toolsetName, '_', table, ".json"); + if (cmSystemTools::FileExists(fullPath)) { + return fullPath; + } + return {}; } cmIDEFlagTable const* cmGlobalVisualStudio10Generator::LoadFlagTable( std::string const& toolSpecificName, std::string const& defaultName, std::string const& table) const { - cmIDEFlagTable const* ret = nullptr; + cmMakefile* mf = this->GetCurrentMakefile(); std::string filename; if (!toolSpecificName.empty()) { - filename = cmGetFlagTableName(toolSpecificName, table); - ret = cmLoadFlagTableJson(filename); + if (cm::optional<std::string> found = + this->FindFlagTable(toolSpecificName, table)) { + filename = std::move(*found); + } else { + mf->IssueMessage(MessageType::FATAL_ERROR, + cmStrCat("JSON flag table for ", table, + " not found for toolset ", toolSpecificName)); + return nullptr; + } } else { std::string const& genericName = this->CanonicalToolsetName(this->GetPlatformToolsetString()); - filename = cmGetFlagTableName(genericName, table); - if (cmSystemTools::FileExists(filename)) { - ret = cmLoadFlagTableJson(filename); + cm::optional<std::string> found = this->FindFlagTable(genericName, table); + if (!found) { + found = this->FindFlagTable(defaultName, table); + } + if (found) { + filename = std::move(*found); } else { - filename = cmGetFlagTableName(defaultName, table); - ret = cmLoadFlagTableJson(filename); + mf->IssueMessage(MessageType::FATAL_ERROR, + cmStrCat("JSON flag table for ", table, + " not found for toolset ", genericName, " ", + defaultName)); + return nullptr; } } - if (!ret) { - cmMakefile* mf = this->GetCurrentMakefile(); - - std::ostringstream e; - /* clang-format off */ - e << "JSON flag table \"" << filename << - "\" could not be loaded.\n"; - /* clang-format on */ - mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); + if (cmIDEFlagTable const* ret = cmLoadFlagTableJson(filename)) { + return ret; } - return ret; + + mf->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("JSON flag table could not be loaded:\n ", filename)); + return nullptr; } cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetClFlagTable() const |