From 8a18bb7cdf2478d68e11a5e532b5134ea92b3678 Mon Sep 17 00:00:00 2001 From: Regina Pfeifer Date: Tue, 10 Sep 2019 21:44:48 +0200 Subject: cmFind*: Port away from cmCommand --- Source/cmCommands.cxx | 13 +++++-------- Source/cmFindBase.cxx | 5 ++++- Source/cmFindBase.h | 6 +++++- Source/cmFindCommon.cxx | 10 ++++++++-- Source/cmFindCommon.h | 14 ++++++++++---- Source/cmFindFileCommand.cxx | 11 ++++++++++- Source/cmFindFileCommand.h | 18 ++++++++---------- Source/cmFindLibraryCommand.cxx | 12 +++++++++--- Source/cmFindLibraryCommand.h | 24 ++++++------------------ Source/cmFindPackageCommand.cxx | 12 +++++++++--- Source/cmFindPackageCommand.h | 27 +++++++-------------------- Source/cmFindPathCommand.cxx | 12 +++++++++--- Source/cmFindPathCommand.h | 24 ++++++------------------ Source/cmFindProgramCommand.cxx | 12 +++++++++--- Source/cmFindProgramCommand.h | 24 ++++++------------------ 15 files changed, 111 insertions(+), 113 deletions(-) diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx index 702b743..dfe130e 100644 --- a/Source/cmCommands.cxx +++ b/Source/cmCommands.cxx @@ -125,14 +125,11 @@ void GetScriptingCommands(cmState* state) state->AddBuiltinCommand("exec_program", cmExecProgramCommand); state->AddBuiltinCommand("execute_process", cmExecuteProcessCommand); state->AddBuiltinCommand("file", cmFileCommand); - state->AddBuiltinCommand("find_file", cm::make_unique()); - state->AddBuiltinCommand("find_library", - cm::make_unique()); - state->AddBuiltinCommand("find_package", - cm::make_unique()); - state->AddBuiltinCommand("find_path", cm::make_unique()); - state->AddBuiltinCommand("find_program", - cm::make_unique()); + state->AddBuiltinCommand("find_file", cmFindFile); + state->AddBuiltinCommand("find_library", cmFindLibrary); + state->AddBuiltinCommand("find_package", cmFindPackage); + state->AddBuiltinCommand("find_path", cmFindPath); + state->AddBuiltinCommand("find_program", cmFindProgram); state->AddBuiltinCommand("foreach", cmForEachCommand); state->AddBuiltinCommand("function", cmFunctionCommand); state->AddBuiltinCommand("get_cmake_property", cmGetCMakePropertyCommand); diff --git a/Source/cmFindBase.cxx b/Source/cmFindBase.cxx index cdc5f63..e0daa4f 100644 --- a/Source/cmFindBase.cxx +++ b/Source/cmFindBase.cxx @@ -16,7 +16,10 @@ #include "cmStringAlgorithms.h" #include "cmSystemTools.h" -cmFindBase::cmFindBase() +class cmExecutionStatus; + +cmFindBase::cmFindBase(cmExecutionStatus& status) + : cmFindCommon(status) { this->AlreadyInCache = false; this->AlreadyInCacheWithoutMetaInfo = false; diff --git a/Source/cmFindBase.h b/Source/cmFindBase.h index 88b5b6c..f75db5f 100644 --- a/Source/cmFindBase.h +++ b/Source/cmFindBase.h @@ -10,6 +10,8 @@ #include "cmFindCommon.h" +class cmExecutionStatus; + /** \class cmFindBase * \brief Base class for most FIND_XXX commands. * @@ -19,7 +21,9 @@ class cmFindBase : public cmFindCommon { public: - cmFindBase(); + cmFindBase(cmExecutionStatus& status); + virtual ~cmFindBase() = default; + /** * This is called when the command is first encountered in * the CMakeLists.txt file. diff --git a/Source/cmFindCommon.cxx b/Source/cmFindCommon.cxx index 9425f99..5606838 100644 --- a/Source/cmFindCommon.cxx +++ b/Source/cmFindCommon.cxx @@ -8,6 +8,7 @@ #include #include "cmAlgorithms.h" +#include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" @@ -24,7 +25,9 @@ cmFindCommon::PathLabel cmFindCommon::PathLabel::SystemEnvironment( cmFindCommon::PathLabel cmFindCommon::PathLabel::CMakeSystem("CMAKE_SYSTEM"); cmFindCommon::PathLabel cmFindCommon::PathLabel::Guess("GUESS"); -cmFindCommon::cmFindCommon() +cmFindCommon::cmFindCommon(cmExecutionStatus& status) + : Makefile(&status.GetMakefile()) + , Status(status) { this->FindRootPathMode = RootPathModeBoth; this->NoDefaultPath = false; @@ -51,7 +54,10 @@ cmFindCommon::cmFindCommon() this->InitializeSearchPathGroups(); } -cmFindCommon::~cmFindCommon() = default; +void cmFindCommon::SetError(std::string const& e) +{ + this->Status.SetError(e); +} void cmFindCommon::InitializeSearchPathGroups() { diff --git a/Source/cmFindCommon.h b/Source/cmFindCommon.h index d95eeb1..8177eac 100644 --- a/Source/cmFindCommon.h +++ b/Source/cmFindCommon.h @@ -10,10 +10,12 @@ #include #include -#include "cmCommand.h" #include "cmPathLabel.h" #include "cmSearchPath.h" +class cmExecutionStatus; +class cmMakefile; + /** \class cmFindCommon * \brief Base class for FIND_XXX implementations. * @@ -21,11 +23,12 @@ * cmFindProgramCommand, cmFindPathCommand, cmFindLibraryCommand, * cmFindFileCommand, and cmFindPackageCommand. */ -class cmFindCommon : public cmCommand +class cmFindCommon { public: - cmFindCommon(); - ~cmFindCommon() override; + cmFindCommon(cmExecutionStatus& status); + + void SetError(std::string const& e); protected: friend class cmSearchPath; @@ -127,6 +130,9 @@ protected: bool SearchAppBundleFirst; bool SearchAppBundleOnly; bool SearchAppBundleLast; + + cmMakefile* Makefile; + cmExecutionStatus& Status; }; #endif diff --git a/Source/cmFindFileCommand.cxx b/Source/cmFindFileCommand.cxx index 9840c4f..29a2bc4 100644 --- a/Source/cmFindFileCommand.cxx +++ b/Source/cmFindFileCommand.cxx @@ -2,7 +2,16 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmFindFileCommand.h" -cmFindFileCommand::cmFindFileCommand() +class cmExecutionStatus; + +cmFindFileCommand::cmFindFileCommand(cmExecutionStatus& status) + : cmFindPathCommand(status) { this->IncludeFileInPath = true; } + +bool cmFindFile(std::vector const& args, + cmExecutionStatus& status) +{ + return cmFindFileCommand(status).InitialPass(args); +} diff --git a/Source/cmFindFileCommand.h b/Source/cmFindFileCommand.h index 152b505..7dc6e55 100644 --- a/Source/cmFindFileCommand.h +++ b/Source/cmFindFileCommand.h @@ -5,11 +5,13 @@ #include "cmConfigure.h" // IWYU pragma: keep -#include "cm_memory.hxx" +#include +#include -#include "cmCommand.h" #include "cmFindPathCommand.h" +class cmExecutionStatus; + /** \class cmFindFileCommand * \brief Define a command to search for an executable program. * @@ -21,14 +23,10 @@ class cmFindFileCommand : public cmFindPathCommand { public: - cmFindFileCommand(); - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr Clone() override - { - return cm::make_unique(); - } + cmFindFileCommand(cmExecutionStatus& status); }; +bool cmFindFile(std::vector const& args, + cmExecutionStatus& status); + #endif diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx index 92c64c8..529e5c8 100644 --- a/Source/cmFindLibraryCommand.cxx +++ b/Source/cmFindLibraryCommand.cxx @@ -18,15 +18,15 @@ class cmExecutionStatus; -cmFindLibraryCommand::cmFindLibraryCommand() +cmFindLibraryCommand::cmFindLibraryCommand(cmExecutionStatus& status) + : cmFindBase(status) { this->EnvironmentPath = "LIB"; this->NamesPerDirAllowed = true; } // cmFindLibraryCommand -bool cmFindLibraryCommand::InitialPass(std::vector const& argsIn, - cmExecutionStatus&) +bool cmFindLibraryCommand::InitialPass(std::vector const& argsIn) { this->VariableDocumentation = "Path to a library."; this->CMakePathName = "LIBRARY"; @@ -490,3 +490,9 @@ std::string cmFindLibraryCommand::FindFrameworkLibraryDirsPerName() // No framework found. return ""; } + +bool cmFindLibrary(std::vector const& args, + cmExecutionStatus& status) +{ + return cmFindLibraryCommand(status).InitialPass(args); +} diff --git a/Source/cmFindLibraryCommand.h b/Source/cmFindLibraryCommand.h index af17d60..b2f71b3 100644 --- a/Source/cmFindLibraryCommand.h +++ b/Source/cmFindLibraryCommand.h @@ -8,9 +8,6 @@ #include #include -#include "cm_memory.hxx" - -#include "cmCommand.h" #include "cmFindBase.h" class cmExecutionStatus; @@ -25,21 +22,9 @@ class cmExecutionStatus; class cmFindLibraryCommand : public cmFindBase { public: - cmFindLibraryCommand(); - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr Clone() override - { - return cm::make_unique(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector const& args, - cmExecutionStatus& status) override; + cmFindLibraryCommand(cmExecutionStatus& status); + + bool InitialPass(std::vector const& args); protected: void AddArchitecturePaths(const char* suffix); @@ -57,4 +42,7 @@ private: std::string FindFrameworkLibraryDirsPerName(); }; +bool cmFindLibrary(std::vector const& args, + cmExecutionStatus& status); + #endif diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 9132760..d99b20b 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -85,7 +85,8 @@ void cmFindPackageCommand::Sort(std::vector::iterator begin, // else do not sort } -cmFindPackageCommand::cmFindPackageCommand() +cmFindPackageCommand::cmFindPackageCommand(cmExecutionStatus& status) + : cmFindCommon(status) { this->CMakePathName = "PACKAGE"; this->Quiet = false; @@ -143,8 +144,7 @@ void cmFindPackageCommand::AppendSearchPathGroups() std::make_pair(PathLabel::SystemRegistry, cmSearchPath(this))); } -bool cmFindPackageCommand::InitialPass(std::vector const& args, - cmExecutionStatus&) +bool cmFindPackageCommand::InitialPass(std::vector const& args) { if (args.empty()) { this->SetError("called with incorrect number of arguments"); @@ -2282,3 +2282,9 @@ bool cmFindPackageCommand::SearchAppBundlePrefix(std::string const& prefix_in) } // TODO: Debug cmsys::Glob double slash problem. + +bool cmFindPackage(std::vector const& args, + cmExecutionStatus& status) +{ + return cmFindPackageCommand(status).InitialPass(args); +} diff --git a/Source/cmFindPackageCommand.h b/Source/cmFindPackageCommand.h index d57b38a..78b4985 100644 --- a/Source/cmFindPackageCommand.h +++ b/Source/cmFindPackageCommand.h @@ -3,9 +3,7 @@ #ifndef cmFindPackageCommand_h #define cmFindPackageCommand_h -#include "cmCommand.h" #include "cmConfigure.h" // IWYU pragma: keep -#include "cmPolicies.h" #include "cm_kwiml.h" #include @@ -15,7 +13,8 @@ #include #include -#include "cm_memory.hxx" +#include "cmFindCommon.h" +#include "cmPolicies.h" // IWYU insists we should forward-declare instead of including , // but we cannot forward-declare reliably because some C++ standard libraries @@ -28,8 +27,6 @@ namespace std { /* clang-format on */ #endif -#include "cmFindCommon.h" - class cmExecutionStatus; class cmSearchPath; @@ -62,22 +59,9 @@ public: std::vector::iterator end, SortOrderType order, SortDirectionType dir); - cmFindPackageCommand(); + cmFindPackageCommand(cmExecutionStatus& status); - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr Clone() override - { - return cm::make_unique(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector const& args, - cmExecutionStatus& status) override; + bool InitialPass(std::vector const& args); private: class PathLabel : public cmFindCommon::PathLabel @@ -246,4 +230,7 @@ struct hash }; } +bool cmFindPackage(std::vector const& args, + cmExecutionStatus& status); + #endif diff --git a/Source/cmFindPathCommand.cxx b/Source/cmFindPathCommand.cxx index 41f5e51..f5e2631 100644 --- a/Source/cmFindPathCommand.cxx +++ b/Source/cmFindPathCommand.cxx @@ -11,15 +11,15 @@ class cmExecutionStatus; -cmFindPathCommand::cmFindPathCommand() +cmFindPathCommand::cmFindPathCommand(cmExecutionStatus& status) + : cmFindBase(status) { this->EnvironmentPath = "INCLUDE"; this->IncludeFileInPath = false; } // cmFindPathCommand -bool cmFindPathCommand::InitialPass(std::vector const& argsIn, - cmExecutionStatus&) +bool cmFindPathCommand::InitialPass(std::vector const& argsIn) { this->VariableDocumentation = "Path to a file."; this->CMakePathName = "INCLUDE"; @@ -145,3 +145,9 @@ std::string cmFindPathCommand::FindFrameworkHeader() } return ""; } + +bool cmFindPath(std::vector const& args, + cmExecutionStatus& status) +{ + return cmFindPathCommand(status).InitialPass(args); +} diff --git a/Source/cmFindPathCommand.h b/Source/cmFindPathCommand.h index 89e2cef..8d1ea8b 100644 --- a/Source/cmFindPathCommand.h +++ b/Source/cmFindPathCommand.h @@ -8,9 +8,6 @@ #include #include -#include "cm_memory.hxx" - -#include "cmCommand.h" #include "cmFindBase.h" class cmExecutionStatus; @@ -25,21 +22,9 @@ class cmExecutionStatus; class cmFindPathCommand : public cmFindBase { public: - cmFindPathCommand(); - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr Clone() override - { - return cm::make_unique(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector const& args, - cmExecutionStatus& status) override; + cmFindPathCommand(cmExecutionStatus& status); + + bool InitialPass(std::vector const& args); bool IncludeFileInPath; @@ -51,4 +36,7 @@ private: std::string FindFrameworkHeader(); }; +bool cmFindPath(std::vector const& args, + cmExecutionStatus& status); + #endif diff --git a/Source/cmFindProgramCommand.cxx b/Source/cmFindProgramCommand.cxx index a2db65c..e0a3fbf 100644 --- a/Source/cmFindProgramCommand.cxx +++ b/Source/cmFindProgramCommand.cxx @@ -88,14 +88,14 @@ struct cmFindProgramHelper } }; -cmFindProgramCommand::cmFindProgramCommand() +cmFindProgramCommand::cmFindProgramCommand(cmExecutionStatus& status) + : cmFindBase(status) { this->NamesPerDirAllowed = true; } // cmFindProgramCommand -bool cmFindProgramCommand::InitialPass(std::vector const& argsIn, - cmExecutionStatus&) +bool cmFindProgramCommand::InitialPass(std::vector const& argsIn) { this->VariableDocumentation = "Path to a program."; this->CMakePathName = "PROGRAM"; @@ -270,3 +270,9 @@ std::string cmFindProgramCommand::GetBundleExecutable( return executable; } + +bool cmFindProgram(std::vector const& args, + cmExecutionStatus& status) +{ + return cmFindProgramCommand(status).InitialPass(args); +} diff --git a/Source/cmFindProgramCommand.h b/Source/cmFindProgramCommand.h index 40e455e..043b43c 100644 --- a/Source/cmFindProgramCommand.h +++ b/Source/cmFindProgramCommand.h @@ -8,9 +8,6 @@ #include #include -#include "cm_memory.hxx" - -#include "cmCommand.h" #include "cmFindBase.h" class cmExecutionStatus; @@ -26,21 +23,9 @@ class cmExecutionStatus; class cmFindProgramCommand : public cmFindBase { public: - cmFindProgramCommand(); - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr Clone() override - { - return cm::make_unique(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector const& args, - cmExecutionStatus& status) override; + cmFindProgramCommand(cmExecutionStatus& status); + + bool InitialPass(std::vector const& args); private: std::string FindProgram(); @@ -51,4 +36,7 @@ private: std::string GetBundleExecutable(std::string const& bundlePath); }; +bool cmFindProgram(std::vector const& args, + cmExecutionStatus& status); + #endif -- cgit v0.12