2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2003-01-22 01:15:22 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2003-01-22 01:15:22 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2003-01-22 01:15:22 +03:00
|
|
|
#include "cmFindPackageCommand.h"
|
2009-09-01 22:04:27 +04:00
|
|
|
|
|
|
|
#include <cmsys/Directory.hxx>
|
2003-07-16 22:52:51 +04:00
|
|
|
#include <cmsys/RegularExpression.hxx>
|
2003-01-22 01:15:22 +03:00
|
|
|
|
2004-10-27 18:47:14 +04:00
|
|
|
#ifdef CMAKE_BUILD_WITH_CMAKE
|
2003-08-08 00:50:38 +04:00
|
|
|
#include "cmVariableWatch.h"
|
2004-10-27 18:47:14 +04:00
|
|
|
#endif
|
2003-08-08 00:50:38 +04:00
|
|
|
|
2009-09-28 17:45:34 +04:00
|
|
|
#if defined(__HAIKU__)
|
|
|
|
#include <StorageKit.h>
|
|
|
|
#endif
|
|
|
|
|
2004-04-26 18:49:34 +04:00
|
|
|
void cmFindPackageNeedBackwardsCompatibility(const std::string& variable,
|
2007-04-11 23:13:05 +04:00
|
|
|
int access_type, void*, const char* newValue,
|
|
|
|
const cmMakefile*)
|
2003-08-08 00:50:38 +04:00
|
|
|
{
|
2007-04-11 23:13:05 +04:00
|
|
|
(void)newValue;
|
2004-10-27 18:47:14 +04:00
|
|
|
#ifdef CMAKE_BUILD_WITH_CMAKE
|
2003-08-08 00:50:38 +04: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 18:47:14 +04:00
|
|
|
#else
|
|
|
|
(void)variable;
|
|
|
|
(void)access_type;
|
|
|
|
#endif
|
2003-08-08 00:50:38 +04:00
|
|
|
}
|
|
|
|
|
2008-01-17 17:02:31 +03:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
cmFindPackageCommand::cmFindPackageCommand()
|
|
|
|
{
|
|
|
|
this->CMakePathName = "PACKAGE";
|
|
|
|
this->Quiet = false;
|
|
|
|
this->Required = false;
|
2011-04-13 18:36:45 +04:00
|
|
|
this->NoUserRegistry = false;
|
2011-04-13 21:14:41 +04:00
|
|
|
this->NoSystemRegistry = false;
|
2008-01-17 17:02:31 +03:00
|
|
|
this->NoBuilds = false;
|
2012-02-21 01:09:10 +04:00
|
|
|
this->UseConfigFiles = true;
|
2012-02-18 00:31:08 +04:00
|
|
|
this->UseFindModules = true;
|
2008-01-17 17:02:31 +03:00
|
|
|
this->DebugMode = false;
|
2008-08-13 03:01:04 +04:00
|
|
|
this->UseLib64Paths = false;
|
2009-01-22 21:18:40 +03:00
|
|
|
this->PolicyScope = true;
|
2008-01-21 16:48:33 +03:00
|
|
|
this->VersionMajor = 0;
|
|
|
|
this->VersionMinor = 0;
|
|
|
|
this->VersionPatch = 0;
|
2008-09-10 18:11:48 +04:00
|
|
|
this->VersionTweak = 0;
|
2008-01-21 16:48:33 +03:00
|
|
|
this->VersionCount = 0;
|
2008-01-29 04:38:48 +03:00
|
|
|
this->VersionExact = false;
|
|
|
|
this->VersionFoundMajor = 0;
|
|
|
|
this->VersionFoundMinor = 0;
|
|
|
|
this->VersionFoundPatch = 0;
|
2008-09-10 18:11:48 +04:00
|
|
|
this->VersionFoundTweak = 0;
|
2008-01-29 04:38:48 +03:00
|
|
|
this->VersionFoundCount = 0;
|
2012-02-28 18:51:10 +04:00
|
|
|
this->RequiredCMakeVersion = 0;
|
2010-11-12 18:47:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
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");
|
2008-01-17 17:02:31 +03:00
|
|
|
this->CommandDocumentation =
|
2012-02-21 01:09:10 +04:00
|
|
|
" find_package(<package> [version] [EXACT] [QUIET] [MODULE]\n"
|
2012-04-18 21:28:45 +04:00
|
|
|
" [REQUIRED] [[COMPONENTS] [components...]]\n"
|
2012-03-18 20:26:24 +04:00
|
|
|
" [OPTIONAL_COMPONENTS components...]\n"
|
2009-01-22 21:18:40 +03:00
|
|
|
" [NO_POLICY_SCOPE])\n"
|
2008-01-22 06:48:07 +03:00
|
|
|
"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. "
|
2012-02-21 01:09:10 +04:00
|
|
|
"The MODULE option disables the second signature documented below. "
|
2008-01-22 06:48:07 +03:00
|
|
|
"The REQUIRED option stops processing with an error message if the "
|
2012-03-18 20:26:24 +04:00
|
|
|
"package cannot be found."
|
|
|
|
"\n"
|
|
|
|
"A package-specific list of required components may be listed after the "
|
2012-04-18 21:28:45 +04:00
|
|
|
"COMPONENTS option (or after the REQUIRED option if present). "
|
2012-03-18 20:26:24 +04:00
|
|
|
"Additional optional components may be listed after OPTIONAL_COMPONENTS. "
|
|
|
|
"Available components and their influence on whether a package is "
|
|
|
|
"considered to be found are defined by the target package."
|
|
|
|
"\n"
|
2008-09-10 18:11:48 +04:00
|
|
|
"The [version] argument requests a version with which the package found "
|
|
|
|
"should be compatible (format is major[.minor[.patch[.tweak]]]). "
|
2008-01-29 04:38:48 +03:00
|
|
|
"The EXACT option requests that the version be matched exactly. "
|
2011-04-07 23:36:05 +04:00
|
|
|
"If no [version] and/or component list is given to a recursive "
|
|
|
|
"invocation inside a find-module, the corresponding arguments "
|
|
|
|
"are forwarded automatically from the outer call (including the "
|
|
|
|
"EXACT flag for [version]). "
|
2008-01-22 06:48:07 +03:00
|
|
|
"Version support is currently provided only on a package-by-package "
|
2008-01-29 04:38:48 +03:00
|
|
|
"basis (details below).\n"
|
2008-01-22 06:48:07 +03: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 04:38:48 +03: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. "
|
2012-02-21 01:09:10 +04:00
|
|
|
"If no module is found and the MODULE option is not given the command "
|
|
|
|
"proceeds to Config mode.\n"
|
2008-01-22 06:48:07 +03:00
|
|
|
"The complete Config mode command signature is:\n"
|
2008-09-10 18:11:48 +04:00
|
|
|
" find_package(<package> [version] [EXACT] [QUIET]\n"
|
2012-04-18 21:28:45 +04:00
|
|
|
" [REQUIRED] [[COMPONENTS] [components...]]\n"
|
2012-02-21 01:09:10 +04:00
|
|
|
" [CONFIG|NO_MODULE]\n"
|
2009-01-22 21:18:40 +03:00
|
|
|
" [NO_POLICY_SCOPE]\n"
|
2008-01-17 17:02:31 +03:00
|
|
|
" [NAMES name1 [name2 ...]]\n"
|
|
|
|
" [CONFIGS config1 [config2 ...]]\n"
|
2008-06-09 23:08:59 +04:00
|
|
|
" [HINTS path1 [path2 ... ]]\n"
|
2008-01-17 17:02:31 +03: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"
|
2009-09-01 22:04:27 +04:00
|
|
|
" [NO_CMAKE_PACKAGE_REGISTRY]\n"
|
2008-01-17 17:02:31 +03:00
|
|
|
" [NO_CMAKE_BUILDS_PATH]\n"
|
|
|
|
" [NO_CMAKE_SYSTEM_PATH]\n"
|
2011-04-13 21:14:41 +04:00
|
|
|
" [NO_CMAKE_SYSTEM_PACKAGE_REGISTRY]\n"
|
2008-01-17 17:02:31 +03:00
|
|
|
" [CMAKE_FIND_ROOT_PATH_BOTH |\n"
|
|
|
|
" ONLY_CMAKE_FIND_ROOT_PATH |\n"
|
|
|
|
" NO_CMAKE_FIND_ROOT_PATH])\n"
|
2012-02-21 01:09:10 +04:00
|
|
|
"The CONFIG option may be used to skip Module mode explicitly and "
|
|
|
|
"switch to Config mode. It is synonymous to using NO_MODULE. "
|
|
|
|
"Config mode is also implied by use of options not specified in the "
|
|
|
|
"reduced signature. "
|
2008-01-17 17:02:31 +03: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"
|
2010-08-29 19:07:39 +04:00
|
|
|
"All configuration files which have been considered by CMake while "
|
|
|
|
"searching for an installation of the package with an appropriate "
|
|
|
|
"version are stored in the cmake variable <package>_CONSIDERED_CONFIGS, "
|
|
|
|
"the associated versions in <package>_CONSIDERED_VERSIONS. "
|
|
|
|
"\n"
|
2008-01-17 17:02:31 +03:00
|
|
|
"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 "
|
2009-01-16 00:16:19 +03:00
|
|
|
"a configuration file CMake will ignore it and search from scratch."
|
2008-01-17 17:02:31 +03:00
|
|
|
"\n"
|
2008-09-10 18:11:48 +04: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 04:38:48 +03: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. "
|
2009-04-19 20:48:30 +04:00
|
|
|
"For a candidate package configuration file \"<config-file>.cmake\" the "
|
2008-01-29 04:38:48 +03:00
|
|
|
"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. "
|
2011-08-02 00:59:18 +04:00
|
|
|
"A basic version file containing generic version matching code can be "
|
2012-02-17 03:36:18 +04:00
|
|
|
"created using the macro write_basic_package_version_file(), see its "
|
2011-08-02 00:59:18 +04:00
|
|
|
"documentation for more details. "
|
2008-01-29 04:38:48 +03:00
|
|
|
"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 18:11:48 +04: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 04:38:48 +03:00
|
|
|
"The version file checks whether it satisfies the requested version "
|
|
|
|
"and sets these variables:\n"
|
2008-09-10 18:11:48 +04:00
|
|
|
" PACKAGE_VERSION = full provided version string\n"
|
2008-01-29 04:38:48 +03:00
|
|
|
" PACKAGE_VERSION_EXACT = true if version is exact match\n"
|
|
|
|
" PACKAGE_VERSION_COMPATIBLE = true if version is compatible\n"
|
2008-10-03 18:41:15 +04:00
|
|
|
" PACKAGE_VERSION_UNSUITABLE = true if unsuitable as any version\n"
|
2008-01-29 04:38:48 +03:00
|
|
|
"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 18:11:48 +04: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 17:57:39 +03: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 04:38:48 +03:00
|
|
|
"\n"
|
2008-01-18 04:59:57 +03: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 04:38:48 +03:00
|
|
|
" find_package(<package> [major[.minor]] [EXACT] [REQUIRED|QUIET])\n"
|
2008-01-18 04:59:57 +03: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 17:02:31 +03:00
|
|
|
"CMake constructs a set of possible installation prefixes for the "
|
2008-01-18 04:59:57 +03: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 17:02:31 +03:00
|
|
|
" <prefix>/ (W)\n"
|
|
|
|
" <prefix>/(cmake|CMake)/ (W)\n"
|
2008-12-17 17:24:05 +03:00
|
|
|
" <prefix>/<name>*/ (W)\n"
|
|
|
|
" <prefix>/<name>*/(cmake|CMake)/ (W)\n"
|
2011-06-08 16:46:31 +04:00
|
|
|
" <prefix>/(lib/<arch>|lib|share)/cmake/<name>*/ (U)\n"
|
|
|
|
" <prefix>/(lib/<arch>|lib|share)/<name>*/ (U)\n"
|
|
|
|
" <prefix>/(lib/<arch>|lib|share)/<name>*/(cmake|CMake)/ (U)\n"
|
2008-01-17 17:02:31 +03: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). "
|
2011-06-08 16:46:31 +04:00
|
|
|
"Paths with lib/<arch> are enabled if CMAKE_LIBRARY_ARCHITECTURE is set. "
|
2008-01-17 17:02:31 +03:00
|
|
|
"If PATH_SUFFIXES is specified the suffixes are appended to each "
|
2008-01-18 04:59:57 +03:00
|
|
|
"(W) or (U) directory entry one-by-one.\n"
|
2008-01-17 17:02:31 +03: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 04:59:57 +03: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 17:02:31 +03: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 23:22:09 +04: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 17:02:31 +03:00
|
|
|
" CMAKE_PREFIX_PATH\n"
|
|
|
|
" CMAKE_FRAMEWORK_PATH\n"
|
|
|
|
" CMAKE_APPBUNDLE_PATH\n"
|
2008-06-09 23:22:09 +04: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"
|
2009-11-04 21:14:57 +03:00
|
|
|
" <package>_DIR\n"
|
2008-01-17 17:02:31 +03:00
|
|
|
" CMAKE_PREFIX_PATH\n"
|
|
|
|
" CMAKE_FRAMEWORK_PATH\n"
|
|
|
|
" CMAKE_APPBUNDLE_PATH\n"
|
2008-06-09 23:08:59 +04: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 17:02:31 +03: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 23:08:59 +04:00
|
|
|
"5. Search project build trees recently configured in a CMake GUI. "
|
2008-01-17 17:02:31 +03: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"
|
2009-09-01 22:04:27 +04:00
|
|
|
"6. Search paths stored in the CMake user package registry. "
|
|
|
|
"This can be skipped if NO_CMAKE_PACKAGE_REGISTRY is passed. "
|
2011-04-13 21:10:08 +04:00
|
|
|
"On Windows a <package> may appear under registry key\n"
|
|
|
|
" HKEY_CURRENT_USER\\Software\\Kitware\\CMake\\Packages\\<package>\n"
|
|
|
|
"as a REG_SZ value, with arbitrary name, that specifies the directory "
|
|
|
|
"containing the package configuration file. "
|
|
|
|
"On UNIX platforms a <package> may appear under the directory\n"
|
|
|
|
" ~/.cmake/packages/<package>\n"
|
|
|
|
"as a file, with arbitrary name, whose content specifies the directory "
|
|
|
|
"containing the package configuration file. "
|
|
|
|
"See the export(PACKAGE) command to create user package registry entries "
|
|
|
|
"for project build trees."
|
2009-09-01 22:04:27 +04:00
|
|
|
"\n"
|
|
|
|
"7. Search cmake variables defined in the Platform files "
|
2008-01-17 17:02:31 +03: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"
|
2011-04-13 21:14:41 +04:00
|
|
|
"8. Search paths stored in the CMake system package registry. "
|
|
|
|
"This can be skipped if NO_CMAKE_SYSTEM_PACKAGE_REGISTRY is passed. "
|
|
|
|
"On Windows a <package> may appear under registry key\n"
|
|
|
|
" HKEY_LOCAL_MACHINE\\Software\\Kitware\\CMake\\Packages\\<package>\n"
|
|
|
|
"as a REG_SZ value, with arbitrary name, that specifies the directory "
|
|
|
|
"containing the package configuration file. "
|
|
|
|
"There is no system package registry on non-Windows platforms."
|
|
|
|
"\n"
|
|
|
|
"9. Search paths specified by the PATHS option. "
|
2008-06-09 23:08:59 +04:00
|
|
|
"These are typically hard-coded guesses.\n"
|
2008-01-17 17:02:31 +03:00
|
|
|
;
|
|
|
|
this->CommandDocumentation += this->GenericDocumentationMacPolicy;
|
|
|
|
this->CommandDocumentation += this->GenericDocumentationRootPath;
|
|
|
|
this->CommandDocumentation += this->GenericDocumentationPathsOrder;
|
2009-01-22 21:18:40 +03:00
|
|
|
this->CommandDocumentation +=
|
|
|
|
"\n"
|
2011-06-17 00:13:00 +04:00
|
|
|
"Every non-REQUIRED find_package() call can be disabled by setting the "
|
|
|
|
"variable CMAKE_DISABLE_FIND_PACKAGE_<package> to TRUE. See the "
|
|
|
|
"documentation for the CMAKE_DISABLE_FIND_PACKAGE_<package> variable for "
|
|
|
|
"more information.\n"
|
2012-04-18 16:57:29 +04:00
|
|
|
"When loading a find module or package configuration file find_package "
|
|
|
|
"defines variables to provide information about the call arguments "
|
|
|
|
"(and restores their original state before returning):\n"
|
|
|
|
" <package>_FIND_REQUIRED = true if REQUIRED option was given\n"
|
|
|
|
" <package>_FIND_QUIETLY = true if QUIET option was given\n"
|
|
|
|
" <package>_FIND_VERSION = full requested version string\n"
|
|
|
|
" <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"
|
|
|
|
" <package>_FIND_VERSION_EXACT = true if EXACT option was given\n"
|
|
|
|
" <package>_FIND_COMPONENTS = list of requested components\n"
|
|
|
|
" <package>_FIND_REQUIRED_<c> = true if component <c> is required\n"
|
|
|
|
" false if component <c> is optional\n"
|
|
|
|
"In Module mode the loaded find module is responsible to honor the "
|
|
|
|
"request detailed by these variables; see the find module for details. "
|
|
|
|
"In Config mode find_package handles REQUIRED, QUIET, and version "
|
|
|
|
"options automatically but leaves it to the package configuration file "
|
|
|
|
"to handle components in a way that makes sense for the package. "
|
|
|
|
"The package configuration file may set <package>_FOUND to false "
|
|
|
|
"to tell find_package that component requirements are not satisfied."
|
|
|
|
"\n"
|
2013-02-01 19:30:57 +04:00
|
|
|
"A package configuration file may include() a <package>Targets.cmake "
|
|
|
|
"file, created by install(EXPORT) in the upstream source, to import "
|
|
|
|
"targets into the downstream consumer. "
|
|
|
|
"When a new version of the upstream adds INTERFACE properties not "
|
|
|
|
"present in a previous version it can change behavior for existing "
|
|
|
|
"downstreams. "
|
|
|
|
"In order to remain source compatible the upstream package configuration "
|
|
|
|
"file may set <package>_NO_INTERFACES to disable INTERFACE properties. "
|
|
|
|
"For example, code of the form:\n"
|
|
|
|
" if(<package>_FIND_VERSION VERSION_LESS <new-version>\n"
|
|
|
|
" AND NOT <package>_INTERFACES)\n"
|
|
|
|
" set(<package>_NO_INTERFACES 1)\n"
|
2013-01-29 19:32:51 +04:00
|
|
|
" endif()\n"
|
|
|
|
" include(\"${CMAKE_CURRENT_LIST_DIR}/<package>Targets.cmake\")\n"
|
2013-02-01 19:30:57 +04:00
|
|
|
"tells <package>Targets.cmake not to provide the INTERFACE properties "
|
|
|
|
"unless the downstream requests at least <new-version> or sets "
|
|
|
|
"<package>_INTERFACES to explicitly request them. "
|
|
|
|
"This allows consumers to decide when to enable the new interfaces when "
|
|
|
|
"upgrading."
|
2013-01-29 19:32:51 +04:00
|
|
|
"\n"
|
2009-01-22 21:18:40 +03:00
|
|
|
"See the cmake_policy() command documentation for discussion of the "
|
|
|
|
"NO_POLICY_SCOPE option."
|
|
|
|
;
|
2008-01-17 17:02:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2012-02-25 10:49:24 +04:00
|
|
|
const char* cmFindPackageCommand::GetFullDocumentation() const
|
2008-01-17 17:02:31 +03:00
|
|
|
{
|
2010-11-12 18:47:28 +03:00
|
|
|
if(this->CommandDocumentation.empty())
|
|
|
|
{
|
2012-02-25 10:49:24 +04:00
|
|
|
const_cast<cmFindPackageCommand *>(this)->GenerateDocumentation();
|
2010-11-12 18:47:28 +03:00
|
|
|
}
|
2008-01-17 17:02:31 +03:00
|
|
|
return this->CommandDocumentation.c_str();
|
|
|
|
}
|
|
|
|
|
2003-01-22 01:15:22 +03:00
|
|
|
//----------------------------------------------------------------------------
|
2008-01-23 18:28:26 +03:00
|
|
|
bool cmFindPackageCommand
|
|
|
|
::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
|
2003-01-22 01:15:22 +03:00
|
|
|
{
|
|
|
|
if(args.size() < 1)
|
|
|
|
{
|
|
|
|
this->SetError("called with incorrect number of arguments");
|
|
|
|
return false;
|
|
|
|
}
|
2004-04-26 18:49:34 +04:00
|
|
|
|
2012-02-28 18:51:10 +04:00
|
|
|
// Lookup required version of CMake.
|
|
|
|
if(const char* rv =
|
|
|
|
this->Makefile->GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION"))
|
|
|
|
{
|
|
|
|
unsigned int v[3] = {0,0,0};
|
|
|
|
sscanf(rv, "%u.%u.%u", &v[0], &v[1], &v[2]);
|
|
|
|
this->RequiredCMakeVersion = CMake_VERSION_ENCODE(v[0],v[1],v[2]);
|
|
|
|
}
|
|
|
|
|
2008-01-17 17:02:31 +03:00
|
|
|
// Check for debug mode.
|
|
|
|
this->DebugMode = this->Makefile->IsOn("CMAKE_FIND_DEBUG_MODE");
|
|
|
|
|
2011-06-08 16:46:31 +04:00
|
|
|
// Lookup target architecture, if any.
|
|
|
|
if(const char* arch =
|
|
|
|
this->Makefile->GetDefinition("CMAKE_LIBRARY_ARCHITECTURE"))
|
|
|
|
{
|
|
|
|
this->LibraryArchitecture = arch;
|
|
|
|
}
|
|
|
|
|
2008-08-13 03:01:04 +04:00
|
|
|
// Lookup whether lib64 paths should be used.
|
2009-09-30 21:45:14 +04:00
|
|
|
if(this->Makefile->PlatformIs64Bit() &&
|
|
|
|
this->Makefile->GetCMakeInstance()
|
|
|
|
->GetPropertyAsBool("FIND_LIBRARY_USE_LIB64_PATHS"))
|
2008-08-13 03:01:04 +04:00
|
|
|
{
|
2009-09-30 21:45:14 +04:00
|
|
|
this->UseLib64Paths = true;
|
2008-08-13 03:01:04 +04:00
|
|
|
}
|
|
|
|
|
2008-01-17 17:02:31 +03:00
|
|
|
// Find the current root path mode.
|
|
|
|
this->SelectDefaultRootPathMode();
|
|
|
|
|
|
|
|
// Find the current bundle/framework search policy.
|
|
|
|
this->SelectDefaultMacMode();
|
|
|
|
|
2006-10-26 19:39:56 +04:00
|
|
|
// Record options.
|
2003-01-22 01:15:22 +03:00
|
|
|
this->Name = args[0];
|
2006-10-26 19:39:56 +04:00
|
|
|
std::string components;
|
|
|
|
const char* components_sep = "";
|
2012-03-18 15:41:28 +04:00
|
|
|
std::set<std::string> requiredComponents;
|
|
|
|
std::set<std::string> optionalComponents;
|
2006-10-26 19:39:56 +04:00
|
|
|
|
2008-01-17 17:02:31 +03: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 19:39:56 +04:00
|
|
|
// Parse the arguments.
|
2012-03-18 15:41:28 +04:00
|
|
|
enum Doing { DoingNone, DoingComponents, DoingOptionalComponents, DoingNames,
|
|
|
|
DoingPaths, DoingPathSuffixes, DoingConfigs, DoingHints };
|
2008-01-17 17:02:31 +03:00
|
|
|
Doing doing = DoingNone;
|
2006-10-26 19:39:56 +04:00
|
|
|
cmsys::RegularExpression version("^[0-9.]+$");
|
|
|
|
bool haveVersion = false;
|
2012-02-28 17:56:50 +04:00
|
|
|
std::set<unsigned int> configArgs;
|
|
|
|
std::set<unsigned int> moduleArgs;
|
2006-10-26 19:39:56 +04:00
|
|
|
for(unsigned int i=1; i < args.size(); ++i)
|
2003-07-16 22:52:51 +04:00
|
|
|
{
|
2006-10-26 19:39:56 +04:00
|
|
|
if(args[i] == "QUIET")
|
2003-07-16 22:52:51 +04:00
|
|
|
{
|
2008-01-17 17:02:31 +03:00
|
|
|
this->Quiet = true;
|
|
|
|
doing = DoingNone;
|
2006-10-26 19:39:56 +04:00
|
|
|
}
|
2008-01-29 04:38:48 +03:00
|
|
|
else if(args[i] == "EXACT")
|
|
|
|
{
|
|
|
|
this->VersionExact = true;
|
|
|
|
this->Compatibility_1_6 = false;
|
|
|
|
doing = DoingNone;
|
|
|
|
}
|
2012-02-21 01:09:10 +04:00
|
|
|
else if(args[i] == "MODULE")
|
|
|
|
{
|
2012-02-28 17:56:50 +04:00
|
|
|
moduleArgs.insert(i);
|
2012-02-21 01:09:10 +04:00
|
|
|
doing = DoingNone;
|
|
|
|
}
|
2012-02-21 01:09:10 +04:00
|
|
|
else if(args[i] == "CONFIG")
|
|
|
|
{
|
2012-02-28 17:56:50 +04:00
|
|
|
configArgs.insert(i);
|
2012-02-21 01:09:10 +04:00
|
|
|
doing = DoingNone;
|
|
|
|
}
|
2006-10-26 19:39:56 +04:00
|
|
|
else if(args[i] == "NO_MODULE")
|
|
|
|
{
|
2012-02-28 17:56:50 +04:00
|
|
|
configArgs.insert(i);
|
2008-01-17 17:02:31 +03:00
|
|
|
doing = DoingNone;
|
2006-10-26 19:39:56 +04:00
|
|
|
}
|
|
|
|
else if(args[i] == "REQUIRED")
|
|
|
|
{
|
2008-01-17 17:02:31 +03:00
|
|
|
this->Required = true;
|
|
|
|
doing = DoingComponents;
|
2006-10-26 19:39:56 +04:00
|
|
|
}
|
|
|
|
else if(args[i] == "COMPONENTS")
|
|
|
|
{
|
2008-01-17 17:02:31 +03:00
|
|
|
this->Compatibility_1_6 = false;
|
|
|
|
doing = DoingComponents;
|
|
|
|
}
|
2012-03-18 15:41:28 +04:00
|
|
|
else if(args[i] == "OPTIONAL_COMPONENTS")
|
|
|
|
{
|
|
|
|
this->Compatibility_1_6 = false;
|
|
|
|
doing = DoingOptionalComponents;
|
|
|
|
}
|
2008-01-17 17:02:31 +03:00
|
|
|
else if(args[i] == "NAMES")
|
|
|
|
{
|
2012-02-28 17:56:50 +04:00
|
|
|
configArgs.insert(i);
|
2008-01-17 17:02:31 +03:00
|
|
|
this->Compatibility_1_6 = false;
|
|
|
|
doing = DoingNames;
|
2003-07-16 22:52:51 +04:00
|
|
|
}
|
2008-01-17 17:02:31 +03:00
|
|
|
else if(args[i] == "PATHS")
|
|
|
|
{
|
2012-02-28 17:56:50 +04:00
|
|
|
configArgs.insert(i);
|
2008-01-17 17:02:31 +03:00
|
|
|
this->Compatibility_1_6 = false;
|
|
|
|
doing = DoingPaths;
|
|
|
|
}
|
2008-06-09 23:08:59 +04:00
|
|
|
else if(args[i] == "HINTS")
|
|
|
|
{
|
2012-02-28 17:56:50 +04:00
|
|
|
configArgs.insert(i);
|
2008-06-09 23:08:59 +04:00
|
|
|
this->Compatibility_1_6 = false;
|
|
|
|
doing = DoingHints;
|
|
|
|
}
|
2008-01-17 17:02:31 +03:00
|
|
|
else if(args[i] == "PATH_SUFFIXES")
|
|
|
|
{
|
2012-02-28 17:56:50 +04:00
|
|
|
configArgs.insert(i);
|
2008-01-17 17:02:31 +03:00
|
|
|
this->Compatibility_1_6 = false;
|
|
|
|
doing = DoingPathSuffixes;
|
|
|
|
}
|
|
|
|
else if(args[i] == "CONFIGS")
|
|
|
|
{
|
2012-02-28 17:56:50 +04:00
|
|
|
configArgs.insert(i);
|
2008-01-17 17:02:31 +03:00
|
|
|
this->Compatibility_1_6 = false;
|
|
|
|
doing = DoingConfigs;
|
|
|
|
}
|
2009-01-22 21:18:40 +03:00
|
|
|
else if(args[i] == "NO_POLICY_SCOPE")
|
|
|
|
{
|
|
|
|
this->PolicyScope = false;
|
|
|
|
this->Compatibility_1_6 = false;
|
|
|
|
doing = DoingNone;
|
|
|
|
}
|
2009-09-01 22:04:27 +04:00
|
|
|
else if(args[i] == "NO_CMAKE_PACKAGE_REGISTRY")
|
|
|
|
{
|
2011-04-13 18:36:45 +04:00
|
|
|
this->NoUserRegistry = true;
|
2012-02-28 17:56:50 +04:00
|
|
|
configArgs.insert(i);
|
2009-09-01 22:04:27 +04:00
|
|
|
this->Compatibility_1_6 = false;
|
|
|
|
doing = DoingNone;
|
|
|
|
}
|
2011-04-13 21:14:41 +04:00
|
|
|
else if(args[i] == "NO_CMAKE_SYSTEM_PACKAGE_REGISTRY")
|
|
|
|
{
|
|
|
|
this->NoSystemRegistry = true;
|
2012-02-28 17:56:50 +04:00
|
|
|
configArgs.insert(i);
|
2011-04-13 21:14:41 +04:00
|
|
|
this->Compatibility_1_6 = false;
|
|
|
|
doing = DoingNone;
|
|
|
|
}
|
2008-01-17 17:02:31 +03:00
|
|
|
else if(args[i] == "NO_CMAKE_BUILDS_PATH")
|
|
|
|
{
|
|
|
|
this->NoBuilds = true;
|
2012-02-28 17:56:50 +04:00
|
|
|
configArgs.insert(i);
|
2008-01-17 17:02:31 +03:00
|
|
|
this->Compatibility_1_6 = false;
|
|
|
|
doing = DoingNone;
|
|
|
|
}
|
|
|
|
else if(this->CheckCommonArgument(args[i]))
|
|
|
|
{
|
2012-02-28 17:56:50 +04:00
|
|
|
configArgs.insert(i);
|
2008-01-17 17:02:31 +03:00
|
|
|
this->Compatibility_1_6 = false;
|
|
|
|
doing = DoingNone;
|
|
|
|
}
|
2012-03-18 15:41:28 +04:00
|
|
|
else if((doing == DoingComponents) || (doing == DoingOptionalComponents))
|
2006-10-26 19:39:56 +04:00
|
|
|
{
|
2012-03-18 15:41:28 +04:00
|
|
|
// Set a variable telling the find script whether this component
|
2006-10-26 19:39:56 +04:00
|
|
|
// is required.
|
2012-03-18 15:41:28 +04:00
|
|
|
const char* isRequired = "1";
|
|
|
|
if (doing == DoingOptionalComponents)
|
|
|
|
{
|
|
|
|
isRequired = "0";
|
|
|
|
optionalComponents.insert(args[i]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
requiredComponents.insert(args[i]);
|
|
|
|
}
|
|
|
|
|
2008-09-07 03:10:02 +04:00
|
|
|
std::string req_var = this->Name + "_FIND_REQUIRED_" + args[i];
|
2012-03-18 15:41:28 +04:00
|
|
|
this->AddFindDefinition(req_var.c_str(), isRequired);
|
2006-07-12 01:10:00 +04:00
|
|
|
|
2006-10-26 19:39:56 +04:00
|
|
|
// Append to the list of required components.
|
|
|
|
components += components_sep;
|
|
|
|
components += args[i];
|
|
|
|
components_sep = ";";
|
|
|
|
}
|
2008-01-17 17:02:31 +03:00
|
|
|
else if(doing == DoingNames)
|
|
|
|
{
|
|
|
|
this->Names.push_back(args[i]);
|
|
|
|
}
|
|
|
|
else if(doing == DoingPaths)
|
|
|
|
{
|
2008-06-09 23:08:59 +04:00
|
|
|
this->AddUserPath(args[i], this->UserPaths);
|
|
|
|
}
|
|
|
|
else if(doing == DoingHints)
|
|
|
|
{
|
|
|
|
this->AddUserPath(args[i], this->UserHints);
|
2008-01-17 17:02:31 +03:00
|
|
|
}
|
|
|
|
else if(doing == DoingPathSuffixes)
|
|
|
|
{
|
|
|
|
this->AddPathSuffix(args[i]);
|
|
|
|
}
|
|
|
|
else if(doing == DoingConfigs)
|
|
|
|
{
|
2008-01-29 04:38:48 +03: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.";
|
2012-02-17 14:43:27 +04:00
|
|
|
this->SetError(e.str().c_str());
|
2008-01-29 04:38:48 +03:00
|
|
|
return false;
|
|
|
|
}
|
2008-01-17 17:02:31 +03:00
|
|
|
this->Configs.push_back(args[i]);
|
|
|
|
}
|
2006-10-26 19:39:56 +04:00
|
|
|
else if(!haveVersion && version.find(args[i].c_str()))
|
|
|
|
{
|
|
|
|
haveVersion = true;
|
2008-01-21 16:48:33 +03:00
|
|
|
this->Version = args[i];
|
2006-10-26 19:39:56 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cmOStringStream e;
|
|
|
|
e << "called with invalid argument \"" << args[i].c_str() << "\"";
|
|
|
|
this->SetError(e.str().c_str());
|
|
|
|
return false;
|
|
|
|
}
|
2003-07-16 22:52:51 +04:00
|
|
|
}
|
2004-04-26 18:49:34 +04:00
|
|
|
|
2012-03-18 15:41:28 +04:00
|
|
|
std::vector<std::string> doubledComponents;
|
|
|
|
std::set_intersection(requiredComponents.begin(), requiredComponents.end(),
|
|
|
|
optionalComponents.begin(), optionalComponents.end(),
|
|
|
|
std::back_inserter(doubledComponents));
|
|
|
|
if(!doubledComponents.empty())
|
|
|
|
{
|
|
|
|
cmOStringStream e;
|
|
|
|
e << "called with components that are both required and optional:\n";
|
|
|
|
for(unsigned int i=0; i<doubledComponents.size(); ++i)
|
|
|
|
{
|
|
|
|
e << " " << doubledComponents[i] << "\n";
|
|
|
|
}
|
|
|
|
this->SetError(e.str().c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-02-28 17:56:50 +04:00
|
|
|
// Maybe choose one mode exclusively.
|
|
|
|
this->UseFindModules = configArgs.empty();
|
|
|
|
this->UseConfigFiles = moduleArgs.empty();
|
|
|
|
if(!this->UseFindModules && !this->UseConfigFiles)
|
|
|
|
{
|
|
|
|
cmOStringStream e;
|
|
|
|
e << "given options exclusive to Module mode:\n";
|
|
|
|
for(std::set<unsigned int>::const_iterator si = moduleArgs.begin();
|
|
|
|
si != moduleArgs.end(); ++si)
|
|
|
|
{
|
|
|
|
e << " " << args[*si] << "\n";
|
|
|
|
}
|
|
|
|
e << "and options exclusive to Config mode:\n";
|
|
|
|
for(std::set<unsigned int>::const_iterator si = configArgs.begin();
|
|
|
|
si != configArgs.end(); ++si)
|
|
|
|
{
|
|
|
|
e << " " << args[*si] << "\n";
|
|
|
|
}
|
|
|
|
e << "The options are incompatible.";
|
|
|
|
this->SetError(e.str().c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-10-03 18:39:53 +04: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.");
|
|
|
|
}
|
|
|
|
|
2011-04-07 23:36:05 +04:00
|
|
|
if(this->Version.empty() || components.empty())
|
2008-10-03 18:40:07 +04:00
|
|
|
{
|
|
|
|
// Check whether we are recursing inside "Find<name>.cmake" within
|
|
|
|
// another find_package(<name>) call.
|
|
|
|
std::string mod = this->Name;
|
|
|
|
mod += "_FIND_MODULE";
|
|
|
|
if(this->Makefile->IsOn(mod.c_str()))
|
|
|
|
{
|
2011-04-07 23:36:05 +04:00
|
|
|
if(this->Version.empty())
|
|
|
|
{
|
|
|
|
// Get version information from the outer call if necessary.
|
|
|
|
// Requested version string.
|
|
|
|
std::string ver = this->Name;
|
|
|
|
ver += "_FIND_VERSION";
|
|
|
|
this->Version = this->Makefile->GetSafeDefinition(ver.c_str());
|
2008-10-03 18:40:07 +04:00
|
|
|
|
2011-04-07 23:36:05 +04:00
|
|
|
// Whether an exact version is required.
|
|
|
|
std::string exact = this->Name;
|
|
|
|
exact += "_FIND_VERSION_EXACT";
|
|
|
|
this->VersionExact = this->Makefile->IsOn(exact.c_str());
|
|
|
|
}
|
|
|
|
if(components.empty())
|
|
|
|
{
|
|
|
|
std::string components_var = this->Name + "_FIND_COMPONENTS";
|
|
|
|
components = this->Makefile->GetSafeDefinition(components_var.c_str());
|
|
|
|
}
|
2008-10-03 18:40:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-21 16:48:33 +03: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 18:11:48 +04: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 16:48:33 +03:00
|
|
|
switch(this->VersionCount)
|
|
|
|
{
|
2008-09-10 18:11:48 +04:00
|
|
|
case 4: this->VersionTweak = parsed_tweak; // no break!
|
2008-01-21 16:48:33 +03: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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-16 23:11:06 +04:00
|
|
|
std::string disableFindPackageVar = "CMAKE_DISABLE_FIND_PACKAGE_";
|
|
|
|
disableFindPackageVar += this->Name;
|
|
|
|
if(this->Makefile->IsOn(disableFindPackageVar.c_str()))
|
|
|
|
{
|
|
|
|
if (this->Required)
|
|
|
|
{
|
|
|
|
cmOStringStream e;
|
|
|
|
e << "for module " << this->Name << " called with REQUIRED, but "
|
|
|
|
<< disableFindPackageVar
|
|
|
|
<< " is enabled. A REQUIRED package cannot be disabled.";
|
|
|
|
this->SetError(e.str().c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-07 03:10:02 +04:00
|
|
|
this->SetModuleVariables(components);
|
2006-10-26 19:39:56 +04:00
|
|
|
|
2008-01-17 17:02:31 +03:00
|
|
|
// See if there is a Find<package>.cmake module.
|
2012-02-18 00:31:08 +04:00
|
|
|
if(this->UseFindModules)
|
2003-01-22 01:15:22 +03:00
|
|
|
{
|
2006-10-26 19:39:56 +04:00
|
|
|
bool foundModule = false;
|
2008-01-17 17:02:31 +03:00
|
|
|
if(!this->FindModule(foundModule))
|
2006-10-26 19:39:56 +04:00
|
|
|
{
|
2008-01-17 17:02:31 +03:00
|
|
|
this->AppendSuccessInformation();
|
2006-10-26 19:39:56 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if(foundModule)
|
|
|
|
{
|
2008-01-17 17:02:31 +03:00
|
|
|
this->AppendSuccessInformation();
|
2006-10-26 19:39:56 +04:00
|
|
|
return true;
|
|
|
|
}
|
2003-01-22 01:15:22 +03:00
|
|
|
}
|
2003-08-08 00:50:38 +04:00
|
|
|
|
2012-02-28 18:51:10 +04:00
|
|
|
if(this->UseFindModules && this->UseConfigFiles &&
|
|
|
|
this->Makefile->IsOn("CMAKE_FIND_PACKAGE_WARN_NO_MODULE"))
|
|
|
|
{
|
|
|
|
cmOStringStream aw;
|
|
|
|
if(this->RequiredCMakeVersion >= CMake_VERSION_ENCODE(2,8,8))
|
|
|
|
{
|
|
|
|
aw << "find_package called without either MODULE or CONFIG option and "
|
|
|
|
"no Find" << this->Name << ".cmake module is in CMAKE_MODULE_PATH. "
|
|
|
|
"Add MODULE to exclusively request Module mode and fail if "
|
|
|
|
"Find" << this->Name << ".cmake is missing. "
|
|
|
|
"Add CONFIG to exclusively request Config mode and search for a "
|
|
|
|
"package configuration file provided by " << this->Name <<
|
|
|
|
" (" << this->Name << "Config.cmake or " <<
|
|
|
|
cmSystemTools::LowerCase(this->Name) << "-config.cmake). ";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aw << "find_package called without NO_MODULE option and no "
|
|
|
|
"Find" << this->Name << ".cmake module is in CMAKE_MODULE_PATH. "
|
|
|
|
"Add NO_MODULE to exclusively request Config mode and search for a "
|
|
|
|
"package configuration file provided by " << this->Name <<
|
|
|
|
" (" << this->Name << "Config.cmake or " <<
|
|
|
|
cmSystemTools::LowerCase(this->Name) << "-config.cmake). "
|
|
|
|
"Otherwise make Find" << this->Name << ".cmake available in "
|
|
|
|
"CMAKE_MODULE_PATH.";
|
|
|
|
}
|
|
|
|
aw << "\n"
|
|
|
|
"(Variable CMAKE_FIND_PACKAGE_WARN_NO_MODULE enabled this warning.)";
|
|
|
|
this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, aw.str());
|
|
|
|
}
|
|
|
|
|
2003-01-22 01:15:22 +03:00
|
|
|
// No find module. Assume the project has a CMake config file. Use
|
2008-01-17 17:02:31 +03:00
|
|
|
// a <package>_DIR cache variable to locate it.
|
2003-07-16 22:52:51 +04:00
|
|
|
this->Variable = this->Name;
|
2003-01-22 01:15:22 +03:00
|
|
|
this->Variable += "_DIR";
|
2004-04-26 18:49:34 +04:00
|
|
|
|
2008-01-17 17:02:31 +03: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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-13 02:20:47 +04:00
|
|
|
// get igonored paths from vars and reroot them.
|
|
|
|
std::vector<std::string> ignored;
|
|
|
|
this->GetIgnoredPaths(ignored);
|
|
|
|
this->RerootPaths(ignored);
|
|
|
|
|
|
|
|
// Construct a set of ignored paths
|
|
|
|
this->IgnoredPaths.clear();
|
|
|
|
this->IgnoredPaths.insert(ignored.begin(), ignored.end());
|
|
|
|
|
2008-01-17 17:02:31 +03:00
|
|
|
// Find and load the package.
|
|
|
|
bool result = this->HandlePackageMode();
|
|
|
|
this->AppendSuccessInformation();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-09-07 03:10:02 +04:00
|
|
|
|
2008-01-17 17:02:31 +03:00
|
|
|
//----------------------------------------------------------------------------
|
2008-09-07 14:52:06 +04:00
|
|
|
void cmFindPackageCommand::SetModuleVariables(const std::string& components)
|
2008-01-17 17:02:31 +03:00
|
|
|
{
|
2012-09-23 20:40:40 +04:00
|
|
|
this->AddFindDefinition("CMAKE_FIND_PACKAGE_NAME", this->Name.c_str());
|
|
|
|
|
2008-09-07 03:10:02 +04:00
|
|
|
// Store the list of components.
|
|
|
|
std::string components_var = this->Name + "_FIND_COMPONENTS";
|
2008-12-09 18:08:54 +03:00
|
|
|
this->AddFindDefinition(components_var.c_str(), components.c_str());
|
2010-08-29 19:07:39 +04:00
|
|
|
|
2008-09-07 03:10:02 +04:00
|
|
|
if(this->Quiet)
|
2008-01-17 17:02:31 +03:00
|
|
|
{
|
2008-09-07 03:10:02 +04:00
|
|
|
// Tell the module that is about to be read that it should find
|
|
|
|
// quietly.
|
|
|
|
std::string quietly = this->Name;
|
|
|
|
quietly += "_FIND_QUIETLY";
|
2008-12-09 18:08:54 +03:00
|
|
|
this->AddFindDefinition(quietly.c_str(), "1");
|
2008-09-07 03:10:02 +04:00
|
|
|
}
|
2008-01-17 17:02:31 +03:00
|
|
|
|
2008-09-07 03:10:02 +04: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";
|
2008-12-09 18:08:54 +03:00
|
|
|
this->AddFindDefinition(req.c_str(), "1");
|
2008-09-07 03:10:02 +04:00
|
|
|
}
|
2008-01-17 17:02:31 +03:00
|
|
|
|
2008-09-07 03:10:02 +04: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";
|
2008-12-09 18:08:54 +03:00
|
|
|
this->AddFindDefinition(ver.c_str(), this->Version.c_str());
|
2008-09-07 03:10:02 +04:00
|
|
|
char buf[64];
|
2008-09-10 18:11:48 +04:00
|
|
|
sprintf(buf, "%u", this->VersionMajor);
|
2008-12-09 18:08:54 +03:00
|
|
|
this->AddFindDefinition((ver+"_MAJOR").c_str(), buf);
|
2008-09-10 18:11:48 +04:00
|
|
|
sprintf(buf, "%u", this->VersionMinor);
|
2008-12-09 18:08:54 +03:00
|
|
|
this->AddFindDefinition((ver+"_MINOR").c_str(), buf);
|
2008-09-10 18:11:48 +04:00
|
|
|
sprintf(buf, "%u", this->VersionPatch);
|
2008-12-09 18:08:54 +03:00
|
|
|
this->AddFindDefinition((ver+"_PATCH").c_str(), buf);
|
2008-09-10 18:11:48 +04:00
|
|
|
sprintf(buf, "%u", this->VersionTweak);
|
2008-12-09 18:08:54 +03:00
|
|
|
this->AddFindDefinition((ver+"_TWEAK").c_str(), buf);
|
2008-09-10 18:11:48 +04:00
|
|
|
sprintf(buf, "%u", this->VersionCount);
|
2008-12-09 18:08:54 +03:00
|
|
|
this->AddFindDefinition((ver+"_COUNT").c_str(), buf);
|
2008-01-21 16:48:33 +03:00
|
|
|
|
2008-09-07 03:10:02 +04:00
|
|
|
// Tell the module whether an exact version has been requested.
|
|
|
|
std::string exact = this->Name;
|
|
|
|
exact += "_FIND_VERSION_EXACT";
|
2008-12-09 18:08:54 +03:00
|
|
|
this->AddFindDefinition(exact.c_str(), this->VersionExact? "1":"0");
|
2008-09-07 03:10:02 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-09 18:08:54 +03:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmFindPackageCommand::AddFindDefinition(const char* var, const char* val)
|
|
|
|
{
|
|
|
|
if(const char* old = this->Makefile->GetDefinition(var))
|
|
|
|
{
|
|
|
|
this->OriginalDefs[var].exists = true;
|
|
|
|
this->OriginalDefs[var].value = old;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->OriginalDefs[var].exists = false;
|
|
|
|
}
|
|
|
|
this->Makefile->AddDefinition(var, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmFindPackageCommand::RestoreFindDefinitions()
|
|
|
|
{
|
|
|
|
for(std::map<cmStdString, OriginalDef>::iterator
|
|
|
|
i = this->OriginalDefs.begin(); i != this->OriginalDefs.end(); ++i)
|
|
|
|
{
|
|
|
|
OriginalDef const& od = i->second;
|
|
|
|
if(od.exists)
|
|
|
|
{
|
|
|
|
this->Makefile->AddDefinition(i->first.c_str(), od.value.c_str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->Makefile->RemoveDefinition(i->first.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-09-07 03:10:02 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
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-10-03 18:40:07 +04:00
|
|
|
// Load the module we found, and set "<name>_FIND_MODULE" to true
|
|
|
|
// while inside it.
|
2008-01-17 17:02:31 +03:00
|
|
|
found = true;
|
2008-10-03 18:40:07 +04:00
|
|
|
std::string var = this->Name;
|
|
|
|
var += "_FIND_MODULE";
|
|
|
|
this->Makefile->AddDefinition(var.c_str(), "1");
|
2009-01-22 21:18:40 +03:00
|
|
|
bool result = this->ReadListFile(mfile.c_str(), DoPolicyScope);
|
2008-10-03 18:40:07 +04:00
|
|
|
this->Makefile->RemoveDefinition(var.c_str());
|
|
|
|
return result;
|
2008-01-17 17:02:31 +03:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmFindPackageCommand::HandlePackageMode()
|
|
|
|
{
|
2010-08-29 19:51:44 +04:00
|
|
|
this->ConsideredConfigs.clear();
|
2010-08-29 19:07:39 +04:00
|
|
|
|
2003-08-08 00:50:38 +04: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 17:02:31 +03:00
|
|
|
if(upperDir == this->Variable)
|
2003-08-08 00:50:38 +04:00
|
|
|
{
|
2008-01-17 17:02:31 +03:00
|
|
|
this->Compatibility_1_6 = false;
|
2003-08-08 00:50:38 +04:00
|
|
|
}
|
2004-04-26 18:49:34 +04:00
|
|
|
|
2003-08-08 00:50:38 +04:00
|
|
|
// Try to find the config file.
|
2006-03-15 19:02:08 +03:00
|
|
|
const char* def = this->Makefile->GetDefinition(this->Variable.c_str());
|
2008-01-17 17:02:31 +03:00
|
|
|
if(this->Compatibility_1_6 && cmSystemTools::IsOff(def))
|
2003-08-08 00:50:38 +04:00
|
|
|
{
|
|
|
|
// Use the setting of the old name of the variable to provide the
|
|
|
|
// value of the new.
|
2006-03-15 19:02:08 +03:00
|
|
|
const char* oldDef = this->Makefile->GetDefinition(upperDir.c_str());
|
2003-08-08 00:50:38 +04:00
|
|
|
if(!cmSystemTools::IsOff(oldDef))
|
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Makefile->AddDefinition(this->Variable.c_str(), oldDef);
|
|
|
|
def = this->Makefile->GetDefinition(this->Variable.c_str());
|
2003-08-08 00:50:38 +04:00
|
|
|
}
|
2004-04-26 18:49:34 +04:00
|
|
|
}
|
2008-01-17 17:02:31 +03:00
|
|
|
|
2009-01-09 01:57:52 +03:00
|
|
|
// Try to load the config file if the directory is known
|
2009-10-07 22:37:30 +04:00
|
|
|
bool fileFound = false;
|
2012-02-21 01:09:10 +04:00
|
|
|
if (this->UseConfigFiles)
|
2003-01-22 01:15:22 +03:00
|
|
|
{
|
2012-02-21 01:09:10 +04:00
|
|
|
if(!cmSystemTools::IsOff(def))
|
2007-08-20 16:49:21 +04:00
|
|
|
{
|
2012-02-21 01:09:10 +04: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()))
|
|
|
|
{
|
|
|
|
dir = "/" + dir;
|
|
|
|
dir = this->Makefile->GetCurrentDirectory() + dir;
|
|
|
|
}
|
|
|
|
// The file location was cached. Look for the correct file.
|
|
|
|
std::string file;
|
|
|
|
if (this->FindConfigFile(dir, file))
|
|
|
|
{
|
|
|
|
this->FileFound = file;
|
|
|
|
fileFound = true;
|
|
|
|
}
|
|
|
|
def = this->Makefile->GetDefinition(this->Variable.c_str());
|
2007-08-20 16:49:21 +04:00
|
|
|
}
|
2012-02-21 01:09:10 +04:00
|
|
|
|
|
|
|
// Search for the config file if it is not already found.
|
|
|
|
if(cmSystemTools::IsOff(def) || !fileFound)
|
2003-01-22 01:15:22 +03:00
|
|
|
{
|
2012-02-21 01:09:10 +04:00
|
|
|
fileFound = this->FindConfig();
|
|
|
|
def = this->Makefile->GetDefinition(this->Variable.c_str());
|
2009-01-09 01:57:52 +03:00
|
|
|
}
|
|
|
|
|
2012-02-21 01:09:10 +04:00
|
|
|
// Sanity check.
|
|
|
|
if(fileFound && this->FileFound.empty())
|
|
|
|
{
|
|
|
|
this->Makefile->IssueMessage(
|
|
|
|
cmake::INTERNAL_ERROR, "fileFound is true but FileFound is empty!");
|
|
|
|
fileFound = false;
|
|
|
|
}
|
2009-10-07 22:37:30 +04:00
|
|
|
}
|
|
|
|
|
2012-03-10 14:21:05 +04:00
|
|
|
std::string foundVar = this->Name;
|
|
|
|
foundVar += "_FOUND";
|
2012-09-19 23:50:55 +04:00
|
|
|
std::string notFoundMessageVar = this->Name;
|
|
|
|
notFoundMessageVar += "_NOT_FOUND_MESSAGE";
|
|
|
|
std::string notFoundMessage;
|
2012-03-10 14:21:05 +04:00
|
|
|
|
2009-01-09 01:57:52 +03:00
|
|
|
// If the directory for the config file was found, try to read the file.
|
|
|
|
bool result = true;
|
|
|
|
bool found = false;
|
2012-03-10 14:21:05 +04:00
|
|
|
bool configFileSetFOUNDFalse = false;
|
|
|
|
|
2009-10-07 22:37:30 +04:00
|
|
|
if(fileFound)
|
2009-01-09 01:57:52 +03:00
|
|
|
{
|
2012-03-10 14:21:05 +04:00
|
|
|
if ((this->Makefile->IsDefinitionSet(foundVar.c_str()))
|
|
|
|
&& (this->Makefile->IsOn(foundVar.c_str()) == false))
|
|
|
|
{
|
|
|
|
// by removing Foo_FOUND here if it is FALSE, we don't really change
|
|
|
|
// the situation for the Config file which is about to be included,
|
|
|
|
// but we make it possible to detect later on whether the Config file
|
|
|
|
// has set Foo_FOUND to FALSE itself:
|
|
|
|
this->Makefile->RemoveDefinition(foundVar.c_str());
|
|
|
|
}
|
2012-09-19 23:50:55 +04:00
|
|
|
this->Makefile->RemoveDefinition(notFoundMessageVar.c_str());
|
2012-03-10 14:21:05 +04:00
|
|
|
|
2009-01-09 01:57:52 +03:00
|
|
|
// Set the version variables before loading the config file.
|
|
|
|
// It may override them.
|
|
|
|
this->StoreVersionFound();
|
|
|
|
|
|
|
|
// Parse the configuration file.
|
2009-01-22 21:18:40 +03:00
|
|
|
if(this->ReadListFile(this->FileFound.c_str(), DoPolicyScope))
|
2009-01-09 01:57:52 +03:00
|
|
|
{
|
|
|
|
// The package has been found.
|
|
|
|
found = true;
|
2012-03-10 14:21:05 +04:00
|
|
|
|
|
|
|
// Check whether the Config file has set Foo_FOUND to FALSE:
|
|
|
|
if ((this->Makefile->IsDefinitionSet(foundVar.c_str()))
|
|
|
|
&& (this->Makefile->IsOn(foundVar.c_str()) == false))
|
|
|
|
{
|
|
|
|
// we get here if the Config file has set Foo_FOUND actively to FALSE
|
|
|
|
found = false;
|
|
|
|
configFileSetFOUNDFalse = true;
|
2012-09-19 23:50:55 +04:00
|
|
|
notFoundMessage = this->Makefile->GetSafeDefinition(
|
|
|
|
notFoundMessageVar.c_str());
|
2012-03-10 14:21:05 +04:00
|
|
|
}
|
2003-01-22 01:15:22 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-01-09 01:57:52 +03:00
|
|
|
// The configuration file is invalid.
|
2008-01-17 17:02:31 +03:00
|
|
|
result = false;
|
2003-01-22 01:15:22 +03:00
|
|
|
}
|
|
|
|
}
|
2012-03-10 14:21:05 +04:00
|
|
|
|
|
|
|
if (result && !found && (!this->Quiet || this->Required))
|
2003-01-22 01:15:22 +03:00
|
|
|
{
|
2008-01-17 17:02:31 +03:00
|
|
|
// The variable is not set.
|
2003-01-22 01:15:22 +03:00
|
|
|
cmOStringStream e;
|
2012-02-21 01:09:10 +04:00
|
|
|
cmOStringStream aw;
|
2012-03-10 14:21:05 +04:00
|
|
|
if (configFileSetFOUNDFalse)
|
|
|
|
{
|
|
|
|
e << "Found package configuration file:\n"
|
|
|
|
" " << this->FileFound << "\n"
|
|
|
|
"but it set " << foundVar << " to FALSE so package \"" <<
|
|
|
|
this->Name << "\" is considered to be NOT FOUND.";
|
2012-09-19 23:50:55 +04:00
|
|
|
if (!notFoundMessage.empty())
|
|
|
|
{
|
|
|
|
e << " Reason given by package: \n" << notFoundMessage << "\n";
|
|
|
|
}
|
2012-03-10 14:21:05 +04:00
|
|
|
}
|
2010-08-29 19:43:45 +04:00
|
|
|
// If there are files in ConsideredConfigs, it means that FooConfig.cmake
|
|
|
|
// have been found, but they didn't have appropriate versions.
|
2012-03-10 14:21:05 +04:00
|
|
|
else if (this->ConsideredConfigs.size() > 0)
|
2008-01-17 17:02:31 +03:00
|
|
|
{
|
2010-08-31 23:10:00 +04:00
|
|
|
e << "Could not find a configuration file for package \""
|
|
|
|
<< this->Name << "\" that "
|
|
|
|
<< (this->VersionExact? "exactly matches" : "is compatible with")
|
|
|
|
<< " requested version \"" << this->Version << "\".\n"
|
|
|
|
<< "The following configuration files were considered but not "
|
|
|
|
"accepted:\n";
|
2010-08-29 19:51:44 +04:00
|
|
|
for(std::vector<ConfigFileInfo>::size_type i=0;
|
|
|
|
i<this->ConsideredConfigs.size(); i++)
|
2010-08-29 19:43:45 +04:00
|
|
|
{
|
2010-08-29 19:51:44 +04:00
|
|
|
e << " " << this->ConsideredConfigs[i].filename
|
|
|
|
<< ", version: " << this->ConsideredConfigs[i].version << "\n";
|
2010-08-29 19:43:45 +04:00
|
|
|
}
|
2008-01-17 17:02:31 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-02-17 14:37:29 +04:00
|
|
|
std::string requestedVersionString;
|
|
|
|
if(!this->Version.empty())
|
|
|
|
{
|
|
|
|
requestedVersionString = " (requested version ";
|
|
|
|
requestedVersionString += this->Version;
|
|
|
|
requestedVersionString += ")";
|
|
|
|
}
|
|
|
|
|
2012-02-21 01:09:10 +04:00
|
|
|
if (this->UseConfigFiles)
|
2010-08-29 19:43:45 +04:00
|
|
|
{
|
2012-02-21 01:09:10 +04:00
|
|
|
if(this->UseFindModules)
|
|
|
|
{
|
|
|
|
e << "By not providing \"Find" << this->Name << ".cmake\" in "
|
|
|
|
"CMAKE_MODULE_PATH this project has asked CMake to find a "
|
|
|
|
"package configuration file provided by \""<<this->Name<< "\", "
|
|
|
|
"but CMake did not find one.\n";
|
|
|
|
}
|
2012-02-24 23:33:21 +04:00
|
|
|
|
2012-02-21 01:09:10 +04:00
|
|
|
if(this->Configs.size() == 1)
|
2010-08-29 19:43:45 +04:00
|
|
|
{
|
2012-02-21 01:09:10 +04:00
|
|
|
e << "Could not find a package configuration file named \""
|
|
|
|
<< this->Configs[0] << "\" provided by package \""
|
2012-02-17 14:37:29 +04:00
|
|
|
<< this->Name << "\"" << requestedVersionString <<".\n";
|
2010-08-29 19:43:45 +04:00
|
|
|
}
|
2012-02-21 01:09:10 +04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
e << "Could not find a package configuration file provided by \""
|
2012-02-17 14:37:29 +04:00
|
|
|
<< this->Name << "\"" << requestedVersionString
|
|
|
|
<< " with any of the following names:\n";
|
2012-02-21 01:09:10 +04:00
|
|
|
for(std::vector<std::string>::const_iterator ci =
|
|
|
|
this->Configs.begin();
|
|
|
|
ci != this->Configs.end(); ++ci)
|
|
|
|
{
|
|
|
|
e << " " << *ci << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
e << "Add the installation prefix of \"" << this->Name << "\" to "
|
|
|
|
"CMAKE_PREFIX_PATH or set \"" << this->Variable << "\" to a "
|
|
|
|
"directory containing one of the above files. "
|
|
|
|
"If \"" << this->Name << "\" provides a separate development "
|
|
|
|
"package or SDK, be sure it has been installed.";
|
2008-01-17 17:02:31 +03:00
|
|
|
}
|
2012-02-21 01:09:10 +04:00
|
|
|
else // if(!this->UseFindModules && !this->UseConfigFiles)
|
|
|
|
{
|
|
|
|
e << "No \"Find" << this->Name << ".cmake\" found in "
|
|
|
|
<< "CMAKE_MODULE_PATH.";
|
2010-08-29 19:43:45 +04:00
|
|
|
|
2012-02-21 01:09:10 +04:00
|
|
|
aw<< "Find"<< this->Name <<".cmake must either be part of this "
|
|
|
|
"project itself, in this case adjust CMAKE_MODULE_PATH so that "
|
|
|
|
"it points to the correct location inside its source tree.\n"
|
|
|
|
"Or it must be installed by a package which has already been "
|
|
|
|
"found via find_package(). In this case make sure that "
|
|
|
|
"package has indeed been found and adjust CMAKE_MODULE_PATH to "
|
|
|
|
"contain the location where that package has installed "
|
|
|
|
"Find" << this->Name << ".cmake. This must be a location "
|
|
|
|
"provided by that package. This error in general means that "
|
|
|
|
"the buildsystem of this project is relying on a Find-module "
|
|
|
|
"without ensuring that it is actually available.\n";
|
|
|
|
}
|
2012-02-24 23:33:21 +04:00
|
|
|
}
|
2010-08-29 19:43:45 +04:00
|
|
|
|
2012-02-21 01:09:10 +04:00
|
|
|
|
2008-09-08 18:08:33 +04:00
|
|
|
this->Makefile->IssueMessage(
|
|
|
|
this->Required? cmake::FATAL_ERROR : cmake::WARNING, e.str());
|
2012-03-07 00:16:24 +04:00
|
|
|
if (this->Required)
|
|
|
|
{
|
|
|
|
cmSystemTools::SetFatalErrorOccured();
|
|
|
|
}
|
2012-02-21 01:09:10 +04:00
|
|
|
|
|
|
|
if (!aw.str().empty())
|
|
|
|
{
|
|
|
|
this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,aw.str());
|
|
|
|
}
|
2003-01-22 01:15:22 +03:00
|
|
|
}
|
2004-04-26 18:49:34 +04:00
|
|
|
|
2003-08-08 00:50:38 +04:00
|
|
|
// Set a variable marking whether the package was found.
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Makefile->AddDefinition(foundVar.c_str(), found? "1":"0");
|
2004-04-26 18:49:34 +04:00
|
|
|
|
2008-01-17 17:02:31 +03:00
|
|
|
// Set a variable naming the configuration file that was found.
|
|
|
|
std::string fileVar = this->Name;
|
|
|
|
fileVar += "_CONFIG";
|
|
|
|
if(found)
|
|
|
|
{
|
2009-01-09 01:57:52 +03:00
|
|
|
this->Makefile->AddDefinition(fileVar.c_str(), this->FileFound.c_str());
|
2008-01-17 17:02:31 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->Makefile->RemoveDefinition(fileVar.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle some ancient compatibility stuff.
|
|
|
|
if(this->Compatibility_1_6)
|
2003-08-08 00:50:38 +04:00
|
|
|
{
|
|
|
|
// Listfiles will be looking for the capitalized version of the
|
|
|
|
// name. Provide it.
|
2006-05-10 23:46:45 +04: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-08 00:50:38 +04:00
|
|
|
}
|
2004-04-26 18:49:34 +04:00
|
|
|
|
2004-10-27 18:47:14 +04:00
|
|
|
#ifdef CMAKE_BUILD_WITH_CMAKE
|
2003-08-08 17:14:33 +04:00
|
|
|
if(!(upperDir == this->Variable))
|
2003-08-08 00:50:38 +04:00
|
|
|
{
|
2008-01-17 17:02:31 +03:00
|
|
|
if(this->Compatibility_1_6)
|
2003-08-08 00:50:38 +04:00
|
|
|
{
|
|
|
|
// Listfiles may use the capitalized version of the name.
|
|
|
|
// Remove any previously added watch.
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Makefile->GetVariableWatch()->RemoveWatch(
|
2003-08-08 00:50:38 +04: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 19:02:08 +03:00
|
|
|
this->Makefile->GetVariableWatch()->AddWatch(
|
2003-08-08 00:50:38 +04:00
|
|
|
upperDir.c_str(),
|
|
|
|
cmFindPackageNeedBackwardsCompatibility
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2004-10-27 18:47:14 +04:00
|
|
|
#endif
|
2004-04-26 18:49:34 +04:00
|
|
|
|
2010-08-29 19:07:39 +04:00
|
|
|
std::string consideredConfigsVar = this->Name;
|
|
|
|
consideredConfigsVar += "_CONSIDERED_CONFIGS";
|
|
|
|
std::string consideredVersionsVar = this->Name;
|
|
|
|
consideredVersionsVar += "_CONSIDERED_VERSIONS";
|
|
|
|
|
|
|
|
std::string consideredConfigFiles;
|
|
|
|
std::string consideredVersions;
|
2010-08-29 19:43:45 +04:00
|
|
|
|
2010-08-31 23:10:00 +04:00
|
|
|
const char* sep = "";
|
2010-08-29 19:51:44 +04:00
|
|
|
for(std::vector<ConfigFileInfo>::size_type i=0;
|
|
|
|
i<this->ConsideredConfigs.size(); i++)
|
2010-08-29 19:07:39 +04:00
|
|
|
{
|
2010-08-31 23:10:00 +04:00
|
|
|
consideredConfigFiles += sep;
|
|
|
|
consideredVersions += sep;
|
2010-08-29 19:51:44 +04:00
|
|
|
consideredConfigFiles += this->ConsideredConfigs[i].filename;
|
|
|
|
consideredVersions += this->ConsideredConfigs[i].version;
|
2010-08-31 23:10:00 +04:00
|
|
|
sep = ";";
|
2010-08-29 19:07:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
this->Makefile->AddDefinition(consideredConfigsVar.c_str(),
|
|
|
|
consideredConfigFiles.c_str());
|
|
|
|
|
|
|
|
this->Makefile->AddDefinition(consideredVersionsVar.c_str(),
|
|
|
|
consideredVersions.c_str());
|
|
|
|
|
2003-01-22 01:15:22 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2009-10-07 22:37:30 +04:00
|
|
|
bool cmFindPackageCommand::FindConfig()
|
2003-01-22 01:15:22 +03:00
|
|
|
{
|
2008-01-17 17:02:31 +03:00
|
|
|
// Compute the set of search prefixes.
|
|
|
|
this->ComputePrefixes();
|
2004-02-29 02:59:19 +03:00
|
|
|
|
2008-01-17 17:02:31 +03:00
|
|
|
// Look for the project's configuration file.
|
|
|
|
bool found = false;
|
2004-04-19 18:36:42 +04:00
|
|
|
|
2008-01-17 17:02:31 +03:00
|
|
|
// Search for frameworks.
|
2009-09-11 16:18:15 +04:00
|
|
|
if(!found && (this->SearchFrameworkFirst || this->SearchFrameworkOnly))
|
2008-01-17 17:02:31 +03:00
|
|
|
{
|
|
|
|
found = this->FindFrameworkConfig();
|
2003-01-22 01:15:22 +03:00
|
|
|
}
|
|
|
|
|
2008-01-17 17:02:31 +03:00
|
|
|
// Search for apps.
|
2009-09-11 16:18:15 +04:00
|
|
|
if(!found && (this->SearchAppBundleFirst || this->SearchAppBundleOnly))
|
2008-01-17 17:02:31 +03:00
|
|
|
{
|
|
|
|
found = this->FindAppBundleConfig();
|
|
|
|
}
|
2004-04-26 18:49:34 +04:00
|
|
|
|
2008-01-17 17:02:31 +03:00
|
|
|
// Search prefixes.
|
|
|
|
if(!found && !(this->SearchFrameworkOnly || this->SearchAppBundleOnly))
|
2003-01-22 01:15:22 +03:00
|
|
|
{
|
2008-01-17 17:02:31 +03:00
|
|
|
found = this->FindPrefixedConfig();
|
2003-01-22 01:15:22 +03:00
|
|
|
}
|
2004-04-26 18:49:34 +04:00
|
|
|
|
2008-01-17 17:02:31 +03:00
|
|
|
// Search for frameworks.
|
|
|
|
if(!found && this->SearchFrameworkLast)
|
2003-01-22 01:15:22 +03:00
|
|
|
{
|
2008-01-17 17:02:31 +03:00
|
|
|
found = this->FindFrameworkConfig();
|
2003-01-22 01:15:22 +03:00
|
|
|
}
|
2004-04-26 18:49:34 +04:00
|
|
|
|
2008-01-17 17:02:31 +03:00
|
|
|
// Search for apps.
|
|
|
|
if(!found && this->SearchAppBundleLast)
|
|
|
|
{
|
|
|
|
found = this->FindAppBundleConfig();
|
|
|
|
}
|
2004-04-26 18:49:34 +04:00
|
|
|
|
2003-01-22 01:15:22 +03:00
|
|
|
// Store the entry in the cache so it can be set by the user.
|
2008-01-17 17:02:31 +03: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 += ".";
|
2009-10-07 22:37:30 +04:00
|
|
|
// We force the value since we do not get here if it was already set.
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Makefile->AddCacheDefinition(this->Variable.c_str(),
|
2008-01-17 17:02:31 +03:00
|
|
|
init.c_str(), help.c_str(),
|
2009-10-07 22:37:30 +04:00
|
|
|
cmCacheManager::PATH, true);
|
|
|
|
return found;
|
2003-01-22 01:15:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2008-01-17 17:02:31 +03:00
|
|
|
bool cmFindPackageCommand::FindPrefixedConfig()
|
2003-01-22 01:15:22 +03:00
|
|
|
{
|
2008-06-06 02:20:16 +04: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 19:00:41 +04:00
|
|
|
{
|
2008-01-17 17:02:31 +03:00
|
|
|
if(this->SearchPrefix(*pi))
|
2004-04-26 19:00:41 +04:00
|
|
|
{
|
2008-01-17 17:02:31 +03:00
|
|
|
return true;
|
2004-04-26 19:00:41 +04:00
|
|
|
}
|
|
|
|
}
|
2008-01-17 17:02:31 +03:00
|
|
|
return false;
|
|
|
|
}
|
2004-04-26 19:00:41 +04:00
|
|
|
|
2008-01-17 17:02:31 +03:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmFindPackageCommand::FindFrameworkConfig()
|
|
|
|
{
|
2008-06-06 02:20:16 +04:00
|
|
|
std::vector<std::string>& prefixes = this->SearchPaths;
|
|
|
|
for(std::vector<std::string>::const_iterator i = prefixes.begin();
|
|
|
|
i != prefixes.end(); ++i)
|
2003-01-22 01:15:22 +03:00
|
|
|
{
|
2008-01-17 17:02:31 +03:00
|
|
|
if(this->SearchFrameworkPrefix(*i))
|
2003-01-22 01:15:22 +03:00
|
|
|
{
|
2008-01-17 17:02:31 +03:00
|
|
|
return true;
|
2003-01-22 01:15:22 +03:00
|
|
|
}
|
|
|
|
}
|
2008-01-17 17:02:31 +03:00
|
|
|
return false;
|
|
|
|
}
|
2004-04-26 18:49:34 +04:00
|
|
|
|
2008-01-17 17:02:31 +03:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmFindPackageCommand::FindAppBundleConfig()
|
|
|
|
{
|
2008-06-06 02:20:16 +04:00
|
|
|
std::vector<std::string>& prefixes = this->SearchPaths;
|
|
|
|
for(std::vector<std::string>::const_iterator i = prefixes.begin();
|
|
|
|
i != prefixes.end(); ++i)
|
2003-01-22 01:15:22 +03:00
|
|
|
{
|
2008-01-17 17:02:31 +03:00
|
|
|
if(this->SearchAppBundlePrefix(*i))
|
2003-01-22 01:15:22 +03:00
|
|
|
{
|
2008-01-17 17:02:31 +03:00
|
|
|
return true;
|
2003-01-22 01:15:22 +03:00
|
|
|
}
|
|
|
|
}
|
2008-01-17 17:02:31 +03:00
|
|
|
return false;
|
2003-01-22 01:15:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2009-01-22 21:18:40 +03:00
|
|
|
bool cmFindPackageCommand::ReadListFile(const char* f, PolicyScopeRule psr)
|
2003-01-22 01:15:22 +03:00
|
|
|
{
|
2009-01-22 21:18:40 +03:00
|
|
|
if(this->Makefile->ReadListFile(this->Makefile->GetCurrentListFile(), f, 0,
|
|
|
|
!this->PolicyScope || psr == NoPolicyScope))
|
2003-01-22 01:15:22 +03:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
std::string e = "Error reading CMake code from \"";
|
|
|
|
e += f;
|
|
|
|
e += "\".";
|
|
|
|
this->SetError(e.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
2007-08-07 23:41:57 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2012-05-06 18:32:10 +04:00
|
|
|
void cmFindPackageCommand::AppendToFoundProperty(bool found)
|
2007-08-07 23:41:57 +04:00
|
|
|
{
|
2012-05-06 18:32:10 +04:00
|
|
|
std::vector<std::string> foundContents;
|
|
|
|
const char *foundProp =
|
|
|
|
this->Makefile->GetCMakeInstance()->GetProperty("PACKAGES_FOUND");
|
|
|
|
if (foundProp && *foundProp)
|
2007-08-07 23:41:57 +04:00
|
|
|
{
|
2012-05-06 18:32:10 +04:00
|
|
|
std::string tmp = foundProp;
|
2007-12-15 22:17:21 +03:00
|
|
|
|
2012-05-06 18:32:10 +04:00
|
|
|
cmSystemTools::ExpandListArgument(tmp, foundContents, false);
|
|
|
|
std::vector<std::string>::iterator nameIt = std::find(
|
|
|
|
foundContents.begin(), foundContents.end(), this->Name);
|
|
|
|
if(nameIt != foundContents.end())
|
2007-08-07 23:41:57 +04:00
|
|
|
{
|
2012-05-06 18:32:10 +04:00
|
|
|
foundContents.erase(nameIt);
|
2007-08-07 23:41:57 +04:00
|
|
|
}
|
2012-05-06 18:32:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> notFoundContents;
|
|
|
|
const char *notFoundProp =
|
|
|
|
this->Makefile->GetCMakeInstance()->GetProperty("PACKAGES_NOT_FOUND");
|
|
|
|
if (notFoundProp && *notFoundProp)
|
|
|
|
{
|
|
|
|
std::string tmp = notFoundProp;
|
|
|
|
|
|
|
|
cmSystemTools::ExpandListArgument(tmp, notFoundContents, false);
|
|
|
|
std::vector<std::string>::iterator nameIt = std::find(
|
|
|
|
notFoundContents.begin(), notFoundContents.end(), this->Name);
|
|
|
|
if(nameIt != notFoundContents.end())
|
2007-08-07 23:41:57 +04:00
|
|
|
{
|
2012-05-06 18:32:10 +04:00
|
|
|
notFoundContents.erase(nameIt);
|
2007-08-07 23:41:57 +04:00
|
|
|
}
|
|
|
|
}
|
2012-05-06 18:32:10 +04:00
|
|
|
|
|
|
|
if(found)
|
|
|
|
{
|
|
|
|
foundContents.push_back(this->Name);
|
|
|
|
}
|
2007-08-07 23:41:57 +04:00
|
|
|
else
|
|
|
|
{
|
2012-05-06 18:32:10 +04:00
|
|
|
notFoundContents.push_back(this->Name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string tmp;
|
|
|
|
const char* sep ="";
|
|
|
|
for(size_t i=0; i<foundContents.size(); i++)
|
|
|
|
{
|
|
|
|
tmp += sep;
|
|
|
|
tmp += foundContents[i];
|
|
|
|
sep = ";";
|
|
|
|
}
|
|
|
|
|
|
|
|
this->Makefile->GetCMakeInstance()->SetProperty("PACKAGES_FOUND",
|
|
|
|
tmp.c_str());
|
|
|
|
|
|
|
|
tmp = "";
|
|
|
|
sep = "";
|
|
|
|
for(size_t i=0; i<notFoundContents.size(); i++)
|
|
|
|
{
|
|
|
|
tmp += sep;
|
|
|
|
tmp += notFoundContents[i];
|
|
|
|
sep = ";";
|
2007-08-07 23:41:57 +04:00
|
|
|
}
|
2012-05-06 18:32:10 +04:00
|
|
|
this->Makefile->GetCMakeInstance()->SetProperty("PACKAGES_NOT_FOUND",
|
|
|
|
tmp.c_str());
|
|
|
|
}
|
2007-08-07 23:41:57 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2008-01-17 17:02:31 +03:00
|
|
|
void cmFindPackageCommand::AppendSuccessInformation()
|
2007-08-07 23:41:57 +04: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());
|
2012-05-06 18:32:10 +04:00
|
|
|
bool packageFound = ((cmSystemTools::IsOn(result))
|
|
|
|
|| (cmSystemTools::IsOn(upperResult)));
|
|
|
|
|
|
|
|
this->AppendToFoundProperty(packageFound);
|
2008-12-09 18:08:54 +03:00
|
|
|
|
2011-07-17 19:48:00 +04:00
|
|
|
// Record whether the find was quiet or not, so this can be used
|
|
|
|
// e.g. in FeatureSummary.cmake
|
|
|
|
std::string quietInfoPropName = "_CMAKE_";
|
|
|
|
quietInfoPropName += this->Name;
|
|
|
|
quietInfoPropName += "_QUIET";
|
|
|
|
this->Makefile->GetCMakeInstance()->SetProperty(quietInfoPropName.c_str(),
|
|
|
|
this->Quiet ? "TRUE" : "FALSE");
|
|
|
|
|
2010-08-24 23:24:54 +04:00
|
|
|
// set a global property to record the required version of this package
|
|
|
|
std::string versionInfoPropName = "_CMAKE_";
|
|
|
|
versionInfoPropName += this->Name;
|
|
|
|
versionInfoPropName += "_REQUIRED_VERSION";
|
|
|
|
std::string versionInfo;
|
|
|
|
if(!this->Version.empty())
|
|
|
|
{
|
|
|
|
versionInfo = this->VersionExact ? "==" : ">=";
|
|
|
|
versionInfo += " ";
|
|
|
|
versionInfo += this->Version;
|
|
|
|
}
|
|
|
|
this->Makefile->GetCMakeInstance()->SetProperty(versionInfoPropName.c_str(),
|
|
|
|
versionInfo.c_str());
|
2012-02-11 21:04:26 +04:00
|
|
|
if (this->Required)
|
|
|
|
{
|
|
|
|
std::string requiredInfoPropName = "_CMAKE_";
|
|
|
|
requiredInfoPropName += this->Name;
|
|
|
|
requiredInfoPropName += "_TYPE";
|
|
|
|
this->Makefile->GetCMakeInstance()->SetProperty(
|
|
|
|
requiredInfoPropName.c_str(), "REQUIRED");
|
|
|
|
}
|
|
|
|
|
2010-08-24 23:24:54 +04:00
|
|
|
|
2008-12-09 18:08:54 +03:00
|
|
|
// Restore original state of "_FIND_" variables we set.
|
|
|
|
this->RestoreFindDefinitions();
|
2007-08-07 23:41:57 +04:00
|
|
|
}
|
2008-01-17 17:02:31 +03:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2008-06-06 02:20:16 +04:00
|
|
|
void cmFindPackageCommand::ComputePrefixes()
|
2008-01-17 17:02:31 +03:00
|
|
|
{
|
2008-06-06 02:20:16 +04:00
|
|
|
this->AddPrefixesCMakeVariable();
|
2008-06-09 23:22:09 +04:00
|
|
|
this->AddPrefixesCMakeEnvironment();
|
2008-06-09 23:08:59 +04:00
|
|
|
this->AddPrefixesUserHints();
|
2008-06-06 02:20:16 +04:00
|
|
|
this->AddPrefixesSystemEnvironment();
|
2011-04-13 18:36:45 +04:00
|
|
|
this->AddPrefixesUserRegistry();
|
2008-06-06 02:20:16 +04:00
|
|
|
this->AddPrefixesBuilds();
|
|
|
|
this->AddPrefixesCMakeSystemVariable();
|
2011-04-13 21:14:41 +04:00
|
|
|
this->AddPrefixesSystemRegistry();
|
2008-06-09 23:08:59 +04:00
|
|
|
this->AddPrefixesUserGuess();
|
2011-09-23 22:27:25 +04:00
|
|
|
this->ComputeFinalPaths();
|
2008-01-17 17:02:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2008-06-06 02:20:16 +04:00
|
|
|
void cmFindPackageCommand::AddPrefixesCMakeEnvironment()
|
2008-01-17 17:02:31 +03: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-06 02:20:16 +04:00
|
|
|
this->AddPathInternal(env, EnvPath);
|
2008-01-17 17:02:31 +03:00
|
|
|
}
|
|
|
|
|
2008-06-06 02:20:16 +04:00
|
|
|
this->AddEnvPath("CMAKE_PREFIX_PATH");
|
|
|
|
this->AddEnvPath("CMAKE_FRAMEWORK_PATH");
|
|
|
|
this->AddEnvPath("CMAKE_APPBUNDLE_PATH");
|
2008-01-17 17:02:31 +03:00
|
|
|
}
|
2008-06-06 02:20:16 +04:00
|
|
|
}
|
2008-01-17 17:02:31 +03:00
|
|
|
|
2008-06-06 02:20:16 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmFindPackageCommand::AddPrefixesCMakeVariable()
|
|
|
|
{
|
2008-01-17 17:02:31 +03:00
|
|
|
if(!this->NoCMakePath && !this->NoDefaultPath)
|
|
|
|
{
|
2008-06-06 02:20:16 +04:00
|
|
|
this->AddCMakePath("CMAKE_PREFIX_PATH");
|
|
|
|
this->AddCMakePath("CMAKE_FRAMEWORK_PATH");
|
|
|
|
this->AddCMakePath("CMAKE_APPBUNDLE_PATH");
|
2008-01-17 17:02:31 +03:00
|
|
|
}
|
2008-06-06 02:20:16 +04:00
|
|
|
}
|
2008-01-17 17:02:31 +03:00
|
|
|
|
2008-06-06 02:20:16 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmFindPackageCommand::AddPrefixesSystemEnvironment()
|
|
|
|
{
|
2008-01-17 17:02:31 +03: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.
|
2009-09-11 16:18:15 +04:00
|
|
|
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-01-17 17:02:31 +03:00
|
|
|
{
|
2008-06-06 02:20:16 +04:00
|
|
|
this->AddPathInternal(cmSystemTools::GetFilenamePath(d), EnvPath);
|
2008-01-17 17:02:31 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-06-06 02:20:16 +04:00
|
|
|
this->AddPathInternal(d, EnvPath);
|
2008-01-17 17:02:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-06-06 02:20:16 +04:00
|
|
|
}
|
2008-01-17 17:02:31 +03:00
|
|
|
|
2009-09-01 22:04:27 +04:00
|
|
|
//----------------------------------------------------------------------------
|
2011-04-13 18:36:45 +04:00
|
|
|
void cmFindPackageCommand::AddPrefixesUserRegistry()
|
2009-09-01 22:04:27 +04:00
|
|
|
{
|
2011-04-13 18:36:45 +04:00
|
|
|
if(this->NoUserRegistry || this->NoDefaultPath)
|
2009-09-01 22:04:27 +04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
2011-04-13 21:17:42 +04:00
|
|
|
this->LoadPackageRegistryWinUser();
|
2009-09-28 17:45:34 +04:00
|
|
|
#elif defined(__HAIKU__)
|
|
|
|
BPath dir;
|
|
|
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, &dir) == B_OK)
|
|
|
|
{
|
|
|
|
dir.Append("cmake/packages");
|
|
|
|
dir.Append(this->Name.c_str());
|
|
|
|
this->LoadPackageRegistryDir(dir.Path());
|
|
|
|
}
|
2009-09-01 22:04:27 +04:00
|
|
|
#else
|
|
|
|
if(const char* home = cmSystemTools::GetEnv("HOME"))
|
|
|
|
{
|
|
|
|
std::string dir = home;
|
|
|
|
dir += "/.cmake/packages/";
|
|
|
|
dir += this->Name;
|
|
|
|
this->LoadPackageRegistryDir(dir);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-04-13 21:14:41 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmFindPackageCommand::AddPrefixesSystemRegistry()
|
|
|
|
{
|
|
|
|
if(this->NoSystemRegistry || this->NoDefaultPath)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
2011-04-13 21:17:42 +04:00
|
|
|
this->LoadPackageRegistryWinSystem();
|
2011-04-13 21:14:41 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-09-01 22:04:27 +04:00
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
|
|
# include <windows.h>
|
|
|
|
# undef GetCurrentDirectory
|
2011-04-13 21:17:42 +04:00
|
|
|
// http://msdn.microsoft.com/en-us/library/aa384253%28v=vs.85%29.aspx
|
|
|
|
# if !defined(KEY_WOW64_32KEY)
|
|
|
|
# define KEY_WOW64_32KEY 0x0200
|
|
|
|
# endif
|
|
|
|
# if !defined(KEY_WOW64_64KEY)
|
|
|
|
# define KEY_WOW64_64KEY 0x0100
|
|
|
|
# endif
|
2009-09-01 22:04:27 +04:00
|
|
|
//----------------------------------------------------------------------------
|
2011-04-13 21:17:42 +04:00
|
|
|
void cmFindPackageCommand::LoadPackageRegistryWinUser()
|
|
|
|
{
|
|
|
|
// HKEY_CURRENT_USER\\Software shares 32-bit and 64-bit views.
|
|
|
|
this->LoadPackageRegistryWin(true, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmFindPackageCommand::LoadPackageRegistryWinSystem()
|
|
|
|
{
|
|
|
|
// HKEY_LOCAL_MACHINE\\SOFTWARE has separate 32-bit and 64-bit views.
|
|
|
|
// Prefer the target platform view first.
|
|
|
|
if(this->Makefile->PlatformIs64Bit())
|
|
|
|
{
|
|
|
|
this->LoadPackageRegistryWin(false, KEY_WOW64_64KEY);
|
|
|
|
this->LoadPackageRegistryWin(false, KEY_WOW64_32KEY);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->LoadPackageRegistryWin(false, KEY_WOW64_32KEY);
|
|
|
|
this->LoadPackageRegistryWin(false, KEY_WOW64_64KEY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmFindPackageCommand::LoadPackageRegistryWin(bool user,
|
|
|
|
unsigned int view)
|
2009-09-01 22:04:27 +04:00
|
|
|
{
|
|
|
|
std::string key = "Software\\Kitware\\CMake\\Packages\\";
|
|
|
|
key += this->Name;
|
|
|
|
std::set<cmStdString> bad;
|
|
|
|
HKEY hKey;
|
2011-04-13 21:14:41 +04:00
|
|
|
if(RegOpenKeyEx(user? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, key.c_str(),
|
2011-04-13 21:17:42 +04:00
|
|
|
0, KEY_QUERY_VALUE|view, &hKey) == ERROR_SUCCESS)
|
2009-09-01 22:04:27 +04:00
|
|
|
{
|
|
|
|
DWORD valueType = REG_NONE;
|
|
|
|
char name[16384];
|
|
|
|
std::vector<char> data(512);
|
|
|
|
bool done = false;
|
|
|
|
DWORD index = 0;
|
|
|
|
while(!done)
|
|
|
|
{
|
|
|
|
DWORD nameSize = static_cast<DWORD>(sizeof(name));
|
|
|
|
DWORD dataSize = static_cast<DWORD>(data.size()-1);
|
|
|
|
switch(RegEnumValue(hKey, index, name, &nameSize,
|
|
|
|
0, &valueType, (BYTE*)&data[0], &dataSize))
|
|
|
|
{
|
|
|
|
case ERROR_SUCCESS:
|
|
|
|
++index;
|
|
|
|
if(valueType == REG_SZ)
|
|
|
|
{
|
|
|
|
data[dataSize] = 0;
|
|
|
|
cmsys_ios::stringstream ss(&data[0]);
|
2011-04-13 19:00:06 +04:00
|
|
|
if(!this->CheckPackageRegistryEntry(ss))
|
2009-09-01 22:04:27 +04:00
|
|
|
{
|
2011-04-13 19:00:06 +04:00
|
|
|
// The entry is invalid.
|
|
|
|
bad.insert(name);
|
2009-09-01 22:04:27 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ERROR_MORE_DATA:
|
|
|
|
data.resize(dataSize+1);
|
|
|
|
break;
|
|
|
|
case ERROR_NO_MORE_ITEMS: default: done = true; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove bad values if possible.
|
2011-04-13 21:14:41 +04:00
|
|
|
if(user && !bad.empty() &&
|
2009-09-01 22:04:27 +04:00
|
|
|
RegOpenKeyEx(HKEY_CURRENT_USER, key.c_str(),
|
2011-04-13 21:17:42 +04:00
|
|
|
0, KEY_SET_VALUE|view, &hKey) == ERROR_SUCCESS)
|
2009-09-01 22:04:27 +04:00
|
|
|
{
|
|
|
|
for(std::set<cmStdString>::const_iterator vi = bad.begin();
|
|
|
|
vi != bad.end(); ++vi)
|
|
|
|
{
|
|
|
|
RegDeleteValue(hKey, vi->c_str());
|
|
|
|
}
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
class cmFindPackageCommandHoldFile
|
|
|
|
{
|
|
|
|
const char* File;
|
|
|
|
public:
|
|
|
|
cmFindPackageCommandHoldFile(const char* f): File(f) {}
|
|
|
|
~cmFindPackageCommandHoldFile()
|
|
|
|
{ if(this->File) { cmSystemTools::RemoveFile(this->File); } }
|
|
|
|
void Release() { this->File = 0; }
|
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmFindPackageCommand::LoadPackageRegistryDir(std::string const& dir)
|
|
|
|
{
|
|
|
|
cmsys::Directory files;
|
|
|
|
if(!files.Load(dir.c_str()))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string fname;
|
|
|
|
for(unsigned long i=0; i < files.GetNumberOfFiles(); ++i)
|
|
|
|
{
|
|
|
|
fname = dir;
|
|
|
|
fname += "/";
|
|
|
|
fname += files.GetFile(i);
|
|
|
|
|
|
|
|
if(!cmSystemTools::FileIsDirectory(fname.c_str()))
|
|
|
|
{
|
|
|
|
// Hold this file hostage until it behaves.
|
|
|
|
cmFindPackageCommandHoldFile holdFile(fname.c_str());
|
|
|
|
|
|
|
|
// Load the file.
|
|
|
|
std::ifstream fin(fname.c_str(), std::ios::in | cmsys_ios_binary);
|
|
|
|
if(fin && this->CheckPackageRegistryEntry(fin))
|
|
|
|
{
|
|
|
|
// The file references an existing package, so release it.
|
|
|
|
holdFile.Release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Wipe out the directory if it is empty.
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmFindPackageCommand::CheckPackageRegistryEntry(std::istream& is)
|
|
|
|
{
|
|
|
|
// Parse the content of one package registry entry.
|
|
|
|
std::string fname;
|
|
|
|
if(cmSystemTools::GetLineFromStream(is, fname) &&
|
|
|
|
cmSystemTools::FileIsFullPath(fname.c_str()))
|
|
|
|
{
|
|
|
|
// The first line in the stream is the full path to a file or
|
|
|
|
// directory containing the package.
|
|
|
|
if(cmSystemTools::FileExists(fname.c_str()))
|
|
|
|
{
|
|
|
|
// The path exists. Look for the package here.
|
|
|
|
if(!cmSystemTools::FileIsDirectory(fname.c_str()))
|
|
|
|
{
|
|
|
|
fname = cmSystemTools::GetFilenamePath(fname);
|
|
|
|
}
|
|
|
|
this->AddPathInternal(fname, FullPath);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// The path does not exist. Assume the stream content is
|
|
|
|
// associated with an old package that no longer exists, and
|
|
|
|
// delete it to keep the package registry clean.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// The first line in the stream is not the full path to a file or
|
|
|
|
// directory. Assume the stream content was created by a future
|
|
|
|
// version of CMake that uses a different format, and leave it.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-06 02:20:16 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmFindPackageCommand::AddPrefixesBuilds()
|
|
|
|
{
|
2008-01-17 17:02:31 +03:00
|
|
|
if(!this->NoBuilds && !this->NoDefaultPath)
|
|
|
|
{
|
|
|
|
// It is likely that CMake will have recently built the project.
|
2009-08-05 17:56:02 +04:00
|
|
|
for(int i=0; i <= 10; ++i)
|
2008-01-17 17:02:31 +03:00
|
|
|
{
|
|
|
|
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-06 02:20:16 +04:00
|
|
|
this->AddPathInternal(f, FullPath);
|
2008-01-17 17:02:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-06-06 02:20:16 +04:00
|
|
|
}
|
2008-01-17 17:02:31 +03:00
|
|
|
|
2008-06-06 02:20:16 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmFindPackageCommand::AddPrefixesCMakeSystemVariable()
|
|
|
|
{
|
2008-01-17 17:02:31 +03:00
|
|
|
if(!this->NoCMakeSystemPath && !this->NoDefaultPath)
|
|
|
|
{
|
2008-06-06 02:20:16 +04:00
|
|
|
this->AddCMakePath("CMAKE_SYSTEM_PREFIX_PATH");
|
|
|
|
this->AddCMakePath("CMAKE_SYSTEM_FRAMEWORK_PATH");
|
|
|
|
this->AddCMakePath("CMAKE_SYSTEM_APPBUNDLE_PATH");
|
2008-01-17 17:02:31 +03:00
|
|
|
}
|
2008-06-06 02:20:16 +04:00
|
|
|
}
|
2008-01-17 17:02:31 +03:00
|
|
|
|
2008-06-06 02:20:16 +04:00
|
|
|
//----------------------------------------------------------------------------
|
2008-06-09 23:08:59 +04:00
|
|
|
void cmFindPackageCommand::AddPrefixesUserGuess()
|
2008-06-06 02:20:16 +04:00
|
|
|
{
|
2008-06-09 23:08:59 +04: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-06 02:20:16 +04:00
|
|
|
}
|
|
|
|
|
2008-01-17 17:02:31 +03: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 04:38:48 +03:00
|
|
|
// Remove duplicate slashes.
|
|
|
|
cmSystemTools::ConvertToUnixSlashes(this->FileFound);
|
2008-01-17 17:02:31 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmFindPackageCommand::FindConfigFile(std::string const& dir,
|
|
|
|
std::string& file)
|
|
|
|
{
|
2010-08-13 02:20:47 +04:00
|
|
|
if (this->IgnoredPaths.count(dir))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-01-17 17:02:31 +03:00
|
|
|
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 04:38:48 +03:00
|
|
|
if(cmSystemTools::FileExists(file.c_str(), true) &&
|
|
|
|
this->CheckVersion(file))
|
2008-01-17 17:02:31 +03:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-01-29 04:38:48 +03:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmFindPackageCommand::CheckVersion(std::string const& config_file)
|
|
|
|
{
|
2010-08-29 19:07:39 +04:00
|
|
|
bool result = false; // by default, assume the version is not ok.
|
|
|
|
bool haveResult = false;
|
|
|
|
std::string version = "unknown";
|
|
|
|
|
2008-01-29 04:38:48 +03:00
|
|
|
// 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";
|
2010-08-29 19:07:39 +04:00
|
|
|
if ((haveResult == false)
|
|
|
|
&& (cmSystemTools::FileExists(version_file.c_str(), true)))
|
2008-01-29 04:38:48 +03:00
|
|
|
{
|
2010-08-29 19:07:39 +04:00
|
|
|
result = this->CheckVersionFile(version_file, version);
|
|
|
|
haveResult = true;
|
2008-01-29 04:38:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Look for fooConfigVersion.cmake
|
|
|
|
version_file = version_file_base;
|
|
|
|
version_file += "Version.cmake";
|
2010-08-29 19:07:39 +04:00
|
|
|
if ((haveResult == false)
|
|
|
|
&& (cmSystemTools::FileExists(version_file.c_str(), true)))
|
2008-01-29 04:38:48 +03:00
|
|
|
{
|
2010-08-29 19:07:39 +04:00
|
|
|
result = this->CheckVersionFile(version_file, version);
|
|
|
|
haveResult = true;
|
2008-01-29 04:38:48 +03:00
|
|
|
}
|
|
|
|
|
2010-08-29 19:07:39 +04:00
|
|
|
|
2008-01-29 04:38:48 +03:00
|
|
|
// If no version was requested a versionless package is acceptable.
|
2010-08-29 19:07:39 +04:00
|
|
|
if ((haveResult == false) && (this->Version.empty()))
|
2008-01-29 04:38:48 +03:00
|
|
|
{
|
2010-08-29 19:07:39 +04:00
|
|
|
result = true;
|
|
|
|
haveResult = true;
|
2008-01-29 04:38:48 +03:00
|
|
|
}
|
|
|
|
|
2010-08-29 19:51:44 +04:00
|
|
|
ConfigFileInfo configFileInfo;
|
|
|
|
configFileInfo.filename = config_file;
|
|
|
|
configFileInfo.version = version;
|
|
|
|
this->ConsideredConfigs.push_back(configFileInfo);
|
2010-08-29 19:07:39 +04:00
|
|
|
|
|
|
|
return result;
|
2008-01-29 04:38:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2010-08-29 19:07:39 +04:00
|
|
|
bool cmFindPackageCommand::CheckVersionFile(std::string const& version_file,
|
|
|
|
std::string& result_version)
|
2008-01-29 04:38:48 +03:00
|
|
|
{
|
|
|
|
// The version file will be loaded in an isolated scope.
|
2009-01-22 18:56:58 +03:00
|
|
|
cmMakefile::ScopePushPop varScope(this->Makefile);
|
|
|
|
cmMakefile::PolicyPushPop polScope(this->Makefile);
|
|
|
|
static_cast<void>(varScope);
|
|
|
|
static_cast<void>(polScope);
|
2008-01-29 04:38:48 +03:00
|
|
|
|
|
|
|
// Clear the output variables.
|
|
|
|
this->Makefile->RemoveDefinition("PACKAGE_VERSION");
|
2008-10-03 18:41:15 +04:00
|
|
|
this->Makefile->RemoveDefinition("PACKAGE_VERSION_UNSUITABLE");
|
2008-01-29 04:38:48 +03:00
|
|
|
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 18:11:48 +04: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 04:38:48 +03:00
|
|
|
|
2009-01-22 21:18:40 +03:00
|
|
|
// Load the version check file. Pass NoPolicyScope because we do
|
|
|
|
// our own policy push/pop independent of CMP0011.
|
2008-10-03 18:41:15 +04:00
|
|
|
bool suitable = false;
|
2009-01-22 21:18:40 +03:00
|
|
|
if(this->ReadListFile(version_file.c_str(), NoPolicyScope))
|
2008-01-29 04:38:48 +03:00
|
|
|
{
|
|
|
|
// Check the output variables.
|
2008-10-03 18:41:15 +04:00
|
|
|
bool okay = this->Makefile->IsOn("PACKAGE_VERSION_EXACT");
|
|
|
|
bool unsuitable = this->Makefile->IsOn("PACKAGE_VERSION_UNSUITABLE");
|
|
|
|
if(!okay && !this->VersionExact)
|
2008-01-29 04:38:48 +03:00
|
|
|
{
|
2008-10-03 18:41:15 +04:00
|
|
|
okay = this->Makefile->IsOn("PACKAGE_VERSION_COMPATIBLE");
|
2008-01-29 04:38:48 +03:00
|
|
|
}
|
2008-10-03 18:41:15 +04:00
|
|
|
|
|
|
|
// The package is suitable if the version is okay and not
|
|
|
|
// explicitly unsuitable.
|
|
|
|
suitable = !unsuitable && (okay || this->Version.empty());
|
|
|
|
if(suitable)
|
2008-01-29 04:38:48 +03:00
|
|
|
{
|
|
|
|
// 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 18:11:48 +04:00
|
|
|
unsigned int parsed_tweak;
|
2008-01-29 04:38:48 +03:00
|
|
|
this->VersionFoundCount =
|
2008-09-10 18:11:48 +04:00
|
|
|
sscanf(this->VersionFound.c_str(), "%u.%u.%u.%u",
|
|
|
|
&parsed_major, &parsed_minor,
|
|
|
|
&parsed_patch, &parsed_tweak);
|
2008-01-29 04:38:48 +03:00
|
|
|
switch(this->VersionFoundCount)
|
|
|
|
{
|
2008-09-10 18:11:48 +04:00
|
|
|
case 4: this->VersionFoundTweak = parsed_tweak; // no break!
|
2008-01-29 04:38:48 +03: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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-29 19:07:39 +04:00
|
|
|
result_version = this->Makefile->GetSafeDefinition("PACKAGE_VERSION");
|
|
|
|
if (result_version.empty())
|
|
|
|
{
|
|
|
|
result_version = "unknown";
|
|
|
|
}
|
|
|
|
|
2008-10-03 18:41:15 +04:00
|
|
|
// Succeed if the version is suitable.
|
|
|
|
return suitable;
|
2008-01-29 04:38:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
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 18:11:48 +04:00
|
|
|
// Store the version components.
|
2008-01-29 04:38:48 +03:00
|
|
|
char buf[64];
|
2008-09-10 18:11:48 +04: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 04:38:48 +03:00
|
|
|
}
|
|
|
|
|
2008-01-17 17:02:31 +03:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
#include <cmsys/Glob.hxx>
|
|
|
|
#include <cmsys/String.h>
|
|
|
|
#include <cmsys/auto_ptr.hxx>
|
|
|
|
|
|
|
|
class cmFileList;
|
|
|
|
class cmFileListGeneratorBase
|
|
|
|
{
|
2008-01-17 18:32:27 +03:00
|
|
|
public:
|
|
|
|
virtual ~cmFileListGeneratorBase() {}
|
2008-01-17 17:02:31 +03: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 18:32:27 +03:00
|
|
|
virtual ~cmFileList() {}
|
2008-01-17 17:02:31 +03: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-13 03:01:04 +04:00
|
|
|
cmFileListGeneratorEnumerate(std::vector<std::string> const& v):
|
|
|
|
cmFileListGeneratorBase(), Vector(v) {}
|
2008-01-17 17:02:31 +03:00
|
|
|
cmFileListGeneratorEnumerate(cmFileListGeneratorEnumerate const& r):
|
|
|
|
cmFileListGeneratorBase(), Vector(r.Vector) {}
|
|
|
|
private:
|
2008-08-13 03:01:04 +04:00
|
|
|
std::vector<std::string> const& Vector;
|
2008-01-17 17:02:31 +03: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 16:19:37 +03:00
|
|
|
cmFileListGeneratorCaseInsensitive(
|
|
|
|
cmFileListGeneratorCaseInsensitive const& r):
|
2008-01-17 17:02:31 +03: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-12-17 17:24:05 +03:00
|
|
|
// PREFIX/(Foo|foo|FOO).*/
|
|
|
|
{
|
|
|
|
cmFindPackageFileList lister(this);
|
|
|
|
lister
|
|
|
|
/ cmFileListGeneratorFixed(prefix)
|
|
|
|
/ cmFileListGeneratorProject(this->Names);
|
|
|
|
if(lister.Search())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// PREFIX/(Foo|foo|FOO).*/(cmake|CMake)/
|
|
|
|
{
|
|
|
|
cmFindPackageFileList lister(this);
|
|
|
|
lister
|
|
|
|
/ cmFileListGeneratorFixed(prefix)
|
|
|
|
/ cmFileListGeneratorProject(this->Names)
|
|
|
|
/ cmFileListGeneratorCaseInsensitive("cmake");
|
|
|
|
if(lister.Search())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-13 03:01:04 +04:00
|
|
|
// Construct list of common install locations (lib and share).
|
|
|
|
std::vector<std::string> common;
|
2011-06-08 16:46:31 +04:00
|
|
|
if(!this->LibraryArchitecture.empty())
|
|
|
|
{
|
|
|
|
common.push_back("lib/"+this->LibraryArchitecture);
|
|
|
|
}
|
2008-08-13 03:01:04 +04:00
|
|
|
if(this->UseLib64Paths)
|
|
|
|
{
|
|
|
|
common.push_back("lib64");
|
|
|
|
}
|
|
|
|
common.push_back("lib");
|
|
|
|
common.push_back("share");
|
|
|
|
|
2011-06-08 16:46:31 +04:00
|
|
|
// PREFIX/(lib/ARCH|lib|share)/cmake/(Foo|foo|FOO).*/
|
2008-12-09 22:07:19 +03:00
|
|
|
{
|
|
|
|
cmFindPackageFileList lister(this);
|
|
|
|
lister
|
|
|
|
/ cmFileListGeneratorFixed(prefix)
|
|
|
|
/ cmFileListGeneratorEnumerate(common)
|
|
|
|
/ cmFileListGeneratorFixed("cmake")
|
|
|
|
/ cmFileListGeneratorProject(this->Names);
|
|
|
|
if(lister.Search())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-08 16:46:31 +04:00
|
|
|
// PREFIX/(lib/ARCH|lib|share)/(Foo|foo|FOO).*/
|
2008-01-17 17:02:31 +03:00
|
|
|
{
|
|
|
|
cmFindPackageFileList lister(this);
|
|
|
|
lister
|
|
|
|
/ cmFileListGeneratorFixed(prefix)
|
2008-08-13 03:01:04 +04:00
|
|
|
/ cmFileListGeneratorEnumerate(common)
|
2008-01-17 17:02:31 +03:00
|
|
|
/ cmFileListGeneratorProject(this->Names);
|
|
|
|
if(lister.Search())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-08 16:46:31 +04:00
|
|
|
// PREFIX/(lib/ARCH|lib|share)/(Foo|foo|FOO).*/(cmake|CMake)/
|
2008-01-17 17:02:31 +03:00
|
|
|
{
|
|
|
|
cmFindPackageFileList lister(this);
|
|
|
|
lister
|
|
|
|
/ cmFileListGeneratorFixed(prefix)
|
2008-08-13 03:01:04 +04:00
|
|
|
/ cmFileListGeneratorEnumerate(common)
|
2008-01-17 17:02:31 +03: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: Debug cmsys::Glob double slash problem.
|