1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmFindPackageCommand.cxx,v $
6 Date: $Date: 2008-01-29 14:57:39 $
7 Version: $Revision: 1.36 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmFindPackageCommand.h"
18 #include <cmsys/RegularExpression.hxx>
20 #ifdef CMAKE_BUILD_WITH_CMAKE
21 #include "cmVariableWatch.h"
24 void cmFindPackageNeedBackwardsCompatibility(const std::string
& variable
,
25 int access_type
, void*, const char* newValue
,
29 #ifdef CMAKE_BUILD_WITH_CMAKE
30 if(access_type
== cmVariableWatch::UNKNOWN_VARIABLE_READ_ACCESS
)
32 std::string message
= "An attempt was made to access a variable: ";
35 " that has not been defined. This variable is created by the "
36 "FIND_PACKAGE command. CMake version 1.6 always converted the "
37 "variable name to upper-case, but this behavior is no longer the "
38 "case. To fix this you might need to set the cache value of "
39 "CMAKE_BACKWARDS_COMPATIBILITY to 1.6 or less. If you are writing a "
40 "CMake listfile, you should change the variable reference to use "
41 "the case of the argument to FIND_PACKAGE.";
42 cmSystemTools::Error(message
.c_str());
50 //----------------------------------------------------------------------------
51 cmFindPackageCommand::cmFindPackageCommand()
53 cmSystemTools::ReplaceString(this->GenericDocumentationRootPath
,
54 "CMAKE_FIND_ROOT_PATH_MODE_XXX",
55 "CMAKE_FIND_ROOT_PATH_MODE_PACKAGE");
56 cmSystemTools::ReplaceString(this->GenericDocumentationPathsOrder
,
57 "FIND_ARGS_XXX", "<package>");
58 cmSystemTools::ReplaceString(this->GenericDocumentationPathsOrder
,
59 "FIND_XXX", "find_package");
60 this->CMakePathName
= "PACKAGE";
62 this->Required
= false;
63 this->NoBuilds
= false;
64 this->NoModule
= false;
65 this->DebugMode
= false;
66 this->VersionMajor
= 0;
67 this->VersionMinor
= 0;
68 this->VersionPatch
= 0;
69 this->VersionCount
= 0;
70 this->VersionExact
= false;
71 this->VersionFoundMajor
= 0;
72 this->VersionFoundMinor
= 0;
73 this->VersionFoundPatch
= 0;
74 this->VersionFoundCount
= 0;
75 this->CommandDocumentation
=
76 " find_package(<package> [major[.minor[.patch]]] [EXACT] [QUIET]\n"
77 " [[REQUIRED|COMPONENTS] [components...]])\n"
78 "Finds and loads settings from an external project. "
79 "<package>_FOUND will be set to indicate whether the package was found. "
80 "When the package is found package-specific information is provided "
81 "through variables documented by the package itself. "
82 "The QUIET option disables messages if the package cannot be found. "
83 "The REQUIRED option stops processing with an error message if the "
84 "package cannot be found. "
85 "A package-specific list of components may be listed after the "
86 "REQUIRED option or after the COMPONENTS option if no REQUIRED "
88 "The \"[major[.minor[.patch]]]\" version argument specifies a desired "
89 "version with which the package found should be compatible. "
90 "The EXACT option requests that the version be matched exactly. "
91 "Version support is currently provided only on a package-by-package "
92 "basis (details below).\n"
93 "User code should generally look for packages using the above simple "
94 "signature. The remainder of this command documentation specifies the "
95 "full command signature and details of the search process. Project "
96 "maintainers wishing to provide a package to be found by this command "
97 "are encouraged to read on.\n"
98 "The command has two modes by which it searches for packages: "
99 "\"Module\" mode and \"Config\" mode. "
100 "Module mode is available when the command is invoked with the above "
101 "reduced signature. "
102 "CMake searches for a file called \"Find<package>.cmake\" in "
103 "the CMAKE_MODULE_PATH followed by the CMake installation. "
104 "If the file is found, it is read and processed by CMake. "
105 "It is responsible for finding the package, checking the version, "
106 "and producing any needed messages. "
107 "Many find-modules provide limited or no support for versioning; "
108 "check the module documentation. "
109 "If no module is found the command proceeds to Config mode.\n"
110 "The complete Config mode command signature is:\n"
111 " find_package(<package> [major[.minor[.patch]]] [EXACT] [QUIET]\n"
112 " [[REQUIRED|COMPONENTS] [components...]] [NO_MODULE]\n"
113 " [NAMES name1 [name2 ...]]\n"
114 " [CONFIGS config1 [config2 ...]]\n"
115 " [PATHS path1 [path2 ... ]]\n"
116 " [PATH_SUFFIXES suffix1 [suffix2 ...]]\n"
117 " [NO_DEFAULT_PATH]\n"
118 " [NO_CMAKE_ENVIRONMENT_PATH]\n"
120 " [NO_SYSTEM_ENVIRONMENT_PATH]\n"
121 " [NO_CMAKE_BUILDS_PATH]\n"
122 " [NO_CMAKE_SYSTEM_PATH]\n"
123 " [CMAKE_FIND_ROOT_PATH_BOTH |\n"
124 " ONLY_CMAKE_FIND_ROOT_PATH |\n"
125 " NO_CMAKE_FIND_ROOT_PATH])\n"
126 "The NO_MODULE option may be used to skip Module mode explicitly. "
127 "It is also implied by use of options not specified in the reduced "
130 "Config mode attempts to locate a configuration file provided by the "
131 "package to be found. A cache entry called <package>_DIR is created to "
132 "hold the directory containing the file. "
133 "By default the command searches for a package with the name <package>. "
134 "If the NAMES option is given the names following it are used instead "
136 "The command searches for a file called \"<name>Config.cmake\" or "
137 "\"<lower-case-name>-config.cmake\" for each name specified. "
138 "A replacement set of possible configuration file names may be given "
139 "using the CONFIGS option. "
140 "The search procedure is specified below. Once found, the configuration "
141 "file is read and processed by CMake. Since the file is provided by the "
142 "package it already knows the location of package contents. "
143 "The full path to the configuration file is stored in the cmake "
144 "variable <package>_CONFIG."
146 "If the package configuration file cannot be found CMake "
147 "will generate an error describing the problem unless the QUIET "
148 "argument is specified. If REQUIRED is specified and the package "
149 "is not found a fatal error is generated and the configure step stops "
150 "executing. If <package>_DIR has been set to a directory not containing "
151 "a configuration file a fatal error is always generated because user "
152 "intervention is required."
154 "When the \"[major[.minor[.patch]]]\" version argument is specified "
155 "Config mode will only find a version of the package that claims "
156 "compatibility with the requested version. "
157 "If the EXACT option is given only a version of the package claiming "
158 "an exact match of the requested version may be found. "
159 "CMake does not establish any convention for the meaning of version "
161 "Package version numbers are checked by \"version\" files provided by "
162 "the packages themselves. "
163 "For a candidate package confguration file \"<config-file>.cmake\" the "
164 "corresponding version file is located next to it and named either "
165 "\"<config-file>-version.cmake\" or \"<config-file>Version.cmake\". "
166 "If no such version file is available then the configuration file "
167 "is assumed to not be compatible with any requested version. "
168 "When a version file is found it is loaded to check the requested "
170 "The version file is loaded in a nested scope in which the following "
171 "variables have been defined:\n"
172 " PACKAGE_FIND_NAME = the <package> name\n"
173 " PACKAGE_FIND_VERSION = full requested version string\n"
174 " PACKAGE_FIND_VERSION_MAJOR = requested major version, if any\n"
175 " PACKAGE_FIND_VERSION_MINOR = requested minor version, if any\n"
176 " PACKAGE_FIND_VERSION_PATCH = requested patch version, if any\n"
177 "The version file checks whether it satisfies the requested version "
178 "and sets these variables:\n"
179 " PACKAGE_VERSION = package version (major[.minor[.patch]])\n"
180 " PACKAGE_VERSION_EXACT = true if version is exact match\n"
181 " PACKAGE_VERSION_COMPATIBLE = true if version is compatible\n"
182 "These variables are checked by the find_package command to determine "
183 "whether the configuration file provides an acceptable version. "
184 "They are not available after the find_package call returns. "
185 "If the version is acceptable the following variables are set:\n"
186 " <package>_VERSION = package version (major[.minor[.patch]])\n"
187 " <package>_VERSION_MAJOR = major from major[.minor[.patch]], if any\n"
188 " <package>_VERSION_MINOR = minor from major[.minor[.patch]], if any\n"
189 " <package>_VERSION_PATCH = patch from major[.minor[.patch]], if any\n"
190 "and the corresponding package configuration file is loaded. "
191 "When multiple package configuration files are available whose version "
192 "files claim compatibility with the version requested it is unspecified "
193 "which one is chosen. "
194 "No attempt is made to choose a highest or closest version number."
196 "Config mode provides an elaborate interface and search procedure. "
197 "Much of the interface is provided for completeness and for use "
198 "internally by find-modules loaded by Module mode. "
199 "Most user code should simply call\n"
200 " find_package(<package> [major[.minor]] [EXACT] [REQUIRED|QUIET])\n"
201 "in order to find a package. Package maintainers providing CMake "
202 "package configuration files are encouraged to name and install "
203 "them such that the procedure outlined below will find them "
204 "without requiring use of additional options."
206 "CMake constructs a set of possible installation prefixes for the "
207 "package. Under each prefix several directories are searched for a "
208 "configuration file. The tables below show the directories searched. "
209 "Each entry is meant for installation trees following Windows (W), "
210 "UNIX (U), or Apple (A) conventions.\n"
212 " <prefix>/(cmake|CMake)/ (W)\n"
213 " <prefix>/(share|lib)/<name>*/ (U)\n"
214 " <prefix>/(share|lib)/<name>*/(cmake|CMake)/ (U)\n"
215 "On systems supporting OS X Frameworks and Application Bundles "
216 "the following directories are searched for frameworks or bundles "
217 "containing a configuration file:\n"
218 " <prefix>/<name>.framework/Resources/ (A)\n"
219 " <prefix>/<name>.framework/Resources/CMake/ (A)\n"
220 " <prefix>/<name>.framework/Versions/*/Resources/ (A)\n"
221 " <prefix>/<name>.framework/Versions/*/Resources/CMake/ (A)\n"
222 " <prefix>/<name>.app/Contents/Resources/ (A)\n"
223 " <prefix>/<name>.app/Contents/Resources/CMake/ (A)\n"
224 "In all cases the <name> is treated as case-insensitive and corresponds "
225 "to any of the names specified (<package> or names given by NAMES). "
226 "If PATH_SUFFIXES is specified the suffixes are appended to each "
227 "(W) or (U) directory entry one-by-one.\n"
228 "This set of directories is intended to work in cooperation with "
229 "projects that provide configuration files in their installation trees. "
230 "Directories above marked with (W) are intended for installations on "
231 "Windows where the prefix may point at the top of an application's "
232 "installation directory. Those marked with (U) are intended for "
233 "installations on UNIX platforms where the prefix is shared by "
234 "multiple packages. This is merely a convention, so all (W) and (U) "
235 "directories are still searched on all platforms. "
236 "Directories marked with (A) are intended for installations on "
237 "Apple platforms. The cmake variables CMAKE_FIND_FRAMEWORK and "
238 "CMAKE_FIND_APPBUNDLE determine the order of preference "
239 "as specified below.\n"
240 "The set of installation prefixes is constructed using the following "
241 "steps. If NO_DEFAULT_PATH is specified steps 1-5 are skipped.\n"
242 "1. Search cmake specific environment variables. This "
243 "can be skipped if NO_CMAKE_ENVIRONMENT_PATH is passed.\n"
244 " CMAKE_PREFIX_PATH\n"
245 " CMAKE_FRAMEWORK_PATH\n"
246 " CMAKE_APPBUNDLE_PATH\n"
247 "2. Search cmake variables with the same names as the cmake specific "
248 "environment variables. These are intended to be used on the command "
249 "line with a -DVAR=value. This can be skipped if NO_CMAKE_PATH "
251 " CMAKE_PREFIX_PATH\n"
252 " CMAKE_FRAMEWORK_PATH\n"
253 " CMAKE_APPBUNDLE_PATH\n"
254 "3. Search the standard system environment variables. "
255 "This can be skipped if NO_SYSTEM_ENVIRONMENT_PATH is passed. "
256 "Path entries ending in \"/bin\" or \"/sbin\" are automatically "
257 "converted to their parent directories.\n"
259 "4. Search project build trees recently configured in a CMake GUI. "
260 "This can be skipped if NO_CMAKE_BUILDS_PATH is passed. "
261 "It is intended for the case when a user is building multiple "
262 "dependent projects one after another.\n"
263 "5. Search cmake variables defined in the Platform files "
264 "for the current system. This can be skipped if NO_CMAKE_SYSTEM_PATH "
266 " CMAKE_SYSTEM_PREFIX_PATH\n"
267 " CMAKE_SYSTEM_FRAMEWORK_PATH\n"
268 " CMAKE_SYSTEM_APPBUNDLE_PATH\n"
269 "6. Search paths specified by the PATHS option.\n"
271 this->CommandDocumentation
+= this->GenericDocumentationMacPolicy
;
272 this->CommandDocumentation
+= this->GenericDocumentationRootPath
;
273 this->CommandDocumentation
+= this->GenericDocumentationPathsOrder
;
276 //----------------------------------------------------------------------------
277 const char* cmFindPackageCommand::GetFullDocumentation()
279 return this->CommandDocumentation
.c_str();
282 //----------------------------------------------------------------------------
283 bool cmFindPackageCommand
284 ::InitialPass(std::vector
<std::string
> const& args
, cmExecutionStatus
&)
288 this->SetError("called with incorrect number of arguments");
292 // Check for debug mode.
293 this->DebugMode
= this->Makefile
->IsOn("CMAKE_FIND_DEBUG_MODE");
295 // Find the current root path mode.
296 this->SelectDefaultRootPathMode();
298 // Find the current bundle/framework search policy.
299 this->SelectDefaultMacMode();
302 this->Name
= args
[0];
303 std::string components
;
304 const char* components_sep
= "";
306 // Check ancient compatibility.
307 this->Compatibility_1_6
=
308 this->Makefile
->GetLocalGenerator()
309 ->NeedBackwardsCompatibility(1, 6);
311 // Always search directly in a generated path.
312 this->SearchPathSuffixes
.push_back("");
314 // Parse the arguments.
315 enum Doing
{ DoingNone
, DoingComponents
, DoingNames
, DoingPaths
,
316 DoingPathSuffixes
, DoingConfigs
};
317 Doing doing
= DoingNone
;
318 cmsys::RegularExpression
version("^[0-9.]+$");
319 bool haveVersion
= false;
320 for(unsigned int i
=1; i
< args
.size(); ++i
)
322 if(args
[i
] == "QUIET")
327 else if(args
[i
] == "EXACT")
329 this->VersionExact
= true;
330 this->Compatibility_1_6
= false;
333 else if(args
[i
] == "NO_MODULE")
335 this->NoModule
= true;
338 else if(args
[i
] == "REQUIRED")
340 this->Required
= true;
341 doing
= DoingComponents
;
343 else if(args
[i
] == "COMPONENTS")
345 this->Compatibility_1_6
= false;
346 doing
= DoingComponents
;
348 else if(args
[i
] == "NAMES")
350 this->NoModule
= true;
351 this->Compatibility_1_6
= false;
354 else if(args
[i
] == "PATHS")
356 this->NoModule
= true;
357 this->Compatibility_1_6
= false;
360 else if(args
[i
] == "PATH_SUFFIXES")
362 this->NoModule
= true;
363 this->Compatibility_1_6
= false;
364 doing
= DoingPathSuffixes
;
366 else if(args
[i
] == "CONFIGS")
368 this->NoModule
= true;
369 this->Compatibility_1_6
= false;
370 doing
= DoingConfigs
;
372 else if(args
[i
] == "NO_CMAKE_BUILDS_PATH")
374 this->NoBuilds
= true;
375 this->NoModule
= true;
376 this->Compatibility_1_6
= false;
379 else if(this->CheckCommonArgument(args
[i
]))
381 this->NoModule
= true;
382 this->Compatibility_1_6
= false;
385 else if(doing
== DoingComponents
)
387 // Set a variable telling the find script this component
389 std::string req_var
= Name
+ "_FIND_REQUIRED_" + args
[i
];
390 this->Makefile
->AddDefinition(req_var
.c_str(), "1");
392 // Append to the list of required components.
393 components
+= components_sep
;
394 components
+= args
[i
];
395 components_sep
= ";";
397 else if(doing
== DoingNames
)
399 this->Names
.push_back(args
[i
]);
401 else if(doing
== DoingPaths
)
403 this->AddUserPath(args
[i
]);
405 else if(doing
== DoingPathSuffixes
)
407 this->AddPathSuffix(args
[i
]);
409 else if(doing
== DoingConfigs
)
411 if(args
[i
].find_first_of(":/\\") != args
[i
].npos
||
412 cmSystemTools::GetFilenameLastExtension(args
[i
]) != ".cmake")
415 e
<< "given CONFIGS option followed by invalid file name \""
416 << args
[i
] << "\". The names given must be file names without "
417 << "a path and with a \".cmake\" extension.";
420 this->Configs
.push_back(args
[i
]);
422 else if(!haveVersion
&& version
.find(args
[i
].c_str()))
425 this->Version
= args
[i
];
430 e
<< "called with invalid argument \"" << args
[i
].c_str() << "\"";
431 this->SetError(e
.str().c_str());
436 if(!this->Version
.empty())
438 // Try to parse the version number and store the results that were
439 // successfully parsed.
440 unsigned int parsed_major
;
441 unsigned int parsed_minor
;
442 unsigned int parsed_patch
;
443 this->VersionCount
= sscanf(this->Version
.c_str(), "%u.%u.%u",
444 &parsed_major
, &parsed_minor
, &parsed_patch
);
445 switch(this->VersionCount
)
447 case 3: this->VersionPatch
= parsed_patch
; // no break!
448 case 2: this->VersionMinor
= parsed_minor
; // no break!
449 case 1: this->VersionMajor
= parsed_major
; // no break!
454 // Store the list of components.
455 std::string components_var
= Name
+ "_FIND_COMPONENTS";
456 this->Makefile
->AddDefinition(components_var
.c_str(), components
.c_str());
458 // See if there is a Find<package>.cmake module.
461 bool foundModule
= false;
462 if(!this->FindModule(foundModule
))
464 this->AppendSuccessInformation();
469 this->AppendSuccessInformation();
474 // No find module. Assume the project has a CMake config file. Use
475 // a <package>_DIR cache variable to locate it.
476 this->Variable
= this->Name
;
477 this->Variable
+= "_DIR";
479 // Add the default name.
480 if(this->Names
.empty())
482 this->Names
.push_back(this->Name
);
485 // Add the default configs.
486 if(this->Configs
.empty())
488 for(std::vector
<std::string
>::const_iterator ni
= this->Names
.begin();
489 ni
!= this->Names
.end(); ++ni
)
491 std::string config
= *ni
;
492 config
+= "Config.cmake";
493 this->Configs
.push_back(config
);
495 config
= cmSystemTools::LowerCase(*ni
);
496 config
+= "-config.cmake";
497 this->Configs
.push_back(config
);
501 // Find and load the package.
502 bool result
= this->HandlePackageMode();
503 this->AppendSuccessInformation();
507 //----------------------------------------------------------------------------
508 bool cmFindPackageCommand::FindModule(bool& found
)
510 std::string module
= "Find";
511 module
+= this->Name
;
513 std::string mfile
= this->Makefile
->GetModulesFile(module
.c_str());
518 // Tell the module that is about to be read that it should find
520 std::string quietly
= this->Name
;
521 quietly
+= "_FIND_QUIETLY";
522 this->Makefile
->AddDefinition(quietly
.c_str(), "1");
527 // Tell the module that is about to be read that it should report
528 // a fatal error if the package is not found.
529 std::string req
= this->Name
;
530 req
+= "_FIND_REQUIRED";
531 this->Makefile
->AddDefinition(req
.c_str(), "1");
534 if(!this->Version
.empty())
536 // Tell the module that is about to be read what version of the
537 // package has been requested.
538 std::string ver
= this->Name
;
539 ver
+= "_FIND_VERSION";
540 this->Makefile
->AddDefinition(ver
.c_str(), this->Version
.c_str());
542 switch(this->VersionCount
)
546 sprintf(buf
, "%u", this->VersionPatch
);
547 this->Makefile
->AddDefinition((ver
+"_PATCH").c_str(), buf
);
551 sprintf(buf
, "%u", this->VersionMinor
);
552 this->Makefile
->AddDefinition((ver
+"_MINOR").c_str(), buf
);
556 sprintf(buf
, "%u", this->VersionMajor
);
557 this->Makefile
->AddDefinition((ver
+"_MAJOR").c_str(), buf
);
562 // Tell the module whether an exact version has been requested.
563 std::string exact
= this->Name
;
564 exact
+= "_FIND_VERSION_EXACT";
565 this->Makefile
->AddDefinition(exact
.c_str(),
566 this->VersionExact
? "1":"0");
569 // Load the module we found.
571 return this->ReadListFile(mfile
.c_str());
576 //----------------------------------------------------------------------------
577 bool cmFindPackageCommand::HandlePackageMode()
579 // Support old capitalization behavior.
580 std::string upperDir
= cmSystemTools::UpperCase(this->Name
);
581 std::string upperFound
= cmSystemTools::UpperCase(this->Name
);
583 upperFound
+= "_FOUND";
584 if(upperDir
== this->Variable
)
586 this->Compatibility_1_6
= false;
589 // Try to find the config file.
590 const char* def
= this->Makefile
->GetDefinition(this->Variable
.c_str());
591 if(this->Compatibility_1_6
&& cmSystemTools::IsOff(def
))
593 // Use the setting of the old name of the variable to provide the
595 const char* oldDef
= this->Makefile
->GetDefinition(upperDir
.c_str());
596 if(!cmSystemTools::IsOff(oldDef
))
598 this->Makefile
->AddDefinition(this->Variable
.c_str(), oldDef
);
599 def
= this->Makefile
->GetDefinition(this->Variable
.c_str());
603 // Search for the config file if it is not already found.
604 if(cmSystemTools::IsOff(def
))
607 def
= this->Makefile
->GetDefinition(this->Variable
.c_str());
610 // If the config file was found, load it.
614 if(!cmSystemTools::IsOff(def
))
616 // Get the directory from the variable value.
617 std::string dir
= def
;
618 cmSystemTools::ConvertToUnixSlashes(dir
);
620 // Treat relative paths with respect to the current source dir.
621 if(!cmSystemTools::FileIsFullPath(dir
.c_str()))
624 dir
= this->Makefile
->GetCurrentDirectory() + dir
;
627 // Find the configuration file.
628 if(this->FindConfigFileToLoad(dir
, file
))
630 // Set the version variables before loading the config file.
631 // It may override them.
632 this->StoreVersionFound();
634 // Parse the configuration file.
635 if(this->ReadListFile(file
.c_str()))
637 // The package has been found.
642 // The configuration file is invalid.
648 // The variable setting is wrong.
650 e
<< "cannot find package " << this->Name
<< " because "
651 << this->Variable
<< " is set to \"" << def
<< "\" "
652 << "which is not a directory containing a package configuration "
653 << "file (or it is not for the requested version). "
654 << "Please set the cache entry " << this->Variable
<< " "
655 << "to the correct directory, or delete it to ask CMake "
657 this->SetError(e
.str().c_str());
661 else if(!this->Quiet
|| this->Required
)
663 // The variable is not set.
665 e
<< "could not find ";
668 e
<< "module Find" << this->Name
<< ".cmake or ";
670 e
<< "a configuration file for package " << this->Name
<< ".\n";
673 e
<< "Adjust CMAKE_MODULE_PATH to find Find"
674 << this->Name
<< ".cmake or set ";
680 e
<< this->Variable
<< " to the directory containing a CMake "
681 << "configuration file for " << this->Name
<< ". ";
682 if(this->Configs
.size() == 1)
684 e
<< "The file will be called " << this->Configs
[0];
688 e
<< "The file will have one of the following names:\n";
689 for(std::vector
<std::string
>::const_iterator ci
= this->Configs
.begin();
690 ci
!= this->Configs
.end(); ++ci
)
692 e
<< " " << *ci
<< "\n";
697 this->SetError(e
.str().c_str());
702 cmSystemTools::Error("find_package ", e
.str().c_str());
706 // Set a variable marking whether the package was found.
707 std::string foundVar
= this->Name
;
708 foundVar
+= "_FOUND";
709 this->Makefile
->AddDefinition(foundVar
.c_str(), found
? "1":"0");
711 // Set a variable naming the configuration file that was found.
712 std::string fileVar
= this->Name
;
713 fileVar
+= "_CONFIG";
716 this->Makefile
->AddDefinition(fileVar
.c_str(), file
.c_str());
720 this->Makefile
->RemoveDefinition(fileVar
.c_str());
723 // Handle some ancient compatibility stuff.
724 if(this->Compatibility_1_6
)
726 // Listfiles will be looking for the capitalized version of the
728 this->Makefile
->AddDefinition
730 this->Makefile
->GetDefinition(this->Variable
.c_str()));
731 this->Makefile
->AddDefinition
733 this->Makefile
->GetDefinition(foundVar
.c_str()));
736 #ifdef CMAKE_BUILD_WITH_CMAKE
737 if(!(upperDir
== this->Variable
))
739 if(this->Compatibility_1_6
)
741 // Listfiles may use the capitalized version of the name.
742 // Remove any previously added watch.
743 this->Makefile
->GetVariableWatch()->RemoveWatch(
745 cmFindPackageNeedBackwardsCompatibility
750 // Listfiles should not be using the capitalized version of the
751 // name. Add a watch to warn the user.
752 this->Makefile
->GetVariableWatch()->AddWatch(
754 cmFindPackageNeedBackwardsCompatibility
763 //----------------------------------------------------------------------------
764 void cmFindPackageCommand::FindConfig()
766 // Compute the set of search prefixes.
767 this->ComputePrefixes();
769 // Look for the project's configuration file.
772 // Search for frameworks.
773 if(!found
&& this->SearchFrameworkFirst
|| this->SearchFrameworkOnly
)
775 found
= this->FindFrameworkConfig();
779 if(!found
&& this->SearchAppBundleFirst
|| this->SearchAppBundleOnly
)
781 found
= this->FindAppBundleConfig();
785 if(!found
&& !(this->SearchFrameworkOnly
|| this->SearchAppBundleOnly
))
787 found
= this->FindPrefixedConfig();
790 // Search for frameworks.
791 if(!found
&& this->SearchFrameworkLast
)
793 found
= this->FindFrameworkConfig();
797 if(!found
&& this->SearchAppBundleLast
)
799 found
= this->FindAppBundleConfig();
802 // Store the entry in the cache so it can be set by the user.
806 init
= cmSystemTools::GetFilenamePath(this->FileFound
);
810 init
= this->Variable
+ "-NOTFOUND";
813 "The directory containing a CMake configuration file for ";
816 this->Makefile
->AddCacheDefinition(this->Variable
.c_str(),
817 init
.c_str(), help
.c_str(),
818 cmCacheManager::PATH
);
821 //----------------------------------------------------------------------------
822 bool cmFindPackageCommand::FindPrefixedConfig()
824 for(std::vector
<std::string
>::const_iterator pi
= this->Prefixes
.begin();
825 pi
!= this->Prefixes
.end(); ++pi
)
827 if(this->SearchPrefix(*pi
))
835 //----------------------------------------------------------------------------
836 bool cmFindPackageCommand::FindFrameworkConfig()
838 for(std::vector
<std::string
>::const_iterator i
= this->Prefixes
.begin();
839 i
!= this->Prefixes
.end(); ++i
)
841 if(this->SearchFrameworkPrefix(*i
))
849 //----------------------------------------------------------------------------
850 bool cmFindPackageCommand::FindAppBundleConfig()
852 for(std::vector
<std::string
>::const_iterator i
= this->Prefixes
.begin();
853 i
!= this->Prefixes
.end(); ++i
)
855 if(this->SearchAppBundlePrefix(*i
))
863 //----------------------------------------------------------------------------
864 bool cmFindPackageCommand::ReadListFile(const char* f
)
866 if(this->Makefile
->ReadListFile(this->Makefile
->GetCurrentListFile(),f
))
870 std::string e
= "Error reading CMake code from \"";
873 this->SetError(e
.c_str());
877 //----------------------------------------------------------------------------
878 void cmFindPackageCommand::AppendToProperty(const char* propertyName
)
880 std::string propertyValue
;
882 this->Makefile
->GetCMakeInstance()->GetProperty(propertyName
);
885 propertyValue
= prop
;
887 std::vector
<std::string
> contents
;
888 cmSystemTools::ExpandListArgument(propertyValue
, contents
, false);
890 bool alreadyInserted
= false;
891 for(std::vector
<std::string
>::const_iterator it
= contents
.begin();
892 it
!= contents
.end(); ++ it
)
894 if (*it
== this->Name
)
896 alreadyInserted
= true;
900 if (!alreadyInserted
)
902 propertyValue
+= ";";
903 propertyValue
+= this->Name
;
908 propertyValue
= this->Name
;
910 this->Makefile
->GetCMakeInstance()->SetProperty(propertyName
,
911 propertyValue
.c_str());
914 //----------------------------------------------------------------------------
915 void cmFindPackageCommand::AppendSuccessInformation()
917 std::string found
= this->Name
;
919 std::string upperFound
= cmSystemTools::UpperCase(found
);
921 const char* upperResult
= this->Makefile
->GetDefinition(upperFound
.c_str());
922 const char* result
= this->Makefile
->GetDefinition(found
.c_str());
923 if ((cmSystemTools::IsOn(result
)) || (cmSystemTools::IsOn(upperResult
)))
925 this->AppendToProperty("PACKAGES_FOUND");
928 this->AppendToProperty("ENABLED_FEATURES");
933 this->AppendToProperty("PACKAGES_NOT_FOUND");
936 this->AppendToProperty("DISABLED_FEATURES");
941 //----------------------------------------------------------------------------
942 void cmFindPackageCommand::AddUserPath(std::string
const& p
)
944 std::string userPath
= p
;
945 cmSystemTools::ExpandRegistryValues(userPath
);
946 this->UserPaths
.push_back(userPath
);
949 //----------------------------------------------------------------------------
950 void cmFindPackageCommand::ComputePrefixes()
952 std::vector
<std::string
>& prefixes
= this->Prefixes
;
953 std::set
<cmStdString
> emmitted
;
955 if(!this->NoCMakeEnvironmentPath
&& !this->NoDefaultPath
)
957 // Check the environment variable with the same name as the cache
960 if(cmSystemTools::GetEnv(this->Variable
.c_str(), env
) && env
.length() > 0)
962 cmSystemTools::ConvertToUnixSlashes(env
);
963 this->AddPathInternal(prefixes
, env
, EnvPath
, &emmitted
);
966 this->AddEnvPath(prefixes
, "CMAKE_PREFIX_PATH", &emmitted
);
967 this->AddEnvPath(prefixes
, "CMAKE_FRAMEWORK_PATH", &emmitted
);
968 this->AddEnvPath(prefixes
, "CMAKE_APPBUNDLE_PATH", &emmitted
);
971 if(!this->NoCMakePath
&& !this->NoDefaultPath
)
973 this->AddCMakePath(prefixes
, "CMAKE_PREFIX_PATH", &emmitted
);
974 this->AddCMakePath(prefixes
, "CMAKE_FRAMEWORK_PATH", &emmitted
);
975 this->AddCMakePath(prefixes
, "CMAKE_APPBUNDLE_PATH", &emmitted
);
978 if(!this->NoSystemEnvironmentPath
&& !this->NoDefaultPath
)
980 // Use the system search path to generate prefixes.
981 // Relative paths are interpreted with respect to the current
982 // working directory.
983 std::vector
<std::string
> tmp
;
984 cmSystemTools::GetPath(tmp
);
985 for(std::vector
<std::string
>::iterator i
= tmp
.begin();
988 std::string
const& d
= *i
;
990 // If the path is a PREFIX/bin case then add its parent instead.
991 if(d
.size() >= 4 && strcmp(d
.c_str()+d
.size()-4, "/bin") == 0 ||
992 d
.size() >= 5 && strcmp(d
.c_str()+d
.size()-5, "/sbin") == 0)
994 this->AddPathInternal(prefixes
,
995 cmSystemTools::GetFilenamePath(d
),
1000 this->AddPathInternal(prefixes
, d
, EnvPath
, &emmitted
);
1005 if(!this->NoBuilds
&& !this->NoDefaultPath
)
1007 // It is likely that CMake will have recently built the project.
1008 for(int i
=1; i
<= 10; ++i
)
1012 "[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\"
1013 "Settings\\StartPath;WhereBuild" << i
<< "]";
1014 std::string f
= r
.str();
1015 cmSystemTools::ExpandRegistryValues(f
);
1016 cmSystemTools::ConvertToUnixSlashes(f
);
1017 if(cmSystemTools::FileIsFullPath(f
.c_str()) &&
1018 cmSystemTools::FileIsDirectory(f
.c_str()))
1020 this->AddPathInternal(prefixes
, f
, FullPath
, &emmitted
);
1025 if(!this->NoCMakeSystemPath
&& !this->NoDefaultPath
)
1027 this->AddCMakePath(prefixes
, "CMAKE_SYSTEM_PREFIX_PATH", &emmitted
);
1028 this->AddCMakePath(prefixes
, "CMAKE_SYSTEM_FRAMEWORK_PATH", &emmitted
);
1029 this->AddCMakePath(prefixes
, "CMAKE_SYSTEM_APPBUNDLE_PATH", &emmitted
);
1032 if(!this->UserPaths
.empty())
1034 // Add paths specified by the caller.
1035 this->AddPathsInternal(prefixes
, this->UserPaths
, CMakePath
, &emmitted
);
1038 // Construct the final set of prefixes.
1039 this->RerootPaths(prefixes
);
1041 // Add a trailing slash to all prefixes to aid the search process.
1042 for(std::vector
<std::string
>::iterator i
= prefixes
.begin();
1043 i
!= prefixes
.end(); ++i
)
1045 std::string
& prefix
= *i
;
1046 if(prefix
[prefix
.size()-1] != '/')
1053 //----------------------------------------------------------------------------
1054 bool cmFindPackageCommand::SearchDirectory(std::string
const& dir
)
1056 assert(!dir
.empty() && dir
[dir
.size()-1] == '/');
1058 // Check each path suffix on this directory.
1059 for(std::vector
<std::string
>::const_iterator
1060 si
= this->SearchPathSuffixes
.begin();
1061 si
!= this->SearchPathSuffixes
.end(); ++si
)
1063 std::string d
= dir
;
1069 if(this->CheckDirectory(d
))
1077 //----------------------------------------------------------------------------
1078 bool cmFindPackageCommand::CheckDirectory(std::string
const& dir
)
1080 assert(!dir
.empty() && dir
[dir
.size()-1] == '/');
1082 // Look for the file in this directory.
1083 std::string d
= dir
.substr(0, dir
.size()-1);
1084 if(this->FindConfigFile(d
, this->FileFound
))
1086 // Remove duplicate slashes.
1087 cmSystemTools::ConvertToUnixSlashes(this->FileFound
);
1093 //----------------------------------------------------------------------------
1094 bool cmFindPackageCommand::FindConfigFile(std::string
const& dir
,
1097 for(std::vector
<std::string
>::const_iterator ci
= this->Configs
.begin();
1098 ci
!= this->Configs
.end(); ++ci
)
1105 fprintf(stderr
, "Checking file [%s]\n", file
.c_str());
1107 if(cmSystemTools::FileExists(file
.c_str(), true) &&
1108 this->CheckVersion(file
))
1116 //----------------------------------------------------------------------------
1117 bool cmFindPackageCommand::FindConfigFileToLoad(std::string
const& dir
,
1120 if(this->FileFound
.empty())
1122 // The file location was cached. Look for the correct file.
1123 return this->FindConfigFile(dir
, file
);
1127 // The file location was just found during this call.
1128 // Use the file found without searching again.
1129 file
= this->FileFound
;
1134 //----------------------------------------------------------------------------
1135 bool cmFindPackageCommand::CheckVersion(std::string
const& config_file
)
1137 // Get the filename without the .cmake extension.
1138 std::string::size_type pos
= config_file
.rfind('.');
1139 std::string version_file_base
= config_file
.substr(0, pos
);
1141 // Look for foo-config-version.cmake
1142 std::string version_file
= version_file_base
;
1143 version_file
+= "-version.cmake";
1144 if(cmSystemTools::FileExists(version_file
.c_str(), true))
1146 return this->CheckVersionFile(version_file
);
1149 // Look for fooConfigVersion.cmake
1150 version_file
= version_file_base
;
1151 version_file
+= "Version.cmake";
1152 if(cmSystemTools::FileExists(version_file
.c_str(), true))
1154 return this->CheckVersionFile(version_file
);
1157 // If no version was requested a versionless package is acceptable.
1158 if(this->Version
.empty())
1163 // No version file found. Assume the version is incompatible.
1167 //----------------------------------------------------------------------------
1168 bool cmFindPackageCommand::CheckVersionFile(std::string
const& version_file
)
1170 // The version file will be loaded in an isolated scope.
1171 this->Makefile
->PushScope();
1173 // Clear the output variables.
1174 this->Makefile
->RemoveDefinition("PACKAGE_VERSION");
1175 this->Makefile
->RemoveDefinition("PACKAGE_VERSION_COMPATIBLE");
1176 this->Makefile
->RemoveDefinition("PACKAGE_VERSION_EXACT");
1178 // Set the input variables.
1179 this->Makefile
->AddDefinition("PACKAGE_FIND_NAME", this->Name
.c_str());
1180 this->Makefile
->AddDefinition("PACKAGE_FIND_VERSION",
1181 this->Version
.c_str());
1182 if(this->VersionCount
>= 3)
1185 sprintf(buf
, "%u", this->VersionPatch
);
1186 this->Makefile
->AddDefinition("PACKAGE_FIND_VERSION_PATCH", buf
);
1190 this->Makefile
->RemoveDefinition("PACKAGE_FIND_VERSION_PATCH");
1192 if(this->VersionCount
>= 2)
1195 sprintf(buf
, "%u", this->VersionMinor
);
1196 this->Makefile
->AddDefinition("PACKAGE_FIND_VERSION_MINOR", buf
);
1200 this->Makefile
->RemoveDefinition("PACKAGE_FIND_VERSION_MINOR");
1202 if(this->VersionCount
>= 1)
1205 sprintf(buf
, "%u", this->VersionMajor
);
1206 this->Makefile
->AddDefinition("PACKAGE_FIND_VERSION_MAJOR", buf
);
1210 this->Makefile
->RemoveDefinition("PACKAGE_FIND_VERSION_MAJOR");
1213 // Load the version check file.
1215 if(this->ReadListFile(version_file
.c_str()))
1217 // Check the output variables.
1218 found
= this->Makefile
->IsOn("PACKAGE_VERSION_EXACT");
1219 if(!found
&& !this->VersionExact
)
1221 found
= this->Makefile
->IsOn("PACKAGE_VERSION_COMPATIBLE");
1223 if(found
|| this->Version
.empty())
1225 // Get the version found.
1226 this->VersionFound
=
1227 this->Makefile
->GetSafeDefinition("PACKAGE_VERSION");
1229 // Try to parse the version number and store the results that were
1230 // successfully parsed.
1231 unsigned int parsed_major
;
1232 unsigned int parsed_minor
;
1233 unsigned int parsed_patch
;
1234 this->VersionFoundCount
=
1235 sscanf(this->VersionFound
.c_str(), "%u.%u.%u",
1236 &parsed_major
, &parsed_minor
, &parsed_patch
);
1237 switch(this->VersionFoundCount
)
1239 case 3: this->VersionFoundPatch
= parsed_patch
; // no break!
1240 case 2: this->VersionFoundMinor
= parsed_minor
; // no break!
1241 case 1: this->VersionFoundMajor
= parsed_major
; // no break!
1247 // Restore the original scope.
1248 this->Makefile
->PopScope();
1250 // Succeed if the version was found or no version was requested.
1251 return found
|| this->Version
.empty();
1254 //----------------------------------------------------------------------------
1255 void cmFindPackageCommand::StoreVersionFound()
1257 // Store the whole version string.
1258 std::string ver
= this->Name
;
1260 if(this->VersionFound
.empty())
1262 this->Makefile
->RemoveDefinition(ver
.c_str());
1266 this->Makefile
->AddDefinition(ver
.c_str(), this->VersionFound
.c_str());
1269 // Store the portions that could be parsed.
1271 switch(this->VersionFoundCount
)
1275 sprintf(buf
, "%u", this->VersionFoundPatch
);
1276 this->Makefile
->AddDefinition((ver
+"_PATCH").c_str(), buf
);
1280 sprintf(buf
, "%u", this->VersionFoundMinor
);
1281 this->Makefile
->AddDefinition((ver
+"_MINOR").c_str(), buf
);
1285 sprintf(buf
, "%u", this->VersionFoundMajor
);
1286 this->Makefile
->AddDefinition((ver
+"_MAJOR").c_str(), buf
);
1292 //----------------------------------------------------------------------------
1293 #include <cmsys/Directory.hxx>
1294 #include <cmsys/Glob.hxx>
1295 #include <cmsys/String.h>
1296 #include <cmsys/auto_ptr.hxx>
1299 class cmFileListGeneratorBase
1302 virtual ~cmFileListGeneratorBase() {}
1304 bool Consider(std::string
const& fullPath
, cmFileList
& listing
);
1306 bool Search(cmFileList
&);
1307 virtual bool Search(std::string
const& parent
, cmFileList
&) = 0;
1308 virtual cmsys::auto_ptr
<cmFileListGeneratorBase
> Clone() const = 0;
1309 friend class cmFileList
;
1310 cmFileListGeneratorBase
* SetNext(cmFileListGeneratorBase
const& next
);
1311 cmsys::auto_ptr
<cmFileListGeneratorBase
> Next
;
1317 cmFileList(): First(), Last(0) {}
1318 virtual ~cmFileList() {}
1319 cmFileList
& operator/(cmFileListGeneratorBase
const& rhs
)
1323 this->Last
= this->Last
->SetNext(rhs
);
1327 this->First
= rhs
.Clone();
1328 this->Last
= this->First
.get();
1334 if(this->First
.get())
1336 return this->First
->Search(*this);
1341 virtual bool Visit(std::string
const& fullPath
) = 0;
1342 friend class cmFileListGeneratorBase
;
1343 cmsys::auto_ptr
<cmFileListGeneratorBase
> First
;
1344 cmFileListGeneratorBase
* Last
;
1347 class cmFindPackageFileList
: public cmFileList
1350 cmFindPackageFileList(cmFindPackageCommand
* fpc
,
1351 bool use_suffixes
= true):
1352 cmFileList(), FPC(fpc
), UseSuffixes(use_suffixes
) {}
1354 bool Visit(std::string
const& fullPath
)
1356 if(this->UseSuffixes
)
1358 return this->FPC
->SearchDirectory(fullPath
);
1362 return this->FPC
->CheckDirectory(fullPath
);
1365 cmFindPackageCommand
* FPC
;
1369 bool cmFileListGeneratorBase::Search(cmFileList
& listing
)
1371 return this->Search("", listing
);
1374 cmFileListGeneratorBase
*
1375 cmFileListGeneratorBase::SetNext(cmFileListGeneratorBase
const& next
)
1377 this->Next
= next
.Clone();
1378 return this->Next
.get();
1381 bool cmFileListGeneratorBase::Consider(std::string
const& fullPath
,
1382 cmFileList
& listing
)
1384 if(this->Next
.get())
1386 return this->Next
->Search(fullPath
+ "/", listing
);
1390 return listing
.Visit(fullPath
+ "/");
1394 class cmFileListGeneratorFixed
: public cmFileListGeneratorBase
1397 cmFileListGeneratorFixed(std::string
const& str
):
1398 cmFileListGeneratorBase(), String(str
) {}
1399 cmFileListGeneratorFixed(cmFileListGeneratorFixed
const& r
):
1400 cmFileListGeneratorBase(), String(r
.String
) {}
1403 virtual bool Search(std::string
const& parent
, cmFileList
& lister
)
1405 std::string fullPath
= parent
+ this->String
;
1406 return this->Consider(fullPath
, lister
);
1408 virtual cmsys::auto_ptr
<cmFileListGeneratorBase
> Clone() const
1410 cmsys::auto_ptr
<cmFileListGeneratorBase
>
1411 g(new cmFileListGeneratorFixed(*this));
1416 class cmFileListGeneratorEnumerate
: public cmFileListGeneratorBase
1419 cmFileListGeneratorEnumerate(const char* p1
, const char* p2
):
1420 cmFileListGeneratorBase()
1422 this->Vector
.push_back(p1
);
1423 this->Vector
.push_back(p2
);
1425 cmFileListGeneratorEnumerate(cmFileListGeneratorEnumerate
const& r
):
1426 cmFileListGeneratorBase(), Vector(r
.Vector
) {}
1428 std::vector
<std::string
> Vector
;
1429 virtual bool Search(std::string
const& parent
, cmFileList
& lister
)
1431 for(std::vector
<std::string
>::const_iterator i
= this->Vector
.begin();
1432 i
!= this->Vector
.end(); ++i
)
1434 if(this->Consider(parent
+ *i
, lister
))
1441 virtual cmsys::auto_ptr
<cmFileListGeneratorBase
> Clone() const
1443 cmsys::auto_ptr
<cmFileListGeneratorBase
>
1444 g(new cmFileListGeneratorEnumerate(*this));
1449 class cmFileListGeneratorProject
: public cmFileListGeneratorBase
1452 cmFileListGeneratorProject(std::vector
<std::string
> const& names
):
1453 cmFileListGeneratorBase(), Names(names
) {}
1454 cmFileListGeneratorProject(cmFileListGeneratorProject
const& r
):
1455 cmFileListGeneratorBase(), Names(r
.Names
) {}
1457 std::vector
<std::string
> const& Names
;
1458 virtual bool Search(std::string
const& parent
, cmFileList
& lister
)
1460 // Construct a list of matches.
1461 std::vector
<std::string
> matches
;
1463 d
.Load(parent
.c_str());
1464 for(unsigned long i
=0; i
< d
.GetNumberOfFiles(); ++i
)
1466 const char* fname
= d
.GetFile(i
);
1467 if(strcmp(fname
, ".") == 0 ||
1468 strcmp(fname
, "..") == 0)
1472 for(std::vector
<std::string
>::const_iterator ni
= this->Names
.begin();
1473 ni
!= this->Names
.end(); ++ni
)
1475 if(cmsysString_strncasecmp(fname
, ni
->c_str(),
1478 matches
.push_back(fname
);
1483 for(std::vector
<std::string
>::const_iterator i
= matches
.begin();
1484 i
!= matches
.end(); ++i
)
1486 if(this->Consider(parent
+ *i
, lister
))
1493 virtual cmsys::auto_ptr
<cmFileListGeneratorBase
> Clone() const
1495 cmsys::auto_ptr
<cmFileListGeneratorBase
>
1496 g(new cmFileListGeneratorProject(*this));
1501 class cmFileListGeneratorMacProject
: public cmFileListGeneratorBase
1504 cmFileListGeneratorMacProject(std::vector
<std::string
> const& names
,
1506 cmFileListGeneratorBase(), Names(names
), Extension(ext
) {}
1507 cmFileListGeneratorMacProject(cmFileListGeneratorMacProject
const& r
):
1508 cmFileListGeneratorBase(), Names(r
.Names
), Extension(r
.Extension
) {}
1510 std::vector
<std::string
> const& Names
;
1511 std::string Extension
;
1512 virtual bool Search(std::string
const& parent
, cmFileList
& lister
)
1514 // Construct a list of matches.
1515 std::vector
<std::string
> matches
;
1517 d
.Load(parent
.c_str());
1518 for(unsigned long i
=0; i
< d
.GetNumberOfFiles(); ++i
)
1520 const char* fname
= d
.GetFile(i
);
1521 if(strcmp(fname
, ".") == 0 ||
1522 strcmp(fname
, "..") == 0)
1526 for(std::vector
<std::string
>::const_iterator ni
= this->Names
.begin();
1527 ni
!= this->Names
.end(); ++ni
)
1529 std::string name
= *ni
;
1530 name
+= this->Extension
;
1531 if(cmsysString_strcasecmp(fname
, name
.c_str()) == 0)
1533 matches
.push_back(fname
);
1538 for(std::vector
<std::string
>::const_iterator i
= matches
.begin();
1539 i
!= matches
.end(); ++i
)
1541 if(this->Consider(parent
+ *i
, lister
))
1548 virtual cmsys::auto_ptr
<cmFileListGeneratorBase
> Clone() const
1550 cmsys::auto_ptr
<cmFileListGeneratorBase
>
1551 g(new cmFileListGeneratorMacProject(*this));
1556 class cmFileListGeneratorCaseInsensitive
: public cmFileListGeneratorBase
1559 cmFileListGeneratorCaseInsensitive(std::string
const& str
):
1560 cmFileListGeneratorBase(), String(str
) {}
1561 cmFileListGeneratorCaseInsensitive(
1562 cmFileListGeneratorCaseInsensitive
const& r
):
1563 cmFileListGeneratorBase(), String(r
.String
) {}
1566 virtual bool Search(std::string
const& parent
, cmFileList
& lister
)
1568 // Look for matching files.
1569 std::vector
<std::string
> matches
;
1571 d
.Load(parent
.c_str());
1572 for(unsigned long i
=0; i
< d
.GetNumberOfFiles(); ++i
)
1574 const char* fname
= d
.GetFile(i
);
1575 if(strcmp(fname
, ".") == 0 ||
1576 strcmp(fname
, "..") == 0)
1580 if(cmsysString_strcasecmp(fname
, this->String
.c_str()) == 0)
1582 if(this->Consider(parent
+ fname
, lister
))
1590 virtual cmsys::auto_ptr
<cmFileListGeneratorBase
> Clone() const
1592 cmsys::auto_ptr
<cmFileListGeneratorBase
>
1593 g(new cmFileListGeneratorCaseInsensitive(*this));
1598 class cmFileListGeneratorGlob
: public cmFileListGeneratorBase
1601 cmFileListGeneratorGlob(std::string
const& str
):
1602 cmFileListGeneratorBase(), Pattern(str
) {}
1603 cmFileListGeneratorGlob(cmFileListGeneratorGlob
const& r
):
1604 cmFileListGeneratorBase(), Pattern(r
.Pattern
) {}
1606 std::string Pattern
;
1607 virtual bool Search(std::string
const& parent
, cmFileList
& lister
)
1609 // Glob the set of matching files.
1610 std::string expr
= parent
;
1611 expr
+= this->Pattern
;
1613 if(!g
.FindFiles(expr
))
1617 std::vector
<std::string
> const& files
= g
.GetFiles();
1619 // Look for directories among the matches.
1620 for(std::vector
<std::string
>::const_iterator fi
= files
.begin();
1621 fi
!= files
.end(); ++fi
)
1623 if(cmSystemTools::FileIsDirectory(fi
->c_str()))
1625 if(this->Consider(*fi
, lister
))
1633 virtual cmsys::auto_ptr
<cmFileListGeneratorBase
> Clone() const
1635 cmsys::auto_ptr
<cmFileListGeneratorBase
>
1636 g(new cmFileListGeneratorGlob(*this));
1641 //----------------------------------------------------------------------------
1642 bool cmFindPackageCommand::SearchPrefix(std::string
const& prefix_in
)
1644 assert(!prefix_in
.empty() && prefix_in
[prefix_in
.size()-1] == '/');
1647 fprintf(stderr
, "Checking prefix [%s]\n", prefix_in
.c_str());
1650 // Skip this if the prefix does not exist.
1651 if(!cmSystemTools::FileIsDirectory(prefix_in
.c_str()))
1656 // PREFIX/ (useful on windows or in build trees)
1657 if(this->SearchDirectory(prefix_in
))
1662 // Strip the trailing slash because the path generator is about to
1664 std::string prefix
= prefix_in
.substr(0, prefix_in
.size()-1);
1666 // PREFIX/(cmake|CMake)/ (useful on windows or in build trees)
1668 cmFindPackageFileList
lister(this);
1670 / cmFileListGeneratorFixed(prefix
)
1671 / cmFileListGeneratorCaseInsensitive("cmake");
1678 // PREFIX/(share|lib)/(Foo|foo|FOO).*/
1680 cmFindPackageFileList
lister(this);
1682 / cmFileListGeneratorFixed(prefix
)
1683 / cmFileListGeneratorEnumerate("lib", "share")
1684 / cmFileListGeneratorProject(this->Names
);
1691 // PREFIX/(share|lib)/(Foo|foo|FOO).*/(cmake|CMake)/
1693 cmFindPackageFileList
lister(this);
1695 / cmFileListGeneratorFixed(prefix
)
1696 / cmFileListGeneratorEnumerate("lib", "share")
1697 / cmFileListGeneratorProject(this->Names
)
1698 / cmFileListGeneratorCaseInsensitive("cmake");
1708 //----------------------------------------------------------------------------
1709 bool cmFindPackageCommand::SearchFrameworkPrefix(std::string
const& prefix_in
)
1711 assert(!prefix_in
.empty() && prefix_in
[prefix_in
.size()-1] == '/');
1714 fprintf(stderr
, "Checking framework prefix [%s]\n", prefix_in
.c_str());
1717 // Strip the trailing slash because the path generator is about to
1719 std::string prefix
= prefix_in
.substr(0, prefix_in
.size()-1);
1721 // <prefix>/Foo.framework/Resources/
1723 cmFindPackageFileList
lister(this);
1725 / cmFileListGeneratorFixed(prefix
)
1726 / cmFileListGeneratorMacProject(this->Names
, ".framework")
1727 / cmFileListGeneratorFixed("Resources");
1733 // <prefix>/Foo.framework/Resources/CMake/
1735 cmFindPackageFileList
lister(this);
1737 / cmFileListGeneratorFixed(prefix
)
1738 / cmFileListGeneratorMacProject(this->Names
, ".framework")
1739 / cmFileListGeneratorFixed("Resources")
1740 / cmFileListGeneratorCaseInsensitive("cmake");
1747 // <prefix>/Foo.framework/Versions/*/Resources/
1749 cmFindPackageFileList
lister(this);
1751 / cmFileListGeneratorFixed(prefix
)
1752 / cmFileListGeneratorMacProject(this->Names
, ".framework")
1753 / cmFileListGeneratorFixed("Versions")
1754 / cmFileListGeneratorGlob("*/Resources");
1761 // <prefix>/Foo.framework/Versions/*/Resources/CMake/
1763 cmFindPackageFileList
lister(this);
1765 / cmFileListGeneratorFixed(prefix
)
1766 / cmFileListGeneratorMacProject(this->Names
, ".framework")
1767 / cmFileListGeneratorFixed("Versions")
1768 / cmFileListGeneratorGlob("*/Resources")
1769 / cmFileListGeneratorCaseInsensitive("cmake");
1779 //----------------------------------------------------------------------------
1780 bool cmFindPackageCommand::SearchAppBundlePrefix(std::string
const& prefix_in
)
1782 assert(!prefix_in
.empty() && prefix_in
[prefix_in
.size()-1] == '/');
1785 fprintf(stderr
, "Checking bundle prefix [%s]\n", prefix_in
.c_str());
1788 // Strip the trailing slash because the path generator is about to
1790 std::string prefix
= prefix_in
.substr(0, prefix_in
.size()-1);
1792 // <prefix>/Foo.app/Contents/Resources
1794 cmFindPackageFileList
lister(this);
1796 / cmFileListGeneratorFixed(prefix
)
1797 / cmFileListGeneratorMacProject(this->Names
, ".app")
1798 / cmFileListGeneratorFixed("Contents/Resources");
1805 // <prefix>/Foo.app/Contents/Resources/CMake
1807 cmFindPackageFileList
lister(this);
1809 / cmFileListGeneratorFixed(prefix
)
1810 / cmFileListGeneratorMacProject(this->Names
, ".app")
1811 / cmFileListGeneratorFixed("Contents/Resources")
1812 / cmFileListGeneratorCaseInsensitive("cmake");
1822 // TODO: Version numbers? Perhaps have a listing component class that
1823 // sorts by lexicographic and numerical ordering. Also try to match
1824 // some command argument for the version. Alternatively provide an
1825 // API that just returns a list of valid directories? Perhaps push a
1826 // scope and try loading the target file just to get its version
1827 // number? Could add a foo-version.cmake or FooVersion.cmake file
1828 // in the projects that contains just version information.
1830 // TODO: Debug cmsys::Glob double slash problem.
1832 // TODO: Add registry entries after cmake system search path?
1833 // Currently the user must specify them with the PATHS option.
1835 // [HKEY_CURRENT_USER\Software\*\Foo*;InstallDir]
1836 // [HKEY_CURRENT_USER\Software\*\*\Foo*;InstallDir]
1837 // [HKEY_LOCAL_MACHINE\Software\*\Foo*;InstallDir]
1838 // [HKEY_LOCAL_MACHINE\Software\*\*\Foo*;InstallDir]