diff options
author | Alex Turbov <i.zaufi@gmail.com> | 2022-07-04 03:21:05 (GMT) |
---|---|---|
committer | Alex Turbov <i.zaufi@gmail.com> | 2022-07-11 13:14:02 (GMT) |
commit | 61eb5d4de54c1fd2c05ac51d9f604a4d7ad4380b (patch) | |
tree | 63d2abbb061b8527ce69b64ea3d01be57c567be7 | |
parent | ef62f213f8c24d58c28ee1812887fc77667ead47 (diff) | |
download | CMake-61eb5d4de54c1fd2c05ac51d9f604a4d7ad4380b.zip CMake-61eb5d4de54c1fd2c05ac51d9f604a4d7ad4380b.tar.gz CMake-61eb5d4de54c1fd2c05ac51d9f604a4d7ad4380b.tar.bz2 |
cmFindPackageCommand: Avoid friendship between command class and generator
-rw-r--r-- | Source/cmFindPackageCommand.cxx | 55 | ||||
-rw-r--r-- | Source/cmFindPackageCommand.h | 2 |
2 files changed, 34 insertions, 23 deletions
diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index f955653..969f59c 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -2147,6 +2147,7 @@ void cmFindPackageCommand::StoreVersionFound() } } +// BEGIN File paths generators namespace { class cmFileList; @@ -2215,25 +2216,24 @@ bool cmFileListGeneratorBase::Consider(std::string const& fullPath, } return listing.Visit(fullPath + '/'); } -} // anonymous namespace class cmFindPackageFileList : public cmFileList { public: - cmFindPackageFileList(cmFindPackageCommand* const fpc) - : FPC(fpc) + using SearchFn = std::function<bool(const std::string&)>; + cmFindPackageFileList(const SearchFn search) + : searchFn(search) { } private: bool Visit(std::string const& fullPath) override { - return this->FPC->SearchDirectory(fullPath); + return this->searchFn(fullPath); } - cmFindPackageCommand* const FPC; + const SearchFn searchFn; }; -namespace { class cmFileListGeneratorFixed : public cmFileListGeneratorBase { public: @@ -2486,6 +2486,7 @@ private: } }; } // anonymous namespace +// END File paths generators bool cmFindPackageCommand::SearchPrefix(std::string const& prefix_in) { @@ -2515,9 +2516,13 @@ bool cmFindPackageCommand::SearchPrefix(std::string const& prefix_in) // add one. std::string const prefix = prefix_in.substr(0, prefix_in.size() - 1); + auto searchFn = [this](const std::string& fullPath) -> bool { + return this->SearchDirectory(fullPath); + }; + // PREFIX/(cmake|CMake)/ (useful on windows or in build trees) { - cmFindPackageFileList lister(this); + cmFindPackageFileList lister(searchFn); lister / cmFileListGeneratorFixed(prefix) / cmFileListGeneratorCaseInsensitive("cmake"); if (lister.Search()) { @@ -2527,7 +2532,7 @@ bool cmFindPackageCommand::SearchPrefix(std::string const& prefix_in) // PREFIX/(Foo|foo|FOO).*/ { - cmFindPackageFileList lister(this); + cmFindPackageFileList lister(searchFn); lister / cmFileListGeneratorFixed(prefix) / cmFileListGeneratorProject(this->Names, this->SortOrder, this->SortDirection); @@ -2538,7 +2543,7 @@ bool cmFindPackageCommand::SearchPrefix(std::string const& prefix_in) // PREFIX/(Foo|foo|FOO).*/(cmake|CMake)/ { - cmFindPackageFileList lister(this); + cmFindPackageFileList lister(searchFn); lister / cmFileListGeneratorFixed(prefix) / cmFileListGeneratorProject(this->Names, this->SortOrder, this->SortDirection) / @@ -2567,7 +2572,7 @@ bool cmFindPackageCommand::SearchPrefix(std::string const& prefix_in) // PREFIX/(lib/ARCH|lib*|share)/cmake/(Foo|foo|FOO).*/ { - cmFindPackageFileList lister(this); + cmFindPackageFileList lister(searchFn); lister / cmFileListGeneratorFixed(prefix) / cmFileListGeneratorEnumerate(common) / cmFileListGeneratorFixed("cmake") / @@ -2580,7 +2585,7 @@ bool cmFindPackageCommand::SearchPrefix(std::string const& prefix_in) // PREFIX/(lib/ARCH|lib*|share)/(Foo|foo|FOO).*/ { - cmFindPackageFileList lister(this); + cmFindPackageFileList lister(searchFn); lister / cmFileListGeneratorFixed(prefix) / cmFileListGeneratorEnumerate(common) / cmFileListGeneratorProject(this->Names, this->SortOrder, @@ -2592,7 +2597,7 @@ bool cmFindPackageCommand::SearchPrefix(std::string const& prefix_in) // PREFIX/(lib/ARCH|lib*|share)/(Foo|foo|FOO).*/(cmake|CMake)/ { - cmFindPackageFileList lister(this); + cmFindPackageFileList lister(searchFn); lister / cmFileListGeneratorFixed(prefix) / cmFileListGeneratorEnumerate(common) / cmFileListGeneratorProject(this->Names, this->SortOrder, @@ -2605,7 +2610,7 @@ bool cmFindPackageCommand::SearchPrefix(std::string const& prefix_in) // PREFIX/(Foo|foo|FOO).*/(lib/ARCH|lib*|share)/cmake/(Foo|foo|FOO).*/ { - cmFindPackageFileList lister(this); + cmFindPackageFileList lister(searchFn); lister / cmFileListGeneratorFixed(prefix) / cmFileListGeneratorProject(this->Names, this->SortOrder, this->SortDirection) / @@ -2620,7 +2625,7 @@ bool cmFindPackageCommand::SearchPrefix(std::string const& prefix_in) // PREFIX/(Foo|foo|FOO).*/(lib/ARCH|lib*|share)/(Foo|foo|FOO).*/ { - cmFindPackageFileList lister(this); + cmFindPackageFileList lister(searchFn); lister / cmFileListGeneratorFixed(prefix) / cmFileListGeneratorProject(this->Names, this->SortOrder, this->SortDirection) / @@ -2634,7 +2639,7 @@ bool cmFindPackageCommand::SearchPrefix(std::string const& prefix_in) // PREFIX/(Foo|foo|FOO).*/(lib/ARCH|lib*|share)/(Foo|foo|FOO).*/(cmake|CMake)/ { - cmFindPackageFileList lister(this); + cmFindPackageFileList lister(searchFn); lister / cmFileListGeneratorFixed(prefix) / cmFileListGeneratorProject(this->Names, this->SortOrder, this->SortDirection) / @@ -2658,9 +2663,13 @@ bool cmFindPackageCommand::SearchFrameworkPrefix(std::string const& prefix_in) // add one. std::string const prefix = prefix_in.substr(0, prefix_in.size() - 1); + auto searchFn = [this](const std::string& fullPath) -> bool { + return this->SearchDirectory(fullPath); + }; + // <prefix>/Foo.framework/Resources/ { - cmFindPackageFileList lister(this); + cmFindPackageFileList lister(searchFn); lister / cmFileListGeneratorFixed(prefix) / cmFileListGeneratorMacProject(this->Names, ".framework") / cmFileListGeneratorFixed("Resources"); @@ -2670,7 +2679,7 @@ bool cmFindPackageCommand::SearchFrameworkPrefix(std::string const& prefix_in) } // <prefix>/Foo.framework/Resources/CMake/ { - cmFindPackageFileList lister(this); + cmFindPackageFileList lister(searchFn); lister / cmFileListGeneratorFixed(prefix) / cmFileListGeneratorMacProject(this->Names, ".framework") / cmFileListGeneratorFixed("Resources") / @@ -2682,7 +2691,7 @@ bool cmFindPackageCommand::SearchFrameworkPrefix(std::string const& prefix_in) // <prefix>/Foo.framework/Versions/*/Resources/ { - cmFindPackageFileList lister(this); + cmFindPackageFileList lister(searchFn); lister / cmFileListGeneratorFixed(prefix) / cmFileListGeneratorMacProject(this->Names, ".framework") / cmFileListGeneratorFixed("Versions") / @@ -2694,7 +2703,7 @@ bool cmFindPackageCommand::SearchFrameworkPrefix(std::string const& prefix_in) // <prefix>/Foo.framework/Versions/*/Resources/CMake/ { - cmFindPackageFileList lister(this); + cmFindPackageFileList lister(searchFn); lister / cmFileListGeneratorFixed(prefix) / cmFileListGeneratorMacProject(this->Names, ".framework") / cmFileListGeneratorFixed("Versions") / @@ -2716,9 +2725,13 @@ bool cmFindPackageCommand::SearchAppBundlePrefix(std::string const& prefix_in) // add one. std::string const prefix = prefix_in.substr(0, prefix_in.size() - 1); + auto searchFn = [this](const std::string& fullPath) -> bool { + return this->SearchDirectory(fullPath); + }; + // <prefix>/Foo.app/Contents/Resources { - cmFindPackageFileList lister(this); + cmFindPackageFileList lister(searchFn); lister / cmFileListGeneratorFixed(prefix) / cmFileListGeneratorMacProject(this->Names, ".app") / cmFileListGeneratorFixed("Contents/Resources"); @@ -2729,7 +2742,7 @@ bool cmFindPackageCommand::SearchAppBundlePrefix(std::string const& prefix_in) // <prefix>/Foo.app/Contents/Resources/CMake { - cmFindPackageFileList lister(this); + cmFindPackageFileList lister(searchFn); lister / cmFileListGeneratorFixed(prefix) / cmFileListGeneratorMacProject(this->Names, ".app") / cmFileListGeneratorFixed("Contents/Resources") / diff --git a/Source/cmFindPackageCommand.h b/Source/cmFindPackageCommand.h index 80fd8f8..28e00a1 100644 --- a/Source/cmFindPackageCommand.h +++ b/Source/cmFindPackageCommand.h @@ -153,8 +153,6 @@ private: bool SearchFrameworkPrefix(std::string const& prefix_in); bool SearchAppBundlePrefix(std::string const& prefix_in); - friend class cmFindPackageFileList; - struct OriginalDef { bool exists; |