Speedup find_* commands (#11412)

Delay computation of the command documentation until it is needed.
It is wasteful to do it in the constructor on every call.

Inspired-By: Christian Ehrlicher <Ch.Ehrlicher@gmx.de>
This commit is contained in:
Brad King 2010-11-12 10:47:28 -05:00
parent e6975fe82f
commit 5303fbf09e
14 changed files with 88 additions and 42 deletions

View File

@ -13,11 +13,17 @@
cmFindBase::cmFindBase()
{
cmSystemTools::ReplaceString(this->GenericDocumentationPathsOrder,
"FIND_ARGS_XXX", "<VAR> NAMES name");
this->AlreadyInCache = false;
this->AlreadyInCacheWithoutMetaInfo = false;
this->GenericDocumentation =
}
//----------------------------------------------------------------------------
void cmFindBase::GenerateDocumentation()
{
this->cmFindCommon::GenerateDocumentation();
cmSystemTools::ReplaceString(this->GenericDocumentationPathsOrder,
"FIND_ARGS_XXX", "<VAR> NAMES name");
this->GenericDocumentation =
" FIND_XXX(<VAR> name1 [path1 path2 ...])\n"
"This is the short-hand signature for the command that "
"is sufficient in many cases. It is the same "
@ -97,7 +103,18 @@ cmFindBase::cmFindBase()
this->GenericDocumentation += this->GenericDocumentationRootPath;
this->GenericDocumentation += this->GenericDocumentationPathsOrder;
}
//----------------------------------------------------------------------------
const char* cmFindBase::GetFullDocumentation()
{
if(this->GenericDocumentation.empty())
{
this->GenerateDocumentation();
}
return this->GenericDocumentation.c_str();
}
//----------------------------------------------------------------------------
bool cmFindBase::ParseArguments(std::vector<std::string> const& argsIn)
{
if(argsIn.size() < 2 )

View File

@ -31,10 +31,10 @@ public:
virtual bool ParseArguments(std::vector<std::string> const& args);
cmTypeMacro(cmFindBase, cmFindCommon);
virtual const char* GetFullDocumentation()
{return this->GenericDocumentation.c_str();}
virtual const char* GetFullDocumentation();
protected:
virtual void GenerateDocumentation();
void PrintFindStuff();
void ExpandPaths();
void AddPathSuffixes();

View File

@ -34,7 +34,11 @@ cmFindCommon::cmFindCommon()
this->SearchFrameworkLast = false;
this->SearchAppBundleOnly = false;
this->SearchAppBundleLast = false;
}
//----------------------------------------------------------------------------
void cmFindCommon::GenerateDocumentation()
{
// Documentation components.
this->GenericDocumentationMacPolicy =
"On Darwin or systems supporting OS X Frameworks, the cmake variable"

View File

@ -56,6 +56,8 @@ protected:
/** Compute the current default bundle/framework search policy. */
void SelectDefaultMacMode();
virtual void GenerateDocumentation();
cmStdString CMakePathName;
RootPathMode FindRootPathMode;

View File

@ -15,11 +15,16 @@
cmFindFileCommand::cmFindFileCommand()
{
this->IncludeFileInPath = true;
}
void cmFindFileCommand::GenerateDocumentation()
{
this->cmFindPathCommand::GenerateDocumentation();
cmSystemTools::ReplaceString(this->GenericDocumentation,
"find_path", "find_file");
cmSystemTools::ReplaceString(this->GenericDocumentation,
"directory containing the named file",
"directory containing the named file",
"full path to named file");
cmSystemTools::ReplaceString(this->GenericDocumentation,
"file in a directory", "full path to a file");
"file in a directory", "full path to a file");
}

View File

@ -44,6 +44,8 @@ public:
}
cmTypeMacro(cmFindFileCommand, cmFindPathCommand);
protected:
virtual void GenerateDocumentation();
};

View File

@ -16,6 +16,13 @@
cmFindLibraryCommand::cmFindLibraryCommand()
{
this->EnvironmentPath = "LIB";
}
//----------------------------------------------------------------------------
void cmFindLibraryCommand::GenerateDocumentation()
{
this->cmFindBase::GenerateDocumentation();
cmSystemTools::ReplaceString(this->GenericDocumentation,
"FIND_XXX", "find_library");
cmSystemTools::ReplaceString(this->GenericDocumentation,
@ -29,7 +36,7 @@ cmFindLibraryCommand::cmFindLibraryCommand()
cmSystemTools::ReplaceString(this->GenericDocumentation,
"XXX_SYSTEM", "LIB");
cmSystemTools::ReplaceString(this->GenericDocumentation,
"CMAKE_SYSTEM_XXX_PATH",
"CMAKE_SYSTEM_XXX_PATH",
"CMAKE_SYSTEM_LIBRARY_PATH");
cmSystemTools::ReplaceString(this->GenericDocumentation,
"SEARCH_XXX_DESC", "library");
@ -38,11 +45,9 @@ cmFindLibraryCommand::cmFindLibraryCommand()
cmSystemTools::ReplaceString(this->GenericDocumentation,
"XXX_SUBDIR", "lib");
cmSystemTools::ReplaceString(this->GenericDocumentation,
"CMAKE_FIND_ROOT_PATH_MODE_XXX",
"CMAKE_FIND_ROOT_PATH_MODE_XXX",
"CMAKE_FIND_ROOT_PATH_MODE_LIBRARY");
this->EnvironmentPath = "LIB";
this->GenericDocumentation +=
this->GenericDocumentation +=
"\n"
"If the library found is a framework, then VAR will be set to "
"the full path to the framework <fullPath>/A.framework. "

View File

@ -64,6 +64,7 @@ protected:
void AddArchitecturePaths(const char* suffix);
void AddLib64Paths();
std::string FindLibrary();
virtual void GenerateDocumentation();
private:
std::string FindNormalLibrary();
std::string FindFrameworkLibrary();

View File

@ -51,13 +51,6 @@ void cmFindPackageNeedBackwardsCompatibility(const std::string& variable,
//----------------------------------------------------------------------------
cmFindPackageCommand::cmFindPackageCommand()
{
cmSystemTools::ReplaceString(this->GenericDocumentationRootPath,
"CMAKE_FIND_ROOT_PATH_MODE_XXX",
"CMAKE_FIND_ROOT_PATH_MODE_PACKAGE");
cmSystemTools::ReplaceString(this->GenericDocumentationPathsOrder,
"FIND_ARGS_XXX", "<package>");
cmSystemTools::ReplaceString(this->GenericDocumentationPathsOrder,
"FIND_XXX", "find_package");
this->CMakePathName = "PACKAGE";
this->Quiet = false;
this->Required = false;
@ -78,6 +71,19 @@ cmFindPackageCommand::cmFindPackageCommand()
this->VersionFoundPatch = 0;
this->VersionFoundTweak = 0;
this->VersionFoundCount = 0;
}
//----------------------------------------------------------------------------
void cmFindPackageCommand::GenerateDocumentation()
{
this->cmFindCommon::GenerateDocumentation();
cmSystemTools::ReplaceString(this->GenericDocumentationRootPath,
"CMAKE_FIND_ROOT_PATH_MODE_XXX",
"CMAKE_FIND_ROOT_PATH_MODE_PACKAGE");
cmSystemTools::ReplaceString(this->GenericDocumentationPathsOrder,
"FIND_ARGS_XXX", "<package>");
cmSystemTools::ReplaceString(this->GenericDocumentationPathsOrder,
"FIND_XXX", "find_package");
this->CommandDocumentation =
" find_package(<package> [version] [EXACT] [QUIET]\n"
" [[REQUIRED|COMPONENTS] [components...]]\n"
@ -318,6 +324,10 @@ cmFindPackageCommand::cmFindPackageCommand()
//----------------------------------------------------------------------------
const char* cmFindPackageCommand::GetFullDocumentation()
{
if(this->CommandDocumentation.empty())
{
this->GenerateDocumentation();
}
return this->CommandDocumentation.c_str();
}

View File

@ -65,6 +65,8 @@ public:
virtual const char* GetFullDocumentation();
cmTypeMacro(cmFindPackageCommand, cmFindCommon);
protected:
virtual void GenerateDocumentation();
private:
void AppendSuccessInformation();
void AppendToProperty(const char* propertyName);

View File

@ -18,6 +18,11 @@ cmFindPathCommand::cmFindPathCommand()
{
this->EnvironmentPath = "INCLUDE";
this->IncludeFileInPath = false;
}
void cmFindPathCommand::GenerateDocumentation()
{
this->cmFindBase::GenerateDocumentation();
cmSystemTools::ReplaceString(this->GenericDocumentation,
"FIND_XXX", "find_path");
cmSystemTools::ReplaceString(this->GenericDocumentation,
@ -31,27 +36,21 @@ cmFindPathCommand::cmFindPathCommand()
cmSystemTools::ReplaceString(this->GenericDocumentation,
"XXX_SYSTEM", "INCLUDE");
cmSystemTools::ReplaceString(this->GenericDocumentation,
"CMAKE_SYSTEM_XXX_PATH",
"CMAKE_SYSTEM_INCLUDE_PATH");
"CMAKE_SYSTEM_XXX_PATH",
"CMAKE_SYSTEM_INCLUDE_PATH");
cmSystemTools::ReplaceString(this->GenericDocumentation,
"SEARCH_XXX_DESC",
"SEARCH_XXX_DESC",
"directory containing the named file");
cmSystemTools::ReplaceString(this->GenericDocumentation,
"SEARCH_XXX", "file in a directory");
cmSystemTools::ReplaceString(this->GenericDocumentation,
"XXX_SUBDIR", "include");
cmSystemTools::ReplaceString(this->GenericDocumentation,
"CMAKE_FIND_ROOT_PATH_MODE_XXX",
"CMAKE_FIND_ROOT_PATH_MODE_XXX",
"CMAKE_FIND_ROOT_PATH_MODE_INCLUDE");
this->ExtraDocAdded = false;
}
const char* cmFindPathCommand::GetFullDocumentation()
{
if(!this->ExtraDocAdded && !this->IncludeFileInPath)
if(!this->IncludeFileInPath)
{
this->GenericDocumentation +=
this->GenericDocumentation +=
"\n"
"When searching for frameworks, if the file is specified as "
"A/b.h, then the framework search will look for "
@ -59,9 +58,7 @@ const char* cmFindPathCommand::GetFullDocumentation()
"If that is found the path will be set to the path to the framework. "
"CMake will convert this to the correct -F option to include the "
"file. ";
this->ExtraDocAdded = true;
}
return this->GenericDocumentation.c_str();
}
// cmFindPathCommand

View File

@ -59,10 +59,10 @@ public:
return "Find the directory containing a file.";
}
virtual const char* GetFullDocumentation();
cmTypeMacro(cmFindPathCommand, cmFindBase);
bool IncludeFileInPath;
bool ExtraDocAdded;
protected:
virtual void GenerateDocumentation();
private:
std::string FindHeaderInFramework(std::string const& file,
std::string const& dir);

View File

@ -16,9 +16,10 @@
#if defined(__APPLE__)
#include <CoreFoundation/CoreFoundation.h>
#endif
cmFindProgramCommand::cmFindProgramCommand()
void cmFindProgramCommand::GenerateDocumentation()
{
this->cmFindBase::GenerateDocumentation();
cmSystemTools::ReplaceString(this->GenericDocumentation,
"FIND_XXX", "find_program");
cmSystemTools::ReplaceString(this->GenericDocumentation,
@ -32,8 +33,8 @@ cmFindProgramCommand::cmFindProgramCommand()
cmSystemTools::ReplaceString(this->GenericDocumentation,
"XXX_SYSTEM", "");
cmSystemTools::ReplaceString(this->GenericDocumentation,
"CMAKE_SYSTEM_XXX_PATH",
"CMAKE_SYSTEM_PROGRAM_PATH");
"CMAKE_SYSTEM_XXX_PATH",
"CMAKE_SYSTEM_PROGRAM_PATH");
cmSystemTools::ReplaceString(this->GenericDocumentation,
"SEARCH_XXX_DESC", "program");
cmSystemTools::ReplaceString(this->GenericDocumentation,
@ -41,7 +42,7 @@ cmFindProgramCommand::cmFindProgramCommand()
cmSystemTools::ReplaceString(this->GenericDocumentation,
"XXX_SUBDIR", "[s]bin");
cmSystemTools::ReplaceString(this->GenericDocumentation,
"CMAKE_FIND_ROOT_PATH_MODE_XXX",
"CMAKE_FIND_ROOT_PATH_MODE_XXX",
"CMAKE_FIND_ROOT_PATH_MODE_PROGRAM");
}

View File

@ -25,7 +25,6 @@
class cmFindProgramCommand : public cmFindBase
{
public:
cmFindProgramCommand();
/**
* This is a virtual constructor for the command.
*/
@ -63,6 +62,7 @@ public:
protected:
std::string FindProgram(std::vector<std::string> names);
virtual void GenerateDocumentation();
private:
std::string FindAppBundle(std::vector<std::string> names);