12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261 |
- /*============================================================================
- CMake - Cross Platform Makefile Generator
- Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
- Distributed under the OSI-approved BSD License (the "License");
- see accompanying file Copyright.txt for details.
- 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.
- ============================================================================*/
- #include "cmFindPackageCommand.h"
- #include <cmsys/Directory.hxx>
- #include <cmsys/RegularExpression.hxx>
- #include <cmsys/Encoding.hxx>
- #ifdef CMAKE_BUILD_WITH_CMAKE
- #include "cmVariableWatch.h"
- #endif
- #if defined(__HAIKU__)
- #include <string.h>
- #include <FindDirectory.h>
- #include <StorageDefs.h>
- #endif
- //----------------------------------------------------------------------------
- cmFindPackageCommand::cmFindPackageCommand()
- {
- this->CMakePathName = "PACKAGE";
- this->Quiet = false;
- this->Required = false;
- this->NoUserRegistry = false;
- this->NoSystemRegistry = false;
- this->NoBuilds = false;
- this->UseConfigFiles = true;
- this->UseFindModules = true;
- this->DebugMode = false;
- this->UseLib64Paths = false;
- this->PolicyScope = true;
- this->VersionMajor = 0;
- this->VersionMinor = 0;
- this->VersionPatch = 0;
- this->VersionTweak = 0;
- this->VersionCount = 0;
- this->VersionExact = false;
- this->VersionFoundMajor = 0;
- this->VersionFoundMinor = 0;
- this->VersionFoundPatch = 0;
- this->VersionFoundTweak = 0;
- this->VersionFoundCount = 0;
- this->RequiredCMakeVersion = 0;
- }
- //----------------------------------------------------------------------------
- bool cmFindPackageCommand
- ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
- {
- if(args.size() < 1)
- {
- this->SetError("called with incorrect number of arguments");
- return false;
- }
- // 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]);
- }
- // Check for debug mode.
- this->DebugMode = this->Makefile->IsOn("CMAKE_FIND_DEBUG_MODE");
- // Lookup target architecture, if any.
- if(const char* arch =
- this->Makefile->GetDefinition("CMAKE_LIBRARY_ARCHITECTURE"))
- {
- this->LibraryArchitecture = arch;
- }
- // Lookup whether lib64 paths should be used.
- if(this->Makefile->PlatformIs64Bit() &&
- this->Makefile->GetCMakeInstance()
- ->GetPropertyAsBool("FIND_LIBRARY_USE_LIB64_PATHS"))
- {
- this->UseLib64Paths = true;
- }
- // Check if User Package Registry should be disabled
- if(this->Makefile->IsOn("CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY"))
- {
- this->NoUserRegistry = true;
- }
- // Check if System Package Registry should be disabled
- if(this->Makefile->IsOn("CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY"))
- {
- this->NoSystemRegistry = true;
- }
- // Find the current root path mode.
- this->SelectDefaultRootPathMode();
- // Find the current bundle/framework search policy.
- this->SelectDefaultMacMode();
- // Record options.
- this->Name = args[0];
- std::string components;
- const char* components_sep = "";
- std::set<std::string> requiredComponents;
- std::set<std::string> optionalComponents;
- // Always search directly in a generated path.
- this->SearchPathSuffixes.push_back("");
- // Parse the arguments.
- enum Doing { DoingNone, DoingComponents, DoingOptionalComponents, DoingNames,
- DoingPaths, DoingPathSuffixes, DoingConfigs, DoingHints };
- Doing doing = DoingNone;
- cmsys::RegularExpression version("^[0-9.]+$");
- bool haveVersion = false;
- std::set<unsigned int> configArgs;
- std::set<unsigned int> moduleArgs;
- for(unsigned int i=1; i < args.size(); ++i)
- {
- if(args[i] == "QUIET")
- {
- this->Quiet = true;
- doing = DoingNone;
- }
- else if(args[i] == "EXACT")
- {
- this->VersionExact = true;
- doing = DoingNone;
- }
- else if(args[i] == "MODULE")
- {
- moduleArgs.insert(i);
- doing = DoingNone;
- }
- else if(args[i] == "CONFIG")
- {
- configArgs.insert(i);
- doing = DoingNone;
- }
- else if(args[i] == "NO_MODULE")
- {
- configArgs.insert(i);
- doing = DoingNone;
- }
- else if(args[i] == "REQUIRED")
- {
- this->Required = true;
- doing = DoingComponents;
- }
- else if(args[i] == "COMPONENTS")
- {
- doing = DoingComponents;
- }
- else if(args[i] == "OPTIONAL_COMPONENTS")
- {
- doing = DoingOptionalComponents;
- }
- else if(args[i] == "NAMES")
- {
- configArgs.insert(i);
- doing = DoingNames;
- }
- else if(args[i] == "PATHS")
- {
- configArgs.insert(i);
- doing = DoingPaths;
- }
- else if(args[i] == "HINTS")
- {
- configArgs.insert(i);
- doing = DoingHints;
- }
- else if(args[i] == "PATH_SUFFIXES")
- {
- configArgs.insert(i);
- doing = DoingPathSuffixes;
- }
- else if(args[i] == "CONFIGS")
- {
- configArgs.insert(i);
- doing = DoingConfigs;
- }
- else if(args[i] == "NO_POLICY_SCOPE")
- {
- this->PolicyScope = false;
- doing = DoingNone;
- }
- else if(args[i] == "NO_CMAKE_PACKAGE_REGISTRY")
- {
- this->NoUserRegistry = true;
- configArgs.insert(i);
- doing = DoingNone;
- }
- else if(args[i] == "NO_CMAKE_SYSTEM_PACKAGE_REGISTRY")
- {
- this->NoSystemRegistry = true;
- configArgs.insert(i);
- doing = DoingNone;
- }
- else if(args[i] == "NO_CMAKE_BUILDS_PATH")
- {
- this->NoBuilds = true;
- configArgs.insert(i);
- doing = DoingNone;
- }
- else if(this->CheckCommonArgument(args[i]))
- {
- configArgs.insert(i);
- doing = DoingNone;
- }
- else if((doing == DoingComponents) || (doing == DoingOptionalComponents))
- {
- // Set a variable telling the find script whether this component
- // is required.
- const char* isRequired = "1";
- if (doing == DoingOptionalComponents)
- {
- isRequired = "0";
- optionalComponents.insert(args[i]);
- }
- else
- {
- requiredComponents.insert(args[i]);
- }
- std::string req_var = this->Name + "_FIND_REQUIRED_" + args[i];
- this->AddFindDefinition(req_var, isRequired);
- // Append to the list of required components.
- components += components_sep;
- components += args[i];
- components_sep = ";";
- }
- else if(doing == DoingNames)
- {
- this->Names.push_back(args[i]);
- }
- else if(doing == DoingPaths)
- {
- this->AddUserPath(args[i], this->UserPaths);
- }
- else if(doing == DoingHints)
- {
- this->AddUserPath(args[i], this->UserHints);
- }
- else if(doing == DoingPathSuffixes)
- {
- this->AddPathSuffix(args[i]);
- }
- else if(doing == DoingConfigs)
- {
- 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.";
- this->SetError(e.str());
- return false;
- }
- this->Configs.push_back(args[i]);
- }
- else if(!haveVersion && version.find(args[i].c_str()))
- {
- haveVersion = true;
- this->Version = args[i];
- }
- else
- {
- cmOStringStream e;
- e << "called with invalid argument \"" << args[i] << "\"";
- this->SetError(e.str());
- return false;
- }
- }
- 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());
- return false;
- }
- // 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());
- return false;
- }
- // 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.");
- }
- if(this->Version.empty() || components.empty())
- {
- // 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))
- {
- 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);
- // Whether an exact version is required.
- std::string exact = this->Name;
- exact += "_FIND_VERSION_EXACT";
- this->VersionExact = this->Makefile->IsOn(exact);
- }
- if(components.empty())
- {
- std::string components_var = this->Name + "_FIND_COMPONENTS";
- components = this->Makefile->GetSafeDefinition(components_var);
- }
- }
- }
- 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;
- unsigned int parsed_tweak;
- this->VersionCount = sscanf(this->Version.c_str(), "%u.%u.%u.%u",
- &parsed_major, &parsed_minor,
- &parsed_patch, &parsed_tweak);
- switch(this->VersionCount)
- {
- case 4: this->VersionTweak = parsed_tweak; // no break!
- 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;
- }
- }
- std::string disableFindPackageVar = "CMAKE_DISABLE_FIND_PACKAGE_";
- disableFindPackageVar += this->Name;
- if(this->Makefile->IsOn(disableFindPackageVar))
- {
- 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());
- return false;
- }
- return true;
- }
- this->SetModuleVariables(components);
- // See if there is a Find<package>.cmake module.
- if(this->UseFindModules)
- {
- bool foundModule = false;
- if(!this->FindModule(foundModule))
- {
- this->AppendSuccessInformation();
- return false;
- }
- if(foundModule)
- {
- this->AppendSuccessInformation();
- return true;
- }
- }
- 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());
- }
- // No find module. Assume the project has a CMake config file. Use
- // a <package>_DIR cache variable to locate it.
- this->Variable = this->Name;
- this->Variable += "_DIR";
- // 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);
- }
- }
- // 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());
- // Find and load the package.
- bool result = this->HandlePackageMode();
- this->AppendSuccessInformation();
- return result;
- }
- //----------------------------------------------------------------------------
- void cmFindPackageCommand::SetModuleVariables(const std::string& components)
- {
- this->AddFindDefinition("CMAKE_FIND_PACKAGE_NAME", this->Name.c_str());
- // Store the list of components.
- std::string components_var = this->Name + "_FIND_COMPONENTS";
- this->AddFindDefinition(components_var, components.c_str());
- if(this->Quiet)
- {
- // Tell the module that is about to be read that it should find
- // quietly.
- std::string quietly = this->Name;
- quietly += "_FIND_QUIETLY";
- this->AddFindDefinition(quietly, "1");
- }
- if(this->Required)
- {
- // Tell the module that is about to be read that it should report
- // a fatal error if the package is not found.
- std::string req = this->Name;
- req += "_FIND_REQUIRED";
- this->AddFindDefinition(req, "1");
- }
- if(!this->Version.empty())
- {
- // Tell the module that is about to be read what version of the
- // package has been requested.
- std::string ver = this->Name;
- ver += "_FIND_VERSION";
- this->AddFindDefinition(ver, this->Version.c_str());
- char buf[64];
- sprintf(buf, "%u", this->VersionMajor);
- this->AddFindDefinition(ver+"_MAJOR", buf);
- sprintf(buf, "%u", this->VersionMinor);
- this->AddFindDefinition(ver+"_MINOR", buf);
- sprintf(buf, "%u", this->VersionPatch);
- this->AddFindDefinition(ver+"_PATCH", buf);
- sprintf(buf, "%u", this->VersionTweak);
- this->AddFindDefinition(ver+"_TWEAK", buf);
- sprintf(buf, "%u", this->VersionCount);
- this->AddFindDefinition(ver+"_COUNT", buf);
- // Tell the module whether an exact version has been requested.
- std::string exact = this->Name;
- exact += "_FIND_VERSION_EXACT";
- this->AddFindDefinition(exact, this->VersionExact? "1":"0");
- }
- }
- //----------------------------------------------------------------------------
- void cmFindPackageCommand::AddFindDefinition(const std::string& 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<std::string, OriginalDef>::iterator
- i = this->OriginalDefs.begin(); i != this->OriginalDefs.end(); ++i)
- {
- OriginalDef const& od = i->second;
- if(od.exists)
- {
- this->Makefile->AddDefinition(i->first, od.value.c_str());
- }
- else
- {
- this->Makefile->RemoveDefinition(i->first);
- }
- }
- }
- //----------------------------------------------------------------------------
- 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() )
- {
- // Load the module we found, and set "<name>_FIND_MODULE" to true
- // while inside it.
- found = true;
- std::string var = this->Name;
- var += "_FIND_MODULE";
- this->Makefile->AddDefinition(var, "1");
- bool result = this->ReadListFile(mfile.c_str(), DoPolicyScope);
- this->Makefile->RemoveDefinition(var);
- return result;
- }
- return true;
- }
- //----------------------------------------------------------------------------
- bool cmFindPackageCommand::HandlePackageMode()
- {
- this->ConsideredConfigs.clear();
- // Support old capitalization behavior.
- std::string upperDir = cmSystemTools::UpperCase(this->Name);
- std::string upperFound = cmSystemTools::UpperCase(this->Name);
- upperDir += "_DIR";
- upperFound += "_FOUND";
- // Try to find the config file.
- const char* def = this->Makefile->GetDefinition(this->Variable);
- // Try to load the config file if the directory is known
- bool fileFound = false;
- if (this->UseConfigFiles)
- {
- if(!cmSystemTools::IsOff(def))
- {
- // 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);
- }
- // Search for the config file if it is not already found.
- if(cmSystemTools::IsOff(def) || !fileFound)
- {
- fileFound = this->FindConfig();
- def = this->Makefile->GetDefinition(this->Variable);
- }
- // Sanity check.
- if(fileFound && this->FileFound.empty())
- {
- this->Makefile->IssueMessage(
- cmake::INTERNAL_ERROR, "fileFound is true but FileFound is empty!");
- fileFound = false;
- }
- }
- std::string foundVar = this->Name;
- foundVar += "_FOUND";
- std::string notFoundMessageVar = this->Name;
- notFoundMessageVar += "_NOT_FOUND_MESSAGE";
- std::string notFoundMessage;
- // If the directory for the config file was found, try to read the file.
- bool result = true;
- bool found = false;
- bool configFileSetFOUNDFalse = false;
- if(fileFound)
- {
- if ((this->Makefile->IsDefinitionSet(foundVar))
- && (this->Makefile->IsOn(foundVar) == 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);
- }
- this->Makefile->RemoveDefinition(notFoundMessageVar);
- // Set the version variables before loading the config file.
- // It may override them.
- this->StoreVersionFound();
- // Parse the configuration file.
- if(this->ReadListFile(this->FileFound.c_str(), DoPolicyScope))
- {
- // The package has been found.
- found = true;
- // Check whether the Config file has set Foo_FOUND to FALSE:
- if ((this->Makefile->IsDefinitionSet(foundVar))
- && (this->Makefile->IsOn(foundVar) == false))
- {
- // we get here if the Config file has set Foo_FOUND actively to FALSE
- found = false;
- configFileSetFOUNDFalse = true;
- notFoundMessage = this->Makefile->GetSafeDefinition(
- notFoundMessageVar);
- }
- }
- else
- {
- // The configuration file is invalid.
- result = false;
- }
- }
- if (result && !found && (!this->Quiet || this->Required))
- {
- // The variable is not set.
- cmOStringStream e;
- cmOStringStream aw;
- 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.";
- if (!notFoundMessage.empty())
- {
- e << " Reason given by package: \n" << notFoundMessage << "\n";
- }
- }
- // If there are files in ConsideredConfigs, it means that FooConfig.cmake
- // have been found, but they didn't have appropriate versions.
- else if (this->ConsideredConfigs.size() > 0)
- {
- 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";
- for(std::vector<ConfigFileInfo>::size_type i=0;
- i<this->ConsideredConfigs.size(); i++)
- {
- e << " " << this->ConsideredConfigs[i].filename
- << ", version: " << this->ConsideredConfigs[i].version << "\n";
- }
- }
- else
- {
- std::string requestedVersionString;
- if(!this->Version.empty())
- {
- requestedVersionString = " (requested version ";
- requestedVersionString += this->Version;
- requestedVersionString += ")";
- }
- if (this->UseConfigFiles)
- {
- 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";
- }
- if(this->Configs.size() == 1)
- {
- e << "Could not find a package configuration file named \""
- << this->Configs[0] << "\" provided by package \""
- << this->Name << "\"" << requestedVersionString <<".\n";
- }
- else
- {
- e << "Could not find a package configuration file provided by \""
- << this->Name << "\"" << requestedVersionString
- << " with any of the following names:\n";
- 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.";
- }
- else // if(!this->UseFindModules && !this->UseConfigFiles)
- {
- e << "No \"Find" << this->Name << ".cmake\" found in "
- << "CMAKE_MODULE_PATH.";
- 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";
- }
- }
- this->Makefile->IssueMessage(
- this->Required? cmake::FATAL_ERROR : cmake::WARNING, e.str());
- if (this->Required)
- {
- cmSystemTools::SetFatalErrorOccured();
- }
- if (!aw.str().empty())
- {
- this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,aw.str());
- }
- }
- // Set a variable marking whether the package was found.
- this->Makefile->AddDefinition(foundVar, found? "1":"0");
- // Set a variable naming the configuration file that was found.
- std::string fileVar = this->Name;
- fileVar += "_CONFIG";
- if(found)
- {
- this->Makefile->AddDefinition(fileVar, this->FileFound.c_str());
- }
- else
- {
- this->Makefile->RemoveDefinition(fileVar);
- }
- std::string consideredConfigsVar = this->Name;
- consideredConfigsVar += "_CONSIDERED_CONFIGS";
- std::string consideredVersionsVar = this->Name;
- consideredVersionsVar += "_CONSIDERED_VERSIONS";
- std::string consideredConfigFiles;
- std::string consideredVersions;
- const char* sep = "";
- for(std::vector<ConfigFileInfo>::size_type i=0;
- i<this->ConsideredConfigs.size(); i++)
- {
- consideredConfigFiles += sep;
- consideredVersions += sep;
- consideredConfigFiles += this->ConsideredConfigs[i].filename;
- consideredVersions += this->ConsideredConfigs[i].version;
- sep = ";";
- }
- this->Makefile->AddDefinition(consideredConfigsVar,
- consideredConfigFiles.c_str());
- this->Makefile->AddDefinition(consideredVersionsVar,
- consideredVersions.c_str());
- return result;
- }
- //----------------------------------------------------------------------------
- bool cmFindPackageCommand::FindConfig()
- {
- // Compute the set of search prefixes.
- this->ComputePrefixes();
- // Look for the project's configuration file.
- bool found = false;
- // Search for frameworks.
- if(!found && (this->SearchFrameworkFirst || this->SearchFrameworkOnly))
- {
- found = this->FindFrameworkConfig();
- }
- // Search for apps.
- if(!found && (this->SearchAppBundleFirst || this->SearchAppBundleOnly))
- {
- found = this->FindAppBundleConfig();
- }
- // Search prefixes.
- if(!found && !(this->SearchFrameworkOnly || this->SearchAppBundleOnly))
- {
- found = this->FindPrefixedConfig();
- }
- // Search for frameworks.
- if(!found && this->SearchFrameworkLast)
- {
- found = this->FindFrameworkConfig();
- }
- // Search for apps.
- if(!found && this->SearchAppBundleLast)
- {
- found = this->FindAppBundleConfig();
- }
- // Store the entry in the cache so it can be set by the user.
- 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 += ".";
- // We force the value since we do not get here if it was already set.
- this->Makefile->AddCacheDefinition(this->Variable,
- init.c_str(), help.c_str(),
- cmCacheManager::PATH, true);
- return found;
- }
- //----------------------------------------------------------------------------
- bool cmFindPackageCommand::FindPrefixedConfig()
- {
- std::vector<std::string>& prefixes = this->SearchPaths;
- for(std::vector<std::string>::const_iterator pi = prefixes.begin();
- pi != prefixes.end(); ++pi)
- {
- if(this->SearchPrefix(*pi))
- {
- return true;
- }
- }
- return false;
- }
- //----------------------------------------------------------------------------
- bool cmFindPackageCommand::FindFrameworkConfig()
- {
- std::vector<std::string>& prefixes = this->SearchPaths;
- for(std::vector<std::string>::const_iterator i = prefixes.begin();
- i != prefixes.end(); ++i)
- {
- if(this->SearchFrameworkPrefix(*i))
- {
- return true;
- }
- }
- return false;
- }
- //----------------------------------------------------------------------------
- bool cmFindPackageCommand::FindAppBundleConfig()
- {
- std::vector<std::string>& prefixes = this->SearchPaths;
- for(std::vector<std::string>::const_iterator i = prefixes.begin();
- i != prefixes.end(); ++i)
- {
- if(this->SearchAppBundlePrefix(*i))
- {
- return true;
- }
- }
- return false;
- }
- //----------------------------------------------------------------------------
- bool cmFindPackageCommand::ReadListFile(const char* f, PolicyScopeRule psr)
- {
- if(this->Makefile->ReadListFile(this->Makefile->GetCurrentListFile(), f, 0,
- !this->PolicyScope || psr == NoPolicyScope))
- {
- return true;
- }
- std::string e = "Error reading CMake code from \"";
- e += f;
- e += "\".";
- this->SetError(e);
- return false;
- }
- //----------------------------------------------------------------------------
- void cmFindPackageCommand::AppendToFoundProperty(bool found)
- {
- std::vector<std::string> foundContents;
- const char *foundProp =
- this->Makefile->GetCMakeInstance()->GetProperty("PACKAGES_FOUND");
- if (foundProp && *foundProp)
- {
- std::string tmp = foundProp;
- cmSystemTools::ExpandListArgument(tmp, foundContents, false);
- std::vector<std::string>::iterator nameIt = std::find(
- foundContents.begin(), foundContents.end(), this->Name);
- if(nameIt != foundContents.end())
- {
- foundContents.erase(nameIt);
- }
- }
- 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())
- {
- notFoundContents.erase(nameIt);
- }
- }
- if(found)
- {
- foundContents.push_back(this->Name);
- }
- else
- {
- 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 = ";";
- }
- this->Makefile->GetCMakeInstance()->SetProperty("PACKAGES_NOT_FOUND",
- tmp.c_str());
- }
- //----------------------------------------------------------------------------
- void cmFindPackageCommand::AppendSuccessInformation()
- {
- {
- std::string transitivePropName = "_CMAKE_";
- transitivePropName += this->Name + "_TRANSITIVE_DEPENDENCY";
- this->Makefile->GetCMakeInstance()
- ->SetProperty(transitivePropName, "False");
- }
- std::string found = this->Name;
- found += "_FOUND";
- std::string upperFound = cmSystemTools::UpperCase(found);
- const char* upperResult = this->Makefile->GetDefinition(upperFound);
- const char* result = this->Makefile->GetDefinition(found);
- bool packageFound = ((cmSystemTools::IsOn(result))
- || (cmSystemTools::IsOn(upperResult)));
- this->AppendToFoundProperty(packageFound);
- // 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,
- this->Quiet ? "TRUE" : "FALSE");
- // 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,
- versionInfo.c_str());
- if (this->Required)
- {
- std::string requiredInfoPropName = "_CMAKE_";
- requiredInfoPropName += this->Name;
- requiredInfoPropName += "_TYPE";
- this->Makefile->GetCMakeInstance()->SetProperty(
- requiredInfoPropName, "REQUIRED");
- }
- // Restore original state of "_FIND_" variables we set.
- this->RestoreFindDefinitions();
- }
- //----------------------------------------------------------------------------
- void cmFindPackageCommand::ComputePrefixes()
- {
- this->AddPrefixesCMakeVariable();
- this->AddPrefixesCMakeEnvironment();
- this->AddPrefixesUserHints();
- this->AddPrefixesSystemEnvironment();
- this->AddPrefixesUserRegistry();
- this->AddPrefixesBuilds();
- this->AddPrefixesCMakeSystemVariable();
- this->AddPrefixesSystemRegistry();
- this->AddPrefixesUserGuess();
- this->ComputeFinalPaths();
- }
- //----------------------------------------------------------------------------
- void cmFindPackageCommand::AddPrefixesCMakeEnvironment()
- {
- 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);
- this->AddPathInternal(env, EnvPath);
- }
- this->AddEnvPath("CMAKE_PREFIX_PATH");
- this->AddEnvPath("CMAKE_FRAMEWORK_PATH");
- this->AddEnvPath("CMAKE_APPBUNDLE_PATH");
- }
- }
- //----------------------------------------------------------------------------
- void cmFindPackageCommand::AddPrefixesCMakeVariable()
- {
- if(!this->NoCMakePath && !this->NoDefaultPath)
- {
- this->AddCMakePath("CMAKE_PREFIX_PATH");
- this->AddCMakePath("CMAKE_FRAMEWORK_PATH");
- this->AddCMakePath("CMAKE_APPBUNDLE_PATH");
- }
- }
- //----------------------------------------------------------------------------
- void cmFindPackageCommand::AddPrefixesSystemEnvironment()
- {
- if(!this->NoSystemEnvironmentPath && !this->NoDefaultPath)
- {
- // Use the system search path to generate prefixes.
- // Relative paths are interpreted with respect to the current
- // working directory.
- std::vector<std::string> tmp;
- cmSystemTools::GetPath(tmp);
- for(std::vector<std::string>::iterator i = tmp.begin();
- i != tmp.end(); ++i)
- {
- std::string const& d = *i;
- // If the path is a PREFIX/bin case then add its parent instead.
- if((cmHasLiteralSuffix(d, "/bin")) ||
- (cmHasLiteralSuffix(d, "/sbin")))
- {
- this->AddPathInternal(cmSystemTools::GetFilenamePath(d), EnvPath);
- }
- else
- {
- this->AddPathInternal(d, EnvPath);
- }
- }
- }
- }
- //----------------------------------------------------------------------------
- void cmFindPackageCommand::AddPrefixesUserRegistry()
- {
- if(this->NoUserRegistry || this->NoDefaultPath)
- {
- return;
- }
- #if defined(_WIN32) && !defined(__CYGWIN__)
- this->LoadPackageRegistryWinUser();
- #elif defined(__HAIKU__)
- char dir[B_PATH_NAME_LENGTH];
- if (find_directory(B_USER_SETTINGS_DIRECTORY, -1, false, dir, sizeof(dir)) ==
- B_OK)
- {
- std::string fname = dir;
- fname += "/cmake/packages/";
- fname += Name;
- this->LoadPackageRegistryDir(fname);
- }
- #else
- if(const char* home = cmSystemTools::GetEnv("HOME"))
- {
- std::string dir = home;
- dir += "/.cmake/packages/";
- dir += this->Name;
- this->LoadPackageRegistryDir(dir);
- }
- #endif
- }
- //----------------------------------------------------------------------------
- void cmFindPackageCommand::AddPrefixesSystemRegistry()
- {
- if(this->NoSystemRegistry || this->NoDefaultPath)
- {
- return;
- }
- #if defined(_WIN32) && !defined(__CYGWIN__)
- this->LoadPackageRegistryWinSystem();
- #endif
- }
- #if defined(_WIN32) && !defined(__CYGWIN__)
- # include <windows.h>
- # undef GetCurrentDirectory
- // 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
- //----------------------------------------------------------------------------
- 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)
- {
- std::wstring key = L"Software\\Kitware\\CMake\\Packages\\";
- key += cmsys::Encoding::ToWide(this->Name);
- std::set<std::wstring> bad;
- HKEY hKey;
- if(RegOpenKeyExW(user? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, key.c_str(),
- 0, KEY_QUERY_VALUE|view, &hKey) == ERROR_SUCCESS)
- {
- DWORD valueType = REG_NONE;
- wchar_t name[16383]; // RegEnumValue docs limit name to 32767 _bytes_
- std::vector<wchar_t> data(512);
- bool done = false;
- DWORD index = 0;
- while(!done)
- {
- DWORD nameSize = static_cast<DWORD>(sizeof(name));
- DWORD dataSize = static_cast<DWORD>(data.size()*sizeof(data[0]));
- switch(RegEnumValueW(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(cmsys::Encoding::ToNarrow(&data[0]));
- if(!this->CheckPackageRegistryEntry(ss))
- {
- // The entry is invalid.
- bad.insert(name);
- }
- }
- break;
- case ERROR_MORE_DATA:
- data.resize((dataSize+sizeof(data[0])-1)/sizeof(data[0]));
- break;
- case ERROR_NO_MORE_ITEMS: default: done = true; break;
- }
- }
- RegCloseKey(hKey);
- }
- // Remove bad values if possible.
- if(user && !bad.empty() &&
- RegOpenKeyExW(HKEY_CURRENT_USER, key.c_str(),
- 0, KEY_SET_VALUE|view, &hKey) == ERROR_SUCCESS)
- {
- for(std::set<std::wstring>::const_iterator vi = bad.begin();
- vi != bad.end(); ++vi)
- {
- RegDeleteValueW(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.
- cmsys::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;
- }
- }
- //----------------------------------------------------------------------------
- void cmFindPackageCommand::AddPrefixesBuilds()
- {
- if(!this->NoBuilds && !this->NoDefaultPath)
- {
- // It is likely that CMake will have recently built the project.
- for(int i=0; i <= 10; ++i)
- {
- cmOStringStream r;
- r <<
- "[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\"
- "Settings\\StartPath;WhereBuild" << i << "]";
- std::string f = r.str();
- cmSystemTools::ExpandRegistryValues(f);
- cmSystemTools::ConvertToUnixSlashes(f);
- if(cmSystemTools::FileIsFullPath(f.c_str()) &&
- cmSystemTools::FileIsDirectory(f.c_str()))
- {
- this->AddPathInternal(f, FullPath);
- }
- }
- }
- }
- //----------------------------------------------------------------------------
- void cmFindPackageCommand::AddPrefixesCMakeSystemVariable()
- {
- if(!this->NoCMakeSystemPath && !this->NoDefaultPath)
- {
- this->AddCMakePath("CMAKE_SYSTEM_PREFIX_PATH");
- this->AddCMakePath("CMAKE_SYSTEM_FRAMEWORK_PATH");
- this->AddCMakePath("CMAKE_SYSTEM_APPBUNDLE_PATH");
- }
- }
- //----------------------------------------------------------------------------
- void cmFindPackageCommand::AddPrefixesUserGuess()
- {
- // 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);
- }
- //----------------------------------------------------------------------------
- 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))
- {
- // Remove duplicate slashes.
- cmSystemTools::ConvertToUnixSlashes(this->FileFound);
- return true;
- }
- return false;
- }
- //----------------------------------------------------------------------------
- bool cmFindPackageCommand::FindConfigFile(std::string const& dir,
- std::string& file)
- {
- if (this->IgnoredPaths.count(dir))
- {
- return false;
- }
- 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());
- }
- if(cmSystemTools::FileExists(file.c_str(), true) &&
- this->CheckVersion(file))
- {
- return true;
- }
- }
- return false;
- }
- //----------------------------------------------------------------------------
- bool cmFindPackageCommand::CheckVersion(std::string const& config_file)
- {
- bool result = false; // by default, assume the version is not ok.
- bool haveResult = false;
- std::string version = "unknown";
- // Get the filename without the .cmake extension.
- std::string::size_type pos = config_file.rfind('.');
- std::string version_file_base = config_file.substr(0, pos);
- // Look for foo-config-version.cmake
- std::string version_file = version_file_base;
- version_file += "-version.cmake";
- if ((haveResult == false)
- && (cmSystemTools::FileExists(version_file.c_str(), true)))
- {
- result = this->CheckVersionFile(version_file, version);
- haveResult = true;
- }
- // Look for fooConfigVersion.cmake
- version_file = version_file_base;
- version_file += "Version.cmake";
- if ((haveResult == false)
- && (cmSystemTools::FileExists(version_file.c_str(), true)))
- {
- result = this->CheckVersionFile(version_file, version);
- haveResult = true;
- }
- // If no version was requested a versionless package is acceptable.
- if ((haveResult == false) && (this->Version.empty()))
- {
- result = true;
- haveResult = true;
- }
- ConfigFileInfo configFileInfo;
- configFileInfo.filename = config_file;
- configFileInfo.version = version;
- this->ConsideredConfigs.push_back(configFileInfo);
- return result;
- }
- //----------------------------------------------------------------------------
- bool cmFindPackageCommand::CheckVersionFile(std::string const& version_file,
- std::string& result_version)
- {
- // The version file will be loaded in an isolated scope.
- cmMakefile::ScopePushPop varScope(this->Makefile);
- cmMakefile::PolicyPushPop polScope(this->Makefile);
- static_cast<void>(varScope);
- static_cast<void>(polScope);
- // Clear the output variables.
- this->Makefile->RemoveDefinition("PACKAGE_VERSION");
- this->Makefile->RemoveDefinition("PACKAGE_VERSION_UNSUITABLE");
- 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());
- 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);
- // Load the version check file. Pass NoPolicyScope because we do
- // our own policy push/pop independent of CMP0011.
- bool suitable = false;
- if(this->ReadListFile(version_file.c_str(), NoPolicyScope))
- {
- // Check the output variables.
- bool okay = this->Makefile->IsOn("PACKAGE_VERSION_EXACT");
- bool unsuitable = this->Makefile->IsOn("PACKAGE_VERSION_UNSUITABLE");
- if(!okay && !this->VersionExact)
- {
- okay = this->Makefile->IsOn("PACKAGE_VERSION_COMPATIBLE");
- }
- // The package is suitable if the version is okay and not
- // explicitly unsuitable.
- suitable = !unsuitable && (okay || this->Version.empty());
- if(suitable)
- {
- // 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;
- unsigned int parsed_tweak;
- this->VersionFoundCount =
- sscanf(this->VersionFound.c_str(), "%u.%u.%u.%u",
- &parsed_major, &parsed_minor,
- &parsed_patch, &parsed_tweak);
- switch(this->VersionFoundCount)
- {
- case 4: this->VersionFoundTweak = parsed_tweak; // no break!
- 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;
- }
- }
- }
- result_version = this->Makefile->GetSafeDefinition("PACKAGE_VERSION");
- if (result_version.empty())
- {
- result_version = "unknown";
- }
- // Succeed if the version is suitable.
- return suitable;
- }
- //----------------------------------------------------------------------------
- void cmFindPackageCommand::StoreVersionFound()
- {
- // Store the whole version string.
- std::string ver = this->Name;
- ver += "_VERSION";
- if(this->VersionFound.empty())
- {
- this->Makefile->RemoveDefinition(ver);
- }
- else
- {
- this->Makefile->AddDefinition(ver, this->VersionFound.c_str());
- }
- // Store the version components.
- char buf[64];
- sprintf(buf, "%u", this->VersionFoundMajor);
- this->Makefile->AddDefinition(ver+"_MAJOR", buf);
- sprintf(buf, "%u", this->VersionFoundMinor);
- this->Makefile->AddDefinition(ver+"_MINOR", buf);
- sprintf(buf, "%u", this->VersionFoundPatch);
- this->Makefile->AddDefinition(ver+"_PATCH", buf);
- sprintf(buf, "%u", this->VersionFoundTweak);
- this->Makefile->AddDefinition(ver+"_TWEAK", buf);
- sprintf(buf, "%u", this->VersionFoundCount);
- this->Makefile->AddDefinition(ver+"_COUNT", buf);
- }
- //----------------------------------------------------------------------------
- #include <cmsys/Glob.hxx>
- #include <cmsys/String.h>
- #include <cmsys/auto_ptr.hxx>
- class cmFileList;
- class cmFileListGeneratorBase
- {
- public:
- virtual ~cmFileListGeneratorBase() {}
- 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) {}
- virtual ~cmFileList() {}
- 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:
- cmFileListGeneratorEnumerate(std::vector<std::string> const& v):
- cmFileListGeneratorBase(), Vector(v) {}
- cmFileListGeneratorEnumerate(cmFileListGeneratorEnumerate const& r):
- cmFileListGeneratorBase(), Vector(r.Vector) {}
- private:
- std::vector<std::string> const& Vector;
- 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) {}
- cmFileListGeneratorCaseInsensitive(
- cmFileListGeneratorCaseInsensitive const& r):
- 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;
- }
- }
- // 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;
- }
- }
- // Construct list of common install locations (lib and share).
- std::vector<std::string> common;
- if(!this->LibraryArchitecture.empty())
- {
- common.push_back("lib/"+this->LibraryArchitecture);
- }
- if(this->UseLib64Paths)
- {
- common.push_back("lib64");
- }
- common.push_back("lib");
- common.push_back("share");
- // PREFIX/(lib/ARCH|lib|share)/cmake/(Foo|foo|FOO).*/
- {
- cmFindPackageFileList lister(this);
- lister
- / cmFileListGeneratorFixed(prefix)
- / cmFileListGeneratorEnumerate(common)
- / cmFileListGeneratorFixed("cmake")
- / cmFileListGeneratorProject(this->Names);
- if(lister.Search())
- {
- return true;
- }
- }
- // PREFIX/(lib/ARCH|lib|share)/(Foo|foo|FOO).*/
- {
- cmFindPackageFileList lister(this);
- lister
- / cmFileListGeneratorFixed(prefix)
- / cmFileListGeneratorEnumerate(common)
- / cmFileListGeneratorProject(this->Names);
- if(lister.Search())
- {
- return true;
- }
- }
- // PREFIX/(lib/ARCH|lib|share)/(Foo|foo|FOO).*/(cmake|CMake)/
- {
- cmFindPackageFileList lister(this);
- lister
- / cmFileListGeneratorFixed(prefix)
- / cmFileListGeneratorEnumerate(common)
- / 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.
|