ENH: change the search path order (if several Tcl/Tk are installed, the "current...
[cmake.git] / Source / cmFindLibraryCommand.cxx
blob9ba2e3733c7d34388adec0bfca1945892f183142
1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmFindLibraryCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2002-06-14 14:37:59 $
7 Version: $Revision: 1.28 $
9 Copyright (c) 2002 Insight Consortium. All rights reserved.
10 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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 "cmFindLibraryCommand.h"
18 #include "cmCacheManager.h"
20 // cmFindLibraryCommand
21 bool cmFindLibraryCommand::InitialPass(std::vector<std::string> const& argsIn)
23 if(argsIn.size() < 2)
25 this->SetError("called with incorrect number of arguments");
26 return false;
28 std::string helpString;
29 size_t size = argsIn.size();
30 std::vector<std::string> argst;
31 for(unsigned int j = 0; j < size; ++j)
33 if(argsIn[j] != "DOC")
35 argst.push_back(argsIn[j]);
37 else
39 if(j+1 < size)
41 helpString = argsIn[j+1];
43 break;
46 std::vector<std::string> args;
47 cmSystemTools::ExpandListArguments(argst, args);
49 std::vector<std::string> path;
50 std::vector<std::string> names;
51 bool foundName = false;
52 bool foundPath = false;
53 bool doingNames = true;
54 for (unsigned int j = 1; j < args.size(); ++j)
56 if(args[j] == "NAMES")
58 doingNames = true;
59 foundName = true;
61 else if (args[j] == "PATHS")
63 doingNames = false;
64 foundPath = true;
66 else
68 if(doingNames)
70 names.push_back(args[j]);
72 else
74 // Glob the entry in case of wildcards.
75 cmSystemTools::GlobDirs(args[j].c_str(), path);
79 // old style name path1 path2 path3
80 if(!foundPath && !foundName)
82 names.clear();
83 path.clear();
84 names.push_back(args[1]);
85 // add any user specified paths
86 for (unsigned int j = 2; j < args.size(); j++)
88 // expand variables
89 std::string exp = args[j];
90 cmSystemTools::ExpandRegistryValues(exp);
92 // Glob the entry in case of wildcards.
93 cmSystemTools::GlobDirs(exp.c_str(), path);
96 if(helpString.size() == 0)
98 helpString = "Where can ";
99 if (names.size() == 0)
101 helpString += "the (unknown) library be found";
103 else if (names.size() == 1)
105 helpString += "the " + names[0] + " library be found";
107 else
109 helpString += "one of the " + names[0];
110 for (unsigned int j = 1; j < names.size() - 1; ++j)
112 helpString += ", " + names[j];
114 helpString += " or " + names[names.size() - 1] + " libraries be found";
118 const char* cacheValue
119 = m_Makefile->GetDefinition(args[0].c_str());
120 if(cacheValue && strcmp(cacheValue, "NOTFOUND"))
122 return true;
125 std::string library;
126 for(std::vector<std::string>::iterator i = names.begin();
127 i != names.end() ; ++i)
129 library = cmSystemTools::FindLibrary(i->c_str(),
130 path,
131 m_Makefile);
132 if(library != "")
134 m_Makefile->AddCacheDefinition(args[0].c_str(),
135 library.c_str(),
136 helpString.c_str(),
137 cmCacheManager::FILEPATH);
138 return true;
141 m_Makefile->AddCacheDefinition(args[0].c_str(),
142 "NOTFOUND",
143 helpString.c_str(),
144 cmCacheManager::FILEPATH);
145 return true;