2003-01-21 22:15:22 +00:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
Program: CMake - Cross-Platform Makefile Generator
|
|
|
|
Module: $RCSfile$
|
|
|
|
Language: C++
|
|
|
|
Date: $Date$
|
|
|
|
Version: $Revision$
|
|
|
|
|
|
|
|
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
|
|
|
|
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
|
|
|
|
|
2004-04-26 14:49:34 +00:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
2003-01-21 22:15:22 +00:00
|
|
|
PURPOSE. See the above copyright notices for more information.
|
|
|
|
|
|
|
|
=========================================================================*/
|
|
|
|
#include "cmFindPackageCommand.h"
|
2003-07-16 18:52:51 +00:00
|
|
|
#include <cmsys/RegularExpression.hxx>
|
2003-01-21 22:15:22 +00:00
|
|
|
|
2004-10-27 14:47:14 +00:00
|
|
|
#ifdef CMAKE_BUILD_WITH_CMAKE
|
2003-08-07 20:50:38 +00:00
|
|
|
#include "cmVariableWatch.h"
|
2004-10-27 14:47:14 +00:00
|
|
|
#endif
|
2003-08-07 20:50:38 +00:00
|
|
|
|
2004-04-26 14:49:34 +00:00
|
|
|
void cmFindPackageNeedBackwardsCompatibility(const std::string& variable,
|
2007-04-11 19:13:05 +00:00
|
|
|
int access_type, void*, const char* newValue,
|
|
|
|
const cmMakefile*)
|
2003-08-07 20:50:38 +00:00
|
|
|
{
|
2007-04-11 19:13:05 +00:00
|
|
|
(void)newValue;
|
2004-10-27 14:47:14 +00:00
|
|
|
#ifdef CMAKE_BUILD_WITH_CMAKE
|
2003-08-07 20:50:38 +00:00
|
|
|
if(access_type == cmVariableWatch::UNKNOWN_VARIABLE_READ_ACCESS)
|
|
|
|
{
|
|
|
|
std::string message = "An attempt was made to access a variable: ";
|
|
|
|
message += variable;
|
|
|
|
message +=
|
|
|
|
" that has not been defined. This variable is created by the "
|
|
|
|
"FIND_PACKAGE command. CMake version 1.6 always converted the "
|
|
|
|
"variable name to upper-case, but this behavior is no longer the "
|
|
|
|
"case. To fix this you might need to set the cache value of "
|
|
|
|
"CMAKE_BACKWARDS_COMPATIBILITY to 1.6 or less. If you are writing a "
|
|
|
|
"CMake listfile, you should change the variable reference to use "
|
|
|
|
"the case of the argument to FIND_PACKAGE.";
|
|
|
|
cmSystemTools::Error(message.c_str());
|
|
|
|
}
|
2004-10-27 14:47:14 +00:00
|
|
|
#else
|
|
|
|
(void)variable;
|
|
|
|
(void)access_type;
|
|
|
|
#endif
|
2003-08-07 20:50:38 +00:00
|
|
|
}
|
|
|
|
|
2008-01-17 14:02:31 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
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;
|
|
|
|
this->NoBuilds = false;
|
|
|
|
this->NoModule = false;
|
|
|
|
this->DebugMode = false;
|
2008-08-12 23:01:04 +00:00
|
|
|
this->UseLib64Paths = false;
|
2008-01-21 13:48:33 +00:00
|
|
|
this->VersionMajor = 0;
|
|
|
|
this->VersionMinor = 0;
|
|
|
|
this->VersionPatch = 0;
|
2008-09-10 14:11:48 +00:00
|
|
|
this->VersionTweak = 0;
|
2008-01-21 13:48:33 +00:00
|
|
|
this->VersionCount = 0;
|
2008-01-29 01:38:48 +00:00
|
|
|
this->VersionExact = false;
|
|
|
|
this->VersionFoundMajor = 0;
|
|
|
|
this->VersionFoundMinor = 0;
|
|
|
|
this->VersionFoundPatch = 0;
|
2008-09-10 14:11:48 +00:00
|
|
|
this->VersionFoundTweak = 0;
|
2008-01-29 01:38:48 +00:00
|
|
|
this->VersionFoundCount = 0;
|
2008-01-17 14:02:31 +00:00
|
|
|
this->CommandDocumentation =
|
2008-09-10 14:11:48 +00:00
|
|
|
" find_package(<package> [version] [EXACT] [QUIET]\n"
|
2008-01-22 03:48:07 +00:00
|
|
|
" [[REQUIRED|COMPONENTS] [components...]])\n"
|
|
|
|
"Finds and loads settings from an external project. "
|
|
|
|
"<package>_FOUND will be set to indicate whether the package was found. "
|
|
|
|
"When the package is found package-specific information is provided "
|
|
|
|
"through variables documented by the package itself. "
|
|
|
|
"The QUIET option disables messages if the package cannot be found. "
|
|
|
|
"The REQUIRED option stops processing with an error message if the "
|
|
|
|
"package cannot be found. "
|
|
|
|
"A package-specific list of components may be listed after the "
|
|
|
|
"REQUIRED option or after the COMPONENTS option if no REQUIRED "
|
|
|
|
"option is given. "
|
2008-09-10 14:11:48 +00:00
|
|
|
"The [version] argument requests a version with which the package found "
|
|
|
|
"should be compatible (format is major[.minor[.patch[.tweak]]]). "
|
2008-01-29 01:38:48 +00:00
|
|
|
"The EXACT option requests that the version be matched exactly. "
|
2008-01-22 03:48:07 +00:00
|
|
|
"Version support is currently provided only on a package-by-package "
|
2008-01-29 01:38:48 +00:00
|
|
|
"basis (details below).\n"
|
2008-01-22 03:48:07 +00:00
|
|
|
"User code should generally look for packages using the above simple "
|
|
|
|
"signature. The remainder of this command documentation specifies the "
|
|
|
|
"full command signature and details of the search process. Project "
|
|
|
|
"maintainers wishing to provide a package to be found by this command "
|
|
|
|
"are encouraged to read on.\n"
|
|
|
|
"The command has two modes by which it searches for packages: "
|
|
|
|
"\"Module\" mode and \"Config\" mode. "
|
|
|
|
"Module mode is available when the command is invoked with the above "
|
|
|
|
"reduced signature. "
|
|
|
|
"CMake searches for a file called \"Find<package>.cmake\" in "
|
|
|
|
"the CMAKE_MODULE_PATH followed by the CMake installation. "
|
|
|
|
"If the file is found, it is read and processed by CMake. "
|
2008-01-29 01:38:48 +00:00
|
|
|
"It is responsible for finding the package, checking the version, "
|
|
|
|
"and producing any needed messages. "
|
|
|
|
"Many find-modules provide limited or no support for versioning; "
|
|
|
|
"check the module documentation. "
|
|
|
|
"If no module is found the command proceeds to Config mode.\n"
|
2008-01-22 03:48:07 +00:00
|
|
|
"The complete Config mode command signature is:\n"
|
2008-09-10 14:11:48 +00:00
|
|
|
" find_package(<package> [version] [EXACT] [QUIET]\n"
|
2008-01-29 01:38:48 +00:00
|
|
|
" [[REQUIRED|COMPONENTS] [components...]] [NO_MODULE]\n"
|
2008-01-17 14:02:31 +00:00
|
|
|
" [NAMES name1 [name2 ...]]\n"
|
|
|
|
" [CONFIGS config1 [config2 ...]]\n"
|
2008-06-09 19:08:59 +00:00
|
|
|
" [HINTS path1 [path2 ... ]]\n"
|
2008-01-17 14:02:31 +00:00
|
|
|
" [PATHS path1 [path2 ... ]]\n"
|
|
|
|
" [PATH_SUFFIXES suffix1 [suffix2 ...]]\n"
|
|
|
|
" [NO_DEFAULT_PATH]\n"
|
|
|
|
" [NO_CMAKE_ENVIRONMENT_PATH]\n"
|
|
|
|
" [NO_CMAKE_PATH]\n"
|
|
|
|
" [NO_SYSTEM_ENVIRONMENT_PATH]\n"
|
|
|
|
" [NO_CMAKE_BUILDS_PATH]\n"
|
|
|
|
" [NO_CMAKE_SYSTEM_PATH]\n"
|
|
|
|
" [CMAKE_FIND_ROOT_PATH_BOTH |\n"
|
|
|
|
" ONLY_CMAKE_FIND_ROOT_PATH |\n"
|
|
|
|
" NO_CMAKE_FIND_ROOT_PATH])\n"
|
2008-01-22 03:48:07 +00:00
|
|
|
"The NO_MODULE option may be used to skip Module mode explicitly. "
|
|
|
|
"It is also implied by use of options not specified in the reduced "
|
|
|
|
"signature. "
|
2008-01-17 14:02:31 +00:00
|
|
|
"\n"
|
|
|
|
"Config mode attempts to locate a configuration file provided by the "
|
|
|
|
"package to be found. A cache entry called <package>_DIR is created to "
|
|
|
|
"hold the directory containing the file. "
|
|
|
|
"By default the command searches for a package with the name <package>. "
|
|
|
|
"If the NAMES option is given the names following it are used instead "
|
|
|
|
"of <package>. "
|
|
|
|
"The command searches for a file called \"<name>Config.cmake\" or "
|
|
|
|
"\"<lower-case-name>-config.cmake\" for each name specified. "
|
|
|
|
"A replacement set of possible configuration file names may be given "
|
|
|
|
"using the CONFIGS option. "
|
|
|
|
"The search procedure is specified below. Once found, the configuration "
|
|
|
|
"file is read and processed by CMake. Since the file is provided by the "
|
|
|
|
"package it already knows the location of package contents. "
|
|
|
|
"The full path to the configuration file is stored in the cmake "
|
|
|
|
"variable <package>_CONFIG."
|
|
|
|
"\n"
|
|
|
|
"If the package configuration file cannot be found CMake "
|
|
|
|
"will generate an error describing the problem unless the QUIET "
|
|
|
|
"argument is specified. If REQUIRED is specified and the package "
|
|
|
|
"is not found a fatal error is generated and the configure step stops "
|
|
|
|
"executing. If <package>_DIR has been set to a directory not containing "
|
|
|
|
"a configuration file a fatal error is always generated because user "
|
|
|
|
"intervention is required."
|
|
|
|
"\n"
|
2008-09-10 14:11:48 +00:00
|
|
|
"When the [version] argument is given Config mode will only find a "
|
|
|
|
"version of the package that claims compatibility with the requested "
|
|
|
|
"version (format is major[.minor[.patch[.tweak]]]). "
|
2008-01-29 01:38:48 +00:00
|
|
|
"If the EXACT option is given only a version of the package claiming "
|
|
|
|
"an exact match of the requested version may be found. "
|
|
|
|
"CMake does not establish any convention for the meaning of version "
|
|
|
|
"numbers. "
|
|
|
|
"Package version numbers are checked by \"version\" files provided by "
|
|
|
|
"the packages themselves. "
|
|
|
|
"For a candidate package confguration file \"<config-file>.cmake\" the "
|
|
|
|
"corresponding version file is located next to it and named either "
|
|
|
|
"\"<config-file>-version.cmake\" or \"<config-file>Version.cmake\". "
|
|
|
|
"If no such version file is available then the configuration file "
|
|
|
|
"is assumed to not be compatible with any requested version. "
|
|
|
|
"When a version file is found it is loaded to check the requested "
|
|
|
|
"version number. "
|
|
|
|
"The version file is loaded in a nested scope in which the following "
|
|
|
|
"variables have been defined:\n"
|
|
|
|
" PACKAGE_FIND_NAME = the <package> name\n"
|
|
|
|
" PACKAGE_FIND_VERSION = full requested version string\n"
|
2008-09-10 14:11:48 +00:00
|
|
|
" PACKAGE_FIND_VERSION_MAJOR = major version if requested, else 0\n"
|
|
|
|
" PACKAGE_FIND_VERSION_MINOR = minor version if requested, else 0\n"
|
|
|
|
" PACKAGE_FIND_VERSION_PATCH = patch version if requested, else 0\n"
|
|
|
|
" PACKAGE_FIND_VERSION_TWEAK = tweak version if requested, else 0\n"
|
|
|
|
" PACKAGE_FIND_VERSION_COUNT = number of version components, 0 to 4\n"
|
2008-01-29 01:38:48 +00:00
|
|
|
"The version file checks whether it satisfies the requested version "
|
|
|
|
"and sets these variables:\n"
|
2008-09-10 14:11:48 +00:00
|
|
|
" PACKAGE_VERSION = full provided version string\n"
|
2008-01-29 01:38:48 +00:00
|
|
|
" PACKAGE_VERSION_EXACT = true if version is exact match\n"
|
|
|
|
" PACKAGE_VERSION_COMPATIBLE = true if version is compatible\n"
|
|
|
|
"These variables are checked by the find_package command to determine "
|
|
|
|
"whether the configuration file provides an acceptable version. "
|
|
|
|
"They are not available after the find_package call returns. "
|
|
|
|
"If the version is acceptable the following variables are set:\n"
|
2008-09-10 14:11:48 +00:00
|
|
|
" <package>_VERSION = full provided version string\n"
|
|
|
|
" <package>_VERSION_MAJOR = major version if provided, else 0\n"
|
|
|
|
" <package>_VERSION_MINOR = minor version if provided, else 0\n"
|
|
|
|
" <package>_VERSION_PATCH = patch version if provided, else 0\n"
|
|
|
|
" <package>_VERSION_TWEAK = tweak version if provided, else 0\n"
|
|
|
|
" <package>_VERSION_COUNT = number of version components, 0 to 4\n"
|
2008-01-29 14:57:39 +00:00
|
|
|
"and the corresponding package configuration file is loaded. "
|
|
|
|
"When multiple package configuration files are available whose version "
|
|
|
|
"files claim compatibility with the version requested it is unspecified "
|
|
|
|
"which one is chosen. "
|
|
|
|
"No attempt is made to choose a highest or closest version number."
|
2008-01-29 01:38:48 +00:00
|
|
|
"\n"
|
2008-01-18 01:59:57 +00:00
|
|
|
"Config mode provides an elaborate interface and search procedure. "
|
|
|
|
"Much of the interface is provided for completeness and for use "
|
|
|
|
"internally by find-modules loaded by Module mode. "
|
|
|
|
"Most user code should simply call\n"
|
2008-01-29 01:38:48 +00:00
|
|
|
" find_package(<package> [major[.minor]] [EXACT] [REQUIRED|QUIET])\n"
|
2008-01-18 01:59:57 +00:00
|
|
|
"in order to find a package. Package maintainers providing CMake "
|
|
|
|
"package configuration files are encouraged to name and install "
|
|
|
|
"them such that the procedure outlined below will find them "
|
|
|
|
"without requiring use of additional options."
|
|
|
|
"\n"
|
2008-01-17 14:02:31 +00:00
|
|
|
"CMake constructs a set of possible installation prefixes for the "
|
2008-01-18 01:59:57 +00:00
|
|
|
"package. Under each prefix several directories are searched for a "
|
|
|
|
"configuration file. The tables below show the directories searched. "
|
|
|
|
"Each entry is meant for installation trees following Windows (W), "
|
|
|
|
"UNIX (U), or Apple (A) conventions.\n"
|
2008-01-17 14:02:31 +00:00
|
|
|
" <prefix>/ (W)\n"
|
|
|
|
" <prefix>/(cmake|CMake)/ (W)\n"
|
2008-01-18 01:59:57 +00:00
|
|
|
" <prefix>/(share|lib)/<name>*/ (U)\n"
|
|
|
|
" <prefix>/(share|lib)/<name>*/(cmake|CMake)/ (U)\n"
|
2008-01-17 14:02:31 +00:00
|
|
|
"On systems supporting OS X Frameworks and Application Bundles "
|
|
|
|
"the following directories are searched for frameworks or bundles "
|
|
|
|
"containing a configuration file:\n"
|
|
|
|
" <prefix>/<name>.framework/Resources/ (A)\n"
|
|
|
|
" <prefix>/<name>.framework/Resources/CMake/ (A)\n"
|
|
|
|
" <prefix>/<name>.framework/Versions/*/Resources/ (A)\n"
|
|
|
|
" <prefix>/<name>.framework/Versions/*/Resources/CMake/ (A)\n"
|
|
|
|
" <prefix>/<name>.app/Contents/Resources/ (A)\n"
|
|
|
|
" <prefix>/<name>.app/Contents/Resources/CMake/ (A)\n"
|
|
|
|
"In all cases the <name> is treated as case-insensitive and corresponds "
|
|
|
|
"to any of the names specified (<package> or names given by NAMES). "
|
|
|
|
"If PATH_SUFFIXES is specified the suffixes are appended to each "
|
2008-01-18 01:59:57 +00:00
|
|
|
"(W) or (U) directory entry one-by-one.\n"
|
2008-01-17 14:02:31 +00:00
|
|
|
"This set of directories is intended to work in cooperation with "
|
|
|
|
"projects that provide configuration files in their installation trees. "
|
|
|
|
"Directories above marked with (W) are intended for installations on "
|
|
|
|
"Windows where the prefix may point at the top of an application's "
|
2008-01-18 01:59:57 +00:00
|
|
|
"installation directory. Those marked with (U) are intended for "
|
|
|
|
"installations on UNIX platforms where the prefix is shared by "
|
|
|
|
"multiple packages. This is merely a convention, so all (W) and (U) "
|
2008-01-17 14:02:31 +00:00
|
|
|
"directories are still searched on all platforms. "
|
|
|
|
"Directories marked with (A) are intended for installations on "
|
|
|
|
"Apple platforms. The cmake variables CMAKE_FIND_FRAMEWORK and "
|
|
|
|
"CMAKE_FIND_APPBUNDLE determine the order of preference "
|
|
|
|
"as specified below.\n"
|
|
|
|
"The set of installation prefixes is constructed using the following "
|
2008-06-09 19:22:09 +00:00
|
|
|
"steps. If NO_DEFAULT_PATH is specified all NO_* options are enabled.\n"
|
|
|
|
"1. Search paths specified in cmake-specific cache variables. "
|
|
|
|
"These are intended to be used on the command line with a -DVAR=value. "
|
|
|
|
"This can be skipped if NO_CMAKE_PATH is passed.\n"
|
2008-01-17 14:02:31 +00:00
|
|
|
" CMAKE_PREFIX_PATH\n"
|
|
|
|
" CMAKE_FRAMEWORK_PATH\n"
|
|
|
|
" CMAKE_APPBUNDLE_PATH\n"
|
2008-06-09 19:22:09 +00:00
|
|
|
"2. Search paths specified in cmake-specific environment variables. "
|
|
|
|
"These are intended to be set in the user's shell configuration. "
|
|
|
|
"This can be skipped if NO_CMAKE_ENVIRONMENT_PATH is passed.\n"
|
2008-01-17 14:02:31 +00:00
|
|
|
" CMAKE_PREFIX_PATH\n"
|
|
|
|
" CMAKE_FRAMEWORK_PATH\n"
|
|
|
|
" CMAKE_APPBUNDLE_PATH\n"
|
2008-06-09 19:08:59 +00:00
|
|
|
"3. Search paths specified by the HINTS option. "
|
|
|
|
"These should be paths computed by system introspection, such as a "
|
|
|
|
"hint provided by the location of another item already found. "
|
|
|
|
"Hard-coded guesses should be specified with the PATHS option.\n"
|
|
|
|
"4. Search the standard system environment variables. "
|
2008-01-17 14:02:31 +00:00
|
|
|
"This can be skipped if NO_SYSTEM_ENVIRONMENT_PATH is passed. "
|
|
|
|
"Path entries ending in \"/bin\" or \"/sbin\" are automatically "
|
|
|
|
"converted to their parent directories.\n"
|
|
|
|
" PATH\n"
|
2008-06-09 19:08:59 +00:00
|
|
|
"5. Search project build trees recently configured in a CMake GUI. "
|
2008-01-17 14:02:31 +00:00
|
|
|
"This can be skipped if NO_CMAKE_BUILDS_PATH is passed. "
|
|
|
|
"It is intended for the case when a user is building multiple "
|
|
|
|
"dependent projects one after another.\n"
|
2008-06-09 19:08:59 +00:00
|
|
|
"6. Search cmake variables defined in the Platform files "
|
2008-01-17 14:02:31 +00:00
|
|
|
"for the current system. This can be skipped if NO_CMAKE_SYSTEM_PATH "
|
|
|
|
"is passed.\n"
|
|
|
|
" CMAKE_SYSTEM_PREFIX_PATH\n"
|
|
|
|
" CMAKE_SYSTEM_FRAMEWORK_PATH\n"
|
|
|
|
" CMAKE_SYSTEM_APPBUNDLE_PATH\n"
|
2008-06-09 19:08:59 +00:00
|
|
|
"7. Search paths specified by the PATHS option. "
|
|
|
|
"These are typically hard-coded guesses.\n"
|
2008-01-17 14:02:31 +00:00
|
|
|
;
|
|
|
|
this->CommandDocumentation += this->GenericDocumentationMacPolicy;
|
|
|
|
this->CommandDocumentation += this->GenericDocumentationRootPath;
|
|
|
|
this->CommandDocumentation += this->GenericDocumentationPathsOrder;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
const char* cmFindPackageCommand::GetFullDocumentation()
|
|
|
|
{
|
|
|
|
return this->CommandDocumentation.c_str();
|
|
|
|
}
|
|
|
|
|
2003-01-21 22:15:22 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2008-01-23 15:28:26 +00:00
|
|
|
bool cmFindPackageCommand
|
|
|
|
::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
|
2003-01-21 22:15:22 +00:00
|
|
|
{
|
|
|
|
if(args.size() < 1)
|
|
|
|
{
|
|
|
|
this->SetError("called with incorrect number of arguments");
|
|
|
|
return false;
|
|
|
|
}
|
2004-04-26 14:49:34 +00:00
|
|
|
|
2008-01-17 14:02:31 +00:00
|
|
|
// Check for debug mode.
|
|
|
|
this->DebugMode = this->Makefile->IsOn("CMAKE_FIND_DEBUG_MODE");
|
|
|
|
|
2008-08-12 23:01:04 +00:00
|
|
|
// Lookup whether lib64 paths should be used.
|
|
|
|
if(const char* sizeof_dptr =
|
|
|
|
this->Makefile->GetDefinition("CMAKE_SIZEOF_VOID_P"))
|
|
|
|
{
|
|
|
|
if(atoi(sizeof_dptr) == 8 &&
|
|
|
|
this->Makefile->GetCMakeInstance()
|
|
|
|
->GetPropertyAsBool("FIND_LIBRARY_USE_LIB64_PATHS"))
|
|
|
|
{
|
|
|
|
this->UseLib64Paths = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-17 14:02:31 +00:00
|
|
|
// Find the current root path mode.
|
|
|
|
this->SelectDefaultRootPathMode();
|
|
|
|
|
|
|
|
// Find the current bundle/framework search policy.
|
|
|
|
this->SelectDefaultMacMode();
|
|
|
|
|
2006-10-26 15:39:56 +00:00
|
|
|
// Record options.
|
2003-01-21 22:15:22 +00:00
|
|
|
this->Name = args[0];
|
2006-10-26 15:39:56 +00:00
|
|
|
std::string components;
|
|
|
|
const char* components_sep = "";
|
|
|
|
|
2008-01-17 14:02:31 +00:00
|
|
|
// Check ancient compatibility.
|
|
|
|
this->Compatibility_1_6 =
|
|
|
|
this->Makefile->GetLocalGenerator()
|
|
|
|
->NeedBackwardsCompatibility(1, 6);
|
|
|
|
|
|
|
|
// Always search directly in a generated path.
|
|
|
|
this->SearchPathSuffixes.push_back("");
|
|
|
|
|
2006-10-26 15:39:56 +00:00
|
|
|
// Parse the arguments.
|
2008-01-17 14:02:31 +00:00
|
|
|
enum Doing { DoingNone, DoingComponents, DoingNames, DoingPaths,
|
2008-06-09 19:08:59 +00:00
|
|
|
DoingPathSuffixes, DoingConfigs, DoingHints };
|
2008-01-17 14:02:31 +00:00
|
|
|
Doing doing = DoingNone;
|
2006-10-26 15:39:56 +00:00
|
|
|
cmsys::RegularExpression version("^[0-9.]+$");
|
|
|
|
bool haveVersion = false;
|
|
|
|
for(unsigned int i=1; i < args.size(); ++i)
|
2003-07-16 18:52:51 +00:00
|
|
|
{
|
2006-10-26 15:39:56 +00:00
|
|
|
if(args[i] == "QUIET")
|
2003-07-16 18:52:51 +00:00
|
|
|
{
|
2008-01-17 14:02:31 +00:00
|
|
|
this->Quiet = true;
|
|
|
|
doing = DoingNone;
|
2006-10-26 15:39:56 +00:00
|
|
|
}
|
2008-01-29 01:38:48 +00:00
|
|
|
else if(args[i] == "EXACT")
|
|
|
|
{
|
|
|
|
this->VersionExact = true;
|
|
|
|
this->Compatibility_1_6 = false;
|
|
|
|
doing = DoingNone;
|
|
|
|
}
|
2006-10-26 15:39:56 +00:00
|
|
|
else if(args[i] == "NO_MODULE")
|
|
|
|
{
|
2008-01-17 14:02:31 +00:00
|
|
|
this->NoModule = true;
|
|
|
|
doing = DoingNone;
|
2006-10-26 15:39:56 +00:00
|
|
|
}
|
|
|
|
else if(args[i] == "REQUIRED")
|
|
|
|
{
|
2008-01-17 14:02:31 +00:00
|
|
|
this->Required = true;
|
|
|
|
doing = DoingComponents;
|
2006-10-26 15:39:56 +00:00
|
|
|
}
|
|
|
|
else if(args[i] == "COMPONENTS")
|
|
|
|
{
|
2008-01-17 14:02:31 +00:00
|
|
|
this->Compatibility_1_6 = false;
|
|
|
|
doing = DoingComponents;
|
|
|
|
}
|
|
|
|
else if(args[i] == "NAMES")
|
|
|
|
{
|
|
|
|
this->NoModule = true;
|
|
|
|
this->Compatibility_1_6 = false;
|
|
|
|
doing = DoingNames;
|
2003-07-16 18:52:51 +00:00
|
|
|
}
|
2008-01-17 14:02:31 +00:00
|
|
|
else if(args[i] == "PATHS")
|
|
|
|
{
|
|
|
|
this->NoModule = true;
|
|
|
|
this->Compatibility_1_6 = false;
|
|
|
|
doing = DoingPaths;
|
|
|
|
}
|
2008-06-09 19:08:59 +00:00
|
|
|
else if(args[i] == "HINTS")
|
|
|
|
{
|
|
|
|
this->NoModule = true;
|
|
|
|
this->Compatibility_1_6 = false;
|
|
|
|
doing = DoingHints;
|
|
|
|
}
|
2008-01-17 14:02:31 +00:00
|
|
|
else if(args[i] == "PATH_SUFFIXES")
|
|
|
|
{
|
|
|
|
this->NoModule = true;
|
|
|
|
this->Compatibility_1_6 = false;
|
|
|
|
doing = DoingPathSuffixes;
|
|
|
|
}
|
|
|
|
else if(args[i] == "CONFIGS")
|
|
|
|
{
|
|
|
|
this->NoModule = true;
|
|
|
|
this->Compatibility_1_6 = false;
|
|
|
|
doing = DoingConfigs;
|
|
|
|
}
|
|
|
|
else if(args[i] == "NO_CMAKE_BUILDS_PATH")
|
|
|
|
{
|
|
|
|
this->NoBuilds = true;
|
|
|
|
this->NoModule = true;
|
|
|
|
this->Compatibility_1_6 = false;
|
|
|
|
doing = DoingNone;
|
|
|
|
}
|
|
|
|
else if(this->CheckCommonArgument(args[i]))
|
|
|
|
{
|
|
|
|
this->NoModule = true;
|
|
|
|
this->Compatibility_1_6 = false;
|
|
|
|
doing = DoingNone;
|
|
|
|
}
|
|
|
|
else if(doing == DoingComponents)
|
2006-10-26 15:39:56 +00:00
|
|
|
{
|
|
|
|
// Set a variable telling the find script this component
|
|
|
|
// is required.
|
2008-09-06 23:10:02 +00:00
|
|
|
std::string req_var = this->Name + "_FIND_REQUIRED_" + args[i];
|
2006-10-26 15:39:56 +00:00
|
|
|
this->Makefile->AddDefinition(req_var.c_str(), "1");
|
2006-07-11 21:10:00 +00:00
|
|
|
|
2006-10-26 15:39:56 +00:00
|
|
|
// Append to the list of required components.
|
|
|
|
components += components_sep;
|
|
|
|
components += args[i];
|
|
|
|
components_sep = ";";
|
|
|
|
}
|
2008-01-17 14:02:31 +00:00
|
|
|
else if(doing == DoingNames)
|
|
|
|
{
|
|
|
|
this->Names.push_back(args[i]);
|
|
|
|
}
|
|
|
|
else if(doing == DoingPaths)
|
|
|
|
{
|
2008-06-09 19:08:59 +00:00
|
|
|
this->AddUserPath(args[i], this->UserPaths);
|
|
|
|
}
|
|
|
|
else if(doing == DoingHints)
|
|
|
|
{
|
|
|
|
this->AddUserPath(args[i], this->UserHints);
|
2008-01-17 14:02:31 +00:00
|
|
|
}
|
|
|
|
else if(doing == DoingPathSuffixes)
|
|
|
|
{
|
|
|
|
this->AddPathSuffix(args[i]);
|
|
|
|
}
|
|
|
|
else if(doing == DoingConfigs)
|
|
|
|
{
|
2008-01-29 01:38:48 +00:00
|
|
|
if(args[i].find_first_of(":/\\") != args[i].npos ||
|
|
|
|
cmSystemTools::GetFilenameLastExtension(args[i]) != ".cmake")
|
|
|
|
{
|
|
|
|
cmOStringStream e;
|
|
|
|
e << "given CONFIGS option followed by invalid file name \""
|
|
|
|
<< args[i] << "\". The names given must be file names without "
|
|
|
|
<< "a path and with a \".cmake\" extension.";
|
|
|
|
return false;
|
|
|
|
}
|
2008-01-17 14:02:31 +00:00
|
|
|
this->Configs.push_back(args[i]);
|
|
|
|
}
|
2006-10-26 15:39:56 +00:00
|
|
|
else if(!haveVersion && version.find(args[i].c_str()))
|
|
|
|
{
|
|
|
|
haveVersion = true;
|
2008-01-21 13:48:33 +00:00
|
|
|
this->Version = args[i];
|
2006-10-26 15:39:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cmOStringStream e;
|
|
|
|
e << "called with invalid argument \"" << args[i].c_str() << "\"";
|
|
|
|
this->SetError(e.str().c_str());
|
|
|
|
return false;
|
|
|
|
}
|
2003-07-16 18:52:51 +00:00
|
|
|
}
|
2004-04-26 14:49:34 +00:00
|
|
|
|
2008-10-03 14:39:53 +00:00
|
|
|
// Ignore EXACT with no version.
|
|
|
|
if(this->Version.empty() && this->VersionExact)
|
|
|
|
{
|
|
|
|
this->VersionExact = false;
|
|
|
|
this->Makefile->IssueMessage(
|
|
|
|
cmake::AUTHOR_WARNING, "Ignoring EXACT since no version is requested.");
|
|
|
|
}
|
|
|
|
|
2008-01-21 13:48:33 +00:00
|
|
|
if(!this->Version.empty())
|
|
|
|
{
|
|
|
|
// Try to parse the version number and store the results that were
|
|
|
|
// successfully parsed.
|
|
|
|
unsigned int parsed_major;
|
|
|
|
unsigned int parsed_minor;
|
|
|
|
unsigned int parsed_patch;
|
2008-09-10 14:11:48 +00:00
|
|
|
unsigned int parsed_tweak;
|
|
|
|
this->VersionCount = sscanf(this->Version.c_str(), "%u.%u.%u.%u",
|
|
|
|
&parsed_major, &parsed_minor,
|
|
|
|
&parsed_patch, &parsed_tweak);
|
2008-01-21 13:48:33 +00:00
|
|
|
switch(this->VersionCount)
|
|
|
|
{
|
2008-09-10 14:11:48 +00:00
|
|
|
case 4: this->VersionTweak = parsed_tweak; // no break!
|
2008-01-21 13:48:33 +00:00
|
|
|
case 3: this->VersionPatch = parsed_patch; // no break!
|
|
|
|
case 2: this->VersionMinor = parsed_minor; // no break!
|
|
|
|
case 1: this->VersionMajor = parsed_major; // no break!
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-06 23:10:02 +00:00
|
|
|
this->SetModuleVariables(components);
|
2006-10-26 15:39:56 +00:00
|
|
|
|
2008-01-17 14:02:31 +00:00
|
|
|
// See if there is a Find<package>.cmake module.
|
|
|
|
if(!this->NoModule)
|
2003-01-21 22:15:22 +00:00
|
|
|
{
|
2006-10-26 15:39:56 +00:00
|
|
|
bool foundModule = false;
|
2008-01-17 14:02:31 +00:00
|
|
|
if(!this->FindModule(foundModule))
|
2006-10-26 15:39:56 +00:00
|
|
|
{
|
2008-01-17 14:02:31 +00:00
|
|
|
this->AppendSuccessInformation();
|
2006-10-26 15:39:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if(foundModule)
|
|
|
|
{
|
2008-01-17 14:02:31 +00:00
|
|
|
this->AppendSuccessInformation();
|
2006-10-26 15:39:56 +00:00
|
|
|
return true;
|
|
|
|
}
|
2003-01-21 22:15:22 +00:00
|
|
|
}
|
2003-08-07 20:50:38 +00:00
|
|
|
|
2003-01-21 22:15:22 +00:00
|
|
|
// No find module. Assume the project has a CMake config file. Use
|
2008-01-17 14:02:31 +00:00
|
|
|
// a <package>_DIR cache variable to locate it.
|
2003-07-16 18:52:51 +00:00
|
|
|
this->Variable = this->Name;
|
2003-01-21 22:15:22 +00:00
|
|
|
this->Variable += "_DIR";
|
2004-04-26 14:49:34 +00:00
|
|
|
|
2008-01-17 14:02:31 +00:00
|
|
|
// Add the default name.
|
|
|
|
if(this->Names.empty())
|
|
|
|
{
|
|
|
|
this->Names.push_back(this->Name);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the default configs.
|
|
|
|
if(this->Configs.empty())
|
|
|
|
{
|
|
|
|
for(std::vector<std::string>::const_iterator ni = this->Names.begin();
|
|
|
|
ni != this->Names.end(); ++ni)
|
|
|
|
{
|
|
|
|
std::string config = *ni;
|
|
|
|
config += "Config.cmake";
|
|
|
|
this->Configs.push_back(config);
|
|
|
|
|
|
|
|
config = cmSystemTools::LowerCase(*ni);
|
|
|
|
config += "-config.cmake";
|
|
|
|
this->Configs.push_back(config);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find and load the package.
|
|
|
|
bool result = this->HandlePackageMode();
|
|
|
|
this->AppendSuccessInformation();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-09-06 23:10:02 +00:00
|
|
|
|
2008-01-17 14:02:31 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2008-09-07 10:52:06 +00:00
|
|
|
void cmFindPackageCommand::SetModuleVariables(const std::string& components)
|
2008-01-17 14:02:31 +00:00
|
|
|
{
|
2008-09-06 23:10:02 +00:00
|
|
|
// Store the list of components.
|
|
|
|
std::string components_var = this->Name + "_FIND_COMPONENTS";
|
|
|
|
this->Makefile->AddDefinition(components_var.c_str(), components.c_str());
|
|
|
|
|
|
|
|
if(this->Quiet)
|
2008-01-17 14:02:31 +00:00
|
|
|
{
|
2008-09-06 23:10:02 +00:00
|
|
|
// Tell the module that is about to be read that it should find
|
|
|
|
// quietly.
|
|
|
|
std::string quietly = this->Name;
|
|
|
|
quietly += "_FIND_QUIETLY";
|
|
|
|
this->Makefile->AddDefinition(quietly.c_str(), "1");
|
|
|
|
}
|
2008-01-17 14:02:31 +00:00
|
|
|
|
2008-09-06 23:10:02 +00:00
|
|
|
if(this->Required)
|
|
|
|
{
|
|
|
|
// Tell the module that is about to be read that it should report
|
|
|
|
// a fatal error if the package is not found.
|
|
|
|
std::string req = this->Name;
|
|
|
|
req += "_FIND_REQUIRED";
|
|
|
|
this->Makefile->AddDefinition(req.c_str(), "1");
|
|
|
|
}
|
2008-01-17 14:02:31 +00:00
|
|
|
|
2008-09-06 23:10:02 +00:00
|
|
|
if(!this->Version.empty())
|
|
|
|
{
|
|
|
|
// Tell the module that is about to be read what version of the
|
|
|
|
// package has been requested.
|
|
|
|
std::string ver = this->Name;
|
|
|
|
ver += "_FIND_VERSION";
|
|
|
|
this->Makefile->AddDefinition(ver.c_str(), this->Version.c_str());
|
|
|
|
char buf[64];
|
2008-09-10 14:11:48 +00:00
|
|
|
sprintf(buf, "%u", this->VersionMajor);
|
|
|
|
this->Makefile->AddDefinition((ver+"_MAJOR").c_str(), buf);
|
|
|
|
sprintf(buf, "%u", this->VersionMinor);
|
|
|
|
this->Makefile->AddDefinition((ver+"_MINOR").c_str(), buf);
|
|
|
|
sprintf(buf, "%u", this->VersionPatch);
|
|
|
|
this->Makefile->AddDefinition((ver+"_PATCH").c_str(), buf);
|
|
|
|
sprintf(buf, "%u", this->VersionTweak);
|
|
|
|
this->Makefile->AddDefinition((ver+"_TWEAK").c_str(), buf);
|
|
|
|
sprintf(buf, "%u", this->VersionCount);
|
|
|
|
this->Makefile->AddDefinition((ver+"_COUNT").c_str(), buf);
|
2008-01-21 13:48:33 +00:00
|
|
|
|
2008-09-06 23:10:02 +00:00
|
|
|
// Tell the module whether an exact version has been requested.
|
|
|
|
std::string exact = this->Name;
|
|
|
|
exact += "_FIND_VERSION_EXACT";
|
|
|
|
this->Makefile->AddDefinition(exact.c_str(),
|
|
|
|
this->VersionExact? "1":"0");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmFindPackageCommand::FindModule(bool& found)
|
|
|
|
{
|
|
|
|
std::string module = "Find";
|
|
|
|
module += this->Name;
|
|
|
|
module += ".cmake";
|
|
|
|
std::string mfile = this->Makefile->GetModulesFile(module.c_str());
|
|
|
|
if ( mfile.size() )
|
|
|
|
{
|
2008-01-17 14:02:31 +00:00
|
|
|
// Load the module we found.
|
|
|
|
found = true;
|
|
|
|
return this->ReadListFile(mfile.c_str());
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmFindPackageCommand::HandlePackageMode()
|
|
|
|
{
|
2003-08-07 20:50:38 +00:00
|
|
|
// Support old capitalization behavior.
|
|
|
|
std::string upperDir = cmSystemTools::UpperCase(this->Name);
|
|
|
|
std::string upperFound = cmSystemTools::UpperCase(this->Name);
|
|
|
|
upperDir += "_DIR";
|
|
|
|
upperFound += "_FOUND";
|
2008-01-17 14:02:31 +00:00
|
|
|
if(upperDir == this->Variable)
|
2003-08-07 20:50:38 +00:00
|
|
|
{
|
2008-01-17 14:02:31 +00:00
|
|
|
this->Compatibility_1_6 = false;
|
2003-08-07 20:50:38 +00:00
|
|
|
}
|
2004-04-26 14:49:34 +00:00
|
|
|
|
2003-08-07 20:50:38 +00:00
|
|
|
// Try to find the config file.
|
2006-03-15 16:02:08 +00:00
|
|
|
const char* def = this->Makefile->GetDefinition(this->Variable.c_str());
|
2008-01-17 14:02:31 +00:00
|
|
|
if(this->Compatibility_1_6 && cmSystemTools::IsOff(def))
|
2003-08-07 20:50:38 +00:00
|
|
|
{
|
|
|
|
// Use the setting of the old name of the variable to provide the
|
|
|
|
// value of the new.
|
2006-03-15 16:02:08 +00:00
|
|
|
const char* oldDef = this->Makefile->GetDefinition(upperDir.c_str());
|
2003-08-07 20:50:38 +00:00
|
|
|
if(!cmSystemTools::IsOff(oldDef))
|
|
|
|
{
|
2006-03-15 16:02:08 +00:00
|
|
|
this->Makefile->AddDefinition(this->Variable.c_str(), oldDef);
|
|
|
|
def = this->Makefile->GetDefinition(this->Variable.c_str());
|
2003-08-07 20:50:38 +00:00
|
|
|
}
|
2004-04-26 14:49:34 +00:00
|
|
|
}
|
2008-01-17 14:02:31 +00:00
|
|
|
|
|
|
|
// Search for the config file if it is not already found.
|
2003-01-21 22:15:22 +00:00
|
|
|
if(cmSystemTools::IsOff(def))
|
|
|
|
{
|
2008-01-17 14:02:31 +00:00
|
|
|
this->FindConfig();
|
|
|
|
def = this->Makefile->GetDefinition(this->Variable.c_str());
|
2003-01-21 22:15:22 +00:00
|
|
|
}
|
2004-04-26 14:49:34 +00:00
|
|
|
|
2003-01-21 22:15:22 +00:00
|
|
|
// If the config file was found, load it.
|
2008-01-17 14:02:31 +00:00
|
|
|
std::string file;
|
2003-01-21 22:15:22 +00:00
|
|
|
bool result = true;
|
|
|
|
bool found = false;
|
|
|
|
if(!cmSystemTools::IsOff(def))
|
|
|
|
{
|
2008-01-17 14:02:31 +00:00
|
|
|
// Get the directory from the variable value.
|
|
|
|
std::string dir = def;
|
|
|
|
cmSystemTools::ConvertToUnixSlashes(dir);
|
|
|
|
|
|
|
|
// Treat relative paths with respect to the current source dir.
|
|
|
|
if(!cmSystemTools::FileIsFullPath(dir.c_str()))
|
2007-08-20 12:49:21 +00:00
|
|
|
{
|
2008-01-17 14:02:31 +00:00
|
|
|
dir = "/" + dir;
|
|
|
|
dir = this->Makefile->GetCurrentDirectory() + dir;
|
2007-08-20 12:49:21 +00:00
|
|
|
}
|
2007-12-15 19:17:21 +00:00
|
|
|
|
2008-01-17 14:02:31 +00:00
|
|
|
// Find the configuration file.
|
2008-01-29 01:38:48 +00:00
|
|
|
if(this->FindConfigFileToLoad(dir, file))
|
2003-01-21 22:15:22 +00:00
|
|
|
{
|
2008-01-29 01:38:48 +00:00
|
|
|
// Set the version variables before loading the config file.
|
|
|
|
// It may override them.
|
|
|
|
this->StoreVersionFound();
|
|
|
|
|
2008-01-17 14:02:31 +00:00
|
|
|
// Parse the configuration file.
|
|
|
|
if(this->ReadListFile(file.c_str()))
|
2003-01-21 22:15:22 +00:00
|
|
|
{
|
2008-01-17 14:02:31 +00:00
|
|
|
// The package has been found.
|
2003-01-21 22:15:22 +00:00
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-01-17 14:02:31 +00:00
|
|
|
// The configuration file is invalid.
|
2003-01-21 22:15:22 +00:00
|
|
|
result = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-01-17 14:02:31 +00:00
|
|
|
// The variable setting is wrong.
|
2003-01-21 22:15:22 +00:00
|
|
|
cmOStringStream e;
|
2008-01-17 14:02:31 +00:00
|
|
|
e << "cannot find package " << this->Name << " because "
|
|
|
|
<< this->Variable << " is set to \"" << def << "\" "
|
|
|
|
<< "which is not a directory containing a package configuration "
|
2008-01-29 01:38:48 +00:00
|
|
|
<< "file (or it is not for the requested version). "
|
2008-01-17 14:02:31 +00:00
|
|
|
<< "Please set the cache entry " << this->Variable << " "
|
|
|
|
<< "to the correct directory, or delete it to ask CMake "
|
|
|
|
<< "to search.";
|
|
|
|
this->SetError(e.str().c_str());
|
|
|
|
result = false;
|
2003-01-21 22:15:22 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-17 14:02:31 +00:00
|
|
|
else if(!this->Quiet || this->Required)
|
2003-01-21 22:15:22 +00:00
|
|
|
{
|
2008-01-17 14:02:31 +00:00
|
|
|
// The variable is not set.
|
2003-01-21 22:15:22 +00:00
|
|
|
cmOStringStream e;
|
2008-09-08 14:08:33 +00:00
|
|
|
e << "Could not find ";
|
2008-01-17 14:02:31 +00:00
|
|
|
if(!this->NoModule)
|
|
|
|
{
|
|
|
|
e << "module Find" << this->Name << ".cmake or ";
|
|
|
|
}
|
|
|
|
e << "a configuration file for package " << this->Name << ".\n";
|
|
|
|
if(!this->NoModule)
|
|
|
|
{
|
|
|
|
e << "Adjust CMAKE_MODULE_PATH to find Find"
|
|
|
|
<< this->Name << ".cmake or set ";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
e << "Set ";
|
|
|
|
}
|
|
|
|
e << this->Variable << " to the directory containing a CMake "
|
|
|
|
<< "configuration file for " << this->Name << ". ";
|
|
|
|
if(this->Configs.size() == 1)
|
|
|
|
{
|
|
|
|
e << "The file will be called " << this->Configs[0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
e << "The file will have one of the following names:\n";
|
|
|
|
for(std::vector<std::string>::const_iterator ci = this->Configs.begin();
|
|
|
|
ci != this->Configs.end(); ++ci)
|
|
|
|
{
|
|
|
|
e << " " << *ci << "\n";
|
|
|
|
}
|
|
|
|
}
|
2008-09-08 14:08:33 +00:00
|
|
|
this->Makefile->IssueMessage(
|
|
|
|
this->Required? cmake::FATAL_ERROR : cmake::WARNING, e.str());
|
2003-01-21 22:15:22 +00:00
|
|
|
}
|
2004-04-26 14:49:34 +00:00
|
|
|
|
2003-08-07 20:50:38 +00:00
|
|
|
// Set a variable marking whether the package was found.
|
2003-07-16 18:52:51 +00:00
|
|
|
std::string foundVar = this->Name;
|
2004-04-26 14:49:34 +00:00
|
|
|
foundVar += "_FOUND";
|
2006-03-15 16:02:08 +00:00
|
|
|
this->Makefile->AddDefinition(foundVar.c_str(), found? "1":"0");
|
2004-04-26 14:49:34 +00:00
|
|
|
|
2008-01-17 14:02:31 +00:00
|
|
|
// Set a variable naming the configuration file that was found.
|
|
|
|
std::string fileVar = this->Name;
|
|
|
|
fileVar += "_CONFIG";
|
|
|
|
if(found)
|
|
|
|
{
|
|
|
|
this->Makefile->AddDefinition(fileVar.c_str(), file.c_str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->Makefile->RemoveDefinition(fileVar.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle some ancient compatibility stuff.
|
|
|
|
if(this->Compatibility_1_6)
|
2003-08-07 20:50:38 +00:00
|
|
|
{
|
|
|
|
// Listfiles will be looking for the capitalized version of the
|
|
|
|
// name. Provide it.
|
2006-05-10 19:46:45 +00:00
|
|
|
this->Makefile->AddDefinition
|
|
|
|
(upperDir.c_str(),
|
|
|
|
this->Makefile->GetDefinition(this->Variable.c_str()));
|
|
|
|
this->Makefile->AddDefinition
|
|
|
|
(upperFound.c_str(),
|
|
|
|
this->Makefile->GetDefinition(foundVar.c_str()));
|
2003-08-07 20:50:38 +00:00
|
|
|
}
|
2004-04-26 14:49:34 +00:00
|
|
|
|
2004-10-27 14:47:14 +00:00
|
|
|
#ifdef CMAKE_BUILD_WITH_CMAKE
|
2003-08-08 13:14:33 +00:00
|
|
|
if(!(upperDir == this->Variable))
|
2003-08-07 20:50:38 +00:00
|
|
|
{
|
2008-01-17 14:02:31 +00:00
|
|
|
if(this->Compatibility_1_6)
|
2003-08-07 20:50:38 +00:00
|
|
|
{
|
|
|
|
// Listfiles may use the capitalized version of the name.
|
|
|
|
// Remove any previously added watch.
|
2006-03-15 16:02:08 +00:00
|
|
|
this->Makefile->GetVariableWatch()->RemoveWatch(
|
2003-08-07 20:50:38 +00:00
|
|
|
upperDir.c_str(),
|
|
|
|
cmFindPackageNeedBackwardsCompatibility
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Listfiles should not be using the capitalized version of the
|
|
|
|
// name. Add a watch to warn the user.
|
2006-03-15 16:02:08 +00:00
|
|
|
this->Makefile->GetVariableWatch()->AddWatch(
|
2003-08-07 20:50:38 +00:00
|
|
|
upperDir.c_str(),
|
|
|
|
cmFindPackageNeedBackwardsCompatibility
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2004-10-27 14:47:14 +00:00
|
|
|
#endif
|
2004-04-26 14:49:34 +00:00
|
|
|
|
2003-01-21 22:15:22 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2008-01-17 14:02:31 +00:00
|
|
|
void cmFindPackageCommand::FindConfig()
|
2003-01-21 22:15:22 +00:00
|
|
|
{
|
2008-01-17 14:02:31 +00:00
|
|
|
// Compute the set of search prefixes.
|
|
|
|
this->ComputePrefixes();
|
2004-02-28 23:59:19 +00:00
|
|
|
|
2008-01-17 14:02:31 +00:00
|
|
|
// Look for the project's configuration file.
|
|
|
|
bool found = false;
|
2004-04-19 14:36:42 +00:00
|
|
|
|
2008-01-17 14:02:31 +00:00
|
|
|
// Search for frameworks.
|
|
|
|
if(!found && this->SearchFrameworkFirst || this->SearchFrameworkOnly)
|
|
|
|
{
|
|
|
|
found = this->FindFrameworkConfig();
|
2003-01-21 22:15:22 +00:00
|
|
|
}
|
|
|
|
|
2008-01-17 14:02:31 +00:00
|
|
|
// Search for apps.
|
|
|
|
if(!found && this->SearchAppBundleFirst || this->SearchAppBundleOnly)
|
|
|
|
{
|
|
|
|
found = this->FindAppBundleConfig();
|
|
|
|
}
|
2004-04-26 14:49:34 +00:00
|
|
|
|
2008-01-17 14:02:31 +00:00
|
|
|
// Search prefixes.
|
|
|
|
if(!found && !(this->SearchFrameworkOnly || this->SearchAppBundleOnly))
|
2003-01-21 22:15:22 +00:00
|
|
|
{
|
2008-01-17 14:02:31 +00:00
|
|
|
found = this->FindPrefixedConfig();
|
2003-01-21 22:15:22 +00:00
|
|
|
}
|
2004-04-26 14:49:34 +00:00
|
|
|
|
2008-01-17 14:02:31 +00:00
|
|
|
// Search for frameworks.
|
|
|
|
if(!found && this->SearchFrameworkLast)
|
2003-01-21 22:15:22 +00:00
|
|
|
{
|
2008-01-17 14:02:31 +00:00
|
|
|
found = this->FindFrameworkConfig();
|
2003-01-21 22:15:22 +00:00
|
|
|
}
|
2004-04-26 14:49:34 +00:00
|
|
|
|
2008-01-17 14:02:31 +00:00
|
|
|
// Search for apps.
|
|
|
|
if(!found && this->SearchAppBundleLast)
|
|
|
|
{
|
|
|
|
found = this->FindAppBundleConfig();
|
|
|
|
}
|
2004-04-26 14:49:34 +00:00
|
|
|
|
2003-01-21 22:15:22 +00:00
|
|
|
// Store the entry in the cache so it can be set by the user.
|
2008-01-17 14:02:31 +00:00
|
|
|
std::string init;
|
|
|
|
if(found)
|
|
|
|
{
|
|
|
|
init = cmSystemTools::GetFilenamePath(this->FileFound);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
init = this->Variable + "-NOTFOUND";
|
|
|
|
}
|
|
|
|
std::string help =
|
|
|
|
"The directory containing a CMake configuration file for ";
|
|
|
|
help += this->Name;
|
|
|
|
help += ".";
|
2006-03-15 16:02:08 +00:00
|
|
|
this->Makefile->AddCacheDefinition(this->Variable.c_str(),
|
2008-01-17 14:02:31 +00:00
|
|
|
init.c_str(), help.c_str(),
|
|
|
|
cmCacheManager::PATH);
|
2003-01-21 22:15:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2008-01-17 14:02:31 +00:00
|
|
|
bool cmFindPackageCommand::FindPrefixedConfig()
|
2003-01-21 22:15:22 +00:00
|
|
|
{
|
2008-06-05 22:20:16 +00:00
|
|
|
std::vector<std::string>& prefixes = this->SearchPaths;
|
|
|
|
for(std::vector<std::string>::const_iterator pi = prefixes.begin();
|
|
|
|
pi != prefixes.end(); ++pi)
|
2004-04-26 15:00:41 +00:00
|
|
|
{
|
2008-01-17 14:02:31 +00:00
|
|
|
if(this->SearchPrefix(*pi))
|
2004-04-26 15:00:41 +00:00
|
|
|
{
|
2008-01-17 14:02:31 +00:00
|
|
|
return true;
|
2004-04-26 15:00:41 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-17 14:02:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
2004-04-26 15:00:41 +00:00
|
|
|
|
2008-01-17 14:02:31 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmFindPackageCommand::FindFrameworkConfig()
|
|
|
|
{
|
2008-06-05 22:20:16 +00:00
|
|
|
std::vector<std::string>& prefixes = this->SearchPaths;
|
|
|
|
for(std::vector<std::string>::const_iterator i = prefixes.begin();
|
|
|
|
i != prefixes.end(); ++i)
|
2003-01-21 22:15:22 +00:00
|
|
|
{
|
2008-01-17 14:02:31 +00:00
|
|
|
if(this->SearchFrameworkPrefix(*i))
|
2003-01-21 22:15:22 +00:00
|
|
|
{
|
2008-01-17 14:02:31 +00:00
|
|
|
return true;
|
2003-01-21 22:15:22 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-17 14:02:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
2004-04-26 14:49:34 +00:00
|
|
|
|
2008-01-17 14:02:31 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmFindPackageCommand::FindAppBundleConfig()
|
|
|
|
{
|
2008-06-05 22:20:16 +00:00
|
|
|
std::vector<std::string>& prefixes = this->SearchPaths;
|
|
|
|
for(std::vector<std::string>::const_iterator i = prefixes.begin();
|
|
|
|
i != prefixes.end(); ++i)
|
2003-01-21 22:15:22 +00:00
|
|
|
{
|
2008-01-17 14:02:31 +00:00
|
|
|
if(this->SearchAppBundlePrefix(*i))
|
2003-01-21 22:15:22 +00:00
|
|
|
{
|
2008-01-17 14:02:31 +00:00
|
|
|
return true;
|
2003-01-21 22:15:22 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-17 14:02:31 +00:00
|
|
|
return false;
|
2003-01-21 22:15:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmFindPackageCommand::ReadListFile(const char* f)
|
|
|
|
{
|
2006-03-15 16:02:08 +00:00
|
|
|
if(this->Makefile->ReadListFile(this->Makefile->GetCurrentListFile(),f))
|
2003-01-21 22:15:22 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
std::string e = "Error reading CMake code from \"";
|
|
|
|
e += f;
|
|
|
|
e += "\".";
|
|
|
|
this->SetError(e.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
2007-08-07 19:41:57 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmFindPackageCommand::AppendToProperty(const char* propertyName)
|
|
|
|
{
|
|
|
|
std::string propertyValue;
|
2007-12-15 19:17:21 +00:00
|
|
|
const char *prop =
|
2007-08-07 19:41:57 +00:00
|
|
|
this->Makefile->GetCMakeInstance()->GetProperty(propertyName);
|
|
|
|
if (prop && *prop)
|
|
|
|
{
|
|
|
|
propertyValue = prop;
|
2007-12-15 19:17:21 +00:00
|
|
|
|
2007-08-07 19:41:57 +00:00
|
|
|
std::vector<std::string> contents;
|
|
|
|
cmSystemTools::ExpandListArgument(propertyValue, contents, false);
|
2007-12-15 19:17:21 +00:00
|
|
|
|
2007-08-07 19:41:57 +00:00
|
|
|
bool alreadyInserted = false;
|
2007-12-15 19:17:21 +00:00
|
|
|
for(std::vector<std::string>::const_iterator it = contents.begin();
|
2007-08-07 19:41:57 +00:00
|
|
|
it != contents.end(); ++ it )
|
|
|
|
{
|
|
|
|
if (*it == this->Name)
|
|
|
|
{
|
|
|
|
alreadyInserted = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!alreadyInserted)
|
|
|
|
{
|
|
|
|
propertyValue += ";";
|
|
|
|
propertyValue += this->Name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
propertyValue = this->Name;
|
|
|
|
}
|
2007-12-15 19:17:21 +00:00
|
|
|
this->Makefile->GetCMakeInstance()->SetProperty(propertyName,
|
2007-08-07 19:41:57 +00:00
|
|
|
propertyValue.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2008-01-17 14:02:31 +00:00
|
|
|
void cmFindPackageCommand::AppendSuccessInformation()
|
2007-08-07 19:41:57 +00:00
|
|
|
{
|
|
|
|
std::string found = this->Name;
|
|
|
|
found += "_FOUND";
|
|
|
|
std::string upperFound = cmSystemTools::UpperCase(found);
|
|
|
|
|
|
|
|
const char* upperResult = this->Makefile->GetDefinition(upperFound.c_str());
|
|
|
|
const char* result = this->Makefile->GetDefinition(found.c_str());
|
|
|
|
if ((cmSystemTools::IsOn(result)) || (cmSystemTools::IsOn(upperResult)))
|
|
|
|
{
|
|
|
|
this->AppendToProperty("PACKAGES_FOUND");
|
2008-01-17 14:02:31 +00:00
|
|
|
if (!this->Quiet)
|
2007-08-07 19:41:57 +00:00
|
|
|
{
|
|
|
|
this->AppendToProperty("ENABLED_FEATURES");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->AppendToProperty("PACKAGES_NOT_FOUND");
|
2008-01-17 14:02:31 +00:00
|
|
|
if (!this->Quiet)
|
2007-08-07 19:41:57 +00:00
|
|
|
{
|
|
|
|
this->AppendToProperty("DISABLED_FEATURES");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-01-17 14:02:31 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2008-06-05 22:20:16 +00:00
|
|
|
void cmFindPackageCommand::ComputePrefixes()
|
2008-01-17 14:02:31 +00:00
|
|
|
{
|
2008-06-05 22:20:16 +00:00
|
|
|
this->AddPrefixesCMakeVariable();
|
2008-06-09 19:22:09 +00:00
|
|
|
this->AddPrefixesCMakeEnvironment();
|
2008-06-09 19:08:59 +00:00
|
|
|
this->AddPrefixesUserHints();
|
2008-06-05 22:20:16 +00:00
|
|
|
this->AddPrefixesSystemEnvironment();
|
|
|
|
this->AddPrefixesBuilds();
|
|
|
|
this->AddPrefixesCMakeSystemVariable();
|
2008-06-09 19:08:59 +00:00
|
|
|
this->AddPrefixesUserGuess();
|
2008-06-05 22:20:16 +00:00
|
|
|
this->ComputeFinalPrefixes();
|
2008-01-17 14:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2008-06-05 22:20:16 +00:00
|
|
|
void cmFindPackageCommand::AddPrefixesCMakeEnvironment()
|
2008-01-17 14:02:31 +00:00
|
|
|
{
|
|
|
|
if(!this->NoCMakeEnvironmentPath && !this->NoDefaultPath)
|
|
|
|
{
|
|
|
|
// Check the environment variable with the same name as the cache
|
|
|
|
// entry.
|
|
|
|
std::string env;
|
|
|
|
if(cmSystemTools::GetEnv(this->Variable.c_str(), env) && env.length() > 0)
|
|
|
|
{
|
|
|
|
cmSystemTools::ConvertToUnixSlashes(env);
|
2008-06-05 22:20:16 +00:00
|
|
|
this->AddPathInternal(env, EnvPath);
|
2008-01-17 14:02:31 +00:00
|
|
|
}
|
|
|
|
|
2008-06-05 22:20:16 +00:00
|
|
|
this->AddEnvPath("CMAKE_PREFIX_PATH");
|
|
|
|
this->AddEnvPath("CMAKE_FRAMEWORK_PATH");
|
|
|
|
this->AddEnvPath("CMAKE_APPBUNDLE_PATH");
|
2008-01-17 14:02:31 +00:00
|
|
|
}
|
2008-06-05 22:20:16 +00:00
|
|
|
}
|
2008-01-17 14:02:31 +00:00
|
|
|
|
2008-06-05 22:20:16 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmFindPackageCommand::AddPrefixesCMakeVariable()
|
|
|
|
{
|
2008-01-17 14:02:31 +00:00
|
|
|
if(!this->NoCMakePath && !this->NoDefaultPath)
|
|
|
|
{
|
2008-06-05 22:20:16 +00:00
|
|
|
this->AddCMakePath("CMAKE_PREFIX_PATH");
|
|
|
|
this->AddCMakePath("CMAKE_FRAMEWORK_PATH");
|
|
|
|
this->AddCMakePath("CMAKE_APPBUNDLE_PATH");
|
2008-01-17 14:02:31 +00:00
|
|
|
}
|
2008-06-05 22:20:16 +00:00
|
|
|
}
|
2008-01-17 14:02:31 +00:00
|
|
|
|
2008-06-05 22:20:16 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmFindPackageCommand::AddPrefixesSystemEnvironment()
|
|
|
|
{
|
2008-01-17 14:02:31 +00:00
|
|
|
if(!this->NoSystemEnvironmentPath && !this->NoDefaultPath)
|
|
|
|
{
|
|
|
|
// Use the system search path to generate prefixes.
|
|
|
|
// Relative paths are interpreted with respect to the current
|
|
|
|
// working directory.
|
|
|
|
std::vector<std::string> tmp;
|
|
|
|
cmSystemTools::GetPath(tmp);
|
|
|
|
for(std::vector<std::string>::iterator i = tmp.begin();
|
|
|
|
i != tmp.end(); ++i)
|
|
|
|
{
|
|
|
|
std::string const& d = *i;
|
|
|
|
|
|
|
|
// If the path is a PREFIX/bin case then add its parent instead.
|
|
|
|
if(d.size() >= 4 && strcmp(d.c_str()+d.size()-4, "/bin") == 0 ||
|
|
|
|
d.size() >= 5 && strcmp(d.c_str()+d.size()-5, "/sbin") == 0)
|
|
|
|
{
|
2008-06-05 22:20:16 +00:00
|
|
|
this->AddPathInternal(cmSystemTools::GetFilenamePath(d), EnvPath);
|
2008-01-17 14:02:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-06-05 22:20:16 +00:00
|
|
|
this->AddPathInternal(d, EnvPath);
|
2008-01-17 14:02:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-06-05 22:20:16 +00:00
|
|
|
}
|
2008-01-17 14:02:31 +00:00
|
|
|
|
2008-06-05 22:20:16 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmFindPackageCommand::AddPrefixesBuilds()
|
|
|
|
{
|
2008-01-17 14:02:31 +00:00
|
|
|
if(!this->NoBuilds && !this->NoDefaultPath)
|
|
|
|
{
|
|
|
|
// It is likely that CMake will have recently built the project.
|
|
|
|
for(int i=1; i <= 10; ++i)
|
|
|
|
{
|
|
|
|
cmOStringStream r;
|
|
|
|
r <<
|
|
|
|
"[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\"
|
|
|
|
"Settings\\StartPath;WhereBuild" << i << "]";
|
|
|
|
std::string f = r.str();
|
|
|
|
cmSystemTools::ExpandRegistryValues(f);
|
|
|
|
cmSystemTools::ConvertToUnixSlashes(f);
|
|
|
|
if(cmSystemTools::FileIsFullPath(f.c_str()) &&
|
|
|
|
cmSystemTools::FileIsDirectory(f.c_str()))
|
|
|
|
{
|
2008-06-05 22:20:16 +00:00
|
|
|
this->AddPathInternal(f, FullPath);
|
2008-01-17 14:02:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-06-05 22:20:16 +00:00
|
|
|
}
|
2008-01-17 14:02:31 +00:00
|
|
|
|
2008-06-05 22:20:16 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmFindPackageCommand::AddPrefixesCMakeSystemVariable()
|
|
|
|
{
|
2008-01-17 14:02:31 +00:00
|
|
|
if(!this->NoCMakeSystemPath && !this->NoDefaultPath)
|
|
|
|
{
|
2008-06-05 22:20:16 +00:00
|
|
|
this->AddCMakePath("CMAKE_SYSTEM_PREFIX_PATH");
|
|
|
|
this->AddCMakePath("CMAKE_SYSTEM_FRAMEWORK_PATH");
|
|
|
|
this->AddCMakePath("CMAKE_SYSTEM_APPBUNDLE_PATH");
|
2008-01-17 14:02:31 +00:00
|
|
|
}
|
2008-06-05 22:20:16 +00:00
|
|
|
}
|
2008-01-17 14:02:31 +00:00
|
|
|
|
2008-06-05 22:20:16 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2008-06-09 19:08:59 +00:00
|
|
|
void cmFindPackageCommand::AddPrefixesUserGuess()
|
2008-06-05 22:20:16 +00:00
|
|
|
{
|
2008-06-09 19:08:59 +00:00
|
|
|
// Add guesses specified by the caller.
|
|
|
|
this->AddPathsInternal(this->UserPaths, CMakePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmFindPackageCommand::AddPrefixesUserHints()
|
|
|
|
{
|
|
|
|
// Add hints specified by the caller.
|
|
|
|
this->AddPathsInternal(this->UserHints, CMakePath);
|
2008-06-05 22:20:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmFindPackageCommand::ComputeFinalPrefixes()
|
|
|
|
{
|
|
|
|
std::vector<std::string>& prefixes = this->SearchPaths;
|
2008-01-17 14:02:31 +00:00
|
|
|
|
|
|
|
// Construct the final set of prefixes.
|
|
|
|
this->RerootPaths(prefixes);
|
|
|
|
|
|
|
|
// Add a trailing slash to all prefixes to aid the search process.
|
2008-06-09 15:57:56 +00:00
|
|
|
this->AddTrailingSlashes(prefixes);
|
2008-01-17 14:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmFindPackageCommand::SearchDirectory(std::string const& dir)
|
|
|
|
{
|
|
|
|
assert(!dir.empty() && dir[dir.size()-1] == '/');
|
|
|
|
|
|
|
|
// Check each path suffix on this directory.
|
|
|
|
for(std::vector<std::string>::const_iterator
|
|
|
|
si = this->SearchPathSuffixes.begin();
|
|
|
|
si != this->SearchPathSuffixes.end(); ++si)
|
|
|
|
{
|
|
|
|
std::string d = dir;
|
|
|
|
if(!si->empty())
|
|
|
|
{
|
|
|
|
d += *si;
|
|
|
|
d += "/";
|
|
|
|
}
|
|
|
|
if(this->CheckDirectory(d))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmFindPackageCommand::CheckDirectory(std::string const& dir)
|
|
|
|
{
|
|
|
|
assert(!dir.empty() && dir[dir.size()-1] == '/');
|
|
|
|
|
|
|
|
// Look for the file in this directory.
|
|
|
|
std::string d = dir.substr(0, dir.size()-1);
|
|
|
|
if(this->FindConfigFile(d, this->FileFound))
|
|
|
|
{
|
2008-01-29 01:38:48 +00:00
|
|
|
// Remove duplicate slashes.
|
|
|
|
cmSystemTools::ConvertToUnixSlashes(this->FileFound);
|
2008-01-17 14:02:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmFindPackageCommand::FindConfigFile(std::string const& dir,
|
|
|
|
std::string& file)
|
|
|
|
{
|
|
|
|
for(std::vector<std::string>::const_iterator ci = this->Configs.begin();
|
|
|
|
ci != this->Configs.end(); ++ci)
|
|
|
|
{
|
|
|
|
file = dir;
|
|
|
|
file += "/";
|
|
|
|
file += *ci;
|
|
|
|
if(this->DebugMode)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Checking file [%s]\n", file.c_str());
|
|
|
|
}
|
2008-01-29 01:38:48 +00:00
|
|
|
if(cmSystemTools::FileExists(file.c_str(), true) &&
|
|
|
|
this->CheckVersion(file))
|
2008-01-17 14:02:31 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-01-29 01:38:48 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmFindPackageCommand::FindConfigFileToLoad(std::string const& dir,
|
|
|
|
std::string& file)
|
|
|
|
{
|
|
|
|
if(this->FileFound.empty())
|
|
|
|
{
|
|
|
|
// The file location was cached. Look for the correct file.
|
|
|
|
return this->FindConfigFile(dir, file);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// The file location was just found during this call.
|
|
|
|
// Use the file found without searching again.
|
|
|
|
file = this->FileFound;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmFindPackageCommand::CheckVersion(std::string const& config_file)
|
|
|
|
{
|
|
|
|
// Get the filename without the .cmake extension.
|
|
|
|
std::string::size_type pos = config_file.rfind('.');
|
|
|
|
std::string version_file_base = config_file.substr(0, pos);
|
|
|
|
|
|
|
|
// Look for foo-config-version.cmake
|
|
|
|
std::string version_file = version_file_base;
|
|
|
|
version_file += "-version.cmake";
|
|
|
|
if(cmSystemTools::FileExists(version_file.c_str(), true))
|
|
|
|
{
|
|
|
|
return this->CheckVersionFile(version_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Look for fooConfigVersion.cmake
|
|
|
|
version_file = version_file_base;
|
|
|
|
version_file += "Version.cmake";
|
|
|
|
if(cmSystemTools::FileExists(version_file.c_str(), true))
|
|
|
|
{
|
|
|
|
return this->CheckVersionFile(version_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If no version was requested a versionless package is acceptable.
|
|
|
|
if(this->Version.empty())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// No version file found. Assume the version is incompatible.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmFindPackageCommand::CheckVersionFile(std::string const& version_file)
|
|
|
|
{
|
|
|
|
// The version file will be loaded in an isolated scope.
|
|
|
|
this->Makefile->PushScope();
|
|
|
|
|
|
|
|
// Clear the output variables.
|
|
|
|
this->Makefile->RemoveDefinition("PACKAGE_VERSION");
|
|
|
|
this->Makefile->RemoveDefinition("PACKAGE_VERSION_COMPATIBLE");
|
|
|
|
this->Makefile->RemoveDefinition("PACKAGE_VERSION_EXACT");
|
|
|
|
|
|
|
|
// Set the input variables.
|
|
|
|
this->Makefile->AddDefinition("PACKAGE_FIND_NAME", this->Name.c_str());
|
|
|
|
this->Makefile->AddDefinition("PACKAGE_FIND_VERSION",
|
|
|
|
this->Version.c_str());
|
2008-09-10 14:11:48 +00:00
|
|
|
char buf[64];
|
|
|
|
sprintf(buf, "%u", this->VersionMajor);
|
|
|
|
this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_MAJOR", buf);
|
|
|
|
sprintf(buf, "%u", this->VersionMinor);
|
|
|
|
this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_MINOR", buf);
|
|
|
|
sprintf(buf, "%u", this->VersionPatch);
|
|
|
|
this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_PATCH", buf);
|
|
|
|
sprintf(buf, "%u", this->VersionTweak);
|
|
|
|
this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_TWEAK", buf);
|
|
|
|
sprintf(buf, "%u", this->VersionCount);
|
|
|
|
this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_COUNT", buf);
|
2008-01-29 01:38:48 +00:00
|
|
|
|
|
|
|
// Load the version check file.
|
|
|
|
bool found = false;
|
|
|
|
if(this->ReadListFile(version_file.c_str()))
|
|
|
|
{
|
|
|
|
// Check the output variables.
|
|
|
|
found = this->Makefile->IsOn("PACKAGE_VERSION_EXACT");
|
|
|
|
if(!found && !this->VersionExact)
|
|
|
|
{
|
|
|
|
found = this->Makefile->IsOn("PACKAGE_VERSION_COMPATIBLE");
|
|
|
|
}
|
|
|
|
if(found || this->Version.empty())
|
|
|
|
{
|
|
|
|
// Get the version found.
|
|
|
|
this->VersionFound =
|
|
|
|
this->Makefile->GetSafeDefinition("PACKAGE_VERSION");
|
|
|
|
|
|
|
|
// Try to parse the version number and store the results that were
|
|
|
|
// successfully parsed.
|
|
|
|
unsigned int parsed_major;
|
|
|
|
unsigned int parsed_minor;
|
|
|
|
unsigned int parsed_patch;
|
2008-09-10 14:11:48 +00:00
|
|
|
unsigned int parsed_tweak;
|
2008-01-29 01:38:48 +00:00
|
|
|
this->VersionFoundCount =
|
2008-09-10 14:11:48 +00:00
|
|
|
sscanf(this->VersionFound.c_str(), "%u.%u.%u.%u",
|
|
|
|
&parsed_major, &parsed_minor,
|
|
|
|
&parsed_patch, &parsed_tweak);
|
2008-01-29 01:38:48 +00:00
|
|
|
switch(this->VersionFoundCount)
|
|
|
|
{
|
2008-09-10 14:11:48 +00:00
|
|
|
case 4: this->VersionFoundTweak = parsed_tweak; // no break!
|
2008-01-29 01:38:48 +00:00
|
|
|
case 3: this->VersionFoundPatch = parsed_patch; // no break!
|
|
|
|
case 2: this->VersionFoundMinor = parsed_minor; // no break!
|
|
|
|
case 1: this->VersionFoundMajor = parsed_major; // no break!
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Restore the original scope.
|
|
|
|
this->Makefile->PopScope();
|
|
|
|
|
|
|
|
// Succeed if the version was found or no version was requested.
|
|
|
|
return found || this->Version.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmFindPackageCommand::StoreVersionFound()
|
|
|
|
{
|
|
|
|
// Store the whole version string.
|
|
|
|
std::string ver = this->Name;
|
|
|
|
ver += "_VERSION";
|
|
|
|
if(this->VersionFound.empty())
|
|
|
|
{
|
|
|
|
this->Makefile->RemoveDefinition(ver.c_str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->Makefile->AddDefinition(ver.c_str(), this->VersionFound.c_str());
|
|
|
|
}
|
|
|
|
|
2008-09-10 14:11:48 +00:00
|
|
|
// Store the version components.
|
2008-01-29 01:38:48 +00:00
|
|
|
char buf[64];
|
2008-09-10 14:11:48 +00:00
|
|
|
sprintf(buf, "%u", this->VersionFoundMajor);
|
|
|
|
this->Makefile->AddDefinition((ver+"_MAJOR").c_str(), buf);
|
|
|
|
sprintf(buf, "%u", this->VersionFoundMinor);
|
|
|
|
this->Makefile->AddDefinition((ver+"_MINOR").c_str(), buf);
|
|
|
|
sprintf(buf, "%u", this->VersionFoundPatch);
|
|
|
|
this->Makefile->AddDefinition((ver+"_PATCH").c_str(), buf);
|
|
|
|
sprintf(buf, "%u", this->VersionFoundTweak);
|
|
|
|
this->Makefile->AddDefinition((ver+"_TWEAK").c_str(), buf);
|
|
|
|
sprintf(buf, "%u", this->VersionFoundCount);
|
|
|
|
this->Makefile->AddDefinition((ver+"_COUNT").c_str(), buf);
|
2008-01-29 01:38:48 +00:00
|
|
|
}
|
|
|
|
|
2008-01-17 14:02:31 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
#include <cmsys/Directory.hxx>
|
|
|
|
#include <cmsys/Glob.hxx>
|
|
|
|
#include <cmsys/String.h>
|
|
|
|
#include <cmsys/auto_ptr.hxx>
|
|
|
|
|
|
|
|
class cmFileList;
|
|
|
|
class cmFileListGeneratorBase
|
|
|
|
{
|
2008-01-17 15:32:27 +00:00
|
|
|
public:
|
|
|
|
virtual ~cmFileListGeneratorBase() {}
|
2008-01-17 14:02:31 +00:00
|
|
|
protected:
|
|
|
|
bool Consider(std::string const& fullPath, cmFileList& listing);
|
|
|
|
private:
|
|
|
|
bool Search(cmFileList&);
|
|
|
|
virtual bool Search(std::string const& parent, cmFileList&) = 0;
|
|
|
|
virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const = 0;
|
|
|
|
friend class cmFileList;
|
|
|
|
cmFileListGeneratorBase* SetNext(cmFileListGeneratorBase const& next);
|
|
|
|
cmsys::auto_ptr<cmFileListGeneratorBase> Next;
|
|
|
|
};
|
|
|
|
|
|
|
|
class cmFileList
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cmFileList(): First(), Last(0) {}
|
2008-01-17 15:32:27 +00:00
|
|
|
virtual ~cmFileList() {}
|
2008-01-17 14:02:31 +00:00
|
|
|
cmFileList& operator/(cmFileListGeneratorBase const& rhs)
|
|
|
|
{
|
|
|
|
if(this->Last)
|
|
|
|
{
|
|
|
|
this->Last = this->Last->SetNext(rhs);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->First = rhs.Clone();
|
|
|
|
this->Last = this->First.get();
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
bool Search()
|
|
|
|
{
|
|
|
|
if(this->First.get())
|
|
|
|
{
|
|
|
|
return this->First->Search(*this);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
virtual bool Visit(std::string const& fullPath) = 0;
|
|
|
|
friend class cmFileListGeneratorBase;
|
|
|
|
cmsys::auto_ptr<cmFileListGeneratorBase> First;
|
|
|
|
cmFileListGeneratorBase* Last;
|
|
|
|
};
|
|
|
|
|
|
|
|
class cmFindPackageFileList: public cmFileList
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cmFindPackageFileList(cmFindPackageCommand* fpc,
|
|
|
|
bool use_suffixes = true):
|
|
|
|
cmFileList(), FPC(fpc), UseSuffixes(use_suffixes) {}
|
|
|
|
private:
|
|
|
|
bool Visit(std::string const& fullPath)
|
|
|
|
{
|
|
|
|
if(this->UseSuffixes)
|
|
|
|
{
|
|
|
|
return this->FPC->SearchDirectory(fullPath);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return this->FPC->CheckDirectory(fullPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cmFindPackageCommand* FPC;
|
|
|
|
bool UseSuffixes;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool cmFileListGeneratorBase::Search(cmFileList& listing)
|
|
|
|
{
|
|
|
|
return this->Search("", listing);
|
|
|
|
}
|
|
|
|
|
|
|
|
cmFileListGeneratorBase*
|
|
|
|
cmFileListGeneratorBase::SetNext(cmFileListGeneratorBase const& next)
|
|
|
|
{
|
|
|
|
this->Next = next.Clone();
|
|
|
|
return this->Next.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmFileListGeneratorBase::Consider(std::string const& fullPath,
|
|
|
|
cmFileList& listing)
|
|
|
|
{
|
|
|
|
if(this->Next.get())
|
|
|
|
{
|
|
|
|
return this->Next->Search(fullPath + "/", listing);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return listing.Visit(fullPath + "/");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class cmFileListGeneratorFixed: public cmFileListGeneratorBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cmFileListGeneratorFixed(std::string const& str):
|
|
|
|
cmFileListGeneratorBase(), String(str) {}
|
|
|
|
cmFileListGeneratorFixed(cmFileListGeneratorFixed const& r):
|
|
|
|
cmFileListGeneratorBase(), String(r.String) {}
|
|
|
|
private:
|
|
|
|
std::string String;
|
|
|
|
virtual bool Search(std::string const& parent, cmFileList& lister)
|
|
|
|
{
|
|
|
|
std::string fullPath = parent + this->String;
|
|
|
|
return this->Consider(fullPath, lister);
|
|
|
|
}
|
|
|
|
virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const
|
|
|
|
{
|
|
|
|
cmsys::auto_ptr<cmFileListGeneratorBase>
|
|
|
|
g(new cmFileListGeneratorFixed(*this));
|
|
|
|
return g;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class cmFileListGeneratorEnumerate: public cmFileListGeneratorBase
|
|
|
|
{
|
|
|
|
public:
|
2008-08-12 23:01:04 +00:00
|
|
|
cmFileListGeneratorEnumerate(std::vector<std::string> const& v):
|
|
|
|
cmFileListGeneratorBase(), Vector(v) {}
|
2008-01-17 14:02:31 +00:00
|
|
|
cmFileListGeneratorEnumerate(cmFileListGeneratorEnumerate const& r):
|
|
|
|
cmFileListGeneratorBase(), Vector(r.Vector) {}
|
|
|
|
private:
|
2008-08-12 23:01:04 +00:00
|
|
|
std::vector<std::string> const& Vector;
|
2008-01-17 14:02:31 +00:00
|
|
|
virtual bool Search(std::string const& parent, cmFileList& lister)
|
|
|
|
{
|
|
|
|
for(std::vector<std::string>::const_iterator i = this->Vector.begin();
|
|
|
|
i != this->Vector.end(); ++i)
|
|
|
|
{
|
|
|
|
if(this->Consider(parent + *i, lister))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const
|
|
|
|
{
|
|
|
|
cmsys::auto_ptr<cmFileListGeneratorBase>
|
|
|
|
g(new cmFileListGeneratorEnumerate(*this));
|
|
|
|
return g;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class cmFileListGeneratorProject: public cmFileListGeneratorBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cmFileListGeneratorProject(std::vector<std::string> const& names):
|
|
|
|
cmFileListGeneratorBase(), Names(names) {}
|
|
|
|
cmFileListGeneratorProject(cmFileListGeneratorProject const& r):
|
|
|
|
cmFileListGeneratorBase(), Names(r.Names) {}
|
|
|
|
private:
|
|
|
|
std::vector<std::string> const& Names;
|
|
|
|
virtual bool Search(std::string const& parent, cmFileList& lister)
|
|
|
|
{
|
|
|
|
// Construct a list of matches.
|
|
|
|
std::vector<std::string> matches;
|
|
|
|
cmsys::Directory d;
|
|
|
|
d.Load(parent.c_str());
|
|
|
|
for(unsigned long i=0; i < d.GetNumberOfFiles(); ++i)
|
|
|
|
{
|
|
|
|
const char* fname = d.GetFile(i);
|
|
|
|
if(strcmp(fname, ".") == 0 ||
|
|
|
|
strcmp(fname, "..") == 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for(std::vector<std::string>::const_iterator ni = this->Names.begin();
|
|
|
|
ni != this->Names.end(); ++ni)
|
|
|
|
{
|
|
|
|
if(cmsysString_strncasecmp(fname, ni->c_str(),
|
|
|
|
ni->length()) == 0)
|
|
|
|
{
|
|
|
|
matches.push_back(fname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(std::vector<std::string>::const_iterator i = matches.begin();
|
|
|
|
i != matches.end(); ++i)
|
|
|
|
{
|
|
|
|
if(this->Consider(parent + *i, lister))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const
|
|
|
|
{
|
|
|
|
cmsys::auto_ptr<cmFileListGeneratorBase>
|
|
|
|
g(new cmFileListGeneratorProject(*this));
|
|
|
|
return g;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class cmFileListGeneratorMacProject: public cmFileListGeneratorBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cmFileListGeneratorMacProject(std::vector<std::string> const& names,
|
|
|
|
const char* ext):
|
|
|
|
cmFileListGeneratorBase(), Names(names), Extension(ext) {}
|
|
|
|
cmFileListGeneratorMacProject(cmFileListGeneratorMacProject const& r):
|
|
|
|
cmFileListGeneratorBase(), Names(r.Names), Extension(r.Extension) {}
|
|
|
|
private:
|
|
|
|
std::vector<std::string> const& Names;
|
|
|
|
std::string Extension;
|
|
|
|
virtual bool Search(std::string const& parent, cmFileList& lister)
|
|
|
|
{
|
|
|
|
// Construct a list of matches.
|
|
|
|
std::vector<std::string> matches;
|
|
|
|
cmsys::Directory d;
|
|
|
|
d.Load(parent.c_str());
|
|
|
|
for(unsigned long i=0; i < d.GetNumberOfFiles(); ++i)
|
|
|
|
{
|
|
|
|
const char* fname = d.GetFile(i);
|
|
|
|
if(strcmp(fname, ".") == 0 ||
|
|
|
|
strcmp(fname, "..") == 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for(std::vector<std::string>::const_iterator ni = this->Names.begin();
|
|
|
|
ni != this->Names.end(); ++ni)
|
|
|
|
{
|
|
|
|
std::string name = *ni;
|
|
|
|
name += this->Extension;
|
|
|
|
if(cmsysString_strcasecmp(fname, name.c_str()) == 0)
|
|
|
|
{
|
|
|
|
matches.push_back(fname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(std::vector<std::string>::const_iterator i = matches.begin();
|
|
|
|
i != matches.end(); ++i)
|
|
|
|
{
|
|
|
|
if(this->Consider(parent + *i, lister))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const
|
|
|
|
{
|
|
|
|
cmsys::auto_ptr<cmFileListGeneratorBase>
|
|
|
|
g(new cmFileListGeneratorMacProject(*this));
|
|
|
|
return g;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class cmFileListGeneratorCaseInsensitive: public cmFileListGeneratorBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cmFileListGeneratorCaseInsensitive(std::string const& str):
|
|
|
|
cmFileListGeneratorBase(), String(str) {}
|
2008-01-18 13:19:37 +00:00
|
|
|
cmFileListGeneratorCaseInsensitive(
|
|
|
|
cmFileListGeneratorCaseInsensitive const& r):
|
2008-01-17 14:02:31 +00:00
|
|
|
cmFileListGeneratorBase(), String(r.String) {}
|
|
|
|
private:
|
|
|
|
std::string String;
|
|
|
|
virtual bool Search(std::string const& parent, cmFileList& lister)
|
|
|
|
{
|
|
|
|
// Look for matching files.
|
|
|
|
std::vector<std::string> matches;
|
|
|
|
cmsys::Directory d;
|
|
|
|
d.Load(parent.c_str());
|
|
|
|
for(unsigned long i=0; i < d.GetNumberOfFiles(); ++i)
|
|
|
|
{
|
|
|
|
const char* fname = d.GetFile(i);
|
|
|
|
if(strcmp(fname, ".") == 0 ||
|
|
|
|
strcmp(fname, "..") == 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(cmsysString_strcasecmp(fname, this->String.c_str()) == 0)
|
|
|
|
{
|
|
|
|
if(this->Consider(parent + fname, lister))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const
|
|
|
|
{
|
|
|
|
cmsys::auto_ptr<cmFileListGeneratorBase>
|
|
|
|
g(new cmFileListGeneratorCaseInsensitive(*this));
|
|
|
|
return g;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class cmFileListGeneratorGlob: public cmFileListGeneratorBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cmFileListGeneratorGlob(std::string const& str):
|
|
|
|
cmFileListGeneratorBase(), Pattern(str) {}
|
|
|
|
cmFileListGeneratorGlob(cmFileListGeneratorGlob const& r):
|
|
|
|
cmFileListGeneratorBase(), Pattern(r.Pattern) {}
|
|
|
|
private:
|
|
|
|
std::string Pattern;
|
|
|
|
virtual bool Search(std::string const& parent, cmFileList& lister)
|
|
|
|
{
|
|
|
|
// Glob the set of matching files.
|
|
|
|
std::string expr = parent;
|
|
|
|
expr += this->Pattern;
|
|
|
|
cmsys::Glob g;
|
|
|
|
if(!g.FindFiles(expr))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
std::vector<std::string> const& files = g.GetFiles();
|
|
|
|
|
|
|
|
// Look for directories among the matches.
|
|
|
|
for(std::vector<std::string>::const_iterator fi = files.begin();
|
|
|
|
fi != files.end(); ++fi)
|
|
|
|
{
|
|
|
|
if(cmSystemTools::FileIsDirectory(fi->c_str()))
|
|
|
|
{
|
|
|
|
if(this->Consider(*fi, lister))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const
|
|
|
|
{
|
|
|
|
cmsys::auto_ptr<cmFileListGeneratorBase>
|
|
|
|
g(new cmFileListGeneratorGlob(*this));
|
|
|
|
return g;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmFindPackageCommand::SearchPrefix(std::string const& prefix_in)
|
|
|
|
{
|
|
|
|
assert(!prefix_in.empty() && prefix_in[prefix_in.size()-1] == '/');
|
|
|
|
if(this->DebugMode)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Checking prefix [%s]\n", prefix_in.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Skip this if the prefix does not exist.
|
|
|
|
if(!cmSystemTools::FileIsDirectory(prefix_in.c_str()))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// PREFIX/ (useful on windows or in build trees)
|
|
|
|
if(this->SearchDirectory(prefix_in))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Strip the trailing slash because the path generator is about to
|
|
|
|
// add one.
|
|
|
|
std::string prefix = prefix_in.substr(0, prefix_in.size()-1);
|
|
|
|
|
|
|
|
// PREFIX/(cmake|CMake)/ (useful on windows or in build trees)
|
|
|
|
{
|
|
|
|
cmFindPackageFileList lister(this);
|
|
|
|
lister
|
|
|
|
/ cmFileListGeneratorFixed(prefix)
|
|
|
|
/ cmFileListGeneratorCaseInsensitive("cmake");
|
|
|
|
if(lister.Search())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-12 23:01:04 +00:00
|
|
|
// Construct list of common install locations (lib and share).
|
|
|
|
std::vector<std::string> common;
|
|
|
|
if(this->UseLib64Paths)
|
|
|
|
{
|
|
|
|
common.push_back("lib64");
|
|
|
|
}
|
|
|
|
common.push_back("lib");
|
|
|
|
common.push_back("share");
|
|
|
|
|
2008-01-17 14:02:31 +00:00
|
|
|
// PREFIX/(share|lib)/(Foo|foo|FOO).*/
|
|
|
|
{
|
|
|
|
cmFindPackageFileList lister(this);
|
|
|
|
lister
|
|
|
|
/ cmFileListGeneratorFixed(prefix)
|
2008-08-12 23:01:04 +00:00
|
|
|
/ cmFileListGeneratorEnumerate(common)
|
2008-01-17 14:02:31 +00:00
|
|
|
/ cmFileListGeneratorProject(this->Names);
|
|
|
|
if(lister.Search())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// PREFIX/(share|lib)/(Foo|foo|FOO).*/(cmake|CMake)/
|
|
|
|
{
|
|
|
|
cmFindPackageFileList lister(this);
|
|
|
|
lister
|
|
|
|
/ cmFileListGeneratorFixed(prefix)
|
2008-08-12 23:01:04 +00:00
|
|
|
/ cmFileListGeneratorEnumerate(common)
|
2008-01-17 14:02:31 +00:00
|
|
|
/ cmFileListGeneratorProject(this->Names)
|
|
|
|
/ cmFileListGeneratorCaseInsensitive("cmake");
|
|
|
|
if(lister.Search())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmFindPackageCommand::SearchFrameworkPrefix(std::string const& prefix_in)
|
|
|
|
{
|
|
|
|
assert(!prefix_in.empty() && prefix_in[prefix_in.size()-1] == '/');
|
|
|
|
if(this->DebugMode)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Checking framework prefix [%s]\n", prefix_in.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Strip the trailing slash because the path generator is about to
|
|
|
|
// add one.
|
|
|
|
std::string prefix = prefix_in.substr(0, prefix_in.size()-1);
|
|
|
|
|
|
|
|
// <prefix>/Foo.framework/Resources/
|
|
|
|
{
|
|
|
|
cmFindPackageFileList lister(this);
|
|
|
|
lister
|
|
|
|
/ cmFileListGeneratorFixed(prefix)
|
|
|
|
/ cmFileListGeneratorMacProject(this->Names, ".framework")
|
|
|
|
/ cmFileListGeneratorFixed("Resources");
|
|
|
|
if(lister.Search())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// <prefix>/Foo.framework/Resources/CMake/
|
|
|
|
{
|
|
|
|
cmFindPackageFileList lister(this);
|
|
|
|
lister
|
|
|
|
/ cmFileListGeneratorFixed(prefix)
|
|
|
|
/ cmFileListGeneratorMacProject(this->Names, ".framework")
|
|
|
|
/ cmFileListGeneratorFixed("Resources")
|
|
|
|
/ cmFileListGeneratorCaseInsensitive("cmake");
|
|
|
|
if(lister.Search())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// <prefix>/Foo.framework/Versions/*/Resources/
|
|
|
|
{
|
|
|
|
cmFindPackageFileList lister(this);
|
|
|
|
lister
|
|
|
|
/ cmFileListGeneratorFixed(prefix)
|
|
|
|
/ cmFileListGeneratorMacProject(this->Names, ".framework")
|
|
|
|
/ cmFileListGeneratorFixed("Versions")
|
|
|
|
/ cmFileListGeneratorGlob("*/Resources");
|
|
|
|
if(lister.Search())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// <prefix>/Foo.framework/Versions/*/Resources/CMake/
|
|
|
|
{
|
|
|
|
cmFindPackageFileList lister(this);
|
|
|
|
lister
|
|
|
|
/ cmFileListGeneratorFixed(prefix)
|
|
|
|
/ cmFileListGeneratorMacProject(this->Names, ".framework")
|
|
|
|
/ cmFileListGeneratorFixed("Versions")
|
|
|
|
/ cmFileListGeneratorGlob("*/Resources")
|
|
|
|
/ cmFileListGeneratorCaseInsensitive("cmake");
|
|
|
|
if(lister.Search())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmFindPackageCommand::SearchAppBundlePrefix(std::string const& prefix_in)
|
|
|
|
{
|
|
|
|
assert(!prefix_in.empty() && prefix_in[prefix_in.size()-1] == '/');
|
|
|
|
if(this->DebugMode)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Checking bundle prefix [%s]\n", prefix_in.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Strip the trailing slash because the path generator is about to
|
|
|
|
// add one.
|
|
|
|
std::string prefix = prefix_in.substr(0, prefix_in.size()-1);
|
|
|
|
|
|
|
|
// <prefix>/Foo.app/Contents/Resources
|
|
|
|
{
|
|
|
|
cmFindPackageFileList lister(this);
|
|
|
|
lister
|
|
|
|
/ cmFileListGeneratorFixed(prefix)
|
|
|
|
/ cmFileListGeneratorMacProject(this->Names, ".app")
|
|
|
|
/ cmFileListGeneratorFixed("Contents/Resources");
|
|
|
|
if(lister.Search())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// <prefix>/Foo.app/Contents/Resources/CMake
|
|
|
|
{
|
|
|
|
cmFindPackageFileList lister(this);
|
|
|
|
lister
|
|
|
|
/ cmFileListGeneratorFixed(prefix)
|
|
|
|
/ cmFileListGeneratorMacProject(this->Names, ".app")
|
|
|
|
/ cmFileListGeneratorFixed("Contents/Resources")
|
|
|
|
/ cmFileListGeneratorCaseInsensitive("cmake");
|
|
|
|
if(lister.Search())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Version numbers? Perhaps have a listing component class that
|
|
|
|
// sorts by lexicographic and numerical ordering. Also try to match
|
|
|
|
// some command argument for the version. Alternatively provide an
|
|
|
|
// API that just returns a list of valid directories? Perhaps push a
|
|
|
|
// scope and try loading the target file just to get its version
|
|
|
|
// number? Could add a foo-version.cmake or FooVersion.cmake file
|
|
|
|
// in the projects that contains just version information.
|
|
|
|
|
|
|
|
// TODO: Debug cmsys::Glob double slash problem.
|
|
|
|
|
|
|
|
// TODO: Add registry entries after cmake system search path?
|
|
|
|
// Currently the user must specify them with the PATHS option.
|
|
|
|
//
|
|
|
|
// [HKEY_CURRENT_USER\Software\*\Foo*;InstallDir]
|
|
|
|
// [HKEY_CURRENT_USER\Software\*\*\Foo*;InstallDir]
|
|
|
|
// [HKEY_LOCAL_MACHINE\Software\*\Foo*;InstallDir]
|
|
|
|
// [HKEY_LOCAL_MACHINE\Software\*\*\Foo*;InstallDir]
|