diff options
author | Robert Maynard <robert.maynard@kitware.com> | 2020-06-15 13:23:49 (GMT) |
---|---|---|
committer | Robert Maynard <robert.maynard@kitware.com> | 2020-06-22 13:13:16 (GMT) |
commit | 7628153edb74ef29e3322fd4163754e301b9cb9a (patch) | |
tree | d2c66602ea5185b4667b40d02af9306d3b0c4929 /Source/cmSourceFile.cxx | |
parent | 6f7853cb42b75715d38a71bce3123390b78a502a (diff) | |
download | CMake-7628153edb74ef29e3322fd4163754e301b9cb9a.zip CMake-7628153edb74ef29e3322fd4163754e301b9cb9a.tar.gz CMake-7628153edb74ef29e3322fd4163754e301b9cb9a.tar.bz2 |
Refactor file extension queries to be more consistent
It was very easy to forgot to check against all language file
extensions. This updates the internal API to have a unified API.
Diffstat (limited to 'Source/cmSourceFile.cxx')
-rw-r--r-- | Source/cmSourceFile.cxx | 31 |
1 files changed, 12 insertions, 19 deletions
diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx index f525439..781ddbc 100644 --- a/Source/cmSourceFile.cxx +++ b/Source/cmSourceFile.cxx @@ -2,7 +2,6 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmSourceFile.h" -#include <array> #include <utility> #include "cmGlobalGenerator.h" @@ -130,13 +129,11 @@ bool cmSourceFile::FindFullPath(std::string* error) // Location path std::string const& lPath = this->Location.GetFullPath(); // List of extension lists - std::array<std::vector<std::string> const*, 2> const extsLists = { - { &makefile->GetCMakeInstance()->GetSourceExtensions(), - &makefile->GetCMakeInstance()->GetHeaderExtensions() } - }; + std::vector<std::string> exts = + makefile->GetCMakeInstance()->GetAllExtensions(); // Tries to find the file in a given directory - auto findInDir = [this, &extsLists, &lPath](std::string const& dir) -> bool { + auto findInDir = [this, &exts, &lPath](std::string const& dir) -> bool { // Compute full path std::string const fullPath = cmSystemTools::CollapseFullPath(lPath, dir); // Try full path @@ -145,14 +142,12 @@ bool cmSourceFile::FindFullPath(std::string* error) return true; } // Try full path with extension - for (auto& exts : extsLists) { - for (std::string const& ext : *exts) { - if (!ext.empty()) { - std::string extPath = cmStrCat(fullPath, '.', ext); - if (cmSystemTools::FileExists(extPath)) { - this->FullPath = extPath; - return true; - } + for (std::string const& ext : exts) { + if (!ext.empty()) { + std::string extPath = cmStrCat(fullPath, '.', ext); + if (cmSystemTools::FileExists(extPath)) { + this->FullPath = extPath; + return true; } } } @@ -175,11 +170,9 @@ bool cmSourceFile::FindFullPath(std::string* error) // Compose error std::string err = cmStrCat("Cannot find source file:\n ", lPath, "\nTried extensions"); - for (auto exts : extsLists) { - for (std::string const& ext : *exts) { - err += " ."; - err += ext; - } + for (std::string const& ext : exts) { + err += " ."; + err += ext; } if (error != nullptr) { *error = std::move(err); |